Skip to content

Commit

Permalink
Added tooltips and hideInInspector option to NIDL and inspectors
Browse files Browse the repository at this point in the history
  • Loading branch information
fLindahl committed Nov 17, 2024
1 parent 51d1e6c commit 1e7466e
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 43 deletions.
23 changes: 12 additions & 11 deletions code/addons/audiofeature/components/audiofeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,57 @@
"clipResource": {
"type": "resource",
"default": "audio:system/placeholder.wav",
"desc": "The audio clip to load upon activation"
"description": "The audio clip to load upon activation"
},
"clipId": {
"type": "uint",
"default": -1,
"desc": "The Audio::ClipId for this emitter."
"description": "The Audio::ClipId for this emitter.",
"hideInInspector": true
},
"volume": {
"type": "float",
"default": 1.0,
"desc": "Max volume"
"description": "Max volume"
},
"autoplay": {
"type": "bool",
"desc": "Set to true if the emitter should start immediately upon creation"
"description": "Set to true if the emitter should start immediately upon creation"
},
"pan": {
"type": "float",
"default": 0.0,
"desc": "2D pan for non spatialized sounds. (L = -1.0, R = 1.0)"
"description": "2D pan for non spatialized sounds. (L = -1.0, R = 1.0)"
},
"loop": {
"type": "bool",
"desc": "Set to true if the emitter should loop after reaching the end of the clip"
"description": "Set to true if the emitter should loop after reaching the end of the clip"
},
"clock": {
"type": "float",
"default": 0.0,
"desc": "Set this to > 0 if you need to delay the start of sounds so that rapidly launched sounds don't all get clumped to the start of the next outgoing sound buffer."
"description": "Set this to > 0 if you need to delay the start of sounds so that rapidly launched sounds don't all get clumped to the start of the next outgoing sound buffer."
}
},
"SpatialAudioEmission": {
"minDistance": {
"type": "float",
"default": 0.0,
"desc": "Minimum audible distance of the sound"
"description": "Minimum audible distance of the sound"
},
"maxDistance": {
"type": "float",
"default": 10000.0,
"desc": "Maximum audible distance of the sound"
"description": "Maximum audible distance of the sound"
},
"attenuation": {
"type": "AudioFeature::AttenuationModel",
"default": 1,
"desc": "The attenuation model to use"
"description": "The attenuation model to use"
}
},
"ClipInstance": {
"id": "uint"
"id": "uint",
},
"PlayAudioEvent": {},
"AudioListener": {},
Expand Down
18 changes: 12 additions & 6 deletions code/addons/graphicsfeature/components/graphicsfeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"PointLight": {
"graphicsEntityId": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"color": {
"type": "color",
Expand All @@ -34,7 +35,8 @@
"SpotLight": {
"graphicsEntityId": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"color": {
"type": "color",
Expand All @@ -61,7 +63,8 @@
"AreaLight": {
"graphicsEntityId": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"shape": {
"type": "GraphicsFeature::AreaLightShape",
Expand Down Expand Up @@ -90,7 +93,8 @@
},
"graphicsEntityId": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"raytracing": "bool",
"anim": {
Expand All @@ -105,10 +109,12 @@
"Camera": {
"viewHandle": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"localTransform": {
"type": "mat4"
"type": "mat4",
"hideInInspector": true
},
"fieldOfView": {
"type": "float",
Expand Down
3 changes: 2 additions & 1 deletion code/addons/physicsfeature/components/physicsfeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"PhysicsActor": {
"actorId": {
"type": "uint",
"default": -1
"default": -1,
"hideInInspector": true
},
"resource": {
"type": "resource",
Expand Down
12 changes: 12 additions & 0 deletions code/application/basegamefeature/components/orientation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ struct Orientation::Traits
"float",
"float"
};
static constexpr const char* field_descriptions[num_fields] = {
nullptr,
nullptr,
nullptr,
nullptr
};
using field_types = std::tuple<float, float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Orientation, x),
offsetof(Orientation, y),
offsetof(Orientation, z),
offsetof(Orientation, w),
};
static constexpr bool field_hide_in_inspector[num_fields] = {
false,
false,
false,
false
};
/// This is the column that the entity orientation will reside in, in every table.
/// NOTE: This can never be changed, due to assumptions that have been made.
static constexpr uint32_t fixed_column_index = 2;
Expand Down
10 changes: 10 additions & 0 deletions code/application/basegamefeature/components/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ struct Position::Traits
"float",
"float"
};
static constexpr const char* field_descriptions[num_fields] = {
nullptr,
nullptr,
nullptr
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Position, x),
offsetof(Position, y),
offsetof(Position, z)
};
static constexpr bool field_hide_in_inspector[num_fields] = {
false,
false,
false
};
/// This is the column that the entity position will reside in, in every table.
/// NOTE: This can never be changed, due to assumptions that have been made.
static constexpr uint32_t fixed_column_index = 1;
Expand Down
10 changes: 10 additions & 0 deletions code/application/basegamefeature/components/scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ struct Scale::Traits
"float",
"float"
};
static constexpr const char* field_descriptions[num_fields] = {
nullptr,
nullptr,
nullptr
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Scale, x),
offsetof(Scale, y),
offsetof(Scale, z)
};
static constexpr bool field_hide_in_inspector[num_fields] = {
false,
false,
false
};
/// This is the column that the entity scale will reside in, in every table.
/// NOTE: This can never be changed, due to assumptions that have been made.
static constexpr uint32_t fixed_column_index = 3;
Expand Down
20 changes: 20 additions & 0 deletions code/application/basegamefeature/components/velocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ struct Velocity::Traits
"float",
"float"
};
static constexpr const char* field_descriptions[num_fields] = {
nullptr,
nullptr,
nullptr
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Velocity, x),
offsetof(Velocity, y),
offsetof(Velocity, z)
};
static constexpr bool field_hide_in_inspector[num_fields] = {
false,
false,
false
};
};

