diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-08-19 13:51:40 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-08-19 14:33:08 -0400 |
| commit | 154436ab88925540f86f43c0ac885c080949aa9b (patch) | |
| tree | 43a22f26286428f0d165fc1ff801cd0cb87092c6 /editor | |
| parent | ebcae77b137a759c453b89a774ece5a755078a38 (diff) | |
pke: ui box type button image
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 173 |
1 files changed, 165 insertions, 8 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 729efcf..42b1c75 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -25,6 +25,7 @@ #include "thread-pool.hpp" #include "vendor-glm-include.hpp" #include "vendor-imgui-ext.hpp" +#include "vendor-stb-image-include.h" #include "vendor-tinyfiledialogs.h" #include "window.hpp" #include "pk.h" @@ -145,6 +146,12 @@ void PkeEditor_Tick(double delta) { if (shouldOpenNewScene) { shouldOpenNewScene = false; if (editor_mstr.active_scene != nullptr) { + // TODO move most of this to the level + pke_ui_box_count_T box_count; + pke_ui_box **root_boxes = pke_ui_get_root_boxes(&box_count); + for (pke_ui_box_count_T i = 0; i < box_count; ++i) { + ECS_MarkForRemoval(root_boxes[i]); + } pke_scene_remove(editor_mstr.active_scene->scene_handle); } ActiveCamera = &NullCamera; @@ -159,6 +166,12 @@ void PkeEditor_Tick(double delta) { shouldOpenLoadSceneDialog = false; auto *task = pk_new<std::packaged_task<void()>>(); new (task) std::packaged_task<void()>( [] { + // TODO move most of this to the level + pke_ui_box_count_T box_count; + pke_ui_box **root_boxes = pke_ui_get_root_boxes(&box_count); + for (pke_ui_box_count_T i = 0; i < box_count; ++i) { + ECS_MarkForRemoval(root_boxes[i]); + } const char * patterns[1] = {"*.pstf"}; char *selectedScene = tinyfd_openFileDialog(nullptr, "cafebabe.pstf", 1, patterns, "Pke Scene Text File", 0); if (editor_mstr.active_scene != nullptr) { @@ -212,6 +225,12 @@ void PkeEditor_Tick(double delta) { shouldRebuildProjectDir = true; } if (editor_mstr.target_scene_path.val != nullptr) { + // TODO move most of this to the level + pke_ui_box_count_T box_count; + pke_ui_box **root_boxes = pke_ui_get_root_boxes(&box_count); + for (pke_ui_box_count_T i = 0; i < box_count; ++i) { + ECS_MarkForRemoval(root_boxes[i]); + } if (editor_mstr.active_scene != nullptr) { pke_scene_remove(editor_mstr.active_scene->scene_handle); } @@ -559,12 +578,13 @@ void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { } void RecordImGuiModalCreateAsset() { + static char assetPath[256]; + static char assetKeyBuffer[AssetKeyLength + 1]; + static AssetType type; + static union pke_asset_details type_data; + assetPath[255] = '\0'; + assetKeyBuffer[AssetKeyLength] = '\0'; if (ImGui::BeginPopupModal("CreateAsset", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - static char assetPath[256]; - static char assetKeyBuffer[AssetKeyLength + 1]; - static AssetType type; - assetPath[255] = '\0'; - assetKeyBuffer[AssetKeyLength] = '\0'; ImGui::InputText("Asset Key", assetKeyBuffer, AssetKeyLength+1); @@ -604,14 +624,25 @@ void RecordImGuiModalCreateAsset() { bool shouldClose = false; + ImGui::BeginDisabled(assetPath[0] == '\0' || type == PKE_ASSET_TYPE_UNSET); if (ImGui::Button("Create")) { AssetKey assetKey = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; memcpy(assetKey, assetKeyBuffer, PK_MIN(AssetKeyLength, strlen(assetKeyBuffer))); - AM_Register(assetKey, type, assetPath); + + // TODO details for other types + if (type == PKE_ASSET_TYPE_TEXTURE) { + int x,y,c; + stbi_info(assetPath, &x, &y, &c); + type_data.texture.width = x; + type_data.texture.height = y; + } + + AM_Register(assetKey, type, assetPath, &type_data); shouldRebuildAssetList = true; pk_arr_clear(&assetEntries); shouldClose = true; } + ImGui::EndDisabled(); ImGui::SameLine(); if (ImGui::Button("Cancel")) { shouldClose = true; @@ -622,6 +653,7 @@ void RecordImGuiModalCreateAsset() { assetTypeMask = 0U; assetKeyBuffer[0] = '\0'; assetPath[0] = '\0'; + memset(&type_data, 0, sizeof(union pke_asset_details)); ImGui::CloseCurrentPopup(); } @@ -1226,20 +1258,83 @@ void RecordImGuiUITree_inner(pke_ui_box *box) { } } void RecordImGuiUITree() { + pke_ui_box *box; + static bool is_creating_new_box = false; + static bool is_child = false; + PKE_UI_BOX_TYPE type = PKE_UI_BOX_TYPE(-1); if (!ImGui::Begin("pke_ui_tree")) { ImGui::End(); return; } + + ImGui::BeginDisabled(selected_ui_box != nullptr); + if (ImGui::Button("Create Root Box")) { + is_creating_new_box = true; + is_child = false; + } + ImGui::EndDisabled(); + ImGui::SameLine(); + ImGui::BeginDisabled(selected_ui_box == nullptr); + if (ImGui::Button("Create Child Box")) { + is_creating_new_box = true; + is_child = true; + } + ImGui::EndDisabled(); + + if (is_creating_new_box) { + ImGui::Text("Select Type:"); + ImGui::Separator(); + if (ImGui::Button("Standard")) { + type = PKE_UI_BOX_TYPE_STANDARD; + } + if (ImGui::Button("Text")) { + type = PKE_UI_BOX_TYPE_TEXT; + } + if (ImGui::Button("Button: Image")) { + type = PKE_UI_BOX_TYPE_BUTTON_IMAGE; + } + if (type != PKE_UI_BOX_TYPE(-1)) { + if (is_child && selected_ui_box != nullptr) { + box = pke_ui_box_new_child(selected_ui_box, type); + } else { + box = pke_ui_box_new_root(type); + } + box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC; + box->flags |= PKE_UI_BOX_FLAG_CENTER_BOTH; + box->max_size = glm::vec2(.6, .6); + selected_ui_box = box; + is_creating_new_box = false; + is_child = false; + type = PKE_UI_BOX_TYPE(-1); + } + } + pke_ui_box_count_T count; pke_ui_box ** root_boxes = pke_ui_get_root_boxes(&count); for (int i = 0; i < count; ++i) { - pke_ui_box *box = root_boxes[i]; + box = root_boxes[i]; RecordImGuiUITree_inner(box); } // if (ImGui::Selectable( ImGui::End(); } void RecordImGuiUIEdit() { + static AssetPickerSearchStruct apss_img_default { + .source = {"cet_txr"}, + .safeKey = {""}, + .type = PKE_ASSET_TYPE_TEXTURE, + }; + static AssetPickerSearchStruct apss_img_hovered { + .source = {"cet_txr"}, + .safeKey = {""}, + .type = PKE_ASSET_TYPE_TEXTURE, + }; + static AssetPickerSearchStruct apss_img_pressed { + .source = {"cet_txr"}, + .safeKey = {""}, + .type = PKE_ASSET_TYPE_TEXTURE, + }; + static uint8_t helper_selected_index = 0; const ImGuiInputTextFlags text_flags = ImGuiInputTextFlags_AllowTabInput; bool changed, changed_sub; if (!ImGui::Begin("pke_ui_edit")) { @@ -1335,6 +1430,67 @@ void RecordImGuiUIEdit() { } changed |= changed_sub; } + if (selected_ui_box->type == PKE_UI_BOX_TYPE_BUTTON_IMAGE) { + assert(selected_ui_box->type_data != nullptr); + ImGui::Text("Type: Button Image"); + ImGui::Separator(); + + ImGui::Text("Image Default: %.16s", selected_ui_box->type_data->button_image.img_key_default); + ImGui::SameLine(); + if (ImGui::Button("Change Default")) { + helper_selected_index = 1u << 0; + ImGui::OpenPopup(apss_img_default.source); + } + + ImGui::Text("Image Hovered: %.16s", selected_ui_box->type_data->button_image.img_key_hovered); + ImGui::SameLine(); + if (ImGui::Button("Change Hovered")) { + helper_selected_index = 1u << 1; + ImGui::OpenPopup(apss_img_hovered.source); + } + + ImGui::Text("Image Pressed: %.16s", selected_ui_box->type_data->button_image.img_key_pressed); + ImGui::SameLine(); + if (ImGui::Button("Change Pressed")) { + helper_selected_index = 1u << 2; + ImGui::OpenPopup(apss_img_pressed.source); + } + + if (helper_selected_index == 1u << 0) { + RecordImGui_AssetPicker(apss_img_default); + } + if (helper_selected_index == 1u << 1) { + RecordImGui_AssetPicker(apss_img_hovered); + } + if (helper_selected_index == 1u << 2) { + RecordImGui_AssetPicker(apss_img_pressed); + } + + if (apss_img_default.selectedItem > 0) { + changed_sub = true; + memcpy(selected_ui_box->type_data->button_image.img_key_default, apss_img_default.safeKey, AssetKeyLength); + apss_img_default.selectedItem = -1; + } + + if (apss_img_hovered.selectedItem > 0) { + changed_sub = true; + memcpy(selected_ui_box->type_data->button_image.img_key_hovered, apss_img_hovered.safeKey, AssetKeyLength); + apss_img_hovered.selectedItem = -1; + } + + if (apss_img_pressed.selectedItem > 0) { + changed_sub = true; + memcpy(selected_ui_box->type_data->button_image.img_key_pressed, apss_img_pressed.safeKey, AssetKeyLength); + apss_img_pressed.selectedItem = -1; + } + + if (changed_sub) { + helper_selected_index = 0; + pke_ui_box_update_textures(selected_ui_box); + } + + changed |= changed_sub; + } if (changed) { pke_ui_force_recalc(); @@ -1809,7 +1965,7 @@ void RecordImGuiSceneBrowser() { } void RecordImGuiSceneEditor() { - if (!ImGui::Begin("SceneEditorEntityTypes", &pkeSettings.editorSettings.isShowingSceneEditor)) { + if (!ImGui::Begin("SceneEditor", &pkeSettings.editorSettings.isShowingSceneEditor)) { ImGui::End(); return; } @@ -1827,6 +1983,7 @@ void RecordImGuiSceneEditor() { } if (ImGui::Button("Clear Selection")) { selectedEntity = nullptr; + selected_ui_box = nullptr; } ImGui::Spacing(); |
