Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialogs #467

Merged
merged 13 commits into from
May 23, 2024
17 changes: 9 additions & 8 deletions [editor]/editor_gui/client/buttonclicked.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
2 changes: 1 addition & 1 deletion [editor]/editor_gui/client/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
9 changes: 5 additions & 4 deletions [editor]/editor_gui/client/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
10 changes: 5 additions & 5 deletions [editor]/editor_gui/client/locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions [editor]/editor_gui/client/mapsettings_gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions [editor]/editor_gui/client/me_gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 11 additions & 20 deletions [editor]/editor_gui/client/save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
8 changes: 6 additions & 2 deletions [editor]/editor_gui/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<info author="Talidan, jbeta" description="Map editor GUI" />

<!-- Required resources -->
<include resource="msgbox" />
<include resource="dialogs" />
<include resource="tooltip" />

<!-- Client-side logic -->
Expand Down Expand Up @@ -53,12 +53,16 @@
<export function="closeSaveDialog" type="client" />
<export function="closeLoadDialog" type="client" />
<export function="guiGetMouseOverElement" type="client" />
<export function="guiShowMessageBox" type="client" />
<export function="openPropertiesBox" type="client" />
<export function="restoreSaveDialog" type="client" />
<export function="stopTest" type="client" />
<export function="restoreSelectedElement" type="client" />

<!-- MessageBox exports -->
<export function="newCallback" type="client" />
<export function="openCallback" type="client" />
<export function="saveCallback" type="client" />

<!-- Browser -->
<script src="client/browser/browserList.lua" type="client" />
<script src="client/browser/browser.lua" type="client" />
Expand Down
8 changes: 4 additions & 4 deletions [editor]/editor_main/client/saveloadtest_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ addEventHandler ( "saveloadtest_return", root,
end
editor_gui.closeLoadDialog()
else
editor_gui.guiShowMessageBox ( "Map resource could not be started!", "error", "Error", true )
exports.dialogs:messageBox("Error", "Map resource could not be started!", false, "ERROR", "OK")
end
elseif ( command ) == "save" then
if ( returnValue ) then
editor_gui.closeSaveDialog()
else
editor_gui.guiShowMessageBox ( "Map resource could not be saved! "..reason, "error", "Error", true )
exports.dialogs:messageBox("Error", "Map resource could not be saved! " .. reason, false, "ERROR", "OK")
editor_gui.restoreSaveDialog()
end
elseif ( command ) == "quickSave" then
reason = reason or "The target resource may be in .zip format or corrupted."
editor_gui.guiShowMessageBox ( "Map resource could not be saved! "..reason, "error", "Error", true )
exports.dialogs:messageBox("Error", "Map resource could not be saved! " .. reason, false, "ERROR", "OK")
editor_gui.restoreSaveDialog()
elseif ( command ) == "test" then
reason = reason or ""
editor_gui.guiShowMessageBox ( "Test could not be started! "..reason, "error", "Error", true )
exports.dialogs:messageBox("Error", "Test resource could not be started! " .. reason, false, "ERROR", "OK")
editor_gui.stopTest()
elseif ( command == "close" ) then
editor_gui.closeSaveDialog()
Expand Down
6 changes: 6 additions & 0 deletions [editor]/msgbox/script.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
--[[-----------DOCUMENTATION---------------
WARNING:
This resource is deprecated as the new 'dialogs' resource replaces it.
SYNTAX:
guibutton,guibutton,guibutton = guiShowMessageBox ( string message, string boxType, string title [, string button1, string button2, stringbutton3] )
REQUIRED ARGUMENTS
Expand Down Expand Up @@ -111,6 +114,9 @@ function guiShowMessageBox ( message, boxType, title, forceShowing, button1, but
if ( forceShowing ) then
guiAttached[cover] = aMessage.Form
end

outputDebugString("This resource is deprecated as the new 'dialogs' resource replaces it.", 2)

return guiButton1, guiButton2, guiButton3
end

Expand Down
Binary file added [gameplay]/dialogs/files/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added [gameplay]/dialogs/files/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added [gameplay]/dialogs/files/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added [gameplay]/dialogs/files/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions [gameplay]/dialogs/meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<meta>
<info author="Nico834" type="script" name="Dialogs" description="Create and manage dialogs with callbacks." version="1.0.0" />
<min_mta_version client="1.6.0" />

<script src="sourceG.lua" type="shared" />
<script src="sourceC.lua" type="client" />

<export function="messageBeep" type="client" />
<export function="messageBox" type="client" />
<export function="messageBoxEx" type="client" />

<file src="files/info.png" />
<file src="files/question.png" />
<file src="files/warning.png" />
<file src="files/error.png" />
</meta>
Loading