From de18c6ff00a7654973f6b30387f7a58ae1370e94 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Fri, 24 May 2024 01:58:11 +0200 Subject: [PATCH] Add resource 'dialogs' to replace old 'msgbox' resource (#467) --- [editor]/editor_gui/client/buttonclicked.lua | 17 +- [editor]/editor_gui/client/interface.lua | 2 +- [editor]/editor_gui/client/load.lua | 9 +- [editor]/editor_gui/client/locations.lua | 10 +- .../editor_gui/client/mapsettings_gui.lua | 12 +- [editor]/editor_gui/client/me_gui.lua | 6 - [editor]/editor_gui/client/save.lua | 31 +- [editor]/editor_gui/meta.xml | 8 +- .../client/saveloadtest_client.lua | 8 +- [editor]/msgbox/script.lua | 6 + [gameplay]/dialogs/files/error.png | Bin 0 -> 2165 bytes [gameplay]/dialogs/files/info.png | Bin 0 -> 2225 bytes [gameplay]/dialogs/files/question.png | Bin 0 -> 2221 bytes [gameplay]/dialogs/files/warning.png | Bin 0 -> 1884 bytes [gameplay]/dialogs/meta.xml | 16 + [gameplay]/dialogs/readme.md | 230 +++++++++++++ [gameplay]/dialogs/sourceC.lua | 310 ++++++++++++++++++ [gameplay]/dialogs/sourceG.lua | 77 +++++ [gameplay]/webbrowser/WebBrowserGUI.lua | 2 +- [gameplay]/webbrowser/meta.xml | 2 +- 20 files changed, 688 insertions(+), 58 deletions(-) create mode 100644 [gameplay]/dialogs/files/error.png create mode 100644 [gameplay]/dialogs/files/info.png create mode 100644 [gameplay]/dialogs/files/question.png create mode 100644 [gameplay]/dialogs/files/warning.png create mode 100644 [gameplay]/dialogs/meta.xml create mode 100644 [gameplay]/dialogs/readme.md create mode 100644 [gameplay]/dialogs/sourceC.lua create mode 100644 [gameplay]/dialogs/sourceG.lua diff --git a/[editor]/editor_gui/client/buttonclicked.lua b/[editor]/editor_gui/client/buttonclicked.lua index 5a6d6e81c..c6880752d 100644 --- a/[editor]/editor_gui/client/buttonclicked.lua +++ b/[editor]/editor_gui/client/buttonclicked.lua @@ -55,18 +55,19 @@ function elementIcons_Clicked ( source, mouseButton ) end end +function newCallback(callbackResult) + if callbackResult == "YES" then + editor_main.newResource() + end + + guiSetInputEnabled(false) +end + --These are individual functions for each topmenu button function topMenuClicked.new () editor_main.dropElement () guiSetInputEnabled(true) - local yes,no = guiShowMessageBox ( "Are you sure you want to create a new map?\nAny unsaved data will be lost.", "info", "New", true, "Yes", "No" ) - addEventHandler ( "onClientGUIClick",yes,function() - editor_main.newResource() - guiSetInputEnabled(false) - end,false ) - addEventHandler ( "onClientGUIClick",no,function() - guiSetInputEnabled(false) - end,false ) + exports.dialogs:messageBox("New", "Are you sure you want to create a new map? Any unsaved data will be lost.", "newCallback", "QUESTION", "YESNO") end function topMenuClicked.open () diff --git a/[editor]/editor_gui/client/interface.lua b/[editor]/editor_gui/client/interface.lua index f7eee626d..ea459fbe0 100644 --- a/[editor]/editor_gui/client/interface.lua +++ b/[editor]/editor_gui/client/interface.lua @@ -7,7 +7,7 @@ local interface = { move_cursor = NOT_REQUIRED, move_freecam = NOT_REQUIRED, move_keyboard = NOT_REQUIRED, - msgbox = NOT_REQUIRED, + dialogs = NOT_REQUIRED, tooltip = NOT_REQUIRED, freeroam = NOT_REQUIRED, } diff --git a/[editor]/editor_gui/client/load.lua b/[editor]/editor_gui/client/load.lua index 5898a29fd..f5756e2ac 100644 --- a/[editor]/editor_gui/client/load.lua +++ b/[editor]/editor_gui/client/load.lua @@ -34,12 +34,13 @@ function openMap() local row = guiGridListGetSelectedItem ( loadDialog.mapsList ) if row == -1 then return end mapName = guiGridListGetItemText ( loadDialog.mapsList, row, 1 ) - open = guiShowMessageBox ( "Are you sure you want to load map \""..mapName.."\"?\nAny unsaved changes will be lost.", "info", "Are you sure?", true, "Open", "Cancel" ) - addEventHandler ( "onClientGUIClick", open, openButton, false ) + exports.dialogs:messageBox("Are you sure?", "Are you sure you want to load map \""..mapName.."\"?\nAny unsaved changes will be lost.", "openCallback", "QUESTION", "YESNO") end -function openButton () - editor_main.openResource ( mapName ) +function openCallback(callbackResult) + if callbackResult == "YES" then + editor_main.openResource ( mapName ) + end end addEvent ( "openShowDialog",true ) diff --git a/[editor]/editor_gui/client/locations.lua b/[editor]/editor_gui/client/locations.lua index 4061b407d..ac085aa8e 100644 --- a/[editor]/editor_gui/client/locations.lua +++ b/[editor]/editor_gui/client/locations.lua @@ -102,11 +102,11 @@ function addBookmark () local z = locations.z:getValue() local world = locations.world:getValue() if name == "" then - guiShowMessageBox ( 'No location name was specified!', "error", "Bad value", true ) + exports.dialogs:messageBox("Bad value", "No location name was specified!", false, "ERROR", "OK") return end if bookmarksTable[name] then - guiShowMessageBox ( 'A location of name "'..name..'" already exists!', "error", "Conflict", true ) + exports.dialogs:messageBox("Bad value", "A location of name \"" .. name .."\" already exists!", false, "ERROR", "OK") return end bookmarksTable[name] = {} @@ -192,15 +192,15 @@ end function setLocation ( x,y,z,world ) if not x then - local button = guiShowMessageBox ( "Invalid \"x position\" specified", "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"x position\" specified", false, "ERROR", "OK") return end if not y then - local button = guiShowMessageBox ( "Invalid \"y position\" specified", "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"y position\" specified", false, "ERROR", "OK") return end if not z then - local button = guiShowMessageBox ( "Invalid \"z position\" specified", "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"z position\" specified", false, "ERROR", "OK") return end if not world then diff --git a/[editor]/editor_gui/client/mapsettings_gui.lua b/[editor]/editor_gui/client/mapsettings_gui.lua index 8d520e1a9..f25aba5e7 100644 --- a/[editor]/editor_gui/client/mapsettings_gui.lua +++ b/[editor]/editor_gui/client/mapsettings_gui.lua @@ -170,29 +170,29 @@ end function confirmMapSettings () local versionText = mapsettings.metaVersion:getValue() if not versionText or not (( string.match (versionText, "^%d+$") ) or ( string.match (versionText, "^%d+%.%d+$") ) or ( string.match (versionText, "^%d+%.%d+%.%d+$") )) then - guiShowMessageBox ( "Invalid META \"Version\" specified", "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid META \"Version\" specified", false, "ERROR", "OK") return end if not mapsettings.timeHour:getValue() or not mapsettings.timeMinute:getValue() or mapsettings.timeHour:getValue() > 23 or mapsettings.timeMinute:getValue() > 59 then - guiShowMessageBox ( "Invalid Time specified", "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid time specified", false, "ERROR", "OK") return end -- if mapsettings.metaAuthor:getValue() == "" then - -- guiShowMessageBox ( "Invalid META \"Author\" specified", "error", "Bad Value", true ) + -- exports.dialogs:messageBox("Bad value", "Invalid META \"Author\" specified", false, "ERROR", "OK") -- return -- end if not tonumber(mapsettings.maxplayers:getValue()) then - guiShowMessageBox ( 'Invalid "Maximum Players" specified', "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"Maximum Players\" specified", false, "ERROR", "OK") return end if not tonumber(mapsettings.minplayers:getValue()) then - guiShowMessageBox ( 'Invalid "Minimum Players" specified', "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"Maximum Players\" specified", false, "ERROR", "OK") return end if mapsettings.minplayers:getValue() >= mapsettings.maxplayers:getValue() then - guiShowMessageBox ( 'Invalid "Minimum Players" specified', "error", "Bad Value", true ) + exports.dialogs:messageBox("Bad value", "Invalid \"Maximum Players\" specified", false, "ERROR", "OK") return end if not tonumber(mapsettings.gamespeed:getValue()) then diff --git a/[editor]/editor_gui/client/me_gui.lua b/[editor]/editor_gui/client/me_gui.lua index e7477c8f3..92626c09e 100644 --- a/[editor]/editor_gui/client/me_gui.lua +++ b/[editor]/editor_gui/client/me_gui.lua @@ -370,12 +370,6 @@ function playSoundFrontEnd ( sound ) return returnValue end -function guiShowMessageBox ( message, boxType, title, forced, button1, button2, button3 ) - playSoundFrontEnd ( 5 ) - local a1,a2,a3 = msgbox.guiShowMessageBox ( message, boxType, title, forced, button1, button2, button3 ) - return a1,a2,a3 -end - function clearNonCreatableElements(elementTable) for elementName,data in pairs(elementTable) do if not data.createable then diff --git a/[editor]/editor_gui/client/save.lua b/[editor]/editor_gui/client/save.lua index b82508a9d..8fb6a2d62 100644 --- a/[editor]/editor_gui/client/save.lua +++ b/[editor]/editor_gui/client/save.lua @@ -54,33 +54,24 @@ function saveMap() mapName = guiGetText ( saveDialog.mapName ) if mapName == "" then return end if mapsInfo[string.lower(mapName)] then - local save,cancel = guiShowMessageBox ( "Are you sure you want to overwrite map \""..mapName.."\"?\n" .. - "This will cause original map data to be lost.", - "info", "Are you sure?", true, "Save", "Cancel" ) - addEventHandler ( "onClientGUIClick", save, saveButton, false ) - addEventHandler ( "onClientGUIClick", cancel, restoreSaveDialog, false ) + exports.dialogs:messageBox("Are you sure?", "Are you sure you want to overwrite map \""..mapName.."\"? This will cause original map data to be lost.", "saveCallback", "QUESTION", "YESNO") guiSetProperty(saveDialog.window, "Disabled", "True") elseif resourcesInfo[string.lower(mapName)] then - guiShowMessageBox ( "Unable to save to \""..mapName.."\". \n" .. - "You cannot overwrite non-map resources.", - "error", "Cannot save", true ) + exports.dialogs:messageBox("Cannot save", "Unable to save to \""..mapName.."\" You cannot overwrite non-map resources.", false, "ERROR", "OK") else - local save,cancel = guiShowMessageBox ( "Are you sure you want to save to \""..mapName.."\"?", - "info", "Are you sure?", true, "Save", "Cancel" ) - addEventHandler ( "onClientGUIClick", save, saveButton, false ) - addEventHandler ( "onClientGUIClick", cancel, restoreSaveDialog, false ) + exports.dialogs:messageBox("Are you sure?", "Are you sure you want to save to \""..mapName.."\"?", "saveCallback", "QUESTION", "YESNO") guiSetProperty(saveDialog.window, "Disabled", "True") end end -function saveButton() - local resourceName = guiGetText ( saveDialog.mapName ) - local directory = guiGetText ( saveDialog.directory ) - editor_main.saveResource ( resourceName, directory ) -end - -function restoreSaveDialog() - guiSetProperty(saveDialog.window, "Disabled", "False") +function saveCallback(callbackResult) + if callbackResult == "YES" then + local resourceName = guiGetText ( saveDialog.mapName ) + local directory = guiGetText ( saveDialog.directory ) + editor_main.saveResource ( resourceName, directory ) + else + guiSetProperty(saveDialog.window, "Disabled", "False") + end end addEvent ( "saveAsShowDialog", true ) diff --git a/[editor]/editor_gui/meta.xml b/[editor]/editor_gui/meta.xml index 1397a1888..3d9269496 100644 --- a/[editor]/editor_gui/meta.xml +++ b/[editor]/editor_gui/meta.xml @@ -2,7 +2,7 @@ - + @@ -53,12 +53,16 @@ - + + + + +