Skip to content

Commit

Permalink
Bunch of small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahicks92 committed Feb 18, 2025
1 parent ee79129 commit 26ee4b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 6 additions & 1 deletion scripts/ui/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Tell the menu itself to do things from click handlers etc.
]]
---@class fa.MenuController
---@field close fun(self)
---@field close_because_textbox fun(self) Temporary hopefully.

---@class fa.MenuCtx
---@field pindex number
Expand Down Expand Up @@ -231,6 +232,11 @@ function mod.declare_menu(opts)
ctx.force_close = true
end

function controller:close_because_textbox()
ctx.force_close = true
ctx.close_is_textbox = true
end

return {
pindex = ctx.pindex,
message = ctx.message,
Expand All @@ -256,7 +262,6 @@ function mod.declare_menu(opts)

---@param ctx fa.MenuTabCtxInternal
function menu_callbacks:on_tab_list_opened(ctx)
print("Opened menu")
ctx.state = {
item_states = {},
prev_items = {},
Expand Down
11 changes: 5 additions & 6 deletions scripts/ui/menus/blueprints-menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ local function render(ctx)
storage.players[ctx.pindex].blueprint_menu.edit_label = true
Graphics.create_text_field_frame(ctx.pindex, "blueprint-edit-label")
ctx.message:fragment({ "fa.ui-blueprints-rename-txtbox" })
ctx.controller:close()
ctx.controller:close_because_textbox()
end)
)

Expand All @@ -130,7 +130,7 @@ local function render(ctx)
storage.players[ctx.pindex].blueprint_menu.edit_description = true
Graphics.create_text_field_frame(ctx.pindex, "blueprint-edit-description")
ctx.message:fragment({ "fa.ui-blueprints-description-txtbox" })
ctx.controller:close()
ctx.controller:close_because_textbox()
end)
)

Expand Down Expand Up @@ -158,8 +158,7 @@ local function render(ctx)
if not p then return end

bp.set_stack({ name = "blueprint", count = 1 })
bp.set_stack(nil) --calls event handler to delete empty planners. ctx.controller:close()

bp.set_stack(nil) --calls event handler to delete empty planners.
ctx.message:fragment({ "fa.blueprints-ui-deleted" })
ctx.controller:close()
end)
Expand All @@ -171,7 +170,7 @@ local function render(ctx)
storage.players[ctx.pindex].blueprint_menu.edit_export = true
Graphics.create_text_field_frame(ctx.pindex, "blueprint-edit-export", bp.export_stack())
ctx.message:fragment({ "fa.ui-blueprints-export-txtbox" })
ctx.controller:close()
ctx.controller:close_because_textbox()
end)
)
end
Expand All @@ -184,7 +183,7 @@ local function render(ctx)
storage.players[pindex].blueprint_menu.edit_import = true
Graphics.create_text_field_frame(pindex, "blueprint-edit-import")
ctx.message:fragment({ "fa.ui-blueprints-import-txtbox" })
ctx.controller:close()
ctx.controller:close_because_textbox()
end)
)

Expand Down
14 changes: 10 additions & 4 deletions scripts/ui/tab-list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ local mod = {}
---@field shared_state table
---@field parameters table Whatever was passed to :open()
---@field force_close boolean If true, close this tablist.
---@field close_is_textbox boolean? If true, leave menu_name alone so that textboxes can tail call.
---@field message fa.MessageBuilder

---@alias fa.ui.SimpleTabHandler fun(self, fa.ui.TabContext)
Expand Down Expand Up @@ -133,7 +134,7 @@ function TabList:_do_callback(pindex, target_tab_index, cb_name, msg_builder, pa
-- Makes assigning to state when initializing etc. work.
tl.tab_states[tabname] = context.state

if context.force_close then self:close(true) end
if context.force_close then self:close(pindex, true, context.close_is_textbox) end
end

local msg = msg_builder:build()
Expand Down Expand Up @@ -200,6 +201,7 @@ function TabList:on_previous_tab(pindex)
end

function TabList:open(pindex, parameters)
assert(self.menu_name)
storage.players[pindex].menu = self.menu_name
storage.players[pindex].in_menu = true

Expand Down Expand Up @@ -237,7 +239,7 @@ function TabList:open(pindex, parameters)
end

---@param force_reset boolean? If true, also dump state.
function TabList:close(pindex, force_reset)
function TabList:close(pindex, force_reset, is_textbox)
-- Our lame event handling story where more than one event handler can get
-- called for the same event combined with the new GUI framework still being
-- WIP means that double-close is apparently possible. We already know we're
Expand All @@ -254,8 +256,12 @@ function TabList:close(pindex, force_reset)

if force_reset then tablist_storage[pindex][self.menu_name] = nil end

storage.players[pindex].menu = nil
storage.players[pindex].in_menu = false
-- Textboxes rely on still being "in the menu" for the duration of the
-- textbox and we aren't far enough along to have hacked that yet.
if not is_textbox then
storage.players[pindex].menu = nil
storage.players[pindex].in_menu = false
end
end

---@param declaration fa.ui.TabListDeclaration
Expand Down

0 comments on commit 26ee4b8

Please sign in to comment.