Skip to content

Commit

Permalink
Feature/duplication brush (#78)
Browse files Browse the repository at this point in the history
* Added duplication brush
  • Loading branch information
Kyjor authored Aug 16, 2024
1 parent c351a03 commit 2e3890d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/editor/JulGameEditor/Components/SceneViewer.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function show_scene_window(main, scene_tex_id, scrolling, zoom_level)
function show_scene_window(main, scene_tex_id, scrolling, zoom_level, duplicationMode)
# CImGui.SetNextWindowSize((350, 560), CImGui.ImGuiCond_FirstUseEver)
CImGui.Begin("Scene") || (CImGui.End(); return)
# GET SIZE OF SCENE TEXTURE
Expand Down Expand Up @@ -76,12 +76,15 @@ function show_scene_window(main, scene_tex_id, scrolling, zoom_level)
# if left click
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
if duplicationMode
handle_mouse_click_duplication(main)
else
handle_mouse_click(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_adjusted)
end
end

# if left click and drag
if is_hovered && CImGui.IsMouseDragging(CImGui.ImGuiMouseButton_Left, mouse_threshold_for_pan)
if is_hovered && (CImGui.IsMouseDragging(CImGui.ImGuiMouseButton_Left, mouse_threshold_for_pan) || duplicationMode)
drag_selected_entity(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_adjusted)
end

Expand Down Expand Up @@ -124,6 +127,17 @@ function handle_mouse_click(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_ad
main.selectedEntity = nearest_entity
end

function handle_mouse_click_duplication(main)
# if main is nothing, return
if main === nothing
return
end

copy = deepcopy(main.selectedEntity)
push!(main.scene.entities, copy)
main.selectedEntity = copy
end

function get_nearest_entity(main, canvas_p0, camPos, mouse_pos_in_canvas_zoom_adjusted)
# if main is nothing, return
if main === nothing
Expand Down
19 changes: 16 additions & 3 deletions src/editor/JulGameEditor/Editor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module Editor

save_file_timer = 0

duplicationMode = false

try
while !quit
try
Expand Down Expand Up @@ -117,7 +119,7 @@ module Editor

try
prevSceneWindowSize = sceneWindowSize
sceneWindowSize = show_scene_window(currentSceneMain, sceneTexture, scrolling, zoom_level)
sceneWindowSize = show_scene_window(currentSceneMain, sceneTexture, scrolling, zoom_level, duplicationMode)
if sceneWindowSize === nothing
sceneWindowSize = prevSceneWindowSize
end
Expand Down Expand Up @@ -327,11 +329,22 @@ module Editor
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
if JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LCTRL") && JulGame.InputModule.get_button_pressed(currentSceneMain.input, "D") && currentSceneMain.selectedEntity !== nothing
copy = deepcopy(currentSceneMain.selectedEntity)
push!(currentSceneMain.scene.entities, copy)
currentSceneMain.selectedEntity = copy
end
# turn on duplication mode with ctrl+shift+d
if JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LCTRL") && JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LSHIFT") && JulGame.InputModule.get_button_pressed(currentSceneMain.input, "D") && currentSceneMain.selectedEntity !== nothing
duplicationMode = !duplicationMode
if duplicationMode
@info "Duplication mode on"
copy = deepcopy(currentSceneMain.selectedEntity)
push!(currentSceneMain.scene.entities, copy)
currentSceneMain.selectedEntity = copy
else
@info "Duplication mode off"
MainLoop.destroy_entity(currentSceneMain, currentSceneMain.selectedEntity)
end
end
end
Expand Down

0 comments on commit 2e3890d

Please sign in to comment.