Make manipulator re-read names and professions if change is suspected.

Namely, if it either invoked View Unit itself, or was queried
(possibly by the rename plugin) via getSelectedUnit.
develop
Alexander Gavrilov 2012-09-20 12:27:03 +04:00
parent 82dc1445cf
commit e2d6a14720
3 changed files with 46 additions and 4 deletions

@ -1510,6 +1510,10 @@ The following mouse shortcuts are also available:
* Left-click on a unit's name or profession to view its properties. * Left-click on a unit's name or profession to view its properties.
* Right-click on a unit's name or profession to zoom to it. * Right-click on a unit's name or profession to zoom to it.
Pressing ESC normally returns to the unit screen, but Shift-ESC would exit
directly to the main dwarf mode screen.
Liquids Liquids
======= =======

@ -2395,6 +2395,8 @@ cursor onto that cell instead of toggling it.</li>
<li>Left-click on a unit's name or profession to view its properties.</li> <li>Left-click on a unit's name or profession to view its properties.</li>
<li>Right-click on a unit's name or profession to zoom to it.</li> <li>Right-click on a unit's name or profession to zoom to it.</li>
</ul> </ul>
<p>Pressing ESC normally returns to the unit screen, but Shift-ESC would exit
directly to the main dwarf mode screen.</p>
</div> </div>
<div class="section" id="id34"> <div class="section" id="id34">
<h2><a class="toc-backref" href="#id182">Liquids</a></h2> <h2><a class="toc-backref" href="#id182">Liquids</a></h2>

@ -331,6 +331,12 @@ class viewscreen_unitlaborsst : public dfhack_viewscreen {
public: public:
void feed(set<df::interface_key> *events); void feed(set<df::interface_key> *events);
void logic() {
dfhack_viewscreen::logic();
if (do_refresh_names)
refreshNames();
}
void render(); void render();
void resize(int w, int h) { calcSize(); } void resize(int w, int h) { calcSize(); }
@ -347,12 +353,14 @@ protected:
vector<UnitInfo *> units; vector<UnitInfo *> units;
altsort_mode altsort; altsort_mode altsort;
bool do_refresh_names;
int first_row, sel_row, num_rows; int first_row, sel_row, num_rows;
int first_column, sel_column; int first_column, sel_column;
int col_widths[DISP_COLUMN_MAX]; int col_widths[DISP_COLUMN_MAX];
int col_offsets[DISP_COLUMN_MAX]; int col_offsets[DISP_COLUMN_MAX];
void refreshNames();
void calcSize (); void calcSize ();
}; };
@ -377,9 +385,6 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
if (!ENUM_ATTR(profession, can_assign_labor, unit->profession)) if (!ENUM_ATTR(profession, can_assign_labor, unit->profession))
cur->allowEdit = false; cur->allowEdit = false;
cur->name = Translation::TranslateName(&unit->name, false);
cur->transname = Translation::TranslateName(&unit->name, true);
cur->profession = Units::getProfessionName(unit);
cur->color = Units::getProfessionColor(unit); cur->color = Units::getProfessionColor(unit);
units.push_back(cur); units.push_back(cur);
@ -387,6 +392,8 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
altsort = ALTSORT_NAME; altsort = ALTSORT_NAME;
first_column = sel_column = 0; first_column = sel_column = 0;
refreshNames();
first_row = 0; first_row = 0;
sel_row = cursor_pos; sel_row = cursor_pos;
calcSize(); calcSize();
@ -403,6 +410,21 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
first_row = units.size() - num_rows; first_row = units.size() - num_rows;
} }
void viewscreen_unitlaborsst::refreshNames()
{
do_refresh_names = false;
for (size_t i = 0; i < units.size(); i++)
{
UnitInfo *cur = units[i];
df::unit *unit = cur->unit;
cur->name = Translation::TranslateName(&unit->name, false);
cur->transname = Translation::TranslateName(&unit->name, true);
cur->profession = Units::getProfessionName(unit);
}
}
void viewscreen_unitlaborsst::calcSize() void viewscreen_unitlaborsst::calcSize()
{ {
num_rows = gps->dimy - 10; num_rows = gps->dimy - 10;
@ -476,16 +498,25 @@ void viewscreen_unitlaborsst::calcSize()
void viewscreen_unitlaborsst::feed(set<df::interface_key> *events) void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
{ {
if (events->count(interface_key::LEAVESCREEN)) bool leave_all = events->count(interface_key::LEAVESCREEN_ALL);
if (leave_all || events->count(interface_key::LEAVESCREEN))
{ {
events->clear(); events->clear();
Screen::dismiss(this); Screen::dismiss(this);
if (leave_all)
{
events->insert(interface_key::LEAVESCREEN);
parent->feed(events);
}
return; return;
} }
if (!units.size()) if (!units.size())
return; return;
if (do_refresh_names)
refreshNames();
if (events->count(interface_key::CURSOR_UP) || events->count(interface_key::CURSOR_UPLEFT) || events->count(interface_key::CURSOR_UPRIGHT)) if (events->count(interface_key::CURSOR_UP) || events->count(interface_key::CURSOR_UPLEFT) || events->count(interface_key::CURSOR_UPRIGHT))
sel_row--; sel_row--;
if (events->count(interface_key::CURSOR_UP_FAST) || events->count(interface_key::CURSOR_UPLEFT_FAST) || events->count(interface_key::CURSOR_UPRIGHT_FAST)) if (events->count(interface_key::CURSOR_UP_FAST) || events->count(interface_key::CURSOR_UPLEFT_FAST) || events->count(interface_key::CURSOR_UPRIGHT_FAST))
@ -758,6 +789,8 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
unitlist->feed(events); unitlist->feed(events);
if (Screen::isDismissed(unitlist)) if (Screen::isDismissed(unitlist))
Screen::dismiss(this); Screen::dismiss(this);
else
do_refresh_names = true;
break; break;
} }
} }
@ -990,6 +1023,9 @@ void viewscreen_unitlaborsst::render()
df::unit *viewscreen_unitlaborsst::getSelectedUnit() df::unit *viewscreen_unitlaborsst::getSelectedUnit()
{ {
// This query might be from the rename plugin
do_refresh_names = true;
return units[sel_row]->unit; return units[sel_row]->unit;
} }