From eecaadfc227b6c6aebd68d480358d3ed3acf6ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Thu, 16 Sep 2021 20:59:55 +0900 Subject: [PATCH] ADD sort order switching button to edit dialogs --- gui/baum_edit.cc | 6 ++++-- gui/baum_edit.h | 2 ++ gui/citybuilding_edit.cc | 16 +++++++++------- gui/citybuilding_edit.h | 2 ++ gui/curiosity_edit.cc | 16 +++++++++------- gui/curiosity_edit.h | 2 ++ gui/extend_edit.cc | 11 ++++++++++- gui/extend_edit.h | 2 +- gui/factory_edit.cc | 19 +++++++++++-------- gui/factory_edit.h | 2 ++ gui/groundobj_edit.cc | 8 +++++--- gui/groundobj_edit.h | 2 ++ 12 files changed, 59 insertions(+), 29 deletions(-) diff --git a/gui/baum_edit.cc b/gui/baum_edit.cc index 5c843fd012..ba7027d149 100644 --- a/gui/baum_edit.cc +++ b/gui/baum_edit.cc @@ -29,12 +29,13 @@ // new tool definition tool_plant_tree_t baum_edit_frame_t::baum_tool; cbuffer_t baum_edit_frame_t::param_str; +bool baum_edit_frame_t::sortreverse = false; static bool compare_tree_desc(const tree_desc_t* a, const tree_desc_t* b) { int diff = strcmp( a->get_name(), b->get_name() ); - return diff < 0; + return baum_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_tree_desc_name(const tree_desc_t* a, const tree_desc_t* b) { @@ -42,7 +43,7 @@ static bool compare_tree_desc_name(const tree_desc_t* a, const tree_desc_t* b) if(diff ==0) { diff = strcmp( a->get_name(), b->get_name() ); } - return diff < 0; + return baum_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } @@ -81,6 +82,7 @@ void baum_edit_frame_t::fill_list() { tree_list.clear(); const bool is_sortedbyname = get_sortedby()==gui_sorting_item_t::BY_NAME_TRANSLATED; + sortreverse = sort_order.pressed; FOR(vector_tpl, const i, tree_builder_t::get_all_desc()) { if ( i && (i->get_allowed_climate_bits() & get_climate()) ) { tree_list.insert_ordered(i, is_sortedbyname ? compare_tree_desc_name : compare_tree_desc); diff --git a/gui/baum_edit.h b/gui/baum_edit.h index 089e2fecfc..a6b961250c 100644 --- a/gui/baum_edit.h +++ b/gui/baum_edit.h @@ -38,6 +38,8 @@ class baum_edit_frame_t : public extend_edit_gui_t public: baum_edit_frame_t(player_t* player_); + static bool sortreverse; + /** * in top-level windows the name is displayed in titlebar * @return the non-translated component name diff --git a/gui/citybuilding_edit.cc b/gui/citybuilding_edit.cc index c2398cff9c..a1e64830dd 100644 --- a/gui/citybuilding_edit.cc +++ b/gui/citybuilding_edit.cc @@ -27,12 +27,13 @@ // new tool definition tool_build_house_t citybuilding_edit_frame_t::haus_tool=tool_build_house_t(); cbuffer_t citybuilding_edit_frame_t::param_str; +bool citybuilding_edit_frame_t::sortreverse = false; static bool compare_building_desc(const building_desc_t* a, const building_desc_t* b) { int diff = strcmp( a->get_name(), b->get_name() ); - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_name(const building_desc_t* a, const building_desc_t* b) { @@ -40,7 +41,7 @@ static bool compare_building_desc_name(const building_desc_t* a, const building_ if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_level_pax(const building_desc_t* a, const building_desc_t* b) { @@ -48,7 +49,7 @@ static bool compare_building_desc_level_pax(const building_desc_t* a, const buil if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_level_mail(const building_desc_t* a, const building_desc_t* b) { @@ -56,7 +57,7 @@ static bool compare_building_desc_level_mail(const building_desc_t* a, const bui if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_date_intro(const building_desc_t* a, const building_desc_t* b) { @@ -64,7 +65,7 @@ static bool compare_building_desc_date_intro(const building_desc_t* a, const bui if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_date_retire(const building_desc_t* a, const building_desc_t* b) { @@ -72,7 +73,7 @@ static bool compare_building_desc_date_retire(const building_desc_t* a, const bu if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_size(const building_desc_t* a, const building_desc_t* b) { @@ -86,7 +87,7 @@ static bool compare_building_desc_size(const building_desc_t* a, const building_ if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return citybuilding_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } @@ -141,6 +142,7 @@ void citybuilding_edit_frame_t::put_item_in_list( const building_desc_t* desc ) const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : bt_timeline_custom.pressed ? ni_timeline_year.get_value()*12 + ni_timeline_month.get_value()-1 : 0; const uint8 chosen_climate = get_climate(); const uint8 sortedby = get_sortedby(); + sortreverse = sort_order.pressed; if( (!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) && ( desc->get_allowed_climate_bits() & chosen_climate) ) { // timeline allows for this, and so does climates setting diff --git a/gui/citybuilding_edit.h b/gui/citybuilding_edit.h index 04cc186d7e..d1dae90c5a 100644 --- a/gui/citybuilding_edit.h +++ b/gui/citybuilding_edit.h @@ -41,6 +41,8 @@ class citybuilding_edit_frame_t : public extend_edit_gui_t public: citybuilding_edit_frame_t(player_t* player); + static bool sortreverse; + /** * in top-level windows the name is displayed in titlebar * @return the non-translated component name diff --git a/gui/curiosity_edit.cc b/gui/curiosity_edit.cc index a95870b587..784ae91a14 100644 --- a/gui/curiosity_edit.cc +++ b/gui/curiosity_edit.cc @@ -25,12 +25,13 @@ // new tool definition tool_build_house_t curiosity_edit_frame_t::haus_tool=tool_build_house_t(); cbuffer_t curiosity_edit_frame_t::param_str; +bool curiosity_edit_frame_t::sortreverse = false; static bool compare_building_desc(const building_desc_t* a, const building_desc_t* b) { int diff = strcmp( a->get_name(), b->get_name() ); - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_name(const building_desc_t* a, const building_desc_t* b) { @@ -38,7 +39,7 @@ static bool compare_building_desc_name(const building_desc_t* a, const building_ if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_level_pax(const building_desc_t* a, const building_desc_t* b) { @@ -46,7 +47,7 @@ static bool compare_building_desc_level_pax(const building_desc_t* a, const buil if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_level_mail(const building_desc_t* a, const building_desc_t* b) { @@ -54,7 +55,7 @@ static bool compare_building_desc_level_mail(const building_desc_t* a, const bui if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_date_intro(const building_desc_t* a, const building_desc_t* b) { @@ -62,7 +63,7 @@ static bool compare_building_desc_date_intro(const building_desc_t* a, const bui if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_date_retire(const building_desc_t* a, const building_desc_t* b) { @@ -70,7 +71,7 @@ static bool compare_building_desc_date_retire(const building_desc_t* a, const bu if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_building_desc_size(const building_desc_t* a, const building_desc_t* b) { @@ -84,7 +85,7 @@ static bool compare_building_desc_size(const building_desc_t* a, const building_ if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return curiosity_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } curiosity_edit_frame_t::curiosity_edit_frame_t(player_t* player_) : @@ -139,6 +140,7 @@ void curiosity_edit_frame_t::put_item_in_list( const building_desc_t* desc ) const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : bt_timeline_custom.pressed ? ni_timeline_year.get_value()*12 + ni_timeline_month.get_value()-1 : 0; const uint8 chosen_climate = get_climate(); const uint8 sortedby = get_sortedby(); + sortreverse = sort_order.pressed; if( (!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) && ( desc->get_allowed_climate_bits() & chosen_climate) ) { // timeline allows for this, and so does climates setting diff --git a/gui/curiosity_edit.h b/gui/curiosity_edit.h index 08998ecae7..bedda86c45 100644 --- a/gui/curiosity_edit.h +++ b/gui/curiosity_edit.h @@ -37,6 +37,8 @@ class curiosity_edit_frame_t : public extend_edit_gui_t public: curiosity_edit_frame_t(player_t* player); + static bool sortreverse; + /** * in top-level windows the name is displayed in titlebar * @return the non-translated component name diff --git a/gui/extend_edit.cc b/gui/extend_edit.cc index b1b6543780..23a54c8972 100644 --- a/gui/extend_edit.cc +++ b/gui/extend_edit.cc @@ -168,9 +168,14 @@ extend_edit_gui_t::extend_edit_gui_t(const char *name, player_t* player_) : cont_filter.end_table(); // Sorting box - gui_aligned_container_t *tbl_sorting = cont_filter.add_table(2,0); + gui_aligned_container_t *tbl_sorting = cont_filter.add_table(3,0); tbl_sorting->new_component("Sort by"); tbl_sorting->add_component(&cb_sortedby); + sort_order.init(button_t::sortarrow_state, ""); + sort_order.set_tooltip(translator::translate("hl_btn_sort_order")); + sort_order.add_listener(this); + sort_order.pressed = false; + tbl_sorting->add_component(&sort_order); cb_sortedby.add_listener(this); cb_sortedby.new_component(gui_sorting_item_t::BY_NAME_TRANSLATED); cb_sortedby.new_component(gui_sorting_item_t::BY_NAME_OBJECT); @@ -246,6 +251,10 @@ bool extend_edit_gui_t::action_triggered( gui_action_creator_t *comp,value_t /* else if( comp==&cb_sortedby ) { fill_list(); } + else if( comp == &sort_order ) { + sort_order.pressed = !sort_order.pressed; + fill_list(); + } return true; } diff --git a/gui/extend_edit.h b/gui/extend_edit.h index 5d8b5fc453..630b0e360a 100644 --- a/gui/extend_edit.h +++ b/gui/extend_edit.h @@ -125,7 +125,7 @@ class extend_edit_gui_t : //image gui_building_t building_image; - button_t bt_obsolete, bt_timeline, bt_climates, bt_timeline_custom; + button_t bt_obsolete, bt_timeline, bt_climates, bt_timeline_custom, sort_order; // we make this available for child classes gui_combobox_t cb_rotation, cb_climates, cb_sortedby; diff --git a/gui/factory_edit.cc b/gui/factory_edit.cc index 52029b210e..09c4ab5aea 100644 --- a/gui/factory_edit.cc +++ b/gui/factory_edit.cc @@ -29,11 +29,13 @@ tool_build_land_chain_t factory_edit_frame_t::land_chain_tool = tool_build_land_ tool_city_chain_t factory_edit_frame_t::city_chain_tool = tool_city_chain_t(); tool_build_factory_t factory_edit_frame_t::fab_tool = tool_build_factory_t(); cbuffer_t factory_edit_frame_t::param_str; +bool factory_edit_frame_t::sortreverse = false; + static bool compare_factory_desc(const factory_desc_t* a, const factory_desc_t* b) { int diff = strcmp( a->get_name(), b->get_name() ); - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_name(const factory_desc_t* a, const factory_desc_t* b) { @@ -41,7 +43,7 @@ static bool compare_factory_desc_name(const factory_desc_t* a, const factory_des if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_level_pax(const factory_desc_t* a, const factory_desc_t* b) { @@ -50,7 +52,7 @@ static bool compare_factory_desc_level_pax(const factory_desc_t* a, const factor if ( diff == 0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_level_mail(const factory_desc_t* a, const factory_desc_t* b) { @@ -59,7 +61,7 @@ static bool compare_factory_desc_level_mail(const factory_desc_t* a, const facto if ( diff == 0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_date_intro(const factory_desc_t* a, const factory_desc_t* b) { @@ -67,7 +69,7 @@ static bool compare_factory_desc_date_intro(const factory_desc_t* a, const facto if ( diff == 0) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_date_retire(const factory_desc_t* a, const factory_desc_t* b) { @@ -75,7 +77,7 @@ static bool compare_factory_desc_date_retire(const factory_desc_t* a, const fact if ( diff == 0) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_size(const factory_desc_t* a, const factory_desc_t* b) { @@ -89,7 +91,7 @@ static bool compare_factory_desc_size(const factory_desc_t* a, const factory_des if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_factory_desc_goods_number(const factory_desc_t* a, const factory_desc_t* b) { @@ -101,7 +103,7 @@ static bool compare_factory_desc_goods_number(const factory_desc_t* a, const fac if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } - return diff < 0; + return factory_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } @@ -161,6 +163,7 @@ void factory_edit_frame_t::fill_list() const bool land_chain = bt_land_chain.pressed; const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : bt_timeline_custom.pressed ? ni_timeline_year.get_value()*12 + ni_timeline_month.get_value()-1 : 0; const uint8 sortedby = get_sortedby(); + sortreverse = sort_order.pressed; factory_list.clear(); diff --git a/gui/factory_edit.h b/gui/factory_edit.h index 02a6bc57aa..562dad0e3f 100644 --- a/gui/factory_edit.h +++ b/gui/factory_edit.h @@ -46,6 +46,8 @@ class factory_edit_frame_t : public extend_edit_gui_t public: factory_edit_frame_t(player_t* player); + static bool sortreverse; + /** * in top-level windows the name is displayed in titlebar * @return the non-translated component name diff --git a/gui/groundobj_edit.cc b/gui/groundobj_edit.cc index 6f6619ac06..dd869d3418 100644 --- a/gui/groundobj_edit.cc +++ b/gui/groundobj_edit.cc @@ -30,12 +30,13 @@ // new tool definition tool_plant_groundobj_t groundobj_edit_frame_t::groundobj_tool; cbuffer_t groundobj_edit_frame_t::param_str; +bool groundobj_edit_frame_t::sortreverse = false; static bool compare_groundobj_desc(const groundobj_desc_t* a, const groundobj_desc_t* b) { int diff = strcmp( a->get_name(), b->get_name() ); - return diff < 0; + return groundobj_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_groundobj_desc_name(const groundobj_desc_t* a, const groundobj_desc_t* b) { @@ -43,7 +44,7 @@ static bool compare_groundobj_desc_name(const groundobj_desc_t* a, const groundo if(diff ==0) { diff = strcmp( a->get_name(), b->get_name() ); } - return diff < 0; + return groundobj_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } static bool compare_groundobj_desc_cost(const groundobj_desc_t* a, const groundobj_desc_t* b) { @@ -51,7 +52,7 @@ static bool compare_groundobj_desc_cost(const groundobj_desc_t* a, const groundo if(diff ==0) { diff = strcmp( a->get_name(), b->get_name() ); } - return diff < 0; + return groundobj_edit_frame_t::sortreverse ? diff > 0 : diff < 0; } @@ -85,6 +86,7 @@ void groundobj_edit_frame_t::fill_list() { groundobj_list.clear(); const uint8 sortedby = get_sortedby(); + sortreverse = sort_order.pressed; FOR(vector_tpl, const i, groundobj_t::get_all_desc()) { if ( i && (i->get_allowed_climate_bits() & get_climate()) ) { switch(sortedby) { diff --git a/gui/groundobj_edit.h b/gui/groundobj_edit.h index c29a382f4b..2ec414f576 100644 --- a/gui/groundobj_edit.h +++ b/gui/groundobj_edit.h @@ -36,6 +36,8 @@ class groundobj_edit_frame_t : public extend_edit_gui_t public: groundobj_edit_frame_t(player_t* player_); + static bool sortreverse; + /** * in top-level windows the name is displayed in titlebar * @return the non-translated component name