Exemplo n.º 1
0
void texpedite::type_selected(twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "type_list", false);

	twindow::tinvalidate_layout_blocker invalidate_layout_blocker(window);
	list.invalidate_layout();

	troop_index_ = list.get_selected_row();
	refresh_tooltip(window);

	// There is maybe no troop after disband. so troop_index_ maybe equal -1.
	if (troop_index_ >= 0) {
		int size = city_.reside_troops().size();
		const unit& u = *city_.reside_troops()[troop_index_];
		for (int index = 0; index < size; index ++) {
			tgrid* grid_ptr = list.get_row_grid(index);
			// tbutton& disband = find_widget<tbutton>(&window, "disband", false);
			tbutton& disband = *dynamic_cast<tbutton*>(grid_ptr->find("disband", false));
			if (index == troop_index_) {
				disband.set_visible(twidget::VISIBLE);
				disband.set_active(u.human());
			} else {
				disband.set_visible(twidget::INVISIBLE);
			}
		}

		tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
		ok->set_active(u.human() && can_move(u));
	}
}
void tstrategy_list::type_selected(twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "type_list", false);

	troop_index_ = list.get_selected_row();
	refresh_tooltip(window);
}
Exemplo n.º 3
0
void temploy::type_selected(twindow& window, tlistbox& list, const int type)
{
	cursel_ = list.get_selected_row();

	set_ok_active(window);

	refresh_tooltip(window);
}
Exemplo n.º 4
0
void tinterior::appoint(twindow& window)
{
	std::stringstream strstr;
	hero* new_mayor = checked_hero_ != -1? fresh_heros_[checked_hero_]: &hero_invalid;
	city_.select_mayor(new_mayor, false);

	tcontrol* control;
	for (int index = 0; index < (int)fresh_heros_.size(); index ++) {
		tgrid* grid_ptr = hero_table_->get_row_grid(index);
		control = dynamic_cast<tcontrol*>(grid_ptr->find("name", true));
		hero& h = *fresh_heros_[index];
		strstr.str("");
		if (h.official_ == hero_official_mayor) {
			strstr << "<format>color=blue text='";
		}
		strstr << h.name();
		if (h.official_ == hero_official_mayor) {
			strstr << "'</format>";
		}
		control->set_label(strstr.str());
	}

	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	// official portrait
	control = find_widget<tcontrol>(&window, "mayor", false, true);
	if (new_mayor->valid()) {
		control->set_label(new_mayor->image());
	} else {
		control->set_label("");
	}

	for (std::vector<department>::iterator d_it = departments_.begin(); d_it != departments_.end(); ++ d_it) {
		tgrid* grid_ptr = list->get_row_grid(d_it->type_);

		d_it->exploiture_ = calculate_exploiture(city_.master(), new_mayor? (*new_mayor): hero_invalid, d_it->type_);

		// exploiture data
		strstr.str("");
		if (d_it->type_ == department::commercial) {
			strstr << calculate_markets(d_it->exploiture_).second;
		} else {
			strstr << calculate_technologies(d_it->exploiture_).second;
		}
		control = dynamic_cast<tcontrol*>(grid_ptr->find("total", true));
		control->set_label(strstr.str());

		strstr.str("");
		strstr << d_it->exploiture_ << "%";
		control = dynamic_cast<tcontrol*>(grid_ptr->find("exploiture", true));
		control->set_label(strstr.str());
	}

	appoint_->set_active(false);
	refresh_tooltip(window);
}
Exemplo n.º 5
0
void temploy::type_selected(twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "type_list", false);

	cursel_ = list.get_selected_row();

	set_ok_active(window);

	refresh_tooltip(window);
}
Exemplo n.º 6
0
void texpedite::set_task(twindow& window)
{
	std::vector<unit*>& reside_troops = city_.reside_troops();
	unit& temp = *reside_troops[troop_index_];

	if (temp.task() == unit::TASK_NONE) {
		temp.set_guard(city_.get_location());

	} else {
		temp.set_task(unit::TASK_NONE);
	}
	set_task_str(window, temp);
	refresh_tooltip(window);
}
Exemplo n.º 7
0
void tplay_card::card_selected(twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "card_list", false);

	card_index_ = list.get_selected_row();
	refresh_tooltip(window);

	int size = current_team_.holded_cards().size();
	for (int index = 0; index < size; index ++) {
		tgrid* grid_ptr = list.get_row_grid(index);
		tbutton& discard = *dynamic_cast<tbutton*>(grid_ptr->find("discard", false));
		if (index == card_index_) {
			discard.set_visible(twidget::VISIBLE);
		} else {
			discard.set_visible(twidget::INVISIBLE);
		}
	}
}
Exemplo n.º 8
0
void trecruit::hero_toggled(twidget* widget)
{
    ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(widget);
    int toggled_index = toggle->get_data();
    std::set<int>::iterator result = checked_heros_.find(toggled_index);

    if (result == checked_heros_.end()) {
        // toggled button isn't in checked_heros_
        if (toggle->get_value()) {
            if (checked_heros_.size() < 3) {
                checked_heros_.insert(toggled_index);
            } else {
                // At most select three heros. decheck it!
                toggle->set_value(false);
                return;
            }
        } else {
            VALIDATE(false, "hero_toggled program error #1");
        }
    } else if (toggle->get_value()) {
        VALIDATE(false, "hero_toggled program error #2");
    } else {
        checked_heros_.erase(result);
    }

    twindow* window = toggle->get_window();
    tbutton* ok = find_widget<tbutton>(window, "ok", false, true);
    const unit_type* t = unit_types_[type_index_];
    if (!checked_heros_.empty() && current_team_.gold() >= t->cost() * cost_exponent_ / 100) {
        if (!t->leader() || master()->official_ == hero_official_leader) {
            ok->set_active(true);
        } else {
            ok->set_active(false);
        }
    } else {
        ok->set_active(false);
    }
    refresh_tooltip(*window);
}
Exemplo n.º 9
0
void trecruit::type_selected(twindow& window)
{
    int gold = current_team_.gold();

    tlistbox& list = find_widget<tlistbox>(&window, "type_list", false);

    type_index_ = list.get_selected_row();

    tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
    const unit_type* t = unit_types_[type_index_];
    if (!checked_heros_.empty() && gold >= t->cost() * cost_exponent_ / 100) {
        if (!t->leader() || master()->official_ == hero_official_leader) {
            ok->set_active(true);
        } else {
            ok->set_active(false);
        }
    } else {
        ok->set_active(false);
    }

    refresh_tooltip(window);
}
Exemplo n.º 10
0
void tinterior::hero_toggled(twidget* widget)
{
	ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(widget);
	int toggled_index = toggle->get_data();

	if (toggled_index != checked_hero_) {
		// toggled button isn't in checked_hero_
		if (toggle->get_value()) {
			if (checked_hero_ == -1) {
				checked_hero_ = toggled_index;
			} else {
				// At most select three heros. decheck it!
				toggle->set_value(false);
				return;
			}
		} else {
			VALIDATE(false, "hero_toggled program error #1");
		}
	} else if (toggle->get_value()) { 
		VALIDATE(false, "hero_toggled program error #2");
	} else {
		checked_hero_ = -1;
	}

	twindow* window = toggle->get_window();

	bool active = true;
	hero* mayor = city_.mayor();
	if ((!mayor->valid() && checked_hero_ == -1) || (mayor->valid() && checked_hero_ != -1 && mayor->number_ == fresh_heros_[checked_hero_]->number_)) {
		active = false;
	}

	appoint_->set_active(active);

	refresh_tooltip(*window);
}
Exemplo n.º 11
0
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);

		tgrid* grid_ptr = list->get_row_grid(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_callback<texpedite, &texpedite::type_selected>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "merit", false)
		, boost::bind(
			&texpedite::merit
			, this
			, boost::ref(window)));

	refresh_tooltip(window);

	tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
	const unit& u = *reside_troops[troop_index_];
	ok->set_active(can_move(u) && u.human());
}
Exemplo n.º 12
0
void tplay_card::pre_show(CVideo& /*video*/, twindow& window)
{
	std::stringstream str;

	tlistbox* list = find_widget<tlistbox>(&window, "card_list", false, true);

	std::vector<size_t>& holded_cards = current_team_.holded_cards();
	int card_index = 0;
	for (std::vector<size_t>::const_iterator itor = holded_cards.begin(); itor != holded_cards.end(); ++ itor, card_index ++) {
		card& c = cards_[*itor];
		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = c.image();
		list_item_item.insert(std::make_pair("icon", list_item));

		// name
		str.str("");
		str << c.name();
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("name", list_item));

		// points
		str.str("");
		str << c.points();
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("points", list_item));

		// range
		str.str("");
		int range = c.range();
		if (range == card::NONE) {
			str << dgettext("wesnoth-card", "None");
		} else if (range == card::SINGLE) {
			str << dgettext("wesnoth-card", "Single");
		} else if (range == card::MULTI) {
			str << dgettext("wesnoth-card", "Multi");
		} 
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("range", list_item));
/*
		// movement
		str.str("");
		str << it->movement_left() << "/" << it->total_movement();
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("movement", list_item));

		str.str("");
		str << it->cost() * cost_exponent / 100 << "/" << it->cost() * 2 / 3;
		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(card_index);
		tbutton& discard = *dynamic_cast<tbutton*>(grid_ptr->find("discard", false));
		connect_signal_mouse_left_click(
			discard
			, boost::bind(
				&tplay_card::discard
				, this
				, _3, _4
				, boost::ref(window)
				, card_index));
		if (card_index) {
			discard.set_visible(twidget::INVISIBLE);
		} else {
			discard.set_visible(twidget::VISIBLE);
		}
	}

	list->set_callback_value_change(dialog_callback<tplay_card, &tplay_card::card_selected>);

	refresh_tooltip(window);
}
Exemplo n.º 13
0
void trecruit::pre_show(CVideo& /*video*/, twindow& window)
{
    // int side_num = city_.side();
    std::stringstream str;

    tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

    int gold = current_team_.gold();

    tlabel* label = find_widget<tlabel>(&window, "title", false, true);
    str << _("Recruit") << "(" << gold << sngettext("unit^Gold", "Gold", gold) << ")";
    label->set_label(str.str());

    switch_type_internal(window);

    list->set_callback_value_change(dialog_callback<trecruit, &trecruit::type_selected>);

    hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);
    fresh_heros_ = city_.fresh_heros();
    std::sort(fresh_heros_.begin(), fresh_heros_.end(), compare_recruit);

    // fill data to hero_table
    catalog_page(window, ABILITY_PAGE, false);

    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "ability", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)ABILITY_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "adaptability", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)ADAPTABILITY_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "personal", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)PERSONAL_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "relation", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)RELATION_PAGE
            , true));

    // prev/next
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "prev", false)
        , boost::bind(
            &trecruit::switch_type
            , this
            , boost::ref(window)
            , false));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "next", false)
        , boost::bind(
            &trecruit::switch_type
            , this
            , boost::ref(window)
            , true));

    tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
    const unit_type* t = unit_types_[type_index_];
    if (!checked_heros_.empty() && gold >= t->cost() * cost_exponent_ / 100) {
        if (!t->leader() || master()->official_ == hero_official_leader) {
            ok->set_active(true);
        } else {
            ok->set_active(false);
        }
    } else {
        ok->set_active(false);
    }
    tbutton* cancel = find_widget<tbutton>(&window, "cancel", false, true);
    cancel->set_visible(rpg_mode_? twidget::INVISIBLE: twidget::VISIBLE);

    if (rpg_mode_) {
        refresh_tooltip(window);
    }
}
Exemplo n.º 14
0
void ttroop_detail::pre_show(CVideo& /*video*/, twindow& window)
{
	std::stringstream str;
	
	if (!title_.empty()) {
		tlabel* label = find_widget<tlabel>(&window, "title", false, true);
		label->set_label(title_);
	}

	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	for (std::vector<const unit*>::const_iterator itor = partial_troops_.begin(); itor != partial_troops_.end(); ++ itor) {
		const unit* it = *itor;

		int side_num = it->side();
		team& current_team = teams_[side_num - 1];

		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = it->absolute_image() + "~RC(" + it->team_color() + ">" + team::get_side_color_index(side_num) + ")";
		list_item_item.insert(std::make_pair("icon", list_item));

		// type/name
		str.str("");
		str << it->type_name() << "(Lv" << it->level() << ")\n";
		str << it->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 << it->hitpoints() << "/\n" << it->max_hitpoints();
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("hp", list_item));

		// xp
		str.str("");
		str << it->experience() << "/\n";
		if (it->can_advance()) {
			str << it->max_experience();
		} else {
			str << "-";
		}
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("xp", list_item));

		// movement
		str.str("");
		str << it->movement_left() << "/" << it->total_movement();
		list_item["label"] = str.str();
		list_item_item.insert(std::make_pair("movement", list_item));

		list->add_row(list_item_item);

		tgrid* grid = list->get_row_grid(list->get_item_count() - 1);
		twidget* widget = grid->find("human", false);
		widget->set_visible(it->human()? twidget::VISIBLE: twidget::INVISIBLE);
	}

	list->set_callback_value_change(dialog_callback<ttroop_detail, &ttroop_detail::type_selected>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "merit", false)
		, boost::bind(
		&ttroop_detail::merit
		, this
		, boost::ref(window)));

	refresh_tooltip(window);
}
void tstrategy_list::pre_show(CVideo& /*video*/, twindow& window)
{
	std::stringstream str;
	
	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	for (size_t i = 0; i < teams_.size(); i ++) {
		// bool survived = units_.side_survived(i + 1);
		bool survived = true;
		if (!survived || (side_ != -1 && i != side_ - 1)) {
			continue;
		}
		const team& current_team = teams_[i];
		const std::vector<strategy>& strategies = current_team.strategies();
		int strategy_index = 0;
		for (std::vector<strategy>::const_iterator it = strategies.begin(); it != strategies.end(); ++ it, strategy_index ++) {
			const strategy& s = *it;
			artifical* target_city = units_.city_from_cityno(s.target_);

			// Add list item
			string_map list_item;
			std::map<std::string, string_map> list_item_item;

			// side
			str.str("");
			str << current_team.name();
			list_item["label"] = str.str();
			list_item_item.insert(std::make_pair("list_side", list_item));

			// target
			str.str("");
			str << target_city->name();
			list_item["label"] = str.str();
			list_item_item.insert(std::make_pair("list_target", list_item));

			// type
			str.str("");
			if (s.type_ == strategy::AGGRESS) {
				str << _("Aggress");
			} else if (s.type_ == strategy::DEFEND) {
				str << _("Defend");
			} else {
				str << _("---");
			}
			list_item["label"] = str.str();
			list_item_item.insert(std::make_pair("list_type", list_item));

			// turns
			str.str("");
			str << s.impletement_turns_;
			list_item["label"] = str.str();
			list_item_item.insert(std::make_pair("list_turns", list_item));

			// ally
			str.str("");
			str << s.allies_.size();
			list_item["label"] = str.str();
			list_item_item.insert(std::make_pair("list_ally", list_item));

			list->add_row(list_item_item);
			strategy_list_.push_back(std::make_pair<int, int>(i, strategy_index));
		}

	}
	list->set_callback_value_change(dialog_callback<tstrategy_list, &tstrategy_list::type_selected>);

	refresh_tooltip(window);
}
Exemplo n.º 16
0
void temploy::pre_show(CVideo& /*video*/, twindow& window)
{
	std::stringstream strstr;
	int value;
	
	if (browse_) {
		tlabel* label = find_widget<tlabel>(&window, "flag", false, true);
		strstr.str("");
		strstr << "(" << _("Browse") << ")";
		label->set_label(strstr.str());
	}

	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	for (std::vector<hero*>::const_iterator it = emploies_.begin(); it != emploies_.end(); ++ it) {
		hero& h = **it;

		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		strstr.str("");
		strstr << h.image();
		if (current_team_.gold() < h.cost_ * ratio_) {
			strstr << "~GS()";
		}
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("icon", list_item));

		// name
		strstr.str("");
		if (h.utype_ != HEROS_NO_UTYPE) {
			const unit_type* ut = unit_types.keytype(h.utype_);
			strstr << tintegrate::generate_img(ut->icon()) << "\n";
		}
		strstr << h.name();
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("name", list_item));

		// cost
		strstr.str("");
		value = h.cost_ * ratio_;
		strstr << value;
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("cost", list_item));

		// leadership
		strstr.str("");
		strstr << fxptoi9(h.leadership_);
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("leadership", list_item));

		// charm
		strstr.str("");
		strstr << fxptoi9(h.charm_);
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("charm", list_item));

		// feature
		strstr.str("");
		strstr << hero::feature_str(h.feature_);
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("feature", list_item));

		// tactic
		strstr.str("");
		if (h.tactic_ != HEROS_NO_TACTIC) {
			strstr << unit_types.tactic(h.tactic_).name();
		}
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("tactic", list_item));

		list->add_row(list_item_item);

		tgrid* grid = list->get_row_grid(list->get_item_count() - 1);
		twidget* widget = grid->find("human", false);
		widget->set_visible(twidget::INVISIBLE);
	}

	list->set_callback_value_change(dialog_callback<temploy, &temploy::type_selected>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "detail", false)
		, boost::bind(
		&temploy::detail
		, this
		, boost::ref(window)));

	set_ok_active(window);

	refresh_tooltip(window);
}
Exemplo n.º 17
0
void tinterior::pre_show(CVideo& /*video*/, twindow& window)
{
	int side_num = current_team_.side();
	std::stringstream strstr;

	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	strstr.str();
	strstr << _("Interior") << "(" << city_.name() << ")";
	label->set_label(strstr.str());
	if (browse_) {
		label = find_widget<tlabel>(&window, "flag", false, true);
		strstr.str("");
		strstr << "(" << _("Browse") << ")";
		label->set_label(strstr.str());
	}

	const unit_type_data::unit_type_map& types = unit_types.types();
	for (unit_type_data::unit_type_map::const_iterator it = types.begin(); it != types.end(); ++ it) {
		if (it->second.master() == hero::number_market) {
			if (market_map_.find(&it->second) != market_map_.end()) {
				continue;
			}
			market_map_.insert(std::make_pair(&it->second, 0));
		}
		if (it->second.master() == hero::number_technology) {
			if (technology_map_.find(&it->second) != technology_map_.end()) {
				continue;
			}
			technology_map_.insert(std::make_pair(&it->second, 0));
		}
	}

	// candidate heros
	const std::vector<hero*>& freshes = city_.fresh_heros();
	std::copy(freshes.begin(), freshes.end(), std::back_inserter(fresh_heros_));
	const std::vector<hero*>& finishes = city_.finish_heros();
	std::copy(finishes.begin(), finishes.end(), std::back_inserter(fresh_heros_));
	for (std::vector<unit*>::iterator it = city_.reside_troops().begin(); it != city_.reside_troops().end(); ++ it) {
		unit& u = **it;
		hero* h = &u.master();
		fresh_heros_.push_back(h);
		if (u.second().valid()) {
			h = &u.second();
			fresh_heros_.push_back(h);
		}
		if (u.third().valid()) {
			h = &u.third();
			fresh_heros_.push_back(h);
		}
	}
	for (std::vector<unit*>::iterator it = city_.field_troops().begin(); it != city_.field_troops().end(); ++ it) {
		unit& u = **it;
		hero* h = &u.master();
		fresh_heros_.push_back(h);
		if (u.second().valid()) {
			h = &u.second();
			fresh_heros_.push_back(h);
		}
		if (u.third().valid()) {
			h = &u.third();
			fresh_heros_.push_back(h);
		}
	}

	// calculate artificals
	const std::vector<map_location>& economy_area = city_.economy_area();
	for (std::vector<map_location>::const_iterator it = economy_area.begin(); it != economy_area.end(); ++ it) {
		unit_map::const_iterator find = units_.find(*it);
		if (!find.valid()) {
			continue;
		}
		std::map<const unit_type*, int>::iterator find2 = market_map_.find(find->type());
		if (find2 != market_map_.end()) {
			find2->second ++;
			continue;
		}
		find2 = technology_map_.find(find->type());
		if (find2 != technology_map_.end()) {
			find2->second ++;
		}
	}

	std::sort(fresh_heros_.begin(), fresh_heros_.end(), compare_politics);

	// mayor
	tcontrol* control = find_widget<tcontrol>(&window, "mayor", false, true);
	hero* mayor = city_.mayor();
	if (mayor->valid()) {
		control->set_label(mayor->image());
	} else {
		control->set_label("");
	}

	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	for (std::vector<department>::const_iterator d_it = departments_.begin(); d_it != departments_.end(); ++ d_it) {
		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = d_it->image_;
		list_item_item.insert(std::make_pair("icon", list_item));

		list_item["label"] = d_it->name_;
		list_item_item.insert(std::make_pair("name", list_item));

		list_item["label"] = d_it->portrait_;
		list_item_item.insert(std::make_pair("portrait", list_item));

		strstr.str("");
		strstr << "X";
		if (d_it->type_ == department::commercial) {
			strstr << calculate_markets(d_it->exploiture_).first;
		} else if (d_it->type_ == department::technology) {
			strstr << calculate_technologies(d_it->exploiture_).first;
		}
		strstr << "=";
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("number", list_item));

		strstr.str("");
		if (d_it->type_ == department::commercial) {
			strstr << calculate_markets(d_it->exploiture_).second;
		} else if (d_it->type_ == department::technology) {
			strstr << calculate_technologies(d_it->exploiture_).second;
		}
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("total", list_item));

		strstr.str("");
		strstr << d_it->exploiture_ << "%";
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("exploiture", list_item));

		list->add_row(list_item_item);
	}

	appoint_ = find_widget<tbutton>(&window, "appoint", false, true);
	appoint_->set_active(false);

	// default: 0th department
	if (mayor->valid()) {
		for (std::vector<hero*>::iterator it = fresh_heros_.begin(); it != fresh_heros_.end(); ++ it) {
			if (*it == mayor) {
				checked_hero_ = std::distance(fresh_heros_.begin(), it);
				break;
			}
		}
		VALIDATE(checked_hero_ != -1, "exist mayor(" + mayor->name() + "), but cannot find mayor in candidate hero.");
	}

	// type_selected(window);
	refresh_tooltip(window);

	list->set_callback_value_change(dialog_callback<tinterior, &tinterior::type_selected>);

	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);
	
	// fill data to hero_table
	catalog_page(window, ABILITY_PAGE, false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ability", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)ABILITY_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "ability", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "adaptability", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)ADAPTABILITY_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "adaptability", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "relation", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)RELATION_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "relation", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		*appoint_
		, boost::bind(
			&tinterior::appoint
			, this
			, boost::ref(window)));
}