Skip to content

Commit 5264fe0

Browse files
committed
Confirm before changing scene
1 parent 88ea22d commit 5264fe0

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

src/editor/JulGameEditor/Editor.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Editor
3434
# Project variables
3535
currentSceneMain = nothing
3636
currentSceneName = ""
37+
currentScenePath = ""
3738
currentSelectedProjectPath = ""
3839
gameInfo = []
3940
##############################
@@ -66,7 +67,7 @@ module Editor
6667
startTime = Ref(UInt64(0))
6768
lastPhysicsTime = Ref(UInt64(SDL2.SDL_GetTicks()))
6869

69-
currentDialogue::Base.RefValue{Tuple{String, String}} = Ref(("", ""))
70+
currentDialog::Base.RefValue{String} = Ref("")
7071

7172
try
7273
while !quit
@@ -104,14 +105,14 @@ module Editor
104105
for scene in scenesLoadedFromFolder[]
105106
if CImGui.Button("$(scene)")
106107
currentSceneName = SceneLoaderModule.get_scene_file_name_from_full_scene_path(scene)
108+
currentScenePath = scene
107109
if currentSceneMain === nothing
108110
JulGame.IS_EDITOR = true
109111
JulGame.PIXELS_PER_UNIT = 16
110-
currentDialogue[] = (String(currentSceneName), scene)
111-
#currentSceneMain.cameraBackgroundColor = (50, 50, 50)
112+
currentDialog[] = "Open scene: $(currentSceneName)"
112113
currentSelectedProjectPath = SceneLoaderModule.get_project_path_from_full_scene_path(scene)
113114
else
114-
JulGame.change_scene(String(currentSceneName))
115+
currentDialog[] = "Open scene: $(currentSceneName)"
115116
end
116117
end
117118
CImGui.NewLine()
@@ -120,14 +121,19 @@ module Editor
120121
CImGui.End()
121122
end
122123

123-
if currentDialogue[] !== ("", "")
124-
println("Opening scene: $(currentDialogue[][2])")
125-
confirmation_dialog(currentDialogue, "Open scene: $(currentDialogue[][1])", () -> load_scene(currentDialogue[][2], renderer))
124+
if currentDialog[] != "" #TODO: make more dynamic
125+
#println("Opening scene: $(currentDialog[][2])")
126+
if confirmation_dialog(currentDialog) == "ok" && currentSceneName != ""
127+
if currentSceneMain === nothing
128+
currentSceneMain = load_scene(currentScenePath, renderer)
129+
currentSceneMain.cameraBackgroundColor = (50, 50, 50)
130+
else
131+
JulGame.change_scene(String(currentSceneName))
132+
end
133+
end
126134
end
127135

128-
129136
uiSelected = false
130-
131137

132138
if sceneWindowSize.x != sceneTextureSize.x || sceneWindowSize.y != sceneTextureSize.y
133139
SDL2.SDL_DestroyTexture(sceneTexture)

src/editor/JulGameEditor/Utils/EditorUtils.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,13 @@ function reset_camera_event(main)
326326
return event
327327
end
328328

329-
function confirmation_dialog(dialogue, title, event::Function)
330-
CImGui.OpenPopup(title)
329+
function confirmation_dialog(dialog)
330+
CImGui.OpenPopup(dialog[])
331331

332-
if CImGui.BeginPopupModal(title, C_NULL, CImGui.ImGuiWindowFlags_AlwaysAutoResize)
332+
if CImGui.BeginPopupModal(dialog[], C_NULL, CImGui.ImGuiWindowFlags_AlwaysAutoResize)
333333
CImGui.Text("Are you sure you would like to open this scene?\nIf you currently have a scene open, any unsaved changes will be lost.\n\n")
334-
CImGui.Separator()
334+
#CImGui.Separator()
335+
CImGui.NewLine()
335336

336337
# @cstatic dont_ask_me_next_time=false begin
337338
# CImGui.PushStyleVar(CImGui.ImGuiStyleVar_FramePadding, (0, 0))
@@ -341,15 +342,20 @@ function confirmation_dialog(dialogue, title, event::Function)
341342

342343
if CImGui.Button("OK", (120, 0))
343344
CImGui.CloseCurrentPopup()
344-
dialogue[] = ("", "")
345-
event()
345+
dialog[] = ""
346+
347+
return "ok"
346348
end
347349
CImGui.SetItemDefaultFocus()
348350
CImGui.SameLine()
349351
if CImGui.Button("Cancel",(120, 0))
350352
CImGui.CloseCurrentPopup()
351-
dialogue[] = ("", "")
353+
dialog[] = ""
354+
355+
return "cancel"
352356
end
353357
CImGui.EndPopup()
358+
359+
return "continue"
354360
end
355361
end

src/editor/JulGameEditor/Utils/SceneUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Load a scene from the specified `scenePath` using the given `renderer`.
7979
The loaded main struct.
8080
"""
8181
function load_scene(scenePath::String, renderer)
82+
println("Loading scene from $scenePath")
8283
game = C_NULL
8384
try
8485
game = SceneLoaderModule.load_scene_from_editor(scenePath, renderer);

src/editor/JulGameEditor/src/imgui.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ Size=1053,718
158158
Collapsed=0
159159
DockId=0x00000002,1
160160

161+
[Window][Open scene: scene.json]
162+
Pos=390,311
163+
Size=500,114
164+
Collapsed=0
165+
166+
[Window][Open scene: title_scene.json]
167+
Pos=390,303
168+
Size=500,114
169+
Collapsed=0
170+
161171
[Table][0x45A0E60D,7]
162172
RefScale=13
163173
Column 0 Width=49

0 commit comments

Comments
 (0)