void trecruit::switch_type_internal(twindow& window) { int side_num = city_.side(); std::stringstream str; int gold = current_team_.gold(); tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); list->clear(); unit_types_.clear(); const std::vector<const unit_type*>& recruits = city_.recruits(game_config::current_level); for (std::vector<const unit_type*>::const_iterator it = recruits.begin(); it != recruits.end(); ++it) { /*** Add list item ***/ const unit_type* type = *it; VALIDATE(type, std::string("could not find unit type ") + type->id()); string_map list_item; std::map<std::string, string_map> list_item_item; if (gold >= type->cost() * cost_exponent_ / 100) { list_item["label"] = type->image() + "~RC(" + type->flag_rgb() + ">" + team::get_side_color_index(side_num) + ")"; } else { list_item["label"] = type->image() + "~GS()"; } list_item_item.insert(std::make_pair("icon", list_item)); list_item["label"] = type->type_name(); list_item_item.insert(std::make_pair("name", list_item)); str.str(""); str << type->cost() * cost_exponent_ / 100 << " " << sngettext("unit^Gold", "Gold", type->cost() * cost_exponent_ / 100); list_item["label"] = str.str(); list_item_item.insert(std::make_pair("cost", list_item)); list->add_row(list_item_item); tgrid* grid_ptr = list->get_row_grid(unit_types_.size()); twidget* widget = grid_ptr->find("leader", false); widget->set_visible(type->leader()? twidget::VISIBLE: twidget::INVISIBLE); unit_types_.push_back(type); } window.invalidate_layout(); if (type_index_ >= (int)list->get_item_count()) { type_index_ = list->get_item_count() - 1; } list->select_row(type_index_); tbutton* prev = find_widget<tbutton>(&window, "prev", false, true); prev->set_active(game_config::current_level != game_config::min_level); tbutton* next = find_widget<tbutton>(&window, "next", false, true); next->set_active(game_config::current_level != game_config::max_level); str.str(""); str << "misc/digit-big.png~CROP(" << 30 * game_config::current_level << ", 0, 30, 45)"; find_widget<tcontrol>(&window, "level", false, false)->set_label(str.str()); type_selected(window); }
void texpedite::disband(bool& handled, bool& halt, int index) { twindow& window = *window_; tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); if (!disband_->button_pressed(index)) { return; } list->remove_row(index); int size = city_.reside_troops().size(); for (int i = index; i < size; i ++) { tgrid* grid_ptr = list->get_row_grid(i); // tbutton& disband = find_widget<tbutton>(&window, "disband", false); tbutton& disband = *dynamic_cast<tbutton*>(grid_ptr->find("disband", false)); disconnect_signal_mouse_left_click( disband , boost::bind( &texpedite::disband , this , _3, _4 , i + 1)); connect_signal_mouse_left_click( disband , boost::bind( &texpedite::disband , this , _3, _4 , i)); disband.set_active(city_.reside_troops()[i]->human()); } tbutton* ok = find_widget<tbutton>(&window, "ok", false, true); if (!city_.reside_troops().empty()) { if (index == size) { index --; } list->select_row(index); const unit& u = *city_.reside_troops()[index]; ok->set_active(can_move(u) && u.human()); } else { ok->set_active(false); } type_selected(window); handled = true; halt = true; window.invalidate_layout(); }
void texpedite::disband(bool& handled, bool& halt, int index) { twindow& window = *window_; tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); if (!disband_->button_pressed(index)) { return; } list->remove_row(index); int size = city_.reside_troops().size(); for (int i = index; i < size; i ++) { twidget* grid_ptr = list->get_row_panel(i); // tbutton& disband = find_widget<tbutton>(&window, "disband", false); tbutton& disband = *dynamic_cast<tbutton*>(grid_ptr->find("disband", false)); disconnect_signal_mouse_left_click( disband , boost::bind( &texpedite::disband , this , _3, _4 , i + 1)); connect_signal_mouse_left_click( disband , boost::bind( &texpedite::disband , this , _3, _4 , i)); disband.set_active(city_.reside_troops()[i]->human()); } type_selected(window, *list); handled = true; halt = true; }
void texpedite::pre_show(CVideo& /*video*/, twindow& window) { window_ = &window; int side_num = city_.side(); team& current_team = teams_[side_num - 1]; std::stringstream str; tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); int cost_exponent = current_team.cost_exponent(); std::vector<unit*>& reside_troops = city_.reside_troops(); int troop_index = 0; for (std::vector<unit*>::const_iterator it = reside_troops.begin(); it != reside_troops.end(); ++ it, troop_index ++) { unit& u = **it; /*** Add list item ***/ string_map list_item; std::map<std::string, string_map> list_item_item; list_item["label"] = u.absolute_image() + "~RC(" + u.team_color() + ">" + team::get_side_color_index(side_num) + ")"; list_item_item.insert(std::make_pair("icon", list_item)); // type/name str.str(""); str << u.type_name() << "(Lv" << u.level() << ")\n"; str << u.name(); list_item["label"] = str.str(); list_item_item.insert(std::make_pair("type", list_item)); // list_item["label"] = it->name(); // list_item_item.insert(std::make_pair("name", list_item)); // hp str.str(""); str << u.hitpoints() << "/\n" << u.max_hitpoints(); list_item["label"] = str.str(); list_item_item.insert(std::make_pair("hp", list_item)); // xp str.str(""); str << u.experience() << "/\n"; if (u.can_advance()) { str << u.max_experience(); } else { str << "-"; } list_item["label"] = str.str(); list_item_item.insert(std::make_pair("xp", list_item)); // movement str.str(""); str << u.movement_left() << "/" << u.total_movement(); list_item["label"] = str.str(); list_item_item.insert(std::make_pair("movement", list_item)); str.str(""); str << u.cost() * cost_exponent / 100 << "/" << calculate_disband_income(u, cost_exponent); list_item["label"] = str.str(); list_item_item.insert(std::make_pair("cost", list_item)); list->add_row(list_item_item); twidget* grid_ptr = list->get_row_panel(troop_index); twidget* widget = grid_ptr->find("human", false); widget->set_visible(u.human()? twidget::VISIBLE: twidget::INVISIBLE); // tbutton& disband = find_widget<tbutton>(&window, "disband", false); tbutton& disband = *dynamic_cast<tbutton*>(grid_ptr->find("disband", false)); connect_signal_mouse_left_click( disband , boost::bind( &texpedite::disband , this , _3, _4 , troop_index)); if (troop_index) { disband.set_visible(twidget::INVISIBLE); } else { disband.set_visible(twidget::VISIBLE); disband.set_active(reside_troops[troop_index]->human()); } } list->set_callback_value_change(dialog_callback3<texpedite, tlistbox, &texpedite::type_selected>); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "hero_list", false) , boost::bind( &texpedite::hero_list , this , boost::ref(window))); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "merit", false) , boost::bind( &texpedite::merit , this , boost::ref(window))); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "task", false) , boost::bind( &texpedite::set_task , this , boost::ref(window))); type_selected(window, *list); }