Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gui/biomes: a way to see where one biome ends and another begins #637

Merged
merged 28 commits into from
Jan 13, 2024

Conversation

TymurGubayev
Copy link
Contributor

@TymurGubayev TymurGubayev commented Mar 12, 2023

image

  • selected biome is highlighted on the map
  • the "tooltip" window under the legend is shown on mouse-hover

@TymurGubayev
Copy link
Contributor Author

This is not quite finished (see tasks), but I'll need help with them.

  1. I can't find a way to change the color of the text on the map. Is there one? I want to (subtly) highlight map tiles of the selected biome.
  2. Is there a way to get the minimap coordinates? I want to place the legend under it. If not, I'll probably move it into the bottom right corner.

@myk002
Copy link
Member

myk002 commented Mar 12, 2023

long time no see! welcome back!

I have not figured out a way to change the color of text being applied to map tiles. It might be possible, but I think you'll be better off using the "on/off" icons that TaxiService provided us. run gui/pathable to see what they look like, and see plugins/pathable.cpp for how they're retrieved from the Textures module. Also see gui/control-panel.lua for an example of getting textures in Lua (though there they're applied to the UI grid and not the map grid). We might be able to provide more colors and shapes, but it might be enough to just have the "on" icon for the currently selected biome and the "off" icon for everything else.

the minimap is always in the upper right corner and is always the same size. You can just use a frame attached to the right edge at a constant offset from the top and you'll be fine. gui/quickfort, for example, has a frame like this to appear just below the minimap.

I've found in the past that overlaying the entire visible map from Lua can be slow. If performance is an issue here, feel free to extend pathable.cpp with another API endpoint for this tool. Much of the logic you need is already there.

gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Outdated

local TITLE = "Biomes"

BiomeVisualizerLegend = nil -- for debugging purposes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for clearing the script environment for debugging/dev purposes, consider using devel/clear-script-env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably don't understand this. Right now, if I make a change in the script, or more specifically in the BiomeVisualizerLegend-class, I execute gui/biomes, and the changes are immediately applied. How would I use devel/clear-script-env instead? Execute first the clear-sript-env and then gui/biomes?.. I don't remember, how can I chain commands in dfhack console?

Copy link
Member

@myk002 myk002 May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd only need to use devel/clear-script-env if you had previously set a global in the script and an update removes the global. for example, if you had function MyClass:onInput(keys) but then you remove the function, it will still be defined and active until you run devel/clear-script-env (or reload the game). If you just change an existing function definition, then there's no problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, then I have to think about whether I set a global or not, and since most of the time I do not, I'll definitely forget the one time I do.

gui/biomes.lua Outdated Show resolved Hide resolved
@myk002
Copy link
Member

myk002 commented Mar 12, 2023

also, if you like the behavior of gui/pathable, you can copy its structure of having the highlighted biome follow the mouse instead of/in addition to having the list selection control which biome is highlighted.

@myk002
Copy link
Member

myk002 commented May 3, 2023

@TymurGubayev have you made any progress on this? I'd love to get it into the next beta!

@TymurGubayev
Copy link
Contributor Author

@myk002 right, I need to finish this one. I'll try to do it this weekend.

Few other minor changes
Other minor tweaks and an attempt at slightly improving performance via caching biome region info
@TymurGubayev
Copy link
Contributor Author

Updated version is almost done, there are few things to still do though.

  1. UI: right now, mousewheel events are captured by the active legends window, preventing user from changing z-level. No idea how can I disable this. Ideally, it should "fall through" to the game if not handled by a widget.
  2. I'd like to move and resize the tooltip window with the legend window. I have no idea how to do this.
  3. Something very strange is happening with the label-widget inside the tooltip window. Line 300 is my workaround. Without it, only a single-line is visible.
  4. Possible bug: There is something strange going on with biomes in the air, either I don't understand something or it's a bug (probably in DFHack, but maybe DF): there are biomes up there that don't exist on a ground level, but also there are square blocks of tiles where biome info is missing (at least if retrieved the way I do it).

@myk002
Copy link
Member

myk002 commented May 11, 2023

  1. Possible bug: There is something strange going on with biomes in the air, either I don't understand something or it's a bug (probably in DFHack, but maybe DF): there are biomes up there that don't exist on a ground level, but also there are square blocks of tiles where biome info is missing (at least if retrieved the way I do it).

I'll respond to the others in the review, but this one I think is expected. At least I've run into it before and I think there's a mantis bug for it. Biomes in the air are the same as the region up and left from the current embark area (or something like that).

Are the blocks where biome info is missing also in the air?

gui/biomes.lua Outdated

--------------------------------------------------------------------------------

if RELOAD then TooltipWindow = nil end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is the kind of stuff you'd use gui/clear-script-env for

gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Outdated
view_id = 'label',
frame = {t = 0, h = 1000},
auto_height = false,
--wtf??? without this the label is always a single line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that updateLayout() calls are not getting to this widget. If you call the TooltipWindow's updateLayout() when the main panel's updateLayout() is called, then they should stay in sync. However, resizing from the line between the two "windows" is not a common UX style, and nothing else in DFHack does it that way. Maybe you could add the tooltip as a widget in BiomeVisualizerLegend, like how gui/control-panel does it? That would simplify the structure quite a bit. You can still specify an interior frame (gui.INTERIOR_FRAME) around the tooltip panel, if you wish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to recreate how hotkeys look, i.e.
image
but also hiding the tooltip if not hovering. I'll give it another try :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the hotkeys panel is not resizable -- nor is the buildingplan panel, which also has that dual-frame look. For a resizable window, I think what you want is a single exterior frame with possibly a thinner interior frame around the tooltip. Otherwise it isn't obvious where the player should go to resize the window. You can still make the extended info disappear and the window shrink when it's not hovered, but I'd actually recommend leaving it. The player can always resize the window or dragging it around if it's in the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out how to make the window shrink dynamically :(
I'll try a version just showing the info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I give up on the resizable version.
List is fix 5 rows, info is fix 15 rows.
image

docs/gui/biomes.rst Outdated Show resolved Hide resolved
docs/gui/biomes.rst Outdated Show resolved Hide resolved
docs/gui/biomes.rst Outdated Show resolved Hide resolved
gui/biomes.lua Outdated Show resolved Hide resolved
@TymurGubayev
Copy link
Contributor Author

Are the blocks where biome info is missing also in the air?

yes they are

@myk002
Copy link
Member

myk002 commented May 11, 2023

Are the blocks where biome info is missing also in the air?

yes they are

ok, then it's probably not worth worrying about. this is almost certainly a vanilla bug

@myk002
Copy link
Member

myk002 commented May 11, 2023

image

I just realized -- you found an embark with 8 biomes? impressive.

@TymurGubayev
Copy link
Contributor Author

I just realized -- you found an embark with 8 biomes? impressive.

:) It only actually has 3, other ones are in the air

