-
Notifications
You must be signed in to change notification settings - Fork 221
Petitions Overlay #1528
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
base: master
Are you sure you want to change the base?
Petitions Overlay #1528
Conversation
Script that add extra information about petitioners to the petitions screen
|
I didn't dig into this too deeply, because I ran into the use of |
| -- Capture the initially selected texpos once. This serves as the reference | ||
| -- value that identifies the currently highlighted row. | ||
| if self.tocheck == nil or self.tocheck == 0 then | ||
| self.tocheck = gps.screentexpos_lower[6 * gps.dimy + starty] or 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails in classic ASCII mode (i.e. commercial version graphics turned off).
In that mode, screen cells always have texpos == 0.
(Unless the cell was set by DFHack.)
| -- Helper that returns a localized caste/profession name for a unit | ||
| local function get_caste_name(race, caste, profession) | ||
| return dfhack.units.getCasteProfessionName(race, caste, profession) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this helper exists. It's a straight passthrough on both call and return.
Is it for possible future customization?
| local u = nil | ||
| for _, unit in ipairs(df.global.world.units.active) do | ||
| if unit.hist_figure_id == hf_id then | ||
| u = unit -- Found the active unit for this histfig | ||
| break | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type df.historical_figure has a unit_id field.
local hf = df.historical_figure.find(hf_id)
local u = (hf) and df.unit.find(hf.unit_id) or nil| local y = starty + i * steps | ||
| local idx = (6 * gps.dimy) + y | ||
| local tex = gps.screentexpos_lower[idx] or 0 | ||
|
|
||
| if tex == self.tocheck then | ||
| return i -- Found the active petition row | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this will fail in ASCII mode.
| -- Determines which petition row is currently selected in the vanilla UI | ||
| -- by comparing screen texture positions. This is a heuristic that tracks | ||
| -- which row's screen texpos matches the initially captured value. | ||
| function getActivePetitionRow(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should look into df.global.game.main_interface.petitions.
If the open field is true, the other fields are valid. Look at selected_agreement_id and at scroll_position.
Note that, in some UI elements, scroll_position is indexed per 3-row list entry, and in others it is indexed per row. You'll need to figure out which this one uses. (It's a terrible situation.)
(Ignore scrolling, it seems to mean that the scroll bar is being dragged by the mouse.)
| if not gps then | ||
| return nil -- If GPS is unavailable, we cannot determine selection | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Harmless but useless, should be removed even if you keep using gps.
df.global.gps is a singleton object created by DF. It will always exist.
| for _, hf_id in ipairs(party0.histfig_ids) do histfig_ids[hf_id] = true end | ||
| elseif #party0.entity_ids > 0 then | ||
| -- Indirect references via an entity | ||
| local ent = df.global.world.entities.all[party0.entity_ids[0]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an id is generally not identical to an index, and should not be treated as one. change to:
local ent = df.historical_entity.find(party0.entity_ids[0])
Script that add extra information about petitioners to the petitions screen
If this PR makes an externally-visible change in behavior, please add an appropriate line to
changelog.txt.