From 208a3e4ae8b94730c2f4e506aae85fad84b76e21 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 15 Mar 2023 01:19:34 -0700 Subject: [PATCH] add minimize/restore button --- docs/changelog.txt | 1 + plugins/lua/buildingplan/planneroverlay.lua | 25 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index e4588e328..0b313c951 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -43,6 +43,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: -@ `buildingplan`: remember choice per building type for whether the player wants to choose specific items -@ `buildingplan`: you can now attach multiple weapons to spike traps -@ `buildingplan`: can now filter by whether a slab is engraved +-@ `buildingplan`: add "minimize" button to temporarily get the planner overlay out of the way if you would rather use the vanilla UI for placing the current building - `blueprint`: now writes blueprints to the ``dfhack-config/blueprints`` directory - `blueprint-library-guide`: library blueprints have moved from ``blueprints`` to ``hack/data/blueprints`` - player-created blueprints should now go in the ``dfhack-config/blueprints`` folder. please move your existing blueprints from ``blueprints`` to ``dfhack-config/blueprints``. you don't need to move the library blueprints -- those can be safely deleted from the old ``blueprints`` directory. diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index df49fe287..255611178 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -260,12 +260,17 @@ PlannerOverlay.ATTRS{ function PlannerOverlay:init() self.selected = 1 + self.minimized = false + + local function is_minimized() return self.minimized end + local function not_is_minimized() return not self.minimized end local main_panel = widgets.Panel{ view_id='main', frame={t=0, l=0, r=0, h=14}, frame_style=gui.MEDIUM_FRAME, frame_background=gui.CLEAR_PEN, + visible=function() return not self.minimized end, } local function make_is_selected_fn(idx) @@ -451,6 +456,7 @@ function PlannerOverlay:init() frame={t=14, l=0, r=0}, frame_style=gui.MEDIUM_FRAME, frame_background=gui.CLEAR_PEN, + visible=function() return not self.minimized end, } error_panel:addviews{ @@ -565,11 +571,16 @@ function PlannerOverlay:onInput(keys) return true end self.selected = 1 + self.minimized = false self.subviews.hollow:setOption(false) self:reset() reset_counts_flag = true return false end + if keys.CUSTOM_ALT_M then + self.minimized = not self.minimized + return true + end if PlannerOverlay.super.onInput(self, keys) then return true end @@ -579,10 +590,15 @@ function PlannerOverlay:onInput(keys) detect_rect.height = self.subviews.main.frame_rect.height + self.subviews.errors.frame_rect.height detect_rect.y2 = detect_rect.y1 + detect_rect.height - 1 - if self.subviews.main:getMousePos(gui.ViewRect{rect=detect_rect}) - or self.subviews.errors:getMousePos() then - return true + local x, y = self.subviews.main:getMousePos(gui.ViewRect{rect=detect_rect}) + if x or self.subviews.errors:getMousePos() then + if x and x == detect_rect.width-2 and y == 0 then + self.minimized = not self.minimized + return true + end + return not self.minimized end + if self.minimized then return false end if not is_construction() and #uibs.errors > 0 then return true end if dfhack.gui.getMousePos() then if is_choosing_area() or cur_building_has_no_area() then @@ -642,6 +658,9 @@ function PlannerOverlay:render(dc) if not is_plannable() then return end self.subviews.errors:updateLayout() PlannerOverlay.super.render(self, dc) + -- render "minimize" button + dc:seek(self.frame_rect.x2-1, self.frame_rect.y1) + dc:char(string.char(self.minimized and 31 or 30), COLOR_RED) end local ONE_BY_ONE = xy2pos(1, 1)