@myk002
Copy link
Member

myk002 commented May 11, 2023

I just realized -- you found an embark with 8 biomes? impressive.

:) It only actually has 3, other ones are in the air

Are you on Discord? figuring out what to do with those phantom biomes might be a good topic for discussion. Should they be hidden in the list? Optionally hidden, with a message saying that they are likely to be buggy? Showing them as identical to the "real" biomes might be confusing.

@TymurGubayev
Copy link
Contributor Author

Are you on Discord? figuring out what to do with those phantom biomes might be a good topic for discussion. Should they be hidden in the list? Optionally hidden, with a message saying that they are likely to be buggy? Showing them as identical to the "real" biomes might be confusing.

I was for a bit on Discord, but I'm not sure I like it there, especially for discussions such as this one.

I think how to show the phantom biomes should depend on what happens if you manage to create a farm up there.
If it works as a farm in any other biome, then IMO there shouldn't be any difference in how they are shown.
If it doesn't, I could show them red, assuming the correct biomes are those at z = 0.

I'm most curious about the missing biomes: will the game explode or will it treat them like ice?

I'm not any good at such science experiments.

gui/biomes.lua Outdated Show resolved Hide resolved
gui/biomes.lua Outdated Show resolved Hide resolved
gui/biomes.lua Outdated Show resolved Hide resolved
gui/biomes.lua Outdated Show resolved Hide resolved

