diff --git a/Nuake/Source/Nuake/UI/WidgetDrawer.h b/Nuake/Source/Nuake/UI/WidgetDrawer.h index 039566f1..a534b0a6 100644 --- a/Nuake/Source/Nuake/UI/WidgetDrawer.h +++ b/Nuake/Source/Nuake/UI/WidgetDrawer.h @@ -14,7 +14,11 @@ namespace Nuake class WidgetDrawer { public: - WidgetDrawer() = default; + WidgetDrawer() + { + RegisterDefaulWidgets(); + } + ~WidgetDrawer() = default; static WidgetDrawer& Get() @@ -23,6 +27,17 @@ namespace Nuake return instance; } + void RegisterDefaulWidgets() + { + auto& drawer = Get(); + drawer.RegisterTypeDrawer(&drawer); + drawer.RegisterTypeDrawer(&drawer); + drawer.RegisterTypeDrawer(&drawer); + drawer.RegisterTypeDrawer(&drawer); + drawer.RegisterTypeDrawer(&drawer); + drawer.RegisterTypeDrawer(&drawer); + } + void DrawFloat(entt::meta_data& type, entt::meta_any& instance) { float stepSize = 1.f; @@ -62,6 +77,172 @@ namespace Nuake } } + void DrawBool(entt::meta_data& type, entt::meta_any& instance) + { + auto prop = type.prop(HashedName::DisplayName); + auto propVal = prop.value(); + const char* displayName = *propVal.try_cast(); + + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = type.get(instance); + bool* boolPtr = fieldVal.try_cast(); + if (boolPtr != nullptr) + { + bool boolProxy = *boolPtr; + std::string controlId = std::string("##") + displayName; + if (ImGui::Checkbox(controlId.c_str(), &boolProxy)) + { + type.set(instance, boolProxy); + } + } + else + { + ImGui::Text("ERR"); + } + } + } + + void DrawString(entt::meta_data& type, entt::meta_any& instance) + { + auto prop = type.prop(HashedName::DisplayName); + auto propVal = prop.value(); + const char* displayName = *propVal.try_cast(); + + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = type.get(instance); + std::string* fieldValPtr = fieldVal.try_cast(); + if (fieldValPtr != nullptr) + { + std::string fieldValProxy = *fieldValPtr; + std::string controlId = std::string("##") + displayName; + ImGui::InputText(controlId.c_str(), &fieldValProxy); + + if (fieldValProxy != *fieldValPtr) + { + type.set(instance, fieldValProxy); + } + } + else + { + ImGui::Text("ERR"); + } + } + } + + void DrawVector2(entt::meta_data& field, entt::meta_any& component) + { + auto prop = field.prop(HashedName::DisplayName); + auto propVal = prop.value(); + const char* displayName = *propVal.try_cast(); + + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = field.get(component); + Vector2* vec2Ptr = fieldVal.try_cast(); + std::string controlId = std::string("##") + displayName; + ImGui::PushID(controlId.c_str()); + + if (ImGuiHelper::DrawVec2(controlId, vec2Ptr, 0.5f, 100.0, 0.01f)) + { + field.set(component, *vec2Ptr); + Engine::GetProject()->IsDirty = true; + } + + ImGui::PopID(); + } + } + + void DrawVector3(entt::meta_data& field, entt::meta_any& component) + { + auto prop = field.prop(HashedName::DisplayName); + auto propVal = prop.value(); + const char* displayName = *propVal.try_cast(); + + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = field.get(component); + Vector3* vec3Ptr = fieldVal.try_cast(); + std::string controlId = std::string("##") + displayName; + ImGui::PushID(controlId.c_str()); + + if (ImGuiHelper::DrawVec3(controlId, vec3Ptr, 0.5f, 100.0, 0.01f)) + { + field.set(component, *vec3Ptr); + Engine::GetProject()->IsDirty = true; + } + + ImGui::PopID(); + } + } + + void DrawDynamicItemList(entt::meta_data& field, entt::meta_any& component) + { + auto propDisplayName = field.prop(HashedName::DisplayName); + const char* displayName = *propDisplayName.value().try_cast(); + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = field.get(component); + auto fieldValPtr = fieldVal.try_cast(); + if (fieldValPtr == nullptr) + { + ImGui::Text("ERR"); + } + + const auto& items = fieldValPtr->items; + const int index = fieldValPtr->index; + + // Check first to see if we are within the bounds + std::string selectedStr = ""; + if (index >= 0 || index < items.size()) + { + selectedStr = items[index]; + } + + std::string controlName = std::string("##") + displayName; + if (ImGui::BeginCombo(controlName.c_str(), selectedStr.c_str())) + { + for (int i = 0; i < items.size(); i++) + { + bool isSelected = (index == i); + std::string name = items[i]; + + if (name.empty()) + { + name = "Empty"; + } + + if (ImGui::Selectable(name.c_str(), isSelected)) + { + field.set(component, i); + } + + if (isSelected) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + } + } + void DrawWidget(entt::meta_data& dataType, entt::meta_any& instance) { entt::id_type dataId = dataType.type().id();