Skip to content

Commit

Permalink
Improved usability of editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Aug 16, 2024
1 parent 2a645e3 commit aa6d8fa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/editor/JulGameEditor/Components/SceneViewer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
76 changes: 44 additions & 32 deletions src/editor/JulGameEditor/Editor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module Editor
zoom_level = Ref(1.0)

animation_window_dict = Ref(Dict())

save_file_timer = 0

try
while !quit
try
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit aa6d8fa

Please sign in to comment.