From aa6d8fa6a26e6e89f32e7d3fb0c29afa6766001b Mon Sep 17 00:00:00 2001 From: Kyle Conel Date: Fri, 16 Aug 2024 08:00:31 -0400 Subject: [PATCH] Improved usability of editor --- src/Main.jl | 1 + .../JulGameEditor/Components/SceneViewer.jl | 10 ++- src/editor/JulGameEditor/Editor.jl | 76 +++++++++++-------- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/Main.jl b/src/Main.jl index 4c95f70..763883c 100644 --- a/src/Main.jl +++ b/src/Main.jl @@ -377,6 +377,7 @@ function destroy_entity(this::Main, entity) if this.scene.entities[i] == entity destroy_entity_components(this, entity) deleteat!(this.scene.entities, i) + this.selectedEntity = nothing break end end diff --git a/src/editor/JulGameEditor/Components/SceneViewer.jl b/src/editor/JulGameEditor/Components/SceneViewer.jl index f62f6b2..5a9d40e 100644 --- a/src/editor/JulGameEditor/Components/SceneViewer.jl +++ b/src/editor/JulGameEditor/Components/SceneViewer.jl @@ -69,14 +69,17 @@ function show_scene_window(main, scene_tex_id, scrolling, zoom_level) camPos = main !== nothing ? ImVec2((main.scene.camera.position.x * scale_unit_factor), (main.scene.camera.position.y * scale_unit_factor)) : ImVec2(0, 0) # Context menu - drag_delta = CImGui.GetMouseDragDelta(CImGui.ImGuiMouseButton_Right) - if CImGui.IsMouseReleased(CImGui.ImGuiMouseButton_Right) && drag_delta.x == 0.0 && drag_delta.y == 0.0 + drag_delta_right = CImGui.GetMouseDragDelta(CImGui.ImGuiMouseButton_Right) + if CImGui.IsMouseReleased(CImGui.ImGuiMouseButton_Right) && drag_delta_right.x == 0.0 && drag_delta_right.y == 0.0 CImGui.OpenPopupOnItemClick("context") end # if left click - if CImGui.IsMouseClicked(CImGui.ImGuiMouseButton_Left) && is_hovered + drag_delta_left = CImGui.GetMouseDragDelta(CImGui.ImGuiMouseButton_Left) + if CImGui.IsMouseReleased(CImGui.ImGuiMouseButton_Left) && is_hovered && drag_delta_left.x == 0.0 && drag_delta_left.y == 0.0 handle_mouse_click(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_adjusted) end + if CImGui.IsMouseClicked(CImGui.ImGuiMouseButton_Left) && is_hovered + end # if left click and drag if is_hovered && CImGui.IsMouseDragging(CImGui.ImGuiMouseButton_Left, mouse_threshold_for_pan) drag_selected_entity(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_adjusted) @@ -85,6 +88,7 @@ function show_scene_window(main, scene_tex_id, scrolling, zoom_level) if CImGui.BeginPopup("context") if CImGui.MenuItem("Delete", "", false, main.selectedEntity !== nothing) println("Delete selected entity") + MainLoop.destroy_entity(main, main.selectedEntity) end CImGui.EndPopup() end diff --git a/src/editor/JulGameEditor/Editor.jl b/src/editor/JulGameEditor/Editor.jl index 05b3900..3ea1f91 100644 --- a/src/editor/JulGameEditor/Editor.jl +++ b/src/editor/JulGameEditor/Editor.jl @@ -56,6 +56,9 @@ module Editor zoom_level = Ref(1.0) animation_window_dict = Ref(Dict()) + + save_file_timer = 0 + try while !quit try @@ -234,38 +237,25 @@ module Editor try #region Entity Inspector CImGui.Begin("Entity Inspector") - #for entityIndex = eachindex(hierarchyEntitySelections) - if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing - CImGui.PushID("AddMenu") - if CImGui.BeginMenu("Add") - ShowEntityContextMenu(currentSceneMain.selectedEntity) - CImGui.EndMenu() - end - CImGui.PopID() - CImGui.Separator() - for entityField in fieldnames(Entity) - # if length(filteredEntities) < entityIndex - # break - # end - show_field_editor(currentSceneMain.selectedEntity, entityField, animation_window_dict) - end - - CImGui.Separator() - if CImGui.Button("Duplicate") - push!(currentSceneMain.scene.entities, deepcopy(currentSceneMain.selectedEntity)) - # TODO: switch to duplicated entity - end - - CImGui.Separator() - CImGui.Text("Delete Entity: NO CONFIRMATION") - if CImGui.Button("Delete") - MainLoop.destroy_entity(currentSceneMain, currentSceneMain.selectedEntity) - break - end - - #break # TODO: Remove this when we can select multiple entities and edit them all at once - end - #end + if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing + CImGui.PushID("AddMenu") + if CImGui.BeginMenu("Add") + ShowEntityContextMenu(currentSceneMain.selectedEntity) + CImGui.EndMenu() + end + CImGui.PopID() + CImGui.Separator() + for entityField in fieldnames(Entity) + show_field_editor(currentSceneMain.selectedEntity, entityField, animation_window_dict) + end + + CImGui.Separator() + if CImGui.Button("Duplicate") + copy = deepcopy(currentSceneMain.selectedEntity) + push!(currentSceneMain.scene.entities, copy) + currentSceneMain.selectedEntity = copy + end + end CImGui.End() catch e log_exceptions("Entity Inspector Window Error:", latest_exceptions, e, is_test_mode) @@ -323,6 +313,28 @@ module Editor SDL2.SDL_RenderClear(renderer) show_game_controls() + + #region Input + if currentSceneMain !== nothing + if JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LCTRL") && JulGame.InputModule.get_button_pressed(currentSceneMain.input, "S") + @info string("Saving scene") + events[1]() + end + # delete selected entity + if JulGame.InputModule.get_button_pressed(currentSceneMain.input, "DELETE") + if currentSceneMain.selectedEntity !== nothing + MainLoop.destroy_entity(currentSceneMain, currentSceneMain.selectedEntity) + end + end + # duplicate selected entity with ctrl+d + if JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LCTRL") && JulGame.InputModule.get_button_pressed(currentSceneMain.input, "D") + if currentSceneMain.selectedEntity !== nothing + copy = deepcopy(currentSceneMain.selectedEntity) + push!(currentSceneMain.scene.entities, copy) + currentSceneMain.selectedEntity = copy + end + end + end ################################# STOP RENDERING HERE CImGui.Render()