diff --git a/gui/baum_edit.cc b/gui/baum_edit.cc index ecda1c180..3927a58ed 100644 --- a/gui/baum_edit.cc +++ b/gui/baum_edit.cc @@ -31,8 +31,12 @@ tool_plant_tree_t baum_edit_frame_t::baum_tool; cbuffer_t baum_edit_frame_t::param_str; - 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; +} +static bool compare_tree_desc_name(const tree_desc_t* a, const tree_desc_t* b) { int diff = strcmp( translator::translate(a->get_name()), translator::translate(b->get_name()) ); if(diff ==0) { @@ -46,15 +50,19 @@ baum_edit_frame_t::baum_edit_frame_t(player_t* player_) : extend_edit_gui_t(translator::translate("baum builder"), player_), tree_list(16) { - bt_timeline.set_text( "Random age" ); - bt_obsolete.set_visible(false); + cont_timeline.set_visible(false); + + bt_randomage.init( button_t::square_state, "Random age"); + bt_randomage.add_listener(this); + bt_randomage.pressed = true; + cont_desc.add_component(&bt_randomage); desc = NULL; baum_tool.set_default_param(NULL); fill_list( is_show_trans_name ); - cont_left.add_component(&tree_image); + cont_right.add_component(&tree_image); building_image.set_visible(false); } @@ -64,9 +72,10 @@ baum_edit_frame_t::baum_edit_frame_t(player_t* player_) : void baum_edit_frame_t::fill_list( bool translate ) { tree_list.clear(); + const bool is_sortedbyname = get_sortedby()==gui_sorting_item_t::BY_NAME_TRANSLATED; FOR(vector_tpl, const i, baum_t::get_all_desc()) { - if (i) { - tree_list.insert_ordered(i, compare_tree_desc); + if ( i && (i->get_allowed_climate_bits() & get_climate()) ) { + tree_list.insert_ordered(i, is_sortedbyname ? compare_tree_desc_name : compare_tree_desc); } } @@ -84,6 +93,14 @@ void baum_edit_frame_t::fill_list( bool translate ) change_item_info( scl.get_selection() ); } +bool baum_edit_frame_t::action_triggered( gui_action_creator_t *comp,value_t e) +{ + if( comp==&bt_randomage ) { + bt_randomage.pressed ^= 1; + change_item_info( scl.get_selection() ); + } + return extend_edit_gui_t::action_triggered(comp,e); +} void baum_edit_frame_t::change_item_info(sint32 entry) @@ -124,7 +141,7 @@ void baum_edit_frame_t::change_item_info(sint32 entry) tree_image.set_image(desc->get_image_id( 0, 3 ), true); param_str.clear(); - param_str.printf( "%i%i,%s", bt_climates.pressed, bt_timeline.pressed, desc->get_name() ); + param_str.printf( "%i%i,%s", bt_climates.pressed, bt_randomage.pressed, desc->get_name() ); baum_tool.set_default_param(param_str); baum_tool.cursor = tool_t::general_tool[TOOL_PLANT_TREE]->cursor; welt->set_tool( &baum_tool, player ); diff --git a/gui/baum_edit.h b/gui/baum_edit.h index 18622ba35..baff75558 100644 --- a/gui/baum_edit.h +++ b/gui/baum_edit.h @@ -29,6 +29,8 @@ private: vector_tpltree_list; + button_t bt_randomage; + void fill_list( bool translate ) OVERRIDE; void change_item_info( sint32 i ) OVERRIDE; @@ -47,6 +49,8 @@ public: * @return the filename for the helptext, or NULL */ const char* get_help_filename() const OVERRIDE { return "baum_build.txt"; } + + bool action_triggered(gui_action_creator_t*, value_t) OVERRIDE; }; #endif diff --git a/gui/citybuilding_edit.cc b/gui/citybuilding_edit.cc index 1ca25d6dc..b05f5a1e8 100644 --- a/gui/citybuilding_edit.cc +++ b/gui/citybuilding_edit.cc @@ -31,29 +31,63 @@ cbuffer_t citybuilding_edit_frame_t::param_str; static bool compare_building_desc(const building_desc_t* a, const building_desc_t* b) { - int diff = a->get_level()-b->get_level(); + int diff = strcmp( a->get_name(), b->get_name() ); + return diff < 0; +} +static bool compare_building_desc_name(const building_desc_t* a, const building_desc_t* b) +{ + int diff = strcmp( translator::translate(a->get_name()), translator::translate(b->get_name()) ); if( diff==0 ) { - diff = a->get_type()-b->get_type(); + diff = strcmp(a->get_name(), b->get_name()); } + return diff < 0; +} +static bool compare_building_desc_level_pax(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_level() - b->get_level(); if( diff==0 ) { diff = strcmp(a->get_name(), b->get_name()); } return diff < 0; } - - -static bool compare_building_desc_trans(const building_desc_t* a, const building_desc_t* b) +static bool compare_building_desc_level_mail(const building_desc_t* a, const building_desc_t* b) { - int diff = strcmp( translator::translate(a->get_name()), translator::translate(b->get_name()) ); + int diff = a->get_mail_level() - b->get_mail_level(); if( diff==0 ) { - diff = a->get_level()-b->get_level(); + diff = strcmp(a->get_name(), b->get_name()); } + return diff < 0; +} +static bool compare_building_desc_date_intro(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_intro_year_month() - b->get_intro_year_month(); if( diff==0 ) { - diff = a->get_type()-b->get_type(); + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_date_retire(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_retire_year_month() - b->get_retire_year_month(); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_size(const building_desc_t* a, const building_desc_t* b) +{ + koord a_koord = a->get_size(); + koord b_koord = b->get_size(); + int diff = a_koord.x * a_koord.y - b_koord.x * b_koord.y; + if( diff==0 ) { + //same area - sort by side to seperate different shapes + diff = a_koord.x - b_koord.x; + } + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); } return diff < 0; } - citybuilding_edit_frame_t::citybuilding_edit_frame_t(player_t* player_) : @@ -67,66 +101,84 @@ citybuilding_edit_frame_t::citybuilding_edit_frame_t(player_t* player_) : bt_res.init( button_t::square_state, "residential house"); bt_res.add_listener(this); bt_res.pressed = true; - cont_right.add_component(&bt_res); + cont_filter.add_component(&bt_res); bt_com.init( button_t::square_state, "shops and stores"); bt_com.add_listener(this); bt_com.pressed = true; - cont_right.add_component(&bt_com); + cont_filter.add_component(&bt_com); bt_ind.init( button_t::square_state, "industrial building"); bt_ind.add_listener(this); - cont_right.add_component(&bt_ind); - bt_com.pressed = true; + bt_ind.pressed = true; + cont_filter.add_component(&bt_ind); + + // add to sorting selection + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_PAX); + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_MAIL); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_INTRO); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_RETIRE); + cb_sortedby.new_component(gui_sorting_item_t::BY_SIZE); + cb_sortedby.set_selection(2); // rotation - gui_aligned_container_t *tbl = cont_right.add_table(2,0); + gui_aligned_container_t *tbl = cont_desc.add_table(2,0); tbl->new_component("Rotation"); tbl->add_component(&cb_rotation); cb_rotation.add_listener(this); cb_rotation.new_component(gui_rotation_item_t::random); - cont_right.end_table(); + cont_desc.end_table(); fill_list( is_show_trans_name ); reset_min_windowsize(); } - +// put item in list according to filter/sorter +void citybuilding_edit_frame_t::put_item_in_list( const building_desc_t* desc ) +{ + const bool allow_obsolete = bt_obsolete.pressed; + const bool use_timeline = bt_timeline.pressed | bt_timeline_custom.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 chosen_climate = get_climate(); + const uint8 sortedby = get_sortedby(); + 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 + switch(sortedby) { + case gui_sorting_item_t::BY_NAME_TRANSLATED: building_list.insert_ordered( desc, compare_building_desc_name ); break; + case gui_sorting_item_t::BY_LEVEL_PAX: building_list.insert_ordered( desc, compare_building_desc_level_pax ); break; + case gui_sorting_item_t::BY_LEVEL_MAIL: building_list.insert_ordered( desc, compare_building_desc_level_mail ); break; + case gui_sorting_item_t::BY_DATE_INTRO: building_list.insert_ordered( desc, compare_building_desc_date_intro ); break; + case gui_sorting_item_t::BY_DATE_RETIRE: building_list.insert_ordered( desc, compare_building_desc_date_retire ); break; + case gui_sorting_item_t::BY_SIZE: building_list.insert_ordered( desc, compare_building_desc_size ); break; + default: building_list.insert_ordered( desc, compare_building_desc ); + } + } +} // fill the current building_list void citybuilding_edit_frame_t::fill_list( bool translate ) { - const bool allow_obsolete = bt_obsolete.pressed; - const bool use_timeline = bt_timeline.pressed; - const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : 0; + building_list.clear(); if(bt_res.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_citybuilding_list(building_desc_t::city_res)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered(desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } if(bt_com.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_citybuilding_list(building_desc_t::city_com)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered(desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } if(bt_ind.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_citybuilding_list(building_desc_t::city_ind)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered(desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } @@ -244,6 +296,7 @@ void citybuilding_edit_frame_t::change_item_info(sint32 entry) if(welt->get_tool(player->get_player_nr())==&haus_tool) { welt->set_tool( tool_t::general_tool[TOOL_QUERY], player ); } + buf.clear(); building_image.init(NULL, 0); cb_rotation.clear_elements(); cb_rotation.new_component(gui_rotation_item_t::random); diff --git a/gui/citybuilding_edit.h b/gui/citybuilding_edit.h index 2764c469b..616c3476f 100644 --- a/gui/citybuilding_edit.h +++ b/gui/citybuilding_edit.h @@ -34,6 +34,7 @@ private: button_t bt_ind; void fill_list( bool translate ) OVERRIDE; + void put_item_in_list( const building_desc_t* desc ); void change_item_info( sint32 i ) OVERRIDE; diff --git a/gui/curiosity_edit.cc b/gui/curiosity_edit.cc index b046a5f07..d7446d55c 100644 --- a/gui/curiosity_edit.cc +++ b/gui/curiosity_edit.cc @@ -32,15 +32,60 @@ static bool compare_building_desc(const building_desc_t* a, const building_desc_ int diff = strcmp( a->get_name(), b->get_name() ); return diff < 0; } - - -static bool compare_building_desc_trans(const building_desc_t* a, const building_desc_t* b) +static bool compare_building_desc_name(const building_desc_t* a, const building_desc_t* b) { int diff = strcmp( translator::translate(a->get_name()), translator::translate(b->get_name()) ); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_level_pax(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_level() - b->get_level(); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_level_mail(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_mail_level() - b->get_mail_level(); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_date_intro(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_intro_year_month() - b->get_intro_year_month(); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_date_retire(const building_desc_t* a, const building_desc_t* b) +{ + int diff = a->get_retire_year_month() - b->get_retire_year_month(); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_building_desc_size(const building_desc_t* a, const building_desc_t* b) +{ + koord a_koord = a->get_size(); + koord b_koord = b->get_size(); + int diff = a_koord.x * a_koord.y - b_koord.x * b_koord.y; + if( diff==0 ) { + //same area - sort by side to seperate different shapes + diff = a_koord.x - b_koord.x; + } + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } return diff < 0; } - - curiosity_edit_frame_t::curiosity_edit_frame_t(player_t* player_) : extend_edit_gui_t(translator::translate("curiosity builder"), player_), @@ -53,24 +98,32 @@ curiosity_edit_frame_t::curiosity_edit_frame_t(player_t* player_) : bt_city_attraction.init( button_t::square_state, "City attraction"); bt_city_attraction.add_listener(this); bt_city_attraction.pressed = true; - cont_right.add_component(&bt_city_attraction); + cont_filter.add_component(&bt_city_attraction); bt_land_attraction.init( button_t::square_state, "Land attraction"); bt_land_attraction.add_listener(this); bt_land_attraction.pressed = true; - cont_right.add_component(&bt_land_attraction); + cont_filter.add_component(&bt_land_attraction); bt_monuments.init( button_t::square_state, "Monument"); bt_monuments.add_listener(this); - cont_right.add_component(&bt_monuments); + cont_filter.add_component(&bt_monuments); + + // add to sorting selection + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_PAX); + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_MAIL); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_INTRO); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_RETIRE); + cb_sortedby.new_component(gui_sorting_item_t::BY_SIZE); + // rotation - gui_aligned_container_t *tbl = cont_right.add_table(2,0); + gui_aligned_container_t *tbl = cont_desc.add_table(2,0); tbl->new_component("Rotation"); tbl->add_component(&cb_rotation); cb_rotation.add_listener(this); cb_rotation.new_component(gui_rotation_item_t::random); - cont_right.end_table(); + cont_desc.end_table(); fill_list( is_show_trans_name ); @@ -78,40 +131,48 @@ curiosity_edit_frame_t::curiosity_edit_frame_t(player_t* player_) : } - +// put item in list according to filter/sorter +void curiosity_edit_frame_t::put_item_in_list( const building_desc_t* desc ) +{ + const bool allow_obsolete = bt_obsolete.pressed; + const bool use_timeline = bt_timeline.pressed | bt_timeline_custom.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 chosen_climate = get_climate(); + const uint8 sortedby = get_sortedby(); + 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 + switch(sortedby) { + case gui_sorting_item_t::BY_NAME_TRANSLATED: building_list.insert_ordered( desc, compare_building_desc_name ); break; + case gui_sorting_item_t::BY_LEVEL_PAX: building_list.insert_ordered( desc, compare_building_desc_level_pax ); break; + case gui_sorting_item_t::BY_LEVEL_MAIL: building_list.insert_ordered( desc, compare_building_desc_level_mail ); break; + case gui_sorting_item_t::BY_DATE_INTRO: building_list.insert_ordered( desc, compare_building_desc_date_intro ); break; + case gui_sorting_item_t::BY_DATE_RETIRE: building_list.insert_ordered( desc, compare_building_desc_date_retire ); break; + case gui_sorting_item_t::BY_SIZE: building_list.insert_ordered( desc, compare_building_desc_size ); break; + default: building_list.insert_ordered( desc, compare_building_desc ); + } + } +} // fill the current building_list void curiosity_edit_frame_t::fill_list( bool translate ) { - const bool allow_obsolete = bt_obsolete.pressed; - const bool use_timeline = bt_timeline.pressed; - const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : 0; - building_list.clear(); if(bt_city_attraction.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_list(building_desc_t::attraction_city)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered( desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } if(bt_land_attraction.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_list(building_desc_t::attraction_land)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered( desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } if(bt_monuments.pressed) { FOR(vector_tpl, const desc, *hausbauer_t::get_list(building_desc_t::monument)) { - if(!use_timeline || (!desc->is_future(month_now) && (!desc->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - building_list.insert_ordered( desc, translate?compare_building_desc_trans:compare_building_desc ); - } + put_item_in_list(desc); } } @@ -236,6 +297,7 @@ void curiosity_edit_frame_t::change_item_info(sint32 entry) building_image.init(NULL, 0); cb_rotation.clear_elements(); cb_rotation.new_component(gui_rotation_item_t::random); + buf.clear(); } reset_min_windowsize(); } diff --git a/gui/curiosity_edit.h b/gui/curiosity_edit.h index fbdb6f799..3989135a7 100644 --- a/gui/curiosity_edit.h +++ b/gui/curiosity_edit.h @@ -30,6 +30,7 @@ private: button_t bt_monuments; void fill_list( bool translate ) OVERRIDE; + void put_item_in_list(const building_desc_t* desc ); void change_item_info( sint32 i ) OVERRIDE; diff --git a/gui/extend_edit.cc b/gui/extend_edit.cc index eabe572a1..b4b739306 100644 --- a/gui/extend_edit.cc +++ b/gui/extend_edit.cc @@ -9,29 +9,55 @@ #include "../simevent.h" #include "../dataobj/translator.h" +#include "../descriptor/ground_desc.h" #include "../player/simplay.h" #include "extend_edit.h" - -static const char* numbers[] = { "0", "1", "2", "3" }; - gui_rotation_item_t::gui_rotation_item_t(uint8 r) : gui_scrolled_list_t::const_text_scrollitem_t(NULL, SYSCOL_TEXT) { rotation = r; - - if (rotation <= 3) { - text = numbers[rotation]; + switch(rotation) { + case 0: text = translator::translate("[0] south-facing"); break; + case 1: text = translator::translate("[1] east-facing"); break; + case 2: text = translator::translate("[2] north-facing"); break; + case 3: text = translator::translate("[3] west-facing"); break; + case 4: text = translator::translate("[4] southeast corner"); break; + case 5: text = translator::translate("[5] northeast corner"); break; + case 6: text = translator::translate("[6] northwest corner"); break; + case 7: text = translator::translate("[7] southwest corner"); break; + case automatic: text = translator::translate("auto"); break; + case random: text = translator::translate("random"); break; + default: text = ""; } - else if (rotation == automatic) { - text = translator::translate("auto"); +} + +gui_climates_item_t::gui_climates_item_t(uint8 c) : gui_scrolled_list_t::const_text_scrollitem_t(NULL, SYSCOL_TEXT) +{ + if(c(); - bt_climates.init( button_t::square_state, "ignore climates"); - bt_climates.add_listener(this); - add_component(&bt_climates); + add_component(&cont_desc); + cont_desc.set_table_layout(1,0); + + new_component(); + + // legacy support + add_component(&cont_right); + cont_right.set_table_layout(1,0); + + // add image + add_component(&building_image); + + + // start filling cont_timeline--------------------------------------------------------------------------------------------- bt_timeline.init( button_t::square_state, "Use timeline start year"); bt_timeline.pressed = welt->get_settings().get_use_timeline(); bt_timeline.add_listener(this); - add_component(&bt_timeline); + cont_timeline.add_component(&bt_timeline, 4); + + bt_timeline_custom.init( button_t::square_state, "Available at custom date:"); + bt_timeline_custom.add_listener(this); + cont_timeline.add_component(&bt_timeline_custom, 4); + + cont_timeline.new_component("Month"); + ni_timeline_month.init( (sint32)(welt->get_current_month()%12+1), 1, 12, gui_numberinput_t::AUTOLINEAR, true ); + ni_timeline_month.add_listener(this); + cont_timeline.add_component(&ni_timeline_month); + cont_timeline.new_component("Year"); + ni_timeline_year.init( (sint32)(welt->get_current_month()/12), 0, 2999, gui_numberinput_t::AUTOLINEAR, false ); + ni_timeline_year.add_listener(this); + cont_timeline.add_component(&ni_timeline_year); bt_obsolete.init( button_t::square_state, "Show obsolete"); bt_obsolete.add_listener(this); - add_component(&bt_obsolete); + cont_timeline.add_component(&bt_obsolete, 4); + // end filling cont_timeline--------------------------------------------------------------------------------------------- + + // start filling cont_filter--------------------------------------------------------------------------------------------- + // climate filter + gui_aligned_container_t *tbl_climate = cont_filter.add_table(2,0); + tbl_climate->new_component("Climate"); + tbl_climate->add_component(&cb_climates); + cb_climates.add_listener(this); + cb_climates.new_component(climate::MAX_CLIMATES); + for(uint8 i=climate::desert_climate; i(i); + } + cb_climates.set_selection(0); + cont_filter.end_table(); + + // Sorting box + cont_filter.add_component(&cb_sortedby); + 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); + cb_sortedby.set_selection(0); + // end filling cont_filter--------------------------------------------------------------------------------------------- + + //filling cont_desc + + bt_climates.init( button_t::square_state, "ignore climates"); + bt_climates.add_listener(this); + cont_desc.add_component(&bt_climates); - add_component(&cont_right); - cont_right.set_table_layout(1,0); scrolly.set_visible(true); add_component(&scrolly); @@ -153,9 +234,29 @@ bool extend_edit_gui_t::action_triggered( gui_action_creator_t *comp,value_t /* fill_list( is_show_trans_name ); } else if( comp==&bt_timeline ) { + bt_timeline_custom.pressed = false; bt_timeline.pressed ^= 1; fill_list( is_show_trans_name ); } + else if ( comp==&bt_timeline_custom ) { + bt_timeline.pressed = false; + bt_timeline_custom.pressed ^= 1; + fill_list( is_show_trans_name ); + } + else if ( comp==&ni_timeline_year && bt_timeline_custom.pressed) { + fill_list( is_show_trans_name ); + } + else if ( comp==&ni_timeline_month && bt_timeline_custom.pressed) { + fill_list( is_show_trans_name ); + } + else if( comp==&cb_climates ) { + fill_list( is_show_trans_name ); + change_item_info(scl.get_selection()); + } + else if( comp==&cb_sortedby ) { + fill_list( is_show_trans_name ); + } + return true; } @@ -167,3 +268,18 @@ uint8 extend_edit_gui_t::get_rotation() const } return 0; } +uint8 extend_edit_gui_t::get_climate() const +{ + if (gui_climates_item_t *item = dynamic_cast( cb_climates.get_selected_item() ) ) { + return item->get_climate(); + } + return ALL_CLIMATES; +} + +uint8 extend_edit_gui_t::get_sortedby() const +{ + if (gui_sorting_item_t *item = dynamic_cast( cb_sortedby.get_selected_item() ) ) { + return item->get_sortedby(); + } + return ALL_CLIMATES; +} \ No newline at end of file diff --git a/gui/extend_edit.h b/gui/extend_edit.h index 83cf89851..7a53ce646 100644 --- a/gui/extend_edit.h +++ b/gui/extend_edit.h @@ -17,6 +17,8 @@ #include "components/gui_fixedwidth_textarea.h" #include "components/gui_building.h" #include "components/gui_combobox.h" +#include "components/gui_numberinput.h" +#include "components/gui_divider.h" #include "../utils/cbuffer_t.h" #include "../simtypes.h" @@ -45,6 +47,54 @@ public: sint8 get_rotation() const { return rotation; } }; +/** + * Entries for climate selection. + */ +class gui_climates_item_t : public gui_scrolled_list_t::const_text_scrollitem_t +{ +private: + const char *text; + uint8 climate_; + +public: + gui_climates_item_t(uint8 r); + + char const* get_text () const OVERRIDE { return text; } + + sint8 get_climate() const { return climate_; } +}; + +/** + * Entries for sorting selection. + */ +class gui_sorting_item_t : public gui_scrolled_list_t::const_text_scrollitem_t +{ +private: + const char *text; + uint8 sorted_by; + +public: + enum sorting_options { + BY_NAME_TRANSLATED, + BY_NAME_OBJECT, + BY_LEVEL_PAX, + BY_LEVEL_MAIL, + BY_DATE_INTRO, + BY_DATE_RETIRE, + BY_SIZE, + BY_COST + }; + + gui_sorting_item_t(uint8 r); + + char const* get_text () const OVERRIDE { return text; } + + sint8 get_sortedby() const { return sorted_by; } +}; + + + + /** * Base class map editor dialogues to select object to place on map. */ @@ -54,8 +104,11 @@ class extend_edit_gui_t : { protected: player_t *player; - /// cont_left: left column, right: between obsolete-button and text-area - gui_aligned_container_t cont_left, cont_right; + /// cont_left: left column, cont_right: above object description + /// cont_filter: Settings about the content of the list (above list) + /// cont_desc: Settings about the active object (eg. rotation) + /// cont_timeline: The timeline-settings above cont_filter + gui_aligned_container_t cont_left, cont_right, cont_filter, cont_desc, cont_timeline; cbuffer_t buf; gui_fixedwidth_textarea_t info_text; @@ -66,10 +119,12 @@ protected: //image gui_building_t building_image; - button_t bt_obsolete, bt_timeline, bt_climates; + button_t bt_obsolete, bt_timeline, bt_climates, bt_timeline_custom; // we make this available for child classes - gui_combobox_t cb_rotation; + gui_combobox_t cb_rotation, cb_climates, cb_sortedby; + + gui_numberinput_t ni_timeline_year, ni_timeline_month; /// show translated names bool is_show_trans_name; @@ -84,6 +139,17 @@ protected: * defaults to zero. */ uint8 get_rotation() const; + + /** + * @returns selected climate of cb_climates. + */ + uint8 get_climate() const; + + /** + * @returns selected sorting method. + */ + uint8 get_sortedby() const; + public: extend_edit_gui_t(const char *name, player_t* player_); diff --git a/gui/factory_edit.cc b/gui/factory_edit.cc index 6cf76682d..ce68325ff 100644 --- a/gui/factory_edit.cc +++ b/gui/factory_edit.cc @@ -30,16 +30,65 @@ 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; - -static bool compare_fabrik_desc(const factory_desc_t* a, const factory_desc_t* b) +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; } - -static bool compare_factory_desc_trans(const factory_desc_t* a, const factory_desc_t* b) +static bool compare_factory_desc_name(const factory_desc_t* a, const factory_desc_t* b) { int diff = strcmp( translator::translate(a->get_name()), translator::translate(b->get_name()) ); + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_factory_desc_level_pax(const factory_desc_t* a, const factory_desc_t* b) +{ + int diff = (a->get_pax_demand() != 65535 ? a->get_pax_demand() : a->get_pax_level()) + -(b->get_pax_demand() != 65535 ? b->get_pax_demand() : b->get_pax_level()); + if ( diff == 0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_factory_desc_level_mail(const factory_desc_t* a, const factory_desc_t* b) +{ + int diff = (a->get_mail_demand() != 65535 ? a->get_mail_demand() : a->get_pax_level()>>2) + -(b->get_mail_demand() != 65535 ? b->get_mail_demand() : b->get_pax_level()>>2); + if ( diff == 0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_factory_desc_date_intro(const factory_desc_t* a, const factory_desc_t* b) +{ + int diff = a->get_building()->get_intro_year_month() - b->get_building()->get_intro_year_month(); + if ( diff = 0) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_factory_desc_date_retire(const factory_desc_t* a, const factory_desc_t* b) +{ + int diff = a->get_building()->get_retire_year_month() - b->get_building()->get_retire_year_month(); + if ( diff = 0) { + diff = strcmp(a->get_name(), b->get_name()); + } + return diff < 0; +} +static bool compare_factory_desc_size(const factory_desc_t* a, const factory_desc_t* b) +{ + koord a_koord = a->get_building()->get_size(); + koord b_koord = b->get_building()->get_size(); + int diff = a_koord.x * a_koord.y - b_koord.x * b_koord.y; + if( diff==0 ) { + //same area - sort by side to seperate different shapes + diff = a_koord.x - b_koord.x; + } + if( diff==0 ) { + diff = strcmp(a->get_name(), b->get_name()); + } return diff < 0; } @@ -52,14 +101,24 @@ factory_edit_frame_t::factory_edit_frame_t(player_t* player_) : bt_city_chain.init( button_t::square_state, "Only city chains"); bt_city_chain.add_listener(this); - cont_right.add_component(&bt_city_chain); + cont_filter.add_component(&bt_city_chain); bt_land_chain.init( button_t::square_state, "Only land chains"); bt_land_chain.add_listener(this); - cont_right.add_component(&bt_land_chain); + cont_filter.add_component(&bt_land_chain); + + // add water to climate selection + cb_climates.new_component(climate::water_climate); + + // add to sorting selection + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_PAX); + cb_sortedby.new_component(gui_sorting_item_t::BY_LEVEL_MAIL); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_INTRO); + cb_sortedby.new_component(gui_sorting_item_t::BY_DATE_RETIRE); + cb_sortedby.new_component(gui_sorting_item_t::BY_SIZE); // rotation, production - gui_aligned_container_t *tbl = cont_right.add_table(2,2); + gui_aligned_container_t *tbl = cont_desc.add_table(2,2); tbl->new_component("Rotation"); tbl->add_component(&cb_rotation); cb_rotation.add_listener(this); @@ -70,7 +129,7 @@ factory_edit_frame_t::factory_edit_frame_t(player_t* player_) : inp_production.set_limits(0,9999); inp_production.add_listener( this ); tbl->add_component(&inp_production); - cont_right.end_table(); + cont_desc.end_table(); fill_list( is_show_trans_name ); @@ -83,10 +142,11 @@ factory_edit_frame_t::factory_edit_frame_t(player_t* player_) : void factory_edit_frame_t::fill_list( bool translate ) { const bool allow_obsolete = bt_obsolete.pressed; - const bool use_timeline = bt_timeline.pressed; + const bool use_timeline = bt_timeline.pressed | bt_timeline_custom.pressed; const bool city_chain = bt_city_chain.pressed; const bool land_chain = bt_land_chain.pressed; - const sint32 month_now = bt_timeline.pressed ? welt->get_current_month() : 0; + 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(); factory_list.clear(); @@ -96,22 +156,23 @@ void factory_edit_frame_t::fill_list( bool translate ) if(desc->get_distribution_weight()>0) { // DistributionWeight=0 is obsoleted item, only for backward compatibility - if(!use_timeline || (!desc->get_building()->is_future(month_now) && (!desc->get_building()->is_retired(month_now) || allow_obsolete)) ) { - // timeline allows for this - - if(city_chain) { - if (desc->get_placement() == factory_desc_t::City && desc->is_consumer_only()) { - factory_list.insert_ordered( desc, translate?compare_factory_desc_trans:compare_fabrik_desc ); + if( (!use_timeline || (!desc->get_building()->is_future(month_now) && (!desc->get_building()->is_retired(month_now) || allow_obsolete))) + && ( desc->get_building()->get_allowed_climate_bits() & get_climate()) ) { + // timeline allows for this, and so does climates setting + + if( ( city_chain && (desc->get_placement() == factory_desc_t::City && desc->is_consumer_only() ) ) + || ( land_chain && (desc->get_placement() != factory_desc_t::City && desc->is_consumer_only() ) ) + || (!city_chain && !land_chain) ) { + switch(sortedby) { + case gui_sorting_item_t::BY_NAME_TRANSLATED: factory_list.insert_ordered( desc, compare_factory_desc_name ); break; + case gui_sorting_item_t::BY_LEVEL_PAX: factory_list.insert_ordered( desc, compare_factory_desc_level_pax ); break; + case gui_sorting_item_t::BY_LEVEL_MAIL: factory_list.insert_ordered( desc, compare_factory_desc_level_mail ); break; + case gui_sorting_item_t::BY_DATE_INTRO: factory_list.insert_ordered( desc, compare_factory_desc_date_intro ); break; + case gui_sorting_item_t::BY_DATE_RETIRE: factory_list.insert_ordered( desc, compare_factory_desc_date_retire ); break; + case gui_sorting_item_t::BY_SIZE: factory_list.insert_ordered( desc, compare_factory_desc_size ); break; + default: factory_list.insert_ordered( desc, compare_factory_desc ); } } - if(land_chain) { - if (desc->get_placement() != factory_desc_t::City && desc->is_consumer_only()) { - factory_list.insert_ordered( desc, translate?compare_factory_desc_trans:compare_fabrik_desc ); - } - } - if(!city_chain && !land_chain) { - factory_list.insert_ordered( desc, translate?compare_factory_desc_trans:compare_fabrik_desc ); - } } } } @@ -307,6 +368,7 @@ void factory_edit_frame_t::change_item_info(sint32 entry) building_image.init(NULL, 0); fac_desc = NULL; welt->set_tool( tool_t::general_tool[TOOL_QUERY], player ); + buf.clear(); } info_text.recalc_size(); reset_min_windowsize();