diff options
| author | Alexander Gavrilov | 2012-09-20 12:27:03 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-20 12:27:03 +0400 |
| commit | e2d6a14720e3fcad3d658040434dbcca9a72fa20 (patch) | |
| tree | 621d2f6e49cb57cc42689231f792f85130481303 /plugins/manipulator.cpp | |
| parent | 82dc1445cf86160cd3e7d33718b7229c1f591fc6 (diff) | |
| download | dfhack-e2d6a14720e3fcad3d658040434dbcca9a72fa20.tar.gz dfhack-e2d6a14720e3fcad3d658040434dbcca9a72fa20.tar.bz2 dfhack-e2d6a14720e3fcad3d658040434dbcca9a72fa20.tar.xz | |
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.
Diffstat (limited to 'plugins/manipulator.cpp')
| -rw-r--r-- | plugins/manipulator.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 033ad8b8..a3ec72a4 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -331,6 +331,12 @@ class viewscreen_unitlaborsst : public dfhack_viewscreen { public: void feed(set<df::interface_key> *events); + void logic() { + dfhack_viewscreen::logic(); + if (do_refresh_names) + refreshNames(); + } + void render(); void resize(int w, int h) { calcSize(); } @@ -347,12 +353,14 @@ protected: vector<UnitInfo *> units; altsort_mode altsort; + bool do_refresh_names; int first_row, sel_row, num_rows; int first_column, sel_column; int col_widths[DISP_COLUMN_MAX]; int col_offsets[DISP_COLUMN_MAX]; + void refreshNames(); 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)) 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); units.push_back(cur); @@ -387,6 +392,8 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur altsort = ALTSORT_NAME; first_column = sel_column = 0; + refreshNames(); + first_row = 0; sel_row = cursor_pos; calcSize(); @@ -403,6 +410,21 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur 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() { num_rows = gps->dimy - 10; @@ -476,16 +498,25 @@ void viewscreen_unitlaborsst::calcSize() 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(); Screen::dismiss(this); + if (leave_all) + { + events->insert(interface_key::LEAVESCREEN); + parent->feed(events); + } return; } if (!units.size()) 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)) sel_row--; 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); if (Screen::isDismissed(unitlist)) Screen::dismiss(this); + else + do_refresh_names = true; break; } } @@ -990,6 +1023,9 @@ void viewscreen_unitlaborsst::render() df::unit *viewscreen_unitlaborsst::getSelectedUnit() { + // This query might be from the rename plugin + do_refresh_names = true; + return units[sel_row]->unit; } |
