summaryrefslogtreecommitdiff
path: root/plugins/manipulator.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-09-23 16:41:14 +0400
committerAlexander Gavrilov2012-09-23 16:41:14 +0400
commit6385128c2854371369763e8c33e399b5da54908b (patch)
tree8844af9521d13eacb528b0155a4cefcba01b217d /plugins/manipulator.cpp
parent825d21c91a24f7f95bf05ad10b54845054a36411 (diff)
downloaddfhack-6385128c2854371369763e8c33e399b5da54908b.tar.gz
dfhack-6385128c2854371369763e8c33e399b5da54908b.tar.bz2
dfhack-6385128c2854371369763e8c33e399b5da54908b.tar.xz
Sort by units.active (arrival), and seek to top/bottom in manipulator.
Diffstat (limited to 'plugins/manipulator.cpp')
-rw-r--r--plugins/manipulator.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp
index a3ec72a4..0b0b99d4 100644
--- a/plugins/manipulator.cpp
+++ b/plugins/manipulator.cpp
@@ -247,12 +247,14 @@ struct UnitInfo
string transname;
string profession;
int8_t color;
+ int active_index;
};
enum altsort_mode {
ALTSORT_NAME,
ALTSORT_PROFESSION,
ALTSORT_HAPPINESS,
+ ALTSORT_ARRIVAL,
ALTSORT_MAX
};
@@ -284,6 +286,14 @@ bool sortByHappiness (const UnitInfo *d1, const UnitInfo *d2)
return (d1->unit->status.happiness < d2->unit->status.happiness);
}
+bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2)
+{
+ if (descending)
+ return (d1->active_index > d2->active_index);
+ else
+ return (d1->active_index < d2->active_index);
+}
+
bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2)
{
if (sort_skill != job_skill::NONE)
@@ -366,12 +376,18 @@ protected:
viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cursor_pos)
{
+ std::map<df::unit*,int> active_idx;
+ auto &active = world->units.active;
+ for (size_t i = 0; i < active.size(); i++)
+ active_idx[active[i]] = i;
+
for (size_t i = 0; i < src.size(); i++)
{
UnitInfo *cur = new UnitInfo;
df::unit *unit = src[i];
cur->unit = unit;
cur->allowEdit = true;
+ cur->active_index = active_idx[unit];
if (unit->race != ui->race_id)
cur->allowEdit = false;
@@ -526,6 +542,15 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
if (events->count(interface_key::CURSOR_DOWN_FAST) || events->count(interface_key::CURSOR_DOWNLEFT_FAST) || events->count(interface_key::CURSOR_DOWNRIGHT_FAST))
sel_row += 10;
+ if ((sel_row > 0) && events->count(interface_key::CURSOR_UP_Z_AUX))
+ {
+ sel_row = 0;
+ }
+ if ((sel_row < units.size()-1) && events->count(interface_key::CURSOR_DOWN_Z_AUX))
+ {
+ sel_row = units.size()-1;
+ }
+
if (sel_row < 0)
sel_row = 0;
if (sel_row > units.size() - 1)
@@ -759,6 +784,9 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
case ALTSORT_HAPPINESS:
std::sort(units.begin(), units.end(), sortByHappiness);
break;
+ case ALTSORT_ARRIVAL:
+ std::sort(units.begin(), units.end(), sortByArrival);
+ break;
}
}
if (events->count(interface_key::CHANGETAB))
@@ -772,6 +800,9 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
altsort = ALTSORT_HAPPINESS;
break;
case ALTSORT_HAPPINESS:
+ altsort = ALTSORT_ARRIVAL;
+ break;
+ case ALTSORT_ARRIVAL:
altsort = ALTSORT_NAME;
break;
}
@@ -1015,6 +1046,9 @@ void viewscreen_unitlaborsst::render()
case ALTSORT_HAPPINESS:
OutputString(15, x, gps->dimy - 2, "Happiness");
break;
+ case ALTSORT_ARRIVAL:
+ OutputString(15, x, gps->dimy - 2, "Arrival");
+ break;
default:
OutputString(15, x, gps->dimy - 2, "Unknown");
break;