1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
* This file is part of the Simutrans project under the Artistic License.
* (see LICENSE.txt)
*/
#include "convoi_filter_frame.h"
#include "convoi_frame.h"
#include "components/gui_convoiinfo.h"
#include "../simcolor.h"
#include "../descriptor/goods_desc.h"
#include "../bauer/goods_manager.h"
#include "../dataobj/translator.h"
const char *convoi_filter_frame_t::filter_buttons_text[FILTER_BUTTONS] = {
"clf_chk_spezial_filter",
"clf_chk_waren",
"clf_chk_noroute",
"clf_chk_stucked",
"clf_chk_noincome",
"clf_chk_indepot",
"clf_chk_noschedule",
"clf_chk_noline",
"clf_chk_obsolete"
};
convoi_filter_frame_t::filter_flag_t convoi_filter_frame_t::filter_buttons_types[FILTER_BUTTONS] = {
special_filter,
ware_filter,
noroute_filter,
stucked_filter,
noincome_filter,
indepot_filter,
noschedule_filter,
noline_filter,
obsolete_filter
};
slist_tpl<const goods_desc_t *>convoi_filter_frame_t::active_ware;
uint32 convoi_filter_frame_t::filter_flags = 0;
convoi_filter_frame_t::convoi_filter_frame_t(player_t *player, convoi_frame_t *m) :
gui_frame_t( translator::translate("clf_title"), player),
main_frame(m),
ware_scrolly(&ware_cont)
{
for( int i=0; i < FILTER_BUTTONS; i++ ) {
filter_buttons[i].init(button_t::square_state, filter_buttons_text[i]);
filter_buttons[i].add_listener(this);
if(filter_buttons_types[i] < sub_filter) {
filter_buttons[i].background_color = color_idx_to_rgb(COL_WHITE);
}
filter_buttons[i].pressed = get_filter(filter_buttons_types[i]);
}
set_table_layout(1,0);
set_alignment(ALIGN_TOP);
add_table(3,0);
{
ware_alle.init(button_t::roundbox, "clf_btn_alle");
ware_alle.add_listener(this);
add_component(&ware_alle);
ware_keine.init(button_t::roundbox, "clf_btn_keine");
ware_keine.add_listener(this);
add_component(&ware_keine);
ware_invers.init(button_t::roundbox, "clf_btn_invers");
ware_invers.add_listener(this);
add_component(&ware_invers);
}
end_table();
add_table( 2, 0 );
{
add_table(2,0);
{
// special buttons
add_component(filter_buttons, 2);
for( int i=2; i<FILTER_BUTTONS; i++ ) {
new_component<gui_margin_t>();
add_component(filter_buttons + i);
}
}
end_table();
ware_scrolly.set_scroll_amount_y(D_BUTTON_HEIGHT);
add_component( &ware_scrolly );
}
end_table();
ware_cont.set_table_layout(2,0);
all_ware.clear();
ware_cont.add_component(filter_buttons + 1,2);
for( int i=0; i < goods_manager_t::get_count(); i++ ) {
const goods_desc_t *ware = goods_manager_t::get_info(i);
if( ware == goods_manager_t::none ) {
continue;
}
if( ware->get_catg() == 0 ) {
// Special freight: Each good is special
ware_cont.new_component<gui_margin_t>();
ware_item_t *item = ware_cont.new_component<ware_item_t>(this, ware);
item->init(button_t::square_state, translator::translate(ware->get_name()));
item->pressed = active_ware.is_contained(ware);
all_ware.append(item);
}
}
// now add other good categories
for( int i=1; i < goods_manager_t::get_max_catg_index(); i++ ) {
const goods_desc_t *ware = goods_manager_t::get_info_catg(i);
if( ware->get_catg() != 0 ) {
ware_cont.new_component<gui_margin_t>();
ware_item_t *item = ware_cont.new_component<ware_item_t>(this, ware);
item->init(button_t::square_state, translator::translate(ware->get_catg_name()));
item->pressed = active_ware.is_contained(ware);
all_ware.append(item);
}
}
set_resizemode(diagonal_resize);
reset_min_windowsize();
}
void convoi_filter_frame_t::init(uint32 filter_flags, const slist_tpl<const goods_desc_t*>* wares)
{
for (int i = 0; i < FILTER_BUTTONS; i++) {
set_filter(filter_buttons_types[i], filter_flags & filter_buttons_types[i]);
filter_buttons[i].pressed = get_filter(filter_buttons_types[i]);
}
if (&active_ware != wares) {
active_ware.clear();
if (wares) {
FOR(slist_tpl<ware_item_t*>, wi, all_ware) {
wi->pressed = wares->is_contained(wi->ware);
if (wi->pressed) {
active_ware.append(wi->ware);
}
}
}
}
}
/**
* This method is called if an action is triggered
*/
bool convoi_filter_frame_t::action_triggered( gui_action_creator_t *comp,value_t /* */)
{
for( int i = 0; i < FILTER_BUTTONS; i++) {
if(comp == filter_buttons + i) {
filter_buttons[i].pressed ^= 1;
set_filter( filter_buttons_types[i], !get_filter(filter_buttons_types[i]) );
sort_list();
return true;
}
}
if(comp == &ware_alle) {
FOR( slist_tpl<ware_item_t *>, wi, all_ware ) {
wi->pressed = true;
}
sort_list();
return true;
}
if(comp == &ware_keine) {
FOR( slist_tpl<ware_item_t *>, wi, all_ware ) {
wi->pressed = false;
}
sort_list();
return true;
}
if( comp == &ware_invers ) {
FOR( slist_tpl<ware_item_t *>, wi, all_ware ) {
wi->pressed ^= true;
}
sort_list();
return true;
}
return false;
}
void convoi_filter_frame_t::sort_list()
{
active_ware.clear();
FOR( slist_tpl<ware_item_t *>, wi, all_ware ) {
if( wi->pressed ) {
/*
uint8 catg = wi->ware->get_catg();
if( catg ) {
// now all goods of this category
for( int i=1; i<goods_manager_t::get_max_catg_index(); i++ ) {
if( goods_manager_t::get_info(i)->get_catg()==catg ) {
active_ware.append( goods_manager_t::get_info(i) );
}
}
}
else {
active_ware.append( wi->ware );
}
*/
active_ware.append( wi->ware );
}
}
main_frame->sort_list( filter_flags, &active_ware );
}
|