diff --git a/src/SceneManagement/SceneWriter.jl b/src/SceneManagement/SceneWriter.jl index 34b37463..db9106c4 100644 --- a/src/SceneManagement/SceneWriter.jl +++ b/src/SceneManagement/SceneWriter.jl @@ -16,6 +16,7 @@ module SceneWriterModule """ function serialize_entities(entities::Array, uiElements::Array, projectPath, sceneName) + println("Serializing entities") entitiesDict = [] uiElementsDict = [] diff --git a/src/UI/TextBox.jl b/src/UI/TextBox.jl index 33e4c983..ad0ce3c8 100644 --- a/src/UI/TextBox.jl +++ b/src/UI/TextBox.jl @@ -69,7 +69,8 @@ module TextBoxModule end function UI.load_font(this::TextBox, basePath::String, fontPath::String) - # println("loading font from $(fontPath)") + println("loading font from base: $(basePath)") + println("loading font from $(fontPath)") this.font = CallSDLFunction(SDL2.TTF_OpenFont, joinpath(basePath, fontPath), this.fontSize) if this.font == C_NULL return diff --git a/src/editor/JulGameEditor/Components/ComponentInputs.jl b/src/editor/JulGameEditor/Components/ComponentInputs.jl index e9bb480b..89e12a6e 100644 --- a/src/editor/JulGameEditor/Components/ComponentInputs.jl +++ b/src/editor/JulGameEditor/Components/ComponentInputs.jl @@ -303,7 +303,13 @@ function show_textbox_fields(textbox) end textbox.fontPath = currentTextInTextBox - CImGui.Button("Load Font") && (UI.load_font(textbox, joinpath(BasePath), joinpath("Fonts", "FiraCode", "ttf", "FiraCode-Regular.ttf"))) + basePath = joinpath(BasePath, "assets", "fonts") + fontPath = joinpath(strip(String(textbox.fontPath))) + if strip(String(currentTextInTextBox)) == "" || joinpath(strip(String(currentTextInTextBox))) == joinpath("Fonts", "FiraCode", "ttf", "FiraCode-Regular.ttf") + basePath = joinpath(pwd(), "..") + fontPath = joinpath("Fonts", "FiraCode", "ttf", "FiraCode-Regular.ttf") + end + CImGui.Button("Load Font") && (UI.load_font(textbox, basePath, fontPath)) else show_textbox_fields(textbox, field) end diff --git a/src/editor/JulGameEditor/Components/ScreenButtonFields.jl b/src/editor/JulGameEditor/Components/ScreenButtonFields.jl index b2b7eebd..d20aa52d 100644 --- a/src/editor/JulGameEditor/Components/ScreenButtonFields.jl +++ b/src/editor/JulGameEditor/Components/ScreenButtonFields.jl @@ -53,7 +53,8 @@ function show_screenbutton_fields(selectedScreenButton, screenButtonField) @c CImGui.InputInt("$(screenButtonField) y", &y, 1) if x != Value.x || y != Value.y - selectedScreenButton.setVector2Value(screenButtonField, convert(Float64, x), convert(Float64, y)) + #selectedScreenButton.setVector2Value(screenButtonField, convert(Float64, x), convert(Float64, y)) + setfield!(selectedScreenButton, screenButtonField, Vector2(x, y)) # JulGame.update_text(selectedScreenButton, selectedScreenButton.text) end elseif fieldName == "autoSizeText" || fieldName == "isCentered" diff --git a/src/editor/JulGameEditor/Components/TextBoxFields.jl b/src/editor/JulGameEditor/Components/TextBoxFields.jl index 26229827..8866dd35 100644 --- a/src/editor/JulGameEditor/Components/TextBoxFields.jl +++ b/src/editor/JulGameEditor/Components/TextBoxFields.jl @@ -47,7 +47,8 @@ function show_textbox_fields(selectedTextBox, textBoxField) @c CImGui.InputInt("$(textBoxField) y", &y, 1) if x != Value.x || y != Value.y - selectedTextBox.setVector2Value(textBoxField, convert(Float64, x), convert(Float64, y)) + #selectedTextBox.setVector2Value(textBoxField, convert(Float64, x), convert(Float64, y)) + setfield!(selectedTextBox, textBoxField, Vector2(x, y)) JulGame.update_text(selectedTextBox, selectedTextBox.text) end elseif fieldName == "autoSizeText" || fieldName == "isCenteredX" || fieldName == "isCenteredY" || fieldName == "isWorldEntity" diff --git a/src/editor/JulGameEditor/Editor.jl b/src/editor/JulGameEditor/Editor.jl index 60dc96c8..8fbfcc1f 100644 --- a/src/editor/JulGameEditor/Editor.jl +++ b/src/editor/JulGameEditor/Editor.jl @@ -44,7 +44,7 @@ module Editor hierarchyUISelections = Bool[] ############################## scenesLoadedFromFolder = Ref(String[]) - latest_exceptions = String[] + latest_exceptions = [] sceneWindowPos = ImVec2(0, 0) sceneWindowSize = ImVec2(startingSize.x, startingSize.y) @@ -125,6 +125,7 @@ module Editor itemSelected = false uiSelected = false + try CImGui.Begin("Hierarchy") if CImGui.TreeNode("Entities") && currentSceneMain !== nothing CImGui.SameLine() @@ -244,98 +245,109 @@ module Editor CImGui.TreePop() end CImGui.End() + catch e + log_exceptions("Hierarchy Window Error:", latest_exceptions, e, is_test_mode) + end show_debug_window(latest_exceptions) - CImGui.Begin("Entity Inspector") - # TODO: Fix this. I know this is bad. I'm sorry. I'll fix it later. - if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing && filteredEntities !== nothing && hierarchyEntitySelections !== nothing && indexin([currentSceneMain.selectedEntity], filteredEntities)[1] !== nothing && hierarchyEntitySelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[begin]] == false - fill!(hierarchyEntitySelections, false) - hierarchyEntitySelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[1]] = true - elseif itemSelected - currentSceneMain.selectedEntity = filteredEntities[indexin([true], hierarchyEntitySelections)[1]] - end - for entityIndex = eachindex(hierarchyEntitySelections) - if hierarchyEntitySelections[entityIndex] || currentSceneMain.selectedEntity == filteredEntities[entityIndex] - CImGui.PushID("AddMenu") - if CImGui.BeginMenu("Add") - ShowEntityContextMenu(filteredEntities[entityIndex]) - CImGui.EndMenu() - end - CImGui.PopID() - CImGui.Separator() - for entityField in fieldnames(Entity) - if length(filteredEntities) < entityIndex + try + CImGui.Begin("Entity Inspector") + # TODO: Fix this. I know this is bad. I'm sorry. I'll fix it later. + if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing && filteredEntities !== nothing && hierarchyEntitySelections !== nothing && indexin([currentSceneMain.selectedEntity], filteredEntities)[1] !== nothing && hierarchyEntitySelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[begin]] == false + fill!(hierarchyEntitySelections, false) + hierarchyEntitySelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[1]] = true + elseif itemSelected + currentSceneMain.selectedEntity = filteredEntities[indexin([true], hierarchyEntitySelections)[1]] + end + for entityIndex = eachindex(hierarchyEntitySelections) + if hierarchyEntitySelections[entityIndex] || currentSceneMain.selectedEntity == filteredEntities[entityIndex] + CImGui.PushID("AddMenu") + if CImGui.BeginMenu("Add") + ShowEntityContextMenu(filteredEntities[entityIndex]) + CImGui.EndMenu() + end + CImGui.PopID() + CImGui.Separator() + for entityField in fieldnames(Entity) + if length(filteredEntities) < entityIndex + break + end + show_field_editor(filteredEntities[entityIndex], entityField) + end + + CImGui.Separator() + if CImGui.Button("Duplicate") + push!(currentSceneMain.scene.entities, deepcopy(currentSceneMain.scene.entities[entityIndex])) + # TODO: switch to duplicated entity + end + + CImGui.Separator() + CImGui.Text("Delete Entity: NO CONFIRMATION") + if CImGui.Button("Delete") + MainLoop.destroy_entity(currentSceneMain, currentSceneMain.scene.entities[entityIndex]) break end - show_field_editor(filteredEntities[entityIndex], entityField) - end - - CImGui.Separator() - if CImGui.Button("Duplicate") - push!(currentSceneMain.scene.entities, deepcopy(currentSceneMain.scene.entities[entityIndex])) - # TODO: switch to duplicated entity - end - - CImGui.Separator() - CImGui.Text("Delete Entity: NO CONFIRMATION") - if CImGui.Button("Delete") - MainLoop.destroy_entity(currentSceneMain, currentSceneMain.scene.entities[entityIndex]) - break + + break # TODO: Remove this when we can select multiple entities and edit them all at once end - - break # TODO: Remove this when we can select multiple entities and edit them all at once end - end + CImGui.End() + catch e + log_exceptions("Entity Inspector Window Error:", latest_exceptions, e, is_test_mode) + end - CImGui.End() + try + + + CImGui.Begin("UI Inspector") + # TODO: Fix this. I know this is bad. I'm sorry. I'll fix it later. + #if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing && filteredEntities !== nothing && hierarchyUISelections !== nothing && indexin([currentSceneMain.selectedEntity], filteredEntities)[1] !== nothing + # fill!(hierarchyUISelections, false) + #hierarchyUISelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[1]] = true + #elseif uiSelected + # currentSceneMain.selectedEntity = filteredEntities[indexin([true], hierarchyUISelections)[1]] + #end + for uiElementIndex = eachindex(hierarchyUISelections) + if hierarchyUISelections[uiElementIndex] # || currentSceneMain.selectedEntity == filteredEntities[entityIndex] + CImGui.PushID("AddMenu") + if CImGui.BeginMenu("Add") + ShowEntityContextMenu(currentSceneMain.scene.uiElements[uiElementIndex]) + CImGui.EndMenu() + end + CImGui.PopID() + CImGui.Separator() - CImGui.Begin("UI Inspector") - # TODO: Fix this. I know this is bad. I'm sorry. I'll fix it later. - #if currentSceneMain !== nothing && currentSceneMain.selectedEntity !== nothing && filteredEntities !== nothing && hierarchyUISelections !== nothing && indexin([currentSceneMain.selectedEntity], filteredEntities)[1] !== nothing - # fill!(hierarchyUISelections, false) - #hierarchyUISelections[indexin([currentSceneMain.selectedEntity], filteredEntities)[1]] = true - #elseif uiSelected - # currentSceneMain.selectedEntity = filteredEntities[indexin([true], hierarchyUISelections)[1]] - #end - for uiElementIndex = eachindex(hierarchyUISelections) - if hierarchyUISelections[uiElementIndex] # || currentSceneMain.selectedEntity == filteredEntities[entityIndex] - CImGui.PushID("AddMenu") - if CImGui.BeginMenu("Add") - ShowEntityContextMenu(currentSceneMain.scene.uiElements[uiElementIndex]) - CImGui.EndMenu() - end - CImGui.PopID() - CImGui.Separator() + if length(currentSceneMain.scene.uiElements) < uiElementIndex + break + end + + if contains("$(typeof(currentSceneMain.scene.uiElements[uiElementIndex]))", "TextBox") + show_textbox_fields(currentSceneMain.scene.uiElements[uiElementIndex]) + else + show_screenbutton_fields(currentSceneMain.scene.uiElements[uiElementIndex]) + end - if length(currentSceneMain.scene.uiElements) < uiElementIndex - break - end - - if contains("$(typeof(currentSceneMain.scene.uiElements[uiElementIndex]))", "TextBox") - show_textbox_fields(currentSceneMain.scene.uiElements[uiElementIndex]) - else - show_screenbutton_fields(currentSceneMain.scene.uiElements[uiElementIndex]) - end + # CImGui.Separator() + # if CImGui.Button("Duplicate") + # push!(currentSceneMain.scene.uiElements, deepcopy(currentSceneMain.scene.uiElements[uiElementIndex])) + # # TODO: switch to duplicated entity + # end - # CImGui.Separator() - # if CImGui.Button("Duplicate") - # push!(currentSceneMain.scene.uiElements, deepcopy(currentSceneMain.scene.uiElements[uiElementIndex])) - # # TODO: switch to duplicated entity - # end - - CImGui.Separator() - CImGui.Text("Delete UI Element: NO CONFIRMATION") - if CImGui.Button("Delete") - MainLoop.DestroyUIElement(currentSceneMain.scene.uiElements[uiElementIndex]) - break + CImGui.Separator() + CImGui.Text("Delete UI Element: NO CONFIRMATION") + if CImGui.Button("Delete") + MainLoop.DestroyUIElement(currentSceneMain.scene.uiElements[uiElementIndex]) + break + end + + break # TODO: Remove this when we can select multiple entities and edit them all at once end - - break # TODO: Remove this when we can select multiple entities and edit them all at once end - end - CImGui.End() - + CImGui.End() + catch e + log_exceptions("UI Inspector Window Error:", latest_exceptions, e, isTestMode) + end SDL2.SDL_SetRenderTarget(renderer, sceneTexture) SDL2.SDL_RenderClear(renderer) @@ -370,20 +382,15 @@ module Editor quit = true end catch e - push!(latest_exceptions, [e, "$(Dates.now())"]) - if length(latest_exceptions) > 10 - deleteat!(latest_exceptions, 1) - end - - @error e - Base.show_backtrace(stdout, catch_backtrace()) + @error "Error in renderloop!" exception=e end end catch e - @warn "Error in renderloop!" exception=e + backup_file_name = backup_file_name = "$(replace(currentSceneName, ".json" => ""))-backup-$(replace(Dates.format(Dates.now(), "yyyy-mm-ddTHH:MM:SS"), ":" => "-")).json" + println("Backup file name: ", backup_file_name) + SceneWriterModule.serialize_entities(currentSceneMain.scene.entities, currentSceneMain.scene.uiElements, currentSelectedProjectPath, backup_file_name) Base.show_backtrace(stderr, catch_backtrace()) - save_scene_event(currentSceneMain.scene.entities, currentSceneMain.scene.uiElements, currentSelectedProjectPath, String(currentSceneName +"-backup-$(Dates.now())")) - println("Scene saved as backup") + @warn "Error in renderloop!" exception=e finally #TODO: fix these: ImGui_ImplSDLRenderer2_Shutdown(); # ImGui_ImplSDL2_Shutdown(); @@ -547,4 +554,15 @@ module Editor splice!(entities, destination : destination, updatedEntities) end + + function log_exceptions(error_type, latest_exceptions, e, is_test_mode) + println("Error: $(is_test_mode): ", e) + push!(latest_exceptions, [e, String("$(Dates.now())")]) + if length(latest_exceptions) > 10 + deleteat!(latest_exceptions, 1) + end + if is_test_mode + @warn "Error in renderloop!" exception=e + end + end end \ No newline at end of file diff --git a/src/editor/JulGameEditor/Windows/DebugWindow.jl b/src/editor/JulGameEditor/Windows/DebugWindow.jl index ce2f7d0e..db841614 100644 --- a/src/editor/JulGameEditor/Windows/DebugWindow.jl +++ b/src/editor/JulGameEditor/Windows/DebugWindow.jl @@ -1,4 +1,4 @@ -function show_debug_window(latestExceptions::Vector{String} = String[]) +function show_debug_window(latestExceptions) @cstatic begin CImGui.Begin("Debug") CImGui.Text("The latest 10 exceptions are:") diff --git a/src/editor/JulGameEditor/src/JulGameEditor.jl b/src/editor/JulGameEditor/src/JulGameEditor.jl index 7134e049..4e5228c1 100644 --- a/src/editor/JulGameEditor/src/JulGameEditor.jl +++ b/src/editor/JulGameEditor/src/JulGameEditor.jl @@ -8,4 +8,4 @@ module JulGameEditor julia_main() = run() end # Uncomment to allow for direct execution of this file. If you want to build this project with PackageCompiler, comment the line below -#JulGameEditor.run() \ No newline at end of file +JulGameEditor.run() \ No newline at end of file diff --git a/src/editor/JulGameEditor/src/imgui.ini b/src/editor/JulGameEditor/src/imgui.ini index 2b55eed2..d5629364 100644 --- a/src/editor/JulGameEditor/src/imgui.ini +++ b/src/editor/JulGameEditor/src/imgui.ini @@ -21,13 +21,13 @@ Collapsed=0 [Window][Debug] Pos=453,808 -Size=1050,272 +Size=861,272 Collapsed=0 DockId=0x00000003,0 [Window][Scene] Pos=453,19 -Size=1050,787 +Size=861,787 Collapsed=0 DockId=0x00000002,0 @@ -43,13 +43,13 @@ Collapsed=0 [Window][Controls] Pos=453,808 -Size=1050,272 +Size=861,272 Collapsed=0 DockId=0x00000003,1 [Window][Dear ImGui Demo] -Pos=1505,19 -Size=415,1061 +Pos=1316,19 +Size=604,1061 Collapsed=0 DockId=0x0000000A,1 @@ -87,8 +87,8 @@ Size=1920,1061 Collapsed=0 [Window][Scene List] -Pos=1505,19 -Size=415,1061 +Pos=1316,19 +Size=604,1061 Collapsed=0 DockId=0x0000000A,0 @@ -164,14 +164,14 @@ Column 2 Weight=1.0000 [Docking][Data] DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1920,1061 Split=X - DockNode ID=0x00000007 Parent=0x7C6B3D9B SizeRef=1503,828 Split=X + DockNode ID=0x00000007 Parent=0x7C6B3D9B SizeRef=1314,828 Split=X DockNode ID=0x00000004 Parent=0x00000007 SizeRef=451,828 Split=Y Selected=0xC7219E3D DockNode ID=0x00000006 Parent=0x00000004 SizeRef=316,503 Selected=0x29EABFBD - DockNode ID=0x0000000B Parent=0x00000004 SizeRef=316,556 Selected=0x60AF69E6 - DockNode ID=0x00000005 Parent=0x00000007 SizeRef=1050,828 Split=Y + DockNode ID=0x0000000B Parent=0x00000004 SizeRef=316,556 Selected=0xC7219E3D + DockNode ID=0x00000005 Parent=0x00000007 SizeRef=861,828 Split=Y DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1440,787 Selected=0xE192E354 DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1440,272 CentralNode=1 Selected=0x67284010 - DockNode ID=0x00000008 Parent=0x7C6B3D9B SizeRef=415,828 Split=Y Selected=0xD04A4B96 + DockNode ID=0x00000008 Parent=0x7C6B3D9B SizeRef=604,828 Split=Y Selected=0xD04A4B96 DockNode ID=0x00000009 Parent=0x00000008 SizeRef=503,414 Selected=0xD04A4B96 DockNode ID=0x0000000A Parent=0x00000008 SizeRef=503,412 Selected=0x77FEF510