diff --git a/data/dfhack-config/buildingplan.json b/data/dfhack-config/buildingplan.json new file mode 100644 index 000000000..9bb3052b7 --- /dev/null +++ b/data/dfhack-config/buildingplan.json @@ -0,0 +1,5 @@ +{ + "planner": { + "minimized": true + } +} \ No newline at end of file diff --git a/docs/changelog.txt b/docs/changelog.txt index 4794122f6..b53717dd0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,7 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes ## Misc Improvements -- `buildingplan`: minimized planner panel stays minimized until you change it again +- `buildingplan`: planner panel is minimized by default and now remembers minimized state - `buildingplan`: can now filter by gems (for gem windows) - ``toggle-kbd-cursor``: add hotkey for toggling the keyboard cursor (Alt-K) - `gui/control-panel`: add preference option for hiding the terminal console on startup diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index 8f12c695f..83a58ebd8 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -4,12 +4,15 @@ local itemselection = require('plugins.buildingplan.itemselection') local filterselection = require('plugins.buildingplan.filterselection') local gui = require('gui') local guidm = require('gui.dwarfmode') +local json = require('json') local overlay = require('plugins.overlay') local pens = require('plugins.buildingplan.pens') local utils = require('utils') local widgets = require('gui.widgets') require('dfhack.buildings') +config = config or json.open('dfhack-config/buildingplan.json') + local uibs = df.global.buildreq reset_counts_flag = false @@ -336,14 +339,14 @@ PlannerOverlay.ATTRS{ function PlannerOverlay:init() self.selected = 1 - self.minimized = false + self.state = ensure_key(config.data, 'planner') local main_panel = widgets.Panel{ view_id='main', frame={t=1, l=0, r=0, h=14}, frame_style=gui.INTERIOR_MEDIUM_FRAME, frame_background=gui.CLEAR_PEN, - visible=function() return not self.minimized end, + visible=self:callback('is_not_minimized'), } local minimized_panel = widgets.Panel{ @@ -355,8 +358,8 @@ function PlannerOverlay:init() {text=' show Planner ', pen=pens.MINI_TEXT_PEN, hpen=pens.MINI_TEXT_HPEN}, {text='['..string.char(31)..']', pen=pens.MINI_BUTT_PEN, hpen=pens.MINI_BUTT_HPEN}, }, - visible=function() return self.minimized end, - on_click=function() self.minimized = not self.minimized end, + visible=self:callback('is_minimized'), + on_click=self:callback('toggle_minimized'), }, widgets.Label{ frame={t=0, r=0, h=1}, @@ -364,8 +367,8 @@ function PlannerOverlay:init() {text=' hide Planner ', pen=pens.MINI_TEXT_PEN, hpen=pens.MINI_TEXT_HPEN}, {text='['..string.char(30)..']', pen=pens.MINI_BUTT_PEN, hpen=pens.MINI_BUTT_HPEN}, }, - visible=function() return not self.minimized end, - on_click=function() self.minimized = not self.minimized end, + visible=self:callback('is_not_minimized'), + on_click=self:callback('toggle_minimized'), }, }, } @@ -554,7 +557,7 @@ function PlannerOverlay:init() view_id='divider', frame={t=10, l=0, r=0, h=1}, on_render=self:callback('draw_divider_h'), - visible=function() return not self.minimized end, + visible=self:callback('is_not_minimized'), } local error_panel = widgets.ResizingPanel{ @@ -562,7 +565,7 @@ function PlannerOverlay:init() frame={t=15, l=0, r=0}, frame_style=gui.BOLD_FRAME, frame_background=gui.CLEAR_PEN, - visible=function() return not self.minimized end, + visible=self:callback('is_not_minimized'), } error_panel:addviews{ @@ -609,7 +612,7 @@ function PlannerOverlay:init() frame={t=0, l=1, w=37, h=1}, frame_inset=0, frame_background=gui.CLEAR_PEN, - visible=function() return not self.minimized end, + visible=self:callback('is_not_minimized'), subviews={ prev_next_selector, }, @@ -624,6 +627,19 @@ function PlannerOverlay:init() } end +function PlannerOverlay:is_minimized() + return self.state.minimized +end + +function PlannerOverlay:is_not_minimized() + return not self.state.minimized +end + +function PlannerOverlay:toggle_minimized() + self.state.minimized = not self.state.minimized + config:write() +end + function PlannerOverlay:draw_divider_h(dc) local x2 = dc.width -1 for x=0,x2 do @@ -735,13 +751,13 @@ function PlannerOverlay:onInput(keys) return false end if keys.CUSTOM_ALT_M then - self.minimized = not self.minimized + self:toggle_minimized() return true end if PlannerOverlay.super.onInput(self, keys) then return true end - if self.minimized then return false end + if self:is_minimized() then return false end if keys._MOUSE_L_DOWN then if is_over_options_panel() then return false end local detect_rect = copyall(self.frame_rect) @@ -837,7 +853,7 @@ function PlannerOverlay:onRenderFrame(dc, rect) uibs.building_type, uibs.building_subtype, uibs.custom_type)) end - if self.minimized then return end + if self:is_minimized() then return end local bounds = get_selected_bounds(self.saved_selection_pos, self.saved_pos) if not bounds then return end