From 5e7d81c2bc8baa650c45f9554003605b6f75b6e6 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 12 Mar 2023 13:58:03 +0100 Subject: [PATCH 01/25] add biomes.lua --- gui/biomes.lua | 213 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 gui/biomes.lua diff --git a/gui/biomes.lua b/gui/biomes.lua new file mode 100644 index 0000000000..2199a2d617 --- /dev/null +++ b/gui/biomes.lua @@ -0,0 +1,213 @@ +-- Show biomes on the map. + +local gui = require('gui') +local widgets = require('gui.widgets') +local guidm = require('gui.dwarfmode') + +local biomeTypeNames = { + MOUNTAIN = "Mountain", + GLACIER = "Glacier", + TUNDRA = "Tundra", + SWAMP_TEMPERATE_FRESHWATER = "Temperate Freshwater Swamp", + SWAMP_TEMPERATE_SALTWATER = "Temperate Saltwater Swamp", + MARSH_TEMPERATE_FRESHWATER = "Temperate Freshwater Marsh", + MARSH_TEMPERATE_SALTWATER = "Temperate Saltwater Marsh", + SWAMP_TROPICAL_FRESHWATER = "Tropical Freshwater Swamp", + SWAMP_TROPICAL_SALTWATER = "Tropical Saltwater Swamp", + SWAMP_MANGROVE = "Mangrove Swamp", + MARSH_TROPICAL_FRESHWATER = "Tropical Freshwater Marsh", + MARSH_TROPICAL_SALTWATER = "Tropical Saltwater Marsh", + FOREST_TAIGA = "Taiga Forest", + FOREST_TEMPERATE_CONIFER = "Temperate Conifer Forest", + FOREST_TEMPERATE_BROADLEAF = "Temperate Broadleaf Forest", + FOREST_TROPICAL_CONIFER = "Tropical Conifer Forest", + FOREST_TROPICAL_DRY_BROADLEAF = "Tropical Dry Broadleaf Forest", + FOREST_TROPICAL_MOIST_BROADLEAF = "Tropical Moist Broadleaf Forest", + GRASSLAND_TEMPERATE = "Temperate Grassland", + SAVANNA_TEMPERATE = "Temperate Savanna", + SHRUBLAND_TEMPERATE = "Temperate Shrubland", + GRASSLAND_TROPICAL = "Tropical Grassland", + SAVANNA_TROPICAL = "Tropical Savanna", + SHRUBLAND_TROPICAL = "Tropical Shrubland", + DESERT_BADLAND = "Badland Desert", + DESERT_ROCK = "Rock Desert", + DESERT_SAND = "Sand Desert", + OCEAN_TROPICAL = "Tropical Ocean", + OCEAN_TEMPERATE = "Temperate Ocean", + OCEAN_ARCTIC = "Arctic Ocean", + POOL_TEMPERATE_FRESHWATER = "Temperate Freshwater Pool", + POOL_TEMPERATE_BRACKISHWATER = "Temperate Brackishwater Pool", + POOL_TEMPERATE_SALTWATER = "Temperate Saltwater Pool", + POOL_TROPICAL_FRESHWATER = "Tropical Freshwater Pool", + POOL_TROPICAL_BRACKISHWATER = "Tropical Brackishwater Pool", + POOL_TROPICAL_SALTWATER = "Tropical Saltwater Pool", + LAKE_TEMPERATE_FRESHWATER = "Temperate Freshwater Lake", + LAKE_TEMPERATE_BRACKISHWATER = "Temperate Brackishwater Lake", + LAKE_TEMPERATE_SALTWATER = "Temperate Saltwater Lake", + LAKE_TROPICAL_FRESHWATER = "Tropical Freshwater Lake", + LAKE_TROPICAL_BRACKISHWATER = "Tropical Brackishwater Lake", + LAKE_TROPICAL_SALTWATER = "Tropical Saltwater Lake", + RIVER_TEMPERATE_FRESHWATER = "Temperate Freshwater River", + RIVER_TEMPERATE_BRACKISHWATER = "Temperate Brackishwater River", + RIVER_TEMPERATE_SALTWATER = "Temperate Saltwater River", + RIVER_TROPICAL_FRESHWATER = "Tropical Freshwater River", + RIVER_TROPICAL_BRACKISHWATER = "Tropical Brackishwater River", + RIVER_TROPICAL_SALTWATER = "Tropical Saltwater River", + SUBTERRANEAN_WATER = "Subterranean Water", + SUBTERRANEAN_CHASM = "Subterranean Chasm", + SUBTERRANEAN_LAVA = "Subterranean Lava", +} + +local function find(t, predicate) + for k, item in pairs(t) do + if predicate(k, item) then + return k, item + end + end + return nil +end + +local biomesMap = {} +local biomeList = {} +local function gatherBiomeInfo() + local maxX, maxY, maxZ = dfhack.maps.getTileSize() + maxX = maxX - 1; maxY = maxY - 1; maxZ = maxZ - 1 + + local z = df.global.window_z + + for y = 0, maxY do + for x = 0, maxX do + local rgnX, rgnY = dfhack.maps.getTileBiomeRgn(x,y,z) + local biomeTypeId = dfhack.maps.getBiomeType(rgnX, rgnY) + local biome = dfhack.maps.getRegionBiome(rgnX, rgnY) + + local biomesZ = biomesMap[z] + if not biomesZ then + biomesZ = {} + biomesMap[z] = biomesZ + end + local biomesZY = biomesZ[y] + if not biomesZY then + biomesZY = {} + biomesZ[y] = biomesZY + end + + local function currentBiome(_, item) + return item.biome == biome + end + local ix = find(biomeList, currentBiome) + if not ix then + local ch = string.char(string.byte('a') + #biomeList) + table.insert(biomeList, {biome = biome, char = ch, typeId = biomeTypeId}) + ix = #biomeList + end + + biomesZY[x] = ix + end + end +end + +gatherBiomeInfo() + +local TITLE = "Biomes" + +BiomeVisualizerLegend = nil -- for debugging purposes +BiomeVisualizerLegend = defclass(BiomeVisualizerLegend, widgets.Window) +BiomeVisualizerLegend.ATTRS { + frame_title=TITLE, + frame_inset=0, + resizable=true, + autoarrange_subviews = true, + autoarrange_gap = 1, + frame = { + w = 47, + h = 10, + l = 5, + t = 8, + }, +} + +local function GetBiomeName(biome, biomeTypeId) + -- based on probe.cpp + local sav = biome.savagery + local evi = biome.evilness; + local sindex = sav > 65 and 2 or sav < 33 and 0 or 1 + local eindex = evi > 65 and 2 or evi < 33 and 0 or 1 + local surr = sindex + eindex * 3 +1; --in Lua arrays are 1-based + + local surroundings = { + "Serene", "Mirthful", "Joyous Wilds", + "Calm", "Wilderness", "Untamed Wilds", + "Sinister", "Haunted", "Terrifying" + } + local surrounding = surroundings[surr] + + local name = biomeTypeNames[df.biome_type[biomeTypeId]] or "DFHACK_Unknown" + + return ([[%s %s]]):format(surrounding, name) +end + +function BiomeVisualizerLegend:init() + self:addviews{ + widgets.List{ + view_id = 'list', + frame = { t = 0 }, + text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, + --cursor_pen = { fg = COLOR_BLACK, bg = COLOR_GREEN }, + --on_select = self:callback('onSelectEntry'), + }, + } + + local choices = {} + for _, biomeExt in ipairs(biomeList) do + table.insert(choices, { + text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), + biomeTypeId = biomeExt.typeId, + }) + end + self.subviews.list:setChoices(choices) +end + +BiomeVisualizer = defclass(BiomeVisualizer, gui.ZScreen) +BiomeVisualizer.ATTRS{ + focus_path='BiomeVisualizer', +} + +local function getMapViewBounds() + local dims = dfhack.gui.getDwarfmodeViewDims() + local x = df.global.window_x + local y = df.global.window_y + return {x1 = dims.map_x1 + x, + y1 = dims.map_y1 + y, + x2 = dims.map_x2 + x, + y2 = dims.map_y2 + y, + } +end + +function BiomeVisualizer:init() + self:addviews{BiomeVisualizerLegend{}} +end + +function BiomeVisualizer:onRenderFrame(dc, rect) + BiomeVisualizer.super.onRenderFrame() + + local function get_overlay_pen(pos) + local safe_index = safe_index + -- 304 = `0`, 353 = `a` + local idxBaseTile = 353 + local biomes = biomesMap + + local N = safe_index(biomes, pos.z, pos.y, pos.x) + if not N then return end + return COLOR_RED, tostring(N), idxBaseTile + (N - 1) + end + local overlay_bounds = getMapViewBounds() + + guidm.renderMapOverlay(get_overlay_pen, overlay_bounds) +end + +function BiomeVisualizer:onDismiss() + view = nil +end + +view = view and view:raise() or BiomeVisualizer{}:show() From 4464035217138079cdc3b62ce3dee5878a734cd5 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 May 2023 13:50:21 +0200 Subject: [PATCH 02/25] position legend widget under minimap Few other minor changes --- gui/biomes.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 2199a2d617..be88a04d7d 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -117,13 +117,14 @@ BiomeVisualizerLegend.ATTRS { frame_title=TITLE, frame_inset=0, resizable=true, + resize_min={h=5, w = 14}, autoarrange_subviews = true, autoarrange_gap = 1, frame = { w = 47, h = 10, - l = 5, - t = 8, + r = 2, + t = 18, }, } @@ -189,7 +190,7 @@ function BiomeVisualizer:init() end function BiomeVisualizer:onRenderFrame(dc, rect) - BiomeVisualizer.super.onRenderFrame() + BiomeVisualizer.super.onRenderFrame(dc, rect) local function get_overlay_pen(pos) local safe_index = safe_index @@ -201,9 +202,8 @@ function BiomeVisualizer:onRenderFrame(dc, rect) if not N then return end return COLOR_RED, tostring(N), idxBaseTile + (N - 1) end - local overlay_bounds = getMapViewBounds() - guidm.renderMapOverlay(get_overlay_pen, overlay_bounds) + guidm.renderMapOverlay(get_overlay_pen, nil) -- nil for bounds means entire viewport end function BiomeVisualizer:onDismiss() From 6c451f7c4447dc97edeed301c0c960272e5c164c Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 May 2023 17:38:45 +0200 Subject: [PATCH 03/25] update biome info when changing z-levels Other minor tweaks and an attempt at slightly improving performance via caching biome region info --- gui/biomes.lua | 63 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index be88a04d7d..c6c397d6a3 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -67,19 +67,37 @@ local function find(t, predicate) return nil end +local regionBiomeMap = {} local biomesMap = {} local biomeList = {} -local function gatherBiomeInfo() +local function gatherBiomeInfo(z) local maxX, maxY, maxZ = dfhack.maps.getTileSize() maxX = maxX - 1; maxY = maxY - 1; maxZ = maxZ - 1 - local z = df.global.window_z + local z = z or df.global.window_z + --for z = 0, maxZ do for y = 0, maxY do for x = 0, maxX do local rgnX, rgnY = dfhack.maps.getTileBiomeRgn(x,y,z) - local biomeTypeId = dfhack.maps.getBiomeType(rgnX, rgnY) - local biome = dfhack.maps.getRegionBiome(rgnX, rgnY) + if rgnX == nil then goto continue end + + local regionBiomesX = regionBiomeMap[rgnX] + if not regionBiomesX then + regionBiomesX = {} + regionBiomeMap[rgnX] = regionBiomesX + end + local regionBiomesXY = regionBiomesX[rgnY] + if not regionBiomesXY then + regionBiomesXY = { + biomeTypeId = dfhack.maps.getBiomeType(rgnX, rgnY), + biome = dfhack.maps.getRegionBiome(rgnX, rgnY), + } + regionBiomesX[rgnY] = regionBiomesXY + end + + local biomeTypeId = regionBiomesXY.biomeTypeId + local biome = regionBiomesXY.biome local biomesZ = biomesMap[z] if not biomesZ then @@ -103,8 +121,11 @@ local function gatherBiomeInfo() end biomesZY[x] = ix + + ::continue:: end end + --end end gatherBiomeInfo() @@ -155,12 +176,21 @@ function BiomeVisualizerLegend:init() frame = { t = 0 }, text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, --cursor_pen = { fg = COLOR_BLACK, bg = COLOR_GREEN }, - --on_select = self:callback('onSelectEntry'), + on_select = self:callback('onSelectEntry'), }, } - local choices = {} - for _, biomeExt in ipairs(biomeList) do + self:UpdateChoices() +end + +function BiomeVisualizerLegend:onSelectEntry(idx, option) + self.SelectedIndex = idx +end + +function BiomeVisualizerLegend:UpdateChoices() + local choices = self.subviews.list:getChoices() or {} + for i = #choices + 1, #biomeList do + local biomeExt = biomeList[i] table.insert(choices, { text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), biomeTypeId = biomeExt.typeId, @@ -186,21 +216,32 @@ local function getMapViewBounds() end function BiomeVisualizer:init() - self:addviews{BiomeVisualizerLegend{}} + self:addviews{BiomeVisualizerLegend{view_id = 'legend'}} end function BiomeVisualizer:onRenderFrame(dc, rect) BiomeVisualizer.super.onRenderFrame(dc, rect) + local z = df.global.window_z + if not biomesMap[z] then + gatherBiomeInfo(z) + self.subviews.legend:UpdateChoices() + end + local function get_overlay_pen(pos) + local self = self local safe_index = safe_index -- 304 = `0`, 353 = `a` local idxBaseTile = 353 + -- 2586 = yellow-ish indicator + local idxHighlightedTile = 2585 local biomes = biomesMap local N = safe_index(biomes, pos.z, pos.y, pos.x) if not N then return end - return COLOR_RED, tostring(N), idxBaseTile + (N - 1) + + local idxTile = (N == self.subviews.legend.SelectedIndex) and idxHighlightedTile or idxBaseTile + (N - 1) + return COLOR_RED, tostring(N), idxTile end guidm.renderMapOverlay(get_overlay_pen, nil) -- nil for bounds means entire viewport @@ -210,4 +251,8 @@ function BiomeVisualizer:onDismiss() view = nil end +if not dfhack.isMapLoaded() then + qerror('gui/biomes requires a map to be loaded') +end + view = view and view:raise() or BiomeVisualizer{}:show() From 689cc5cf54b533b6003b1d4af73967a1578cb4f4 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 May 2023 21:38:01 +0200 Subject: [PATCH 04/25] add "tooltip" --- gui/biomes.lua | 138 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 7 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index c6c397d6a3..f260542cf6 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -1,5 +1,7 @@ -- Show biomes on the map. +local RELOAD = false -- set to true to help with debugging + local gui = require('gui') local widgets = require('gui.widgets') local guidm = require('gui.dwarfmode') @@ -130,17 +132,17 @@ end gatherBiomeInfo() +-------------------------------------------------------------------------------- + local TITLE = "Biomes" -BiomeVisualizerLegend = nil -- for debugging purposes +if RELOAD then BiomeVisualizerLegend = nil end BiomeVisualizerLegend = defclass(BiomeVisualizerLegend, widgets.Window) BiomeVisualizerLegend.ATTRS { frame_title=TITLE, frame_inset=0, resizable=true, resize_min={h=5, w = 14}, - autoarrange_subviews = true, - autoarrange_gap = 1, frame = { w = 47, h = 10, @@ -174,8 +176,7 @@ function BiomeVisualizerLegend:init() widgets.List{ view_id = 'list', frame = { t = 0 }, - text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, - --cursor_pen = { fg = COLOR_BLACK, bg = COLOR_GREEN }, + text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, -- this makes selection stand out more on_select = self:callback('onSelectEntry'), }, } @@ -194,11 +195,128 @@ function BiomeVisualizerLegend:UpdateChoices() table.insert(choices, { text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), biomeTypeId = biomeExt.typeId, + biome = biomeExt.biome, }) end self.subviews.list:setChoices(choices) end +do -- implementation of onMouseHoverEntry(idx, option) + function BiomeVisualizerLegend:onRenderFrame(dc, rect) + BiomeVisualizerLegend.super.onRenderFrame(self, dc, rect) + + local list = self.subviews.list + local currentHoverIx = list:getIdxUnderMouse() + local oldIx = self.HoverIndex + if currentHoverIx ~= oldIx then + self.HoverIndex = currentHoverIx + if self.onMouseHoverEntry then + local choices = list:getChoices() + self:onMouseHoverEntry(currentHoverIx, choices[currentHoverIx]) + end + end + end +end + +local function add_field_text(lines, biome, field_name) + lines[#lines+1] = ("%s: %s"):format(field_name, biome[field_name]) + lines[#lines+1] = NEWLINE +end + +function BiomeVisualizerLegend:onMouseHoverEntry(idx, option) + if not idx then + self:ShowTooltip(nil) + return + end + + local text = {} + text[#text+1] = ("type: %s"):format(df.biome_type[option.biomeTypeId]) + text[#text+1] = NEWLINE + + local biome = option.biome + + add_field_text(text, biome, "savagery") + add_field_text(text, biome, "evilness") + table.insert(text, NEWLINE) + + add_field_text(text, biome, "elevation") + add_field_text(text, biome, "rainfall") + add_field_text(text, biome, "drainage") + add_field_text(text, biome, "vegetation") + add_field_text(text, biome, "temperature") + add_field_text(text, biome, "volcanism") + table.insert(text, NEWLINE) + + local flags = biome.flags + if flags.is_lake then + text[#text+1] = "lake" + text[#text+1] = NEWLINE + end + if flags.is_brook then + text[#text+1] = "brook" + text[#text+1] = NEWLINE + end + + self:ShowTooltip(text) +end + +function BiomeVisualizerLegend:ShowTooltip(text) + self.TooltipWindow = self.TooltipWindow or self.parent_view.subviews.legend_tooltip + self.TooltipWindow:ShowTooltip(text) +end + +-------------------------------------------------------------------------------- + +if RELOAD then TooltipWindow = nil end +TooltipWindow = defclass(TooltipWindow, widgets.Window) + +local function calc_tooltip_frame(frame) + local frame = copyall(frame) + frame.t = frame.t + frame.h + frame.h = 15 + return frame +end + +TooltipWindow.ATTRS { + visible = false, + frame_title=DEFAULT_NIL, + frame_inset=0, + resizable=false, + frame_style = gui.PANEL_FRAME, + autoarrange_subviews = true, + autoarrange_gap = 0, + frame = calc_tooltip_frame(BiomeVisualizerLegend.ATTRS.frame), + -- + parent_window = DEFAULT_NIL, +} + +function TooltipWindow:init() + self:addviews{ + widgets.Label{ + view_id = 'label', + frame = {t = 0, h = 1000}, + auto_height = false, + --wtf??? without this the label is always a single line + text={NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,} + }, + } +end + +function TooltipWindow:ShowTooltip(text) + if not text or text == "" or not self.parent_window then + self.visible = false + return + end + + local parent = self.parent_window + local lbl = self.subviews.label + lbl:setText(text) + self.visible = true +end + +-------------------------------------------------------------------------------- + +if RELOAD then BiomeVisualizer = nil end BiomeVisualizer = defclass(BiomeVisualizer, gui.ZScreen) BiomeVisualizer.ATTRS{ focus_path='BiomeVisualizer', @@ -216,11 +334,13 @@ local function getMapViewBounds() end function BiomeVisualizer:init() - self:addviews{BiomeVisualizerLegend{view_id = 'legend'}} + local legend = BiomeVisualizerLegend{view_id = 'legend'} + local legend_tooltip = TooltipWindow{view_id = 'legend_tooltip', parent_window = legend} + self:addviews{legend, legend_tooltip} end function BiomeVisualizer:onRenderFrame(dc, rect) - BiomeVisualizer.super.onRenderFrame(dc, rect) + BiomeVisualizer.super.onRenderFrame(self, dc, rect) local z = df.global.window_z if not biomesMap[z] then @@ -255,4 +375,8 @@ if not dfhack.isMapLoaded() then qerror('gui/biomes requires a map to be loaded') end +if RELOAD and view then + view:dismiss() +end + view = view and view:raise() or BiomeVisualizer{}:show() From 012eff858fd71fbb15ed02670ef7df04268b3864 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 May 2023 15:31:38 +0200 Subject: [PATCH 05/25] add selected icon, improve text mode experience --- gui/biomes.lua | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index f260542cf6..a10b73ec12 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -6,6 +6,9 @@ local gui = require('gui') local widgets = require('gui.widgets') local guidm = require('gui.dwarfmode') +local TILE_HIGHLIGHTED = 2585 -- yellow-ish indicator +local TILE_STARTING_SYMBOL = 353 -- `a` + local biomeTypeNames = { MOUNTAIN = "Mountain", GLACIER = "Glacier", @@ -176,6 +179,7 @@ function BiomeVisualizerLegend:init() widgets.List{ view_id = 'list', frame = { t = 0 }, + icon_width = 1, text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, -- this makes selection stand out more on_select = self:callback('onSelectEntry'), }, @@ -184,6 +188,19 @@ function BiomeVisualizerLegend:init() self:UpdateChoices() end +local PEN_ACTIVE_ICON = dfhack.pen.parse{tile=TILE_HIGHLIGHTED} +local PEN_NO_ICON = nil + +function BiomeVisualizerLegend:get_icon_pen_callback(ix) + return function () + if self.SelectedIndex == ix then + return PEN_ACTIVE_ICON + else + return PEN_NO_ICON + end + end +end + function BiomeVisualizerLegend:onSelectEntry(idx, option) self.SelectedIndex = idx end @@ -194,6 +211,7 @@ function BiomeVisualizerLegend:UpdateChoices() local biomeExt = biomeList[i] table.insert(choices, { text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), + icon = self:get_icon_pen_callback(#choices+1), biomeTypeId = biomeExt.typeId, biome = biomeExt.biome, }) @@ -322,17 +340,6 @@ BiomeVisualizer.ATTRS{ focus_path='BiomeVisualizer', } -local function getMapViewBounds() - local dims = dfhack.gui.getDwarfmodeViewDims() - local x = df.global.window_x - local y = df.global.window_y - return {x1 = dims.map_x1 + x, - y1 = dims.map_y1 + y, - x2 = dims.map_x2 + x, - y2 = dims.map_y2 + y, - } -end - function BiomeVisualizer:init() local legend = BiomeVisualizerLegend{view_id = 'legend'} local legend_tooltip = TooltipWindow{view_id = 'legend_tooltip', parent_window = legend} @@ -351,17 +358,20 @@ function BiomeVisualizer:onRenderFrame(dc, rect) local function get_overlay_pen(pos) local self = self local safe_index = safe_index - -- 304 = `0`, 353 = `a` - local idxBaseTile = 353 - -- 2586 = yellow-ish indicator - local idxHighlightedTile = 2585 local biomes = biomesMap local N = safe_index(biomes, pos.z, pos.y, pos.x) if not N then return end - local idxTile = (N == self.subviews.legend.SelectedIndex) and idxHighlightedTile or idxBaseTile + (N - 1) - return COLOR_RED, tostring(N), idxTile + local idxSelected = self.subviews.legend.SelectedIndex + local idxTile = (N == idxSelected) + and TILE_HIGHLIGHTED + or TILE_STARTING_SYMBOL + (N-1) + local color = (N == idxSelected) + and COLOR_CYAN + or COLOR_GREY + local ch = string.char(string.byte('a') + (N-1)) + return color, ch, idxTile end guidm.renderMapOverlay(get_overlay_pen, nil) -- nil for bounds means entire viewport From 1602ee82e682a5bb3d8f25ecf7e79b8f390dbdfb Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 May 2023 15:42:04 +0200 Subject: [PATCH 06/25] remove whitespaces --- gui/biomes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index a10b73ec12..bd252b59d8 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -86,7 +86,7 @@ local function gatherBiomeInfo(z) for x = 0, maxX do local rgnX, rgnY = dfhack.maps.getTileBiomeRgn(x,y,z) if rgnX == nil then goto continue end - + local regionBiomesX = regionBiomeMap[rgnX] if not regionBiomesX then regionBiomesX = {} From 44bf199f85606060859b8cef4b22781c512bf8b6 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 May 2023 15:43:40 +0200 Subject: [PATCH 07/25] Create biomes.rst --- doc/gui/biomes.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 doc/gui/biomes.rst diff --git a/doc/gui/biomes.rst b/doc/gui/biomes.rst new file mode 100644 index 0000000000..89a800bfb5 --- /dev/null +++ b/doc/gui/biomes.rst @@ -0,0 +1,17 @@ +gui/biomes +========== + +.. dfhack-tool:: + :summary: Shows biomes map overlay. + :tags: fort inspection map + +This script shows biomes map overlay. +Hover over a biome entry in the list to get detailed info about it. + + +Usage +----- + +:: + + gui/biomes From fc4ea454d80c48498e934f8b56455408654596dd Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 May 2023 15:49:41 +0200 Subject: [PATCH 08/25] move biomes.rst to the correct folder --- {doc => docs}/gui/biomes.rst | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) rename {doc => docs}/gui/biomes.rst (93%) diff --git a/doc/gui/biomes.rst b/docs/gui/biomes.rst similarity index 93% rename from doc/gui/biomes.rst rename to docs/gui/biomes.rst index 89a800bfb5..c3964e0789 100644 --- a/doc/gui/biomes.rst +++ b/docs/gui/biomes.rst @@ -1,17 +1,17 @@ -gui/biomes -========== - -.. dfhack-tool:: - :summary: Shows biomes map overlay. - :tags: fort inspection map - -This script shows biomes map overlay. -Hover over a biome entry in the list to get detailed info about it. - - -Usage ------ - -:: - - gui/biomes +gui/biomes +========== + +.. dfhack-tool:: + :summary: Shows biomes map overlay. + :tags: fort inspection map + +This script shows biomes map overlay. +Hover over a biome entry in the list to get detailed info about it. + + +Usage +----- + +:: + + gui/biomes From 8543bd87c64fa360f172e3c2e719e3c94fc8905e Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 May 2023 15:50:57 +0200 Subject: [PATCH 09/25] use linux line endings --- docs/gui/biomes.rst | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/gui/biomes.rst b/docs/gui/biomes.rst index c3964e0789..89a800bfb5 100644 --- a/docs/gui/biomes.rst +++ b/docs/gui/biomes.rst @@ -1,17 +1,17 @@ -gui/biomes -========== - -.. dfhack-tool:: - :summary: Shows biomes map overlay. - :tags: fort inspection map - -This script shows biomes map overlay. -Hover over a biome entry in the list to get detailed info about it. - - -Usage ------ - -:: - - gui/biomes +gui/biomes +========== + +.. dfhack-tool:: + :summary: Shows biomes map overlay. + :tags: fort inspection map + +This script shows biomes map overlay. +Hover over a biome entry in the list to get detailed info about it. + + +Usage +----- + +:: + + gui/biomes From 85c695bcc99bfcd56d09783c2cb801d2d0ac0dfd Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 11:56:00 +0200 Subject: [PATCH 10/25] Update docs/gui/biomes.rst Co-authored-by: Myk --- docs/gui/biomes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gui/biomes.rst b/docs/gui/biomes.rst index 89a800bfb5..777ee7e43b 100644 --- a/docs/gui/biomes.rst +++ b/docs/gui/biomes.rst @@ -2,7 +2,7 @@ gui/biomes ========== .. dfhack-tool:: - :summary: Shows biomes map overlay. + :summary: Visualize and inspect biome regions on the map. :tags: fort inspection map This script shows biomes map overlay. From 03f071e94ec460ad06bb21c17e00593bc3d2b876 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 11:56:15 +0200 Subject: [PATCH 11/25] Update docs/gui/biomes.rst Co-authored-by: Myk --- docs/gui/biomes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gui/biomes.rst b/docs/gui/biomes.rst index 777ee7e43b..899d345f42 100644 --- a/docs/gui/biomes.rst +++ b/docs/gui/biomes.rst @@ -5,7 +5,7 @@ gui/biomes :summary: Visualize and inspect biome regions on the map. :tags: fort inspection map -This script shows biomes map overlay. +This script shows the boundaries of the biome regions on the map. Hover over a biome entry in the list to get detailed info about it. From 36fb3311ce5add7d2b2edcb84aef22164214e106 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 11:56:23 +0200 Subject: [PATCH 12/25] Update docs/gui/biomes.rst Co-authored-by: Myk --- docs/gui/biomes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gui/biomes.rst b/docs/gui/biomes.rst index 899d345f42..550b0b30fa 100644 --- a/docs/gui/biomes.rst +++ b/docs/gui/biomes.rst @@ -14,4 +14,4 @@ Usage :: - gui/biomes + gui/biomes From ee5151ca8dc4d17ad2710cbcf2bac501ffbdf606 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 20:17:42 +0200 Subject: [PATCH 13/25] minor changes --- gui/biomes.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index bd252b59d8..47f4e97b9a 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -1,4 +1,4 @@ --- Show biomes on the map. +-- Visualize and inspect biome regions on the map. local RELOAD = false -- set to true to help with debugging @@ -6,8 +6,11 @@ local gui = require('gui') local widgets = require('gui.widgets') local guidm = require('gui.dwarfmode') -local TILE_HIGHLIGHTED = 2585 -- yellow-ish indicator -local TILE_STARTING_SYMBOL = 353 -- `a` +local TILE_HIGHLIGHTED = dfhack.textures.getOnOffTexposStart() -- yellow-ish indicator +if TILE_HIGHLIGHTED < 0 then -- use a fallback + TILE_HIGHLIGHTED = 88 -- `X` +end +local TILE_STARTING_SYMBOL = 97 -- `a` local biomeTypeNames = { MOUNTAIN = "Mountain", @@ -338,6 +341,7 @@ if RELOAD then BiomeVisualizer = nil end BiomeVisualizer = defclass(BiomeVisualizer, gui.ZScreen) BiomeVisualizer.ATTRS{ focus_path='BiomeVisualizer', + pass_movement_keys=true, } function BiomeVisualizer:init() From cc3b8035ff0d6043cce67c76431b014caab5d445 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 21:47:24 +0200 Subject: [PATCH 14/25] always gather biome info at the very bottom first --- gui/biomes.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 47f4e97b9a..a6ba47da2d 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -136,7 +136,9 @@ local function gatherBiomeInfo(z) --end end -gatherBiomeInfo() +-- always gather info at the very bottom first: this ensures the important biomes are +-- always in the same order (high up in the air strange things happen) +gatherBiomeInfo(0) -------------------------------------------------------------------------------- From cd63dedad889e8ea204af71a805e28fafb3c54fc Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 22:24:45 +0200 Subject: [PATCH 15/25] no longer resizable, tooltip inside the panel --- gui/biomes.lua | 112 ++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 66 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index a6ba47da2d..3619dad05b 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -145,15 +145,16 @@ gatherBiomeInfo(0) local TITLE = "Biomes" if RELOAD then BiomeVisualizerLegend = nil end +local DEFAULT_LIST_HEIGHT = 5 BiomeVisualizerLegend = defclass(BiomeVisualizerLegend, widgets.Window) BiomeVisualizerLegend.ATTRS { frame_title=TITLE, frame_inset=0, - resizable=true, + resizable=false, resize_min={h=5, w = 14}, frame = { w = 47, - h = 10, + h = DEFAULT_LIST_HEIGHT + 2 + 15, r = 2, t = 18, }, @@ -180,15 +181,35 @@ local function GetBiomeName(biome, biomeTypeId) end function BiomeVisualizerLegend:init() - self:addviews{ - widgets.List{ - view_id = 'list', - frame = { t = 0 }, - icon_width = 1, - text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, -- this makes selection stand out more - on_select = self:callback('onSelectEntry'), + local list = widgets.List{ + view_id = 'list', + frame = { t = 0, h = DEFAULT_LIST_HEIGHT, w = self.frame.w }, + frame_inset = 0, + icon_width = 1, + text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, -- this makes selection stand out more + on_select = self:callback('onSelectEntry'), + } + local tooltip_panel = widgets.Panel{ + view_id='tooltip_panel', + autoarrange_subviews=true, + frame = { t = list.frame.h + 1, h = 15 }, + frame_style=gui.INTERIOR_FRAME, + frame_background=gui.CLEAR_PEN, + subviews={ + widgets.Label{ + view_id='label', + text_to_wrap='', + scroll_keys={}, + }, }, } + self:addviews{ + list, + tooltip_panel, + } + + self.list = list + self.tooltip_panel = tooltip_panel self:UpdateChoices() end @@ -208,10 +229,13 @@ end function BiomeVisualizerLegend:onSelectEntry(idx, option) self.SelectedIndex = idx + self.SelectedOption = option + + self:ShowTooltip(option) end function BiomeVisualizerLegend:UpdateChoices() - local choices = self.subviews.list:getChoices() or {} + local choices = self.list:getChoices() or {} for i = #choices + 1, #biomeList do local biomeExt = biomeList[i] table.insert(choices, { @@ -221,14 +245,14 @@ function BiomeVisualizerLegend:UpdateChoices() biome = biomeExt.biome, }) end - self.subviews.list:setChoices(choices) + self.list:setChoices(choices) end do -- implementation of onMouseHoverEntry(idx, option) function BiomeVisualizerLegend:onRenderFrame(dc, rect) BiomeVisualizerLegend.super.onRenderFrame(self, dc, rect) - local list = self.subviews.list + local list = self.list local currentHoverIx = list:getIdxUnderMouse() local oldIx = self.HoverIndex if currentHoverIx ~= oldIx then @@ -246,12 +270,7 @@ local function add_field_text(lines, biome, field_name) lines[#lines+1] = NEWLINE end -function BiomeVisualizerLegend:onMouseHoverEntry(idx, option) - if not idx then - self:ShowTooltip(nil) - return - end - +local function get_tooltip_text(option) local text = {} text[#text+1] = ("type: %s"):format(df.biome_type[option.biomeTypeId]) text[#text+1] = NEWLINE @@ -280,61 +299,22 @@ function BiomeVisualizerLegend:onMouseHoverEntry(idx, option) text[#text+1] = NEWLINE end - self:ShowTooltip(text) + return text end -function BiomeVisualizerLegend:ShowTooltip(text) - self.TooltipWindow = self.TooltipWindow or self.parent_view.subviews.legend_tooltip - self.TooltipWindow:ShowTooltip(text) -end - --------------------------------------------------------------------------------- - -if RELOAD then TooltipWindow = nil end -TooltipWindow = defclass(TooltipWindow, widgets.Window) - -local function calc_tooltip_frame(frame) - local frame = copyall(frame) - frame.t = frame.t + frame.h - frame.h = 15 - return frame +function BiomeVisualizerLegend:onMouseHoverEntry(idx, option) + self:ShowTooltip(option or self.SelectedOption) end -TooltipWindow.ATTRS { - visible = false, - frame_title=DEFAULT_NIL, - frame_inset=0, - resizable=false, - frame_style = gui.PANEL_FRAME, - autoarrange_subviews = true, - autoarrange_gap = 0, - frame = calc_tooltip_frame(BiomeVisualizerLegend.ATTRS.frame), - -- - parent_window = DEFAULT_NIL, -} +function BiomeVisualizerLegend:ShowTooltip(option) + local text = get_tooltip_text(option) -function TooltipWindow:init() - self:addviews{ - widgets.Label{ - view_id = 'label', - frame = {t = 0, h = 1000}, - auto_height = false, - --wtf??? without this the label is always a single line - text={NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,NEWLINE,} - }, - } -end + local tooltip_panel = self.tooltip_panel + local lbl = tooltip_panel.subviews.label -function TooltipWindow:ShowTooltip(text) - if not text or text == "" or not self.parent_window then - self.visible = false - return - end - - local parent = self.parent_window - local lbl = self.subviews.label lbl:setText(text) - self.visible = true + + -- tooltip_panel:updateLayout() end -------------------------------------------------------------------------------- From 1c14eafa557ecde9454b7a1d558ba4bfd884249a Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 22:26:25 +0200 Subject: [PATCH 16/25] remove commented out code --- gui/biomes.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 3619dad05b..c1ad8f9668 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -313,8 +313,6 @@ function BiomeVisualizerLegend:ShowTooltip(option) local lbl = tooltip_panel.subviews.label lbl:setText(text) - - -- tooltip_panel:updateLayout() end -------------------------------------------------------------------------------- From b03ae09878eeb08d14757aa9330f4e4df0beb2a4 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Thu, 11 May 2023 22:42:46 +0200 Subject: [PATCH 17/25] clarify a comment --- gui/biomes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index c1ad8f9668..1f101262ef 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -1,6 +1,6 @@ -- Visualize and inspect biome regions on the map. -local RELOAD = false -- set to true to help with debugging +local RELOAD = false -- set to true when actively working on this script local gui = require('gui') local widgets = require('gui.widgets') From 10652752a3e06fe04146e4014177b825b84bfaff Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 13 May 2023 11:44:21 +0200 Subject: [PATCH 18/25] make resizable again, other small changes --- gui/biomes.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 1f101262ef..8a9c6f11c5 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -6,6 +6,9 @@ local gui = require('gui') local widgets = require('gui.widgets') local guidm = require('gui.dwarfmode') +local INITIAL_LIST_HEIGHT = 5 +local INITIAL_INFO_HEIGHT = 15 + local TILE_HIGHLIGHTED = dfhack.textures.getOnOffTexposStart() -- yellow-ish indicator if TILE_HIGHLIGHTED < 0 then -- use a fallback TILE_HIGHLIGHTED = 88 -- `X` @@ -145,16 +148,16 @@ gatherBiomeInfo(0) local TITLE = "Biomes" if RELOAD then BiomeVisualizerLegend = nil end -local DEFAULT_LIST_HEIGHT = 5 BiomeVisualizerLegend = defclass(BiomeVisualizerLegend, widgets.Window) BiomeVisualizerLegend.ATTRS { frame_title=TITLE, frame_inset=0, - resizable=false, + resizable=true, resize_min={h=5, w = 14}, frame = { w = 47, - h = DEFAULT_LIST_HEIGHT + 2 + 15, + h = INITIAL_LIST_HEIGHT + 2 + INITIAL_INFO_HEIGHT, + -- just under the minimap: r = 2, t = 18, }, @@ -183,7 +186,7 @@ end function BiomeVisualizerLegend:init() local list = widgets.List{ view_id = 'list', - frame = { t = 0, h = DEFAULT_LIST_HEIGHT, w = self.frame.w }, + frame = { t = 0, b = INITIAL_INFO_HEIGHT + 1 }, frame_inset = 0, icon_width = 1, text_pen = { fg = COLOR_GREY, bg = COLOR_BLACK }, -- this makes selection stand out more @@ -192,7 +195,7 @@ function BiomeVisualizerLegend:init() local tooltip_panel = widgets.Panel{ view_id='tooltip_panel', autoarrange_subviews=true, - frame = { t = list.frame.h + 1, h = 15 }, + frame = { b = 0, h = INITIAL_INFO_HEIGHT }, frame_style=gui.INTERIOR_FRAME, frame_background=gui.CLEAR_PEN, subviews={ @@ -326,8 +329,7 @@ BiomeVisualizer.ATTRS{ function BiomeVisualizer:init() local legend = BiomeVisualizerLegend{view_id = 'legend'} - local legend_tooltip = TooltipWindow{view_id = 'legend_tooltip', parent_window = legend} - self:addviews{legend, legend_tooltip} + self:addviews{legend} end function BiomeVisualizer:onRenderFrame(dc, rect) @@ -371,6 +373,7 @@ end if RELOAD and view then view:dismiss() + -- view is nil now end view = view and view:raise() or BiomeVisualizer{}:show() From fc38f8302d71f8e36c7d6dceeeb43a5de0126b07 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 20 May 2023 18:37:38 +0200 Subject: [PATCH 19/25] make the map overlay blink in text mode Other minor changes Co-authored-by: Myk --- gui/biomes.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 8a9c6f11c5..71285c9714 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -85,7 +85,7 @@ local function gatherBiomeInfo(z) local maxX, maxY, maxZ = dfhack.maps.getTileSize() maxX = maxX - 1; maxY = maxY - 1; maxZ = maxZ - 1 - local z = z or df.global.window_z + z = z or df.global.window_z --for z = 0, maxZ do for y = 0, maxY do @@ -274,6 +274,10 @@ local function add_field_text(lines, biome, field_name) end local function get_tooltip_text(option) + if not option then + return "" + end + local text = {} text[#text+1] = ("type: %s"):format(df.biome_type[option.biomeTypeId]) text[#text+1] = NEWLINE @@ -335,6 +339,10 @@ end function BiomeVisualizer:onRenderFrame(dc, rect) BiomeVisualizer.super.onRenderFrame(self, dc, rect) + if not dfhack.screen.inGraphicsMode() and not gui.blink_visible(500) then + return + end + local z = df.global.window_z if not biomesMap[z] then gatherBiomeInfo(z) From 0b37a9a7ce1addabcbe5ee6a3fc312a724700b3a Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 31 Dec 2023 12:10:30 +0100 Subject: [PATCH 20/25] use new textures API --- gui/biomes.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 71285c9714..470babcef1 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -9,7 +9,8 @@ local guidm = require('gui.dwarfmode') local INITIAL_LIST_HEIGHT = 5 local INITIAL_INFO_HEIGHT = 15 -local TILE_HIGHLIGHTED = dfhack.textures.getOnOffTexposStart() -- yellow-ish indicator +local textures = dfhack.textures.loadTileset('hack/data/art/on-off.png', 8, 12, true) +local TILE_HIGHLIGHTED = dfhack.textures.getTexposByHandle(textures[1]) -- yellow-ish indicator if TILE_HIGHLIGHTED < 0 then -- use a fallback TILE_HIGHLIGHTED = 88 -- `X` end From 7885ac3a9734382d658ad07322a7f8d0a897083a Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 Jan 2024 16:24:17 +0100 Subject: [PATCH 21/25] use special textures for map overlay tiles --- gui/biomes.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 470babcef1..bd112d1f7e 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -9,12 +9,20 @@ local guidm = require('gui.dwarfmode') local INITIAL_LIST_HEIGHT = 5 local INITIAL_INFO_HEIGHT = 15 -local textures = dfhack.textures.loadTileset('hack/data/art/on-off.png', 8, 12, true) -local TILE_HIGHLIGHTED = dfhack.textures.getTexposByHandle(textures[1]) -- yellow-ish indicator +local texturesOnOff8x12 = dfhack.textures.loadTileset('hack/data/art/on-off.png', 8, 12, true) +local LIST_ITEM_HIGHLIGHTED = dfhack.textures.getTexposByHandle(texturesOnOff8x12[1]) -- yellow-ish indicator + +local texturesOnOff = dfhack.textures.loadTileset('hack/data/art/on-off - top-left.png', 32, 32, true) +local TILE_HIGHLIGHTED = dfhack.textures.getTexposByHandle(texturesOnOff[1]) -- yellow-ish indicator if TILE_HIGHLIGHTED < 0 then -- use a fallback TILE_HIGHLIGHTED = 88 -- `X` end -local TILE_STARTING_SYMBOL = 97 -- `a` + +local texturesSmallLetters = dfhack.textures.loadTileset('hack/data/art/curses_small_letters - top-left.png', 32, 32, true) +local TILE_STARTING_SYMBOL = dfhack.textures.getTexposByHandle(texturesSmallLetters[1]) +if TILE_STARTING_SYMBOL < 0 then -- use a fallback + TILE_STARTING_SYMBOL = 97 -- `a` +end local biomeTypeNames = { MOUNTAIN = "Mountain", @@ -218,7 +226,7 @@ function BiomeVisualizerLegend:init() self:UpdateChoices() end -local PEN_ACTIVE_ICON = dfhack.pen.parse{tile=TILE_HIGHLIGHTED} +local PEN_ACTIVE_ICON = dfhack.pen.parse{tile=LIST_ITEM_HIGHLIGHTED} local PEN_NO_ICON = nil function BiomeVisualizerLegend:get_icon_pen_callback(ix) From 746aacfe6598586e1ead8f63685a5d24f6652b7b Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 Jan 2024 16:24:45 +0100 Subject: [PATCH 22/25] adjust tooltip based on map tile hovered over --- gui/biomes.lua | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index bd112d1f7e..981a1e837f 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -239,6 +239,18 @@ function BiomeVisualizerLegend:get_icon_pen_callback(ix) end end +function BiomeVisualizerLegend:get_text_pen_callback(ix) + return function () + if self.MapHoverIndex == ix then + return self.SelectedIndex == ix + and { fg = COLOR_BLACK, bg = COLOR_LIGHTCYAN } + or { fg = COLOR_BLACK, bg = COLOR_GREY } + else + return nil + end + end +end + function BiomeVisualizerLegend:onSelectEntry(idx, option) self.SelectedIndex = idx self.SelectedOption = option @@ -251,7 +263,10 @@ function BiomeVisualizerLegend:UpdateChoices() for i = #choices + 1, #biomeList do local biomeExt = biomeList[i] table.insert(choices, { - text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), + text = {{ + pen = self:get_text_pen_callback(#choices+1), + text = ([[%s: %s]]):format(biomeExt.char, GetBiomeName(biomeExt.biome, biomeExt.typeId)), + }}, icon = self:get_icon_pen_callback(#choices+1), biomeTypeId = biomeExt.typeId, biome = biomeExt.biome, @@ -331,6 +346,26 @@ function BiomeVisualizerLegend:ShowTooltip(option) lbl:setText(text) end +function BiomeVisualizerLegend:onRenderBody(painter) + local thisPos = self:getMouseFramePos() + local pos = dfhack.gui.getMousePos() + + if not thisPos and pos then + local N = safe_index(biomesMap, pos.z, pos.y, pos.x) + if N then + local choices = self.list:getChoices() + local option = choices[N] + + self.MapHoverIndex = N + self:ShowTooltip(option) + end + else + self.MapHoverIndex = nil + end + + BiomeVisualizerLegend.super.onRenderBody(self, painter) +end + -------------------------------------------------------------------------------- if RELOAD then BiomeVisualizer = nil end From 9481147a662cd58783079261c124e81f121324dc Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 Jan 2024 16:28:02 +0100 Subject: [PATCH 23/25] remove trailing whitespace --- gui/biomes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index 981a1e837f..e16a9f5fe6 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -349,7 +349,7 @@ end function BiomeVisualizerLegend:onRenderBody(painter) local thisPos = self:getMouseFramePos() local pos = dfhack.gui.getMousePos() - + if not thisPos and pos then local N = safe_index(biomesMap, pos.z, pos.y, pos.x) if N then From bea7f703a49be5416fc9f88c79aa8b9fb7cf15d9 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sat, 6 Jan 2024 16:35:01 +0100 Subject: [PATCH 24/25] add changelog entry --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 439ad2ec69..0a580e31d2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -30,6 +30,7 @@ Template for new versions: - `control-panel`: new commandline interface for control panel functions - `uniform-unstick`: (reinstated) force squad members to drop items that they picked up in the wrong order so they can get everything equipped properly - `gui/reveal`: temporarily unhide terrain and then automatically hide it again when you're ready to unpause +- `gui/biomes`: visualize and inspect biome regions on the map ## New Features - `uniform-unstick`: add overlay to the squad equipment screen to show a equipment conflict report and give you a one-click button to fix From f963104f68a14435eac15e4228d029b61bf71af3 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Sun, 7 Jan 2024 12:23:21 +0100 Subject: [PATCH 25/25] adjust tileset file names --- gui/biomes.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/biomes.lua b/gui/biomes.lua index e16a9f5fe6..8627b7cc52 100644 --- a/gui/biomes.lua +++ b/gui/biomes.lua @@ -12,13 +12,13 @@ local INITIAL_INFO_HEIGHT = 15 local texturesOnOff8x12 = dfhack.textures.loadTileset('hack/data/art/on-off.png', 8, 12, true) local LIST_ITEM_HIGHLIGHTED = dfhack.textures.getTexposByHandle(texturesOnOff8x12[1]) -- yellow-ish indicator -local texturesOnOff = dfhack.textures.loadTileset('hack/data/art/on-off - top-left.png', 32, 32, true) +local texturesOnOff = dfhack.textures.loadTileset('hack/data/art/on-off_top-left.png', 32, 32, true) local TILE_HIGHLIGHTED = dfhack.textures.getTexposByHandle(texturesOnOff[1]) -- yellow-ish indicator if TILE_HIGHLIGHTED < 0 then -- use a fallback TILE_HIGHLIGHTED = 88 -- `X` end -local texturesSmallLetters = dfhack.textures.loadTileset('hack/data/art/curses_small_letters - top-left.png', 32, 32, true) +local texturesSmallLetters = dfhack.textures.loadTileset('hack/data/art/curses-small-letters_top-left.png', 32, 32, true) local TILE_STARTING_SYMBOL = dfhack.textures.getTexposByHandle(texturesSmallLetters[1]) if TILE_STARTING_SYMBOL < 0 then -- use a fallback TILE_STARTING_SYMBOL = 97 -- `a`