local z = z or df.global.window_z

--for z = 0, maxZ do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used? also the corresponding --end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was too slow. I'd like to leave it there for future reference though.

gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Show resolved Hide resolved
Other minor changes

Co-authored-by: Myk <[email protected]>
@TymurGubayev
Copy link
Contributor Author

dfhack.textures.getOnOffTexposStart() doesn't exist anymore. What do I replace it with?

@ab9rf
Copy link
Member

ab9rf commented Dec 30, 2023

dfhack.textures.getOnOffTexposStart() doesn't exist anymore. What do I replace it with?

dfhack/dfhack commit fe8bd4fa786369f7a95ae7925fc992095cc1fb2d may be informative (part of DFHack/dfhack#3663)

@myk002
Copy link
Member

myk002 commented Dec 31, 2023

unsuspend might be a good model to follow for the new textures api:
https://github.com/DFHack/scripts/blob/master/unsuspend.lua#L15

@myk002
Copy link
Member

myk002 commented Dec 31, 2023

could you rebase onto current master and add a changelog entry for the new tool?

@myk002
Copy link
Member

myk002 commented Dec 31, 2023

It looks like the used texture needs to change. Since the switch to SDL2, textures are stretched to cover the entire map tile:
image

gui/pathable switched to cursor textures:
image

@TymurGubayev
Copy link
Contributor Author

It looks like the used texture needs to change. Since the switch to SDL2, textures are stretched to cover the entire map tile:
gui/pathable switched to cursor textures:

well, I have an idea about that actually:

image

this happens if I cut the 8x12 "on" indicator and place it in the top left corner on a different 32x32 png image with a transparent background.
This is done easily, the next question is, what to do with all the letters. I see the following possibilities.

  1. Leave it as is, as the letters naturally have a lot of transparent pixels in them, so it isn't too ugly; in which case I'll probably switch to the cursor texture because otherwise, the mix of indicators in a corner and letters over whole tiles looks a bit weird.
  2. Get or create a texture with letters in the corner of a 32x32 (haven't looked too hard for it), which would be some work involved and we'd end up with a somewhat big texture file.
  3. Create required textures on the fly, including the indicator one.

I'd much prefer the 3rd approach, especially since we already have half of the required API: createTile/createTileset. The missing half is something to get the pixels from a loaded texture, or maybe some method to resize textures, etc.

@myk002
Copy link
Member

myk002 commented Jan 6, 2024

I tried (1) for the unsuspend overlay (displaying if a building is suspended or planned), but it just did not look good. I ended up designing new textures (rather, I asked someone more artistic than myself to design them): https://github.com/DFHack/dfhack/blob/develop/data/art/unsuspend.png

Adding another texture map to our art directory wouldn't be onerous. It's 5k for 5 unsuspend images, so 26 letters would be about 25k.

If you'd like to finish up the dynamic texture API, that would be cool, but I'm not sure if we should wait for that for this PR -- I'd rather get this released sooner rather than later.

:tags: fort inspection map

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about also allowing the player to hover the mouse cursor over the map to select the region in the list? If the keyboard cursors are used and the mouse hasn't moved, then that can take precedence to move the list cursor. Then when the mouse moves, it can be the selector again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented... Now that I re-read your comment, probably not exactly what you had in mind, but hopefully close enough

gui/biomes.lua Show resolved Hide resolved
gui/biomes.lua Show resolved Hide resolved
@TymurGubayev
Copy link
Contributor Author

where do I put art assets for scripts?

I'd like to add the following two.

curses_small_letters - top-left
on-off - top-left

Then it looks like this (mouse over a "b" tile)
image

@myk002
Copy link
Member

myk002 commented Jan 6, 2024

where do I put art assets for scripts?

all assets should go in the dfhack repo in the data/art/ directory.

Copy link
Member

@myk002 myk002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it. Great job!

@myk002 myk002 merged commit 874929d into DFHack:master Jan 13, 2024
10 checks passed
@TymurGubayev
Copy link
Contributor Author

yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants