diff --git a/game/engines/default/engine/ui/Dialog.lua b/game/engines/default/engine/ui/Dialog.lua index 9e9d01e1174075fd8c645ae60ebcc9d53de695e4..974b8d2a819eb1d9b7293aa3597749861646ea44 100644 --- a/game/engines/default/engine/ui/Dialog.lua +++ b/game/engines/default/engine/ui/Dialog.lua @@ -145,14 +145,14 @@ function _M:simpleLongPopup(title, text, w, fct, no_leave, force_height) end --- Requests a simple yes-no dialog -function _M:yesnoPopup(title, text, fct, yes_text, no_text, no_leave, escape) +function _M:yesnoPopup(title, text, fct, yes_text, no_text, no_leave, escape, preexit_fct) local w, h = self.font:size(text) local d = new(title, 1, 1) -- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end) - local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true) end} - local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false) end} - if not no_leave then d.key:addBind("EXIT", function() game:unregisterDialog(d) game:unregisterDialog(d) fct(escape) end) end + local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() if preexit_fct then preexit_fct(true) end game:unregisterDialog(d) fct(true) end} + local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() if preexit_fct then preexit_fct(false) end game:unregisterDialog(d) fct(false) end} + if not no_leave then d.key:addBind("EXIT", function() if preexit_fct then preexit_fct(escape) end game:unregisterDialog(d) fct(escape) end) end d:loadUI{ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w+20, height=h+5, text=text}}, {left = 3, bottom = 3, ui=ok}, @@ -166,17 +166,17 @@ function _M:yesnoPopup(title, text, fct, yes_text, no_text, no_leave, escape) end --- Requests a long yes-no dialog -function _M:yesnoLongPopup(title, text, w, fct, yes_text, no_text, no_leave, escape) +function _M:yesnoLongPopup(title, text, w, fct, yes_text, no_text, no_leave, escape, preexit_fct) local d - local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true) end} - local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false) end} + local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() if preexit_fct then preexit_fct(true) end game:unregisterDialog(d) fct(true) end} + local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() if preexit_fct then preexit_fct(false) end game:unregisterDialog(d) fct(false) end} w = math.max(w + 20, ok.w + cancel.w + 10) d = new(title, w + 6, 1) -- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end) - if not no_leave then d.key:addBind("EXIT", function() game:unregisterDialog(d) game:unregisterDialog(d) fct(escape) end) end + if not no_leave then d.key:addBind("EXIT", function() if preexit_fct then preexit_fct(escape) end game:unregisterDialog(d) fct(escape) end) end d:loadUI{ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w, auto_height = true, text=text}}, {left = 3, bottom = 3, ui=ok}, @@ -190,15 +190,15 @@ function _M:yesnoLongPopup(title, text, w, fct, yes_text, no_text, no_leave, esc end --- Requests a simple yes-no dialog -function _M:yesnocancelPopup(title, text, fct, yes_text, no_text, cancel_text, no_leave, escape) +function _M:yesnocancelPopup(title, text, fct, yes_text, no_text, cancel_text, no_leave, escape, preexit_fct) local w, h = self.font:size(text) local d = new(title, 1, 1) -- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end) - local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true, false) end} - local no = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false, false) end} - local cancel = require("engine.ui.Button").new{text=cancel_text or "Cancel", fct=function() game:unregisterDialog(d) fct(false, true) end} - if not no_leave then d.key:addBind("EXIT", function() game:unregisterDialog(d) game:unregisterDialog(d) fct(false, not escape) end) end + local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() if preexit_fct then preexit_fct(true, false) end game:unregisterDialog(d) fct(true, false) end} + local no = require("engine.ui.Button").new{text=no_text or "No", fct=function() if preexit_fct then preexit_fct(false, false) end game:unregisterDialog(d) fct(false, false) end} + local cancel = require("engine.ui.Button").new{text=cancel_text or "Cancel", fct=function() if preexit_fct then preexit_fct(false, true) end game:unregisterDialog(d) fct(false, true) end} + if not no_leave then d.key:addBind("EXIT", function() if preexit_fct then preexit_fct(false, not escape) end game:unregisterDialog(d) fct(false, not escape) end) end d:loadUI{ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w+20, height=h + 5, text=text}}, {left = 3, bottom = 3, ui=ok}, @@ -213,14 +213,14 @@ function _M:yesnocancelPopup(title, text, fct, yes_text, no_text, cancel_text, n end --- Requests a simple yes-no dialog -function _M:yesnocancelLongPopup(title, text, w, fct, yes_text, no_text, cancel_text, no_leave, escape) +function _M:yesnocancelLongPopup(title, text, w, fct, yes_text, no_text, cancel_text, no_leave, escape, preexit_fct) local d = new(title, 1, 1) -- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end) - local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true, false) end} - local no = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false, false) end} - local cancel = require("engine.ui.Button").new{text=cancel_text or "Cancel", fct=function() game:unregisterDialog(d) fct(false, true) end} - if not no_leave then d.key:addBind("EXIT", function() game:unregisterDialog(d) game:unregisterDialog(d) fct(false, not escape) end) end + local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() if preexit_fct then preexit_fct(true, false) end game:unregisterDialog(d) fct(true, false) end} + local no = require("engine.ui.Button").new{text=no_text or "No", fct=function() if preexit_fct then preexit_fct(false, false) end game:unregisterDialog(d) fct(false, false) end} + local cancel = require("engine.ui.Button").new{text=cancel_text or "Cancel", fct=function() if preexit_fct then preexit_fct(false, true) end game:unregisterDialog(d) fct(false, true) end} + if not no_leave then d.key:addBind("EXIT", function() game:unregisterDialog(d) if preexit_fct then preexit_fct(false, not escape) end game:unregisterDialog(d) fct(false, not escape) end) end d:loadUI{ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w+20, auto_height=true, text=text}}, {left = 3, bottom = 3, ui=ok}, diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua index ed6458e432c78578201b8d41d2d5220248c48e09..03ca019e9372ab51f28e2c8537792af277f49bc1 100644 --- a/game/engines/default/engine/utils.lua +++ b/game/engines/default/engine/utils.lua @@ -308,6 +308,11 @@ function table.from_list(t, k, v) return tt end +function table.hasInList(t, v) + for i = #t, 1, -1 do if t[i] == v then return true end end + return false +end + function table.removeFromList(t, ...) for _, v in ipairs{...} do for i = #t, 1, -1 do if t[i] == v then table.remove(t, i) end end diff --git a/game/modules/tome/dialogs/Birther.lua b/game/modules/tome/dialogs/Birther.lua index 9aa40c94e5e50be2e77260c1cb95766551c1e250..b25642ce905166c2980ddb380e0f865ba51eda3b 100644 --- a/game/modules/tome/dialogs/Birther.lua +++ b/game/modules/tome/dialogs/Birther.lua @@ -330,8 +330,8 @@ end --- Make a default character when using cheat mode, for easier testing function _M:makeDefault() self:setDescriptor("sex", "Female") - -- self:setDescriptor("world", "Maj'Eyal") - self:setDescriptor("world", "Infinite") + self:setDescriptor("world", "Maj'Eyal") + -- self:setDescriptor("world", "Infinite") self:setDescriptor("difficulty", "Normal") self:setDescriptor("permadeath", "Adventure") self:setDescriptor("race", "Human") diff --git a/game/modules/tome/dialogs/LevelupDialog.lua b/game/modules/tome/dialogs/LevelupDialog.lua index 3371a3a115e08bd79b0c3c3db2fabdb27dfd4530..0ac7cb170738f85750028c8d663bb781bcf7ed07 100644 --- a/game/modules/tome/dialogs/LevelupDialog.lua +++ b/game/modules/tome/dialogs/LevelupDialog.lua @@ -214,7 +214,7 @@ function _M:finish() local lvl_raw = self.actor:getTalentLevelRaw(t_id) local old_lvl = self.actor_dup:getTalentLevel(t_id) local old_lvl_raw = self.actor_dup:getTalentLevelRaw(t_id) - t.on_levelup_close(self, t, lvl, old_lvl, lvl_raw, old_lvl_raw, true) + t.on_levelup_close(self.actor, t, lvl, old_lvl, lvl_raw, old_lvl_raw, true) end end return true