From 24757e8cca3d5c87806d6bf18674a672e0388550 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Thu, 12 Mar 2026 00:38:28 +0100 Subject: [PATCH] end window WIP --- impostor.inc | 2 + inc/decision/decision.go_to_end.lua | 7 +++ inc/decision/decision.manager.lua | 6 +-- inc/init/init.context.lua | 4 ++ inc/init/init.module.lua | 2 +- inc/screen/screen.home.lua | 1 + inc/window/window.end.lua | 77 +++++++++++++++++++++++++++++ inc/window/window.register.lua | 3 ++ 8 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 inc/decision/decision.go_to_end.lua create mode 100644 inc/window/window.end.lua diff --git a/impostor.inc b/impostor.inc index ae7dac2..d3e0332 100644 --- a/impostor.inc +++ b/impostor.inc @@ -24,6 +24,7 @@ decision/decision.go_to_home.lua decision/decision.go_to_toilet.lua decision/decision.go_to_walking_to_office.lua decision/decision.go_to_office.lua +decision/decision.go_to_end.lua decision/decision.go_to_walking_to_home.lua decision/decision.go_to_sleep.lua decision/decision.do_work.lua @@ -40,6 +41,7 @@ screen/screen.walking_to_home.lua screen/screen.work.lua window/window.manager.lua window/window.register.lua +window/window.end.lua window/window.splash.lua window/window.intro.lua window/window.menu.lua diff --git a/inc/decision/decision.go_to_end.lua b/inc/decision/decision.go_to_end.lua new file mode 100644 index 0000000..9e59099 --- /dev/null +++ b/inc/decision/decision.go_to_end.lua @@ -0,0 +1,7 @@ +Decision.register({ + id = "go_to_end", + label = "Break the cycle", + handle = function() + Window.set_current("end") + end, +}) diff --git a/inc/decision/decision.manager.lua b/inc/decision/decision.manager.lua index 1aeaf1c..330a1d9 100644 --- a/inc/decision/decision.manager.lua +++ b/inc/decision/decision.manager.lua @@ -10,11 +10,11 @@ local _decisions = {} --- @param[opt] decision.handle function Called when the decision is selected. Defaults to noop. function Decision.register(decision) if not decision or not decision.id then - PopupWindow.show({"Error: Invalid decision object registered (missing id)!"}) + trace("Error: Invalid decision object registered (missing id)!") return end if not decision.label then - PopupWindow.show({"Error: Invalid decision object registered (missing label)!"}) + trace("Error: Invalid decision object registered (missing label)!") return end @@ -92,7 +92,7 @@ end function Decision.filter_available(decisions_list) local available = {} for _, decision in ipairs(decisions_list) do - if decision and decision.condition() then + if decision and (not decision.condition or decision.condition()) then table.insert(available, decision) end end diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 7434246..e282b50 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -42,6 +42,10 @@ function Context.initial_data() current_situation = nil, }, day_count = 1, + _end = { + state = "choice", + selection = 1, + }, } end diff --git a/inc/init/init.module.lua b/inc/init/init.module.lua index a1b9759..3a9654b 100644 --- a/inc/init/init.module.lua +++ b/inc/init/init.module.lua @@ -14,4 +14,4 @@ Audio = {} Focus = {} Day = {} Timer = {} -Trigger = {} \ No newline at end of file +Trigger = {} diff --git a/inc/screen/screen.home.lua b/inc/screen/screen.home.lua index 56048b5..e5104ea 100644 --- a/inc/screen/screen.home.lua +++ b/inc/screen/screen.home.lua @@ -5,6 +5,7 @@ Screen.register({ "go_to_toilet", "go_to_walking_to_office", "go_to_sleep", + "go_to_end", }, background = "bedroom" }) diff --git a/inc/window/window.end.lua b/inc/window/window.end.lua new file mode 100644 index 0000000..fb4cfa1 --- /dev/null +++ b/inc/window/window.end.lua @@ -0,0 +1,77 @@ +EndWindow = {} + +--- Draws the end screen window. +--- @within EndWindow +function EndWindow.draw() + cls(Config.colors.black) + + if Context._end.state == "choice" then + local lines = { + "This is not a workplace.", + "This is a cycle.", + "And if it is a cycle...", + "it can be broken." + } + + local y = 40 + for _, line in ipairs(lines) do + Print.text_center(line, Config.screen.width / 2, y, Config.colors.white) + y = y + 10 + end + + y = y + 20 + local yes_color = Context._end.selection == 1 and Config.colors.light_blue or Config.colors.white + local no_color = Context._end.selection == 2 and Config.colors.light_blue or Config.colors.white + + local yes_text = (Context._end.selection == 1 and "> YES" or " YES") + local no_text = (Context._end.selection == 2 and "> NO" or " NO") + + local centerX = Config.screen.width / 2 + Print.text(yes_text, centerX - 40, y, yes_color) + Print.text(no_text, centerX + 10, y, no_color) + elseif Context._end.state == "ending" then + Print.text_center("Game over -- good ending.", Config.screen.width / 2, 50, Config.colors.light_blue) + Print.text_center("Congratulations!", Config.screen.width / 2, 70, Config.colors.white) + Print.text_center("Press Z to return to menu", Config.screen.width / 2, 110, Config.colors.light_grey) + end +end + +--- Updates the end screen logic. +--- @within EndWindow +function EndWindow.update() + if Context._end.state == "choice" then + if Input.left() or Input.up() then + if Context._end.selection == 2 then + Audio.sfx_beep() + Context._end.selection = 1 + end + elseif Input.right() or Input.down() then + if Context._end.selection == 1 then + Audio.sfx_beep() + Context._end.selection = 2 + end + end + + if Input.menu_confirm() then + Audio.sfx_select() + if Context._end.selection == 1 then + Context._end.state = "ending" + else + -- NO: increment day and go home + Day.increase() + Context.game.current_screen = "home" + Window.set_current("game") + -- Initialize home screen + local home_screen = Screen.get_by_id("home") + if home_screen and home_screen.init then + home_screen.init() + end + end + end + elseif Context._end.state == "ending" then + if Input.menu_confirm() then + Window.set_current("menu") + MenuWindow.refresh_menu_items() + end + end +end diff --git a/inc/window/window.register.lua b/inc/window/window.register.lua index a49db0d..d9f82b2 100644 --- a/inc/window/window.register.lua +++ b/inc/window/window.register.lua @@ -30,3 +30,6 @@ Window.register("minigame_ddr", MinigameDDRWindow) MysteriousManWindow = {} Window.register("mysterious_man", MysteriousManWindow) + +EndWindow = {} +Window.register("end", EndWindow)