From a751df4219a99026b937b254bec593287e1f3d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-David=20Be=CC=81langer?= Date: Tue, 10 Jun 2014 22:59:28 -0400 Subject: [PATCH] Allow to toggle between Profession and Squad view instead of wasting screen space with a new column --- plugins/manipulator.cpp | 100 +++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index ecba97b6d..4f22a44be 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -254,8 +254,7 @@ struct UnitInfo enum altsort_mode { ALTSORT_NAME, - ALTSORT_PROFESSION, - ALTSORT_SQUAD, + ALTSORT_PROFESSION_OR_SQUAD, ALTSORT_HAPPINESS, ALTSORT_ARRIVAL, ALTSORT_MAX @@ -355,8 +354,7 @@ bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2) enum display_columns { DISP_COLUMN_HAPPINESS, DISP_COLUMN_NAME, - DISP_COLUMN_PROFESSION, - DISP_COLUMN_SQUAD, + DISP_COLUMN_PROFESSION_OR_SQUAD, DISP_COLUMN_LABORS, DISP_COLUMN_MAX, }; @@ -386,6 +384,7 @@ public: protected: vector units; altsort_mode altsort; + bool show_squad; bool do_refresh_names; int first_row, sel_row, num_rows; @@ -438,6 +437,7 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector &src, int cur units.push_back(cur); } altsort = ALTSORT_NAME; + show_squad = false; first_column = sel_column = 0; refreshNames(); @@ -496,13 +496,11 @@ void viewscreen_unitlaborsst::calcSize() int col_maxwidth[DISP_COLUMN_MAX]; col_minwidth[DISP_COLUMN_HAPPINESS] = 4; col_maxwidth[DISP_COLUMN_HAPPINESS] = 4; - col_minwidth[DISP_COLUMN_NAME] = 12; - col_maxwidth[DISP_COLUMN_NAME] = 12; // adjusted in the loop below - col_minwidth[DISP_COLUMN_PROFESSION] = 10; - col_maxwidth[DISP_COLUMN_PROFESSION] = 10; // adjusted in the loop below - col_minwidth[DISP_COLUMN_SQUAD] = 10; - col_maxwidth[DISP_COLUMN_SQUAD] = 10; // adjusted in the loop below - col_minwidth[DISP_COLUMN_LABORS] = num_columns / 2; // 50% + col_minwidth[DISP_COLUMN_NAME] = 16; + col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below + col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; + col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; // adjusted in the loop below + col_minwidth[DISP_COLUMN_LABORS] = num_columns*3/5; // 60% col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS; // get max_name/max_prof from strings length @@ -510,10 +508,13 @@ void viewscreen_unitlaborsst::calcSize() { if (col_maxwidth[DISP_COLUMN_NAME] < units[i]->name.size()) col_maxwidth[DISP_COLUMN_NAME] = units[i]->name.size(); - if (col_maxwidth[DISP_COLUMN_PROFESSION] < units[i]->profession.size()) - col_maxwidth[DISP_COLUMN_PROFESSION] = units[i]->profession.size(); - if (col_maxwidth[DISP_COLUMN_SQUAD] < units[i]->squad_info.size()) - col_maxwidth[DISP_COLUMN_SQUAD] = units[i]->squad_info.size(); + if (show_squad) { + if (col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] < units[i]->squad_info.size()) + col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = units[i]->squad_info.size(); + } else { + if (col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] < units[i]->profession.size()) + col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = units[i]->profession.size(); + } } // check how much room we have @@ -784,21 +785,10 @@ void viewscreen_unitlaborsst::feed(set *events) } break; - case DISP_COLUMN_PROFESSION: - if (enabler->mouse_lbut || enabler->mouse_rbut) - { - input_sort = ALTSORT_PROFESSION; - if (enabler->mouse_lbut) - events->insert(interface_key::SECONDSCROLL_PAGEDOWN); - if (enabler->mouse_rbut) - events->insert(interface_key::SECONDSCROLL_PAGEUP); - } - break; - - case DISP_COLUMN_SQUAD: + case DISP_COLUMN_PROFESSION_OR_SQUAD: if (enabler->mouse_lbut || enabler->mouse_rbut) { - input_sort = ALTSORT_SQUAD; + input_sort = ALTSORT_PROFESSION_OR_SQUAD; if (enabler->mouse_lbut) events->insert(interface_key::SECONDSCROLL_PAGEDOWN); if (enabler->mouse_rbut) @@ -825,8 +815,7 @@ void viewscreen_unitlaborsst::feed(set *events) break; case DISP_COLUMN_NAME: - case DISP_COLUMN_PROFESSION: - case DISP_COLUMN_SQUAD: + case DISP_COLUMN_PROFESSION_OR_SQUAD: // left-click to view, right-click to zoom if (enabler->mouse_lbut) { @@ -922,11 +911,8 @@ void viewscreen_unitlaborsst::feed(set *events) case ALTSORT_NAME: std::sort(units.begin(), units.end(), sortByName); break; - case ALTSORT_PROFESSION: - std::sort(units.begin(), units.end(), sortByProfession); - break; - case ALTSORT_SQUAD: - std::sort(units.begin(), units.end(), sortBySquad); + case ALTSORT_PROFESSION_OR_SQUAD: + std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession); break; case ALTSORT_HAPPINESS: std::sort(units.begin(), units.end(), sortByHappiness); @@ -941,12 +927,9 @@ void viewscreen_unitlaborsst::feed(set *events) switch (altsort) { case ALTSORT_NAME: - altsort = ALTSORT_PROFESSION; - break; - case ALTSORT_PROFESSION: - altsort = ALTSORT_SQUAD; + altsort = ALTSORT_PROFESSION_OR_SQUAD; break; - case ALTSORT_SQUAD: + case ALTSORT_PROFESSION_OR_SQUAD: altsort = ALTSORT_HAPPINESS; break; case ALTSORT_HAPPINESS: @@ -957,6 +940,10 @@ void viewscreen_unitlaborsst::feed(set *events) break; } } + if (events->count(interface_key::OPTION20)) + { + show_squad = !show_squad; + } if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, parent)) { @@ -998,8 +985,7 @@ void viewscreen_unitlaborsst::render() Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_HAPPINESS], 2, "Hap."); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name"); - Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION], 2, "Profession"); - Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_SQUAD], 2, "Squad"); + Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 2, show_squad ? "Squad" : "Profession"); for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++) { @@ -1069,17 +1055,17 @@ void viewscreen_unitlaborsst::render() name.resize(col_widths[DISP_COLUMN_NAME]); Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_NAME], 4 + row, name); - string profession = cur->profession; - profession.resize(col_widths[DISP_COLUMN_PROFESSION]); - fg = cur->color; bg = 0; - - Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_PROFESSION], 4 + row, profession); - - fg = 15; - string squad = cur->squad_info; - squad.resize(col_widths[DISP_COLUMN_SQUAD]); - Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_SQUAD], 4 + row, squad); + string profession_or_squad; + if (show_squad) { + fg = 11; + profession_or_squad = cur->squad_info; + } else { + fg = cur->color; + profession_or_squad = cur->profession; + } + profession_or_squad.resize(col_widths[DISP_COLUMN_PROFESSION_OR_SQUAD]); + Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 4 + row, profession_or_squad); // Print unit's skills and labor assignments for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++) @@ -1209,6 +1195,9 @@ void viewscreen_unitlaborsst::render() OutputString(10, x, y, Screen::getKeyDisplay(interface_key::LEAVESCREEN)); OutputString(15, x, y, ": Done, "); + OutputString(10, x, y, Screen::getKeyDisplay(interface_key::OPTION20)); + OutputString(15, x, y, ": Toggle View, "); + OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_DOWN)); OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_UP)); OutputString(15, x, y, ": Sort by Skill, "); @@ -1223,11 +1212,8 @@ void viewscreen_unitlaborsst::render() case ALTSORT_NAME: OutputString(15, x, y, "Name"); break; - case ALTSORT_PROFESSION: - OutputString(15, x, y, "Profession"); - break; - case ALTSORT_SQUAD: - OutputString(15, x, y, "Squad"); + case ALTSORT_PROFESSION_OR_SQUAD: + OutputString(15, x, y, show_squad ? "Squad" : "Profession"); break; case ALTSORT_HAPPINESS: OutputString(15, x, y, "Happiness");