//------------------------------------------------------------------------------
Expand All @@ -84,12 +94,22 @@ struct AngularVelocity::Traits
"float",
"float"
};
static constexpr const char* field_descriptions[num_fields] = {
nullptr,
nullptr,
nullptr
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(AngularVelocity, x),
offsetof(AngularVelocity, y),
offsetof(AngularVelocity, z)
};
static constexpr bool field_hide_in_inspector[num_fields] = {
false,
false,
false
};
};

} // namespace Game
9 changes: 8 additions & 1 deletion code/application/game/componentinspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ void
ComponentDrawFuncT<Util::StringAtom>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
ImGui::Text(((Util::StringAtom*)data)->Value());
if (((Util::StringAtom*)data)->IsValid())
{
ImGui::Text(((Util::StringAtom*)data)->Value());
}
else
{
ImGui::Text("None");
}
if (ImGui::BeginDragDropTarget())
{
auto payload = ImGui::AcceptDragDropPayload("resource");
Expand Down
56 changes: 36 additions & 20 deletions code/application/game/componentinspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,45 @@ InspectorDrawField(ComponentId component, void* data, bool* commit)
{
if constexpr (i < TYPE::Traits::num_fields)
{
using field_tuple = typename TYPE::Traits::field_types;
using field_type = typename std::tuple_element<i, field_tuple>::type;
Util::String fieldName = TYPE::Traits::field_names[i];
fieldName.CamelCaseToWords();
fieldName.Capitalize();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::Text(fieldName.AsCharPtr());
ImGui::TableSetColumnIndex(1);
ComponentDrawFuncT<field_type>(component, (byte*)data + TYPE::Traits::field_byte_offsets[i], commit);

ImGui::SameLine();
ImGuiStyle const& style = ImGui::GetStyle();
float widthNeeded = ImGui::CalcTextSize(TYPE::Traits::field_typenames[i]).x + style.FramePadding.x * 2.f + style.ItemSpacing.x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - widthNeeded);
ImGui::AlignTextToFramePadding();
ImGui::TextDisabled(TYPE::Traits::field_typenames[i]);

if constexpr (i < TYPE::Traits::num_fields - 1)
if constexpr (TYPE::Traits::field_hide_in_inspector[i])
{
ImGui::TableNextRow();
// Just move to the next field
InspectorDrawField<TYPE, i + 1>(component, data, commit);
}
else
{
using field_tuple = typename TYPE::Traits::field_types;
using field_type = typename std::tuple_element<i, field_tuple>::type;
Util::String fieldName = TYPE::Traits::field_names[i];
fieldName.CamelCaseToWords();
fieldName.Capitalize();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::Text(fieldName.AsCharPtr());
if (TYPE::Traits::field_descriptions[i] != nullptr)
{
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
ImGui::SetTooltip(TYPE::Traits::field_descriptions[i]);
}
}
ImGui::TableSetColumnIndex(1);
ComponentDrawFuncT<field_type>(component, (byte*)data + TYPE::Traits::field_byte_offsets[i], commit);

ImGui::SameLine();
ImGuiStyle const& style = ImGui::GetStyle();
float widthNeeded =
ImGui::CalcTextSize(TYPE::Traits::field_typenames[i]).x + style.FramePadding.x * 2.f + style.ItemSpacing.x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - widthNeeded);
ImGui::AlignTextToFramePadding();
ImGui::TextDisabled(TYPE::Traits::field_typenames[i]);

if constexpr (i < TYPE::Traits::num_fields - 1)
{
ImGui::TableNextRow();
InspectorDrawField<TYPE, i + 1>(component, data, commit);
}
}
}
}

Expand Down
Loading

0 comments on commit 1e7466e

Please sign in to comment.