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

[Modal Window Helper] Return botton / choice #4529

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions data/scripts/creaturescripts/player/modal_window_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ end

function ModalWindow:addButton(name, callback)
if type(name) ~= "string" then
io.write("ModalWindow:addButton: name must be a string.")
io.write("ModalWindow:addButton: name must be a string.\n")
name = tostring(name)
end

if self.buttons[name] then
io.write("ModalWindow: Button with name '" .. name .. "' already exists.")
io.write("ModalWindow: Button with name '" .. name .. "' already exists.\n")
return false
end

local id = #self.buttons + 1
local button = { id = id, name = name, callback = callback }
self.buttons[id] = button
self.buttons[name] = button
return true
return button
end

function ModalWindow:removeButton(name)
if type(name) ~= "string" then
io.write("ModalWindow:removeButton: name must be a string.")
io.write("ModalWindow:removeButton: name must be a string.\n")
name = tostring(name)
end

local button = self.buttons[name]
if not button then
io.write("ModalWindow: Button with name '" .. name .. "' does not exist.")
io.write("ModalWindow: Button with name '" .. name .. "' does not exist.\n")
return false
end

Expand All @@ -73,18 +73,18 @@ end

function ModalWindow:callButton(name, player, button, choice)
if type(name) ~= "string" then
io.write("ModalWindow:callButton: name must be a string.")
io.write("ModalWindow:callButton: name must be a string.\n")
name = tostring(name)
end

local button = self.buttons[name]
if not button then
io.write("ModalWindow: Button with name '" .. name .. "' does not exist.")
io.write("ModalWindow: Button with name '" .. name .. "' does not exist.\n")
return false
end

if not button.callback then
io.write("ModalWindow: Button with name '" .. name .. "' has no callback.")
io.write("ModalWindow: Button with name '" .. name .. "' has no callback.\n")
return false
end
return button.callback(player, button, choice)
Expand Down Expand Up @@ -112,26 +112,26 @@ end

function ModalWindow:addChoice(text, callback)
if type(text) ~= "string" then
io.write("ModalWindow:addChoice: text must be a string.")
io.write("ModalWindow:addChoice: text must be a string.\n")
text = tostring(text)
end

local id = #self.choices + 1
local choice = { id = id, text = text, callback = callback }
self.choices[id] = choice
self.choices[text] = choice
return true
return choice
end

function ModalWindow:removeChoice(text)
if type(text) ~= "string" then
io.write("ModalWindow:removeChoice: text must be a string.")
io.write("ModalWindow:removeChoice: text must be a string.\n")
text = tostring(text)
end

local choice = self.choices[text]
if not choice then
io.write("ModalWindow: Choice with text '" .. text .. "' does not exist.")
io.write("ModalWindow: Choice with text '" .. text .. "' does not exist.\n")
return false
end

Expand All @@ -142,18 +142,18 @@ end

function ModalWindow:callChoice(text, player, button, choice)
if type(text) ~= "string" then
io.write("ModalWindow:callChoice: text must be a string.")
io.write("ModalWindow:callChoice: text must be a string.\n")
text = tostring(text)
end

local choice = self.choices[text]
if not choice then
io.write("ModalWindow: Choice with text '" .. text .. "' does not exist.")
io.write("ModalWindow: Choice with text '" .. text .. "' does not exist.\n")
return false
end

if not choice.callback then
io.write("ModalWindow: Choice with text '" .. text .. "' has no callback.")
io.write("ModalWindow: Choice with text '" .. text .. "' has no callback.\n")
return false
end
return choice.callback(player, button, choice)
Expand Down
Loading