Example #1
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)));
}
Example #2
0
void tcontrol_setting::pre_show(CVideo& /*video*/, twindow& window)
{
	std::stringstream ss;
	const std::pair<std::string, gui2::tcontrol_definition_ptr>& widget = u_.widget();

	ss.str("");
	ss << widget.first;
	if (widget.second.get()) {
		ss << "(" << tintegrate::generate_format(widget.second->id, "yellow") << ")"; 
		// ss << "    " << widget.second->description;
	}
	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	label->set_label(ss.str());

	// border size

	// horizontal layout
	set_horizontal_layout_label(window);
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "_set_horizontal_layout", false)
			, boost::bind(
				&tcontrol_setting::set_horizontal_layout
				, this
				, boost::ref(window)));

	// vertical layout
	set_vertical_layout_label(window);
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "_set_vertical_layout", false)
			, boost::bind(
				&tcontrol_setting::set_vertical_layout
				, this
				, boost::ref(window)));

	// linked_group
	set_linked_group_label(window);
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "_set_linked_group", false)
			, boost::bind(
				&tcontrol_setting::set_linked_group
				, this
				, boost::ref(window)));

	// linked_group
	set_textdomain_label(window, true);
	set_textdomain_label(window, false);
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "textdomain_label", false)
			, boost::bind(
				&tcontrol_setting::set_textdomain
				, this
				, boost::ref(window)
				, true));
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "textdomain_tooltip", false)
			, boost::bind(
				&tcontrol_setting::set_textdomain
				, this
				, boost::ref(window)
				, false));
	
	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "save", false)
			, boost::bind(
				&tcontrol_setting::save
				, this
				, boost::ref(window)
				, _3, _4));

	ttext_box* text_box = find_widget<ttext_box>(&window, "_border", false, true);
	text_box->set_label(str_cast(cell_.widget.cell.border_size_));
	if (cell_.widget.cell.flags_ & tgrid::BORDER_LEFT) {
		find_widget<ttoggle_button>(&window, "_border_left", false, true)->set_value(true);
	}
	if (cell_.widget.cell.flags_ & tgrid::BORDER_RIGHT) {
		find_widget<ttoggle_button>(&window, "_border_right", false, true)->set_value(true);
	}
	if (cell_.widget.cell.flags_ & tgrid::BORDER_TOP) {
		find_widget<ttoggle_button>(&window, "_border_top", false, true)->set_value(true);
	}
	if (cell_.widget.cell.flags_ & tgrid::BORDER_BOTTOM) {
		find_widget<ttoggle_button>(&window, "_border_bottom", false, true)->set_value(true);
	}

	text_box = find_widget<ttext_box>(&window, "_id", false, true);
	text_box->set_maximum_length(max_id_len);
	text_box->set_label(cell_.id);

	find_widget<ttext_box>(&window, "_width", false, true)->set_value(cell_.widget.width);
	find_widget<ttext_box>(&window, "_height", false, true)->set_value(cell_.widget.height);
	find_widget<tscroll_text_box>(&window, "_label", false, true)->set_label(cell_.widget.label);
	find_widget<tscroll_text_box>(&window, "_tooltip", false, true)->set_label(cell_.widget.tooltip);
}
Example #3
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);
}
Example #4
0
void tunit_recall::pre_show(twindow& window)
{
	tlabel& title = find_widget<tlabel>(&window, "title", true);
	title.set_label(title.label() + get_title_suffix(team_.side()));

	ttext_box* filter
			= find_widget<ttext_box>(&window, "filter_box", false, true);

	filter->set_text_changed_callback(
			std::bind(&tunit_recall::filter_text_changed, this, _1, _2));

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

#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(*list,
			std::bind(&tunit_recall::list_item_clicked,
				*this, std::ref(window)));
#else
	list.set_callback_value_change(
			dialog_callback<tunit_recall, &tunit_recall::list_item_clicked>);
#endif

	list.clear();

	window.keyboard_capture(filter);
	window.add_to_keyboard_chain(&list);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "dismiss", false),
		std::bind(&tunit_recall::dismiss_unit, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "show_help", false),
		std::bind(&tunit_recall::show_help, this, std::ref(window)));

	for(const unit_const_ptr& unit : recall_list_) {
		std::map<std::string, string_map> row_data;
		string_map column;

		std::string mods = unit->image_mods();

		if(unit->can_recruit()) {
			mods += "~BLIT(" + unit::leader_crown() + ")";
		}

		for(const std::string& overlay : unit->overlays()) {
			mods += "~BLIT(" + overlay + ")";
		}

		column["use_markup"] = "true";

		column["label"] = unit->absolute_image() + mods;
		row_data.emplace("unit_image", column);

		column["label"] = unit->type_name();
		row_data.emplace("unit_type", column);

		column["label"] = format_cost_string(unit->recall_cost(), team_.recall_cost());
		row_data.emplace("unit_recall_cost", column);

		const std::string& name = !unit->name().empty() ? unit->name().str() : utils::unicode_en_dash;
		column["label"] = name;
		row_data.emplace("unit_name", column);

		column["label"] = format_level_string(unit->level());
		row_data.emplace("unit_level", column);

		std::stringstream exp_str;
		exp_str << font::span_color(unit->xp_color()) << unit->experience() << "/"
		        << (unit->can_advance() ? std::to_string(unit->max_experience()) : utils::unicode_en_dash) << "</span>";

		column["label"] = exp_str.str();
		row_data.emplace("unit_experience", column);

		// Since the table widgets use heavy formatting, we save a bare copy
		// of certain options to filter on.
		std::string filter_text = unit->type_name() + " " + name + " " + std::to_string(unit->level());

		std::string traits;
		for(const std::string& trait : unit->trait_names()) {
			traits += (traits.empty() ? "" : "\n") + trait;
			filter_text += " " + trait;
		}

		column["label"] = !traits.empty() ? traits : utils::unicode_en_dash;
		row_data.emplace("unit_traits", column);

		list.add_row(row_data);
		filter_options_.push_back(filter_text);
	}

	list.register_sorting_option(0, [this](const int i) { return recall_list_[i]->type_name().str(); });
	list.register_sorting_option(1, [this](const int i) { return recall_list_[i]->name().str(); });
	list.register_sorting_option(2, [this](const int i) { return recall_list_[i]->level(); });
	list.register_sorting_option(3, [this](const int i) { return recall_list_[i]->experience(); });
	list.register_sorting_option(4, [this](const int i) {
		return !recall_list_[i]->trait_names().empty() ? recall_list_[i]->trait_names().front().str() : "";
	});

	list_item_clicked(window);
}
Example #5
0
void tformula_debugger::pre_show(CVideo& /*video*/, twindow& window)
{
	// stack label
	tcontrol* stack_label
			= find_widget<tcontrol>(&window, "stack", false, true);

	std::stringstream stack_text;
	std::string indent = "  ";
	int c = 0;
	FOREACH(const AUTO & i, fdb_.get_call_stack())
	{
		for(int d = 0; d < c; ++d) {
			stack_text << indent;
		}
		stack_text << "#<span color=\"green\">" << i.counter()
				   << "</span>: \"<span color=\"green\">" << i.name()
				   << "</span>\": '" << i.str() << "' " << std::endl;
		++c;
	}

	stack_label->set_use_markup(true);
	stack_label->set_label(stack_text.str());
	window.keyboard_capture(stack_label);

	// execution trace label
	tcontrol* execution_label
			= find_widget<tcontrol>(&window, "execution", false, true);

	std::stringstream execution_text;
	FOREACH(const AUTO & i, fdb_.get_execution_trace())
	{
		for(int d = 0; d < i.level(); ++d) {
			execution_text << indent;
		}
		if(!i.evaluated()) {
			execution_text << "#<span color=\"green\">" << i.counter()
						   << "</span>: \"<span color=\"green\">" << i.name()
						   << "</span>\": '" << i.str() << "' " << std::endl;
		} else {
			execution_text << "#<span color=\"yellow\">" << i.counter()
						   << "</span>: \"<span color=\"yellow\">" << i.name()
						   << "</span>\": '" << i.str() << "' = "
						   << "<span color=\"red\">"
						   << i.value().to_debug_string(NULL, false)
						   << "</span>" << std::endl;
		}
	}

	execution_label->set_use_markup(true);
	execution_label->set_label(execution_text.str());

	// state
	std::string state_str;
	bool is_end = false;
	if(!fdb_.get_current_breakpoint()) {
		state_str = "";
	} else {
		state_str = fdb_.get_current_breakpoint()->name();
		if(state_str == "End") {
			is_end = true;
		}
	}

	find_widget<tcontrol>(&window, "state", false).set_label(state_str);

	// callbacks
	tbutton& step_button = find_widget<tbutton>(&window, "step", false);
	connect_signal_mouse_left_click(
			step_button,
			boost::bind(&tformula_debugger::callback_step_button,
						this,
						boost::ref(window)));

	tbutton& stepout_button = find_widget<tbutton>(&window, "stepout", false);
	connect_signal_mouse_left_click(
			stepout_button,
			boost::bind(&tformula_debugger::callback_stepout_button,
						this,
						boost::ref(window)));

	tbutton& next_button = find_widget<tbutton>(&window, "next", false);
	connect_signal_mouse_left_click(
			next_button,
			boost::bind(&tformula_debugger::callback_next_button,
						this,
						boost::ref(window)));

	tbutton& continue_button = find_widget<tbutton>(&window, "continue", false);
	connect_signal_mouse_left_click(
			continue_button,
			boost::bind(&tformula_debugger::callback_continue_button,
						this,
						boost::ref(window)));

	if(is_end) {
		step_button.set_active(false);
		stepout_button.set_active(false);
		next_button.set_active(false);
		continue_button.set_active(false);
	}
}
Example #6
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);
	}
}
Example #7
0
void tduel::reset_turn(twindow& window)
{
	std::stringstream str;

	str.str("");
	str << "misc/digit-big.png~CROP(" << 30 * (turn_ + 1) << ", 0, 30, 45)";
	find_widget<tcontrol>(&window, "turn", false, false)->set_label(str.str());

	// set up card
	for (int index = 0; index < 2; index ++) {
		setting* t = setting_ + index;
		t->cards_.clear();
		if (!t->deadfight_) {
			t->deadfight_ = (rand() % 16) < t->skill_;
		}
		if (!t->fightback_) {
			t->fightback_ = (rand() % 64) < t->skill_;
		}

		char c = index? 'r': 'l';
		for (int index2 = 4; index2 >= 0; index2 --) {
			str.str("");
			str << c << "card" << index2;
			ttoggle_button* toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
			if (t->count_ <= index2) {
				toggle->set_visible(twidget::INVISIBLE);
				continue;
			}
			if (index == 1) {
				toggle->set_active(false);
			}

			int type = rand() % nb_items;
			int point = t->min_point_ + rand() % (t->max_point_ - t->min_point_ + 1);
			t->cards_.insert(std::pair<int, int>(type, point));
		}
		int index2 = 0;
		for (std::multimap<int, int>::const_iterator c_itor = t->cards_.begin(); c_itor != t->cards_.end(); ++ c_itor, index2 ++) {
			str.str("");
			str << c << "card" << index2;
			ttoggle_button* toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
			if (index == 0) {
				connect_signal_mouse_left_click(
					 *toggle
					, boost::bind(
					  &tduel::on_card
					, this
					, boost::ref(window)
					, index2));
			}
			for (int i = 0; i < 6; i ++) {
				toggle->canvas()[i].set_variable("foreground", variant(menu_items[c_itor->first]));
			}
			str.str("");
			str << c_itor->second;
			toggle->set_label(str.str());
			// reset lcard/rcard.
			toggle->set_value(false);
			toggle->set_dirty();
		}

		// total card
		str.str("");
		str << c << "total";
		ttoggle_button* toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
		for (int i = 0; i < 6; i ++) {
			toggle->canvas()[i].set_variable("foreground", variant(""));
		}
		toggle->set_label("0");
		toggle->set_active(false);

		// skill
		str.str("");
		str << c << "skill";
		find_widget<tcontrol>(&window, str.str(), false, false)->set_label("");

		// deadfight
		str.str("");
		str << c << "skill0";
		toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
		toggle->set_value(false);
		for (int i = 0; i < 6; i ++) {
			if (t->deadfight_) {
				toggle->canvas()[i].set_variable("image", variant("misc/deadfight.png"));
			} else {
				toggle->canvas()[i].set_variable("image", variant(""));
			}
		}
		if (index == 0) {
			toggle->set_active(t->deadfight_);
		} else {
			toggle->set_active(false);
		}

		// fightback
		str.str("");
		str << c << "skill1";
		toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
		toggle->set_value(false);
		for (int i = 0; i < 6; i ++) {
			if (t->fightback_) {
				toggle->canvas()[i].set_variable("image", variant("misc/fightback.png"));
			} else {
				toggle->canvas()[i].set_variable("image", variant(""));
			}
		}
		if (index == 0) {
			toggle->set_active(t->fightback_);
		} else {
			toggle->set_active(false);
		}
	}
	endturn_->set_active(false);
}
Example #8
0
void tlobby_main::pre_show(twindow& window)
{
	SCOPE_LB;
	roomlistbox_ = find_widget<tlistbox>(&window, "room_list", false, true);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(
			*roomlistbox_,
			std::bind(&tlobby_main::room_switch_callback,
						*this,
						std::ref(window)));
#else
	roomlistbox_->set_callback_value_change(
			dialog_callback<tlobby_main, &tlobby_main::room_switch_callback>);
#endif

	gamelistbox_ = find_widget<tlistbox>(&window, "game_list", false, true);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(
			*gamelistbox_,
			std::bind(&tlobby_main::gamelist_change_callback,
						*this,
						std::ref(window)));
#else
	gamelistbox_->set_callback_value_change(
			dialog_callback<tlobby_main,
							&tlobby_main::gamelist_change_callback>);
#endif

	window.keyboard_capture(gamelistbox_);

	player_list_.init(window);

	player_list_.sort_by_name->set_value(preferences::playerlist_sort_name());
	player_list_.sort_by_relation->set_value(preferences::playerlist_sort_relation());
	player_list_.update_sort_icons();

	player_list_.sort_by_name->set_callback_state_change(
			std::bind(&tlobby_main::player_filter_callback, this, _1));
	player_list_.sort_by_relation->set_callback_state_change(
			std::bind(&tlobby_main::player_filter_callback, this, _1));

	chat_log_container_ = find_widget<tmulti_page>(&window, "chat_log_container", false, true);

	window.set_enter_disabled(true);

	window_ = &window;

	chat_input_ = find_widget<ttext_box>(&window, "chat_input", false, true);
	assert(chat_input_);
	connect_signal_pre_key_press(
		*chat_input_,
		std::bind(&tlobby_main::chat_input_keypress_callback,
				this,
				_3,
				_4,
				_5,
				std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "create", false),
		std::bind(&tlobby_main::create_button_callback,
				this,
				std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "refresh", false),
		std::bind(&tlobby_main::refresh_button_callback,
				this,
				std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "show_preferences", false),
		std::bind(&tlobby_main::show_preferences_button_callback,
				this,
				std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "join_global", false),
		std::bind(&tlobby_main::join_global_button_callback,
				this,
				std::ref(window)));
	find_widget<tbutton>(&window, "join_global", false).set_active(false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "observe_global", false),
		std::bind(&tlobby_main::observe_global_button_callback,
				this,
				std::ref(window)));

	find_widget<tbutton>(&window, "observe_global", false).set_active(false);

	ttoggle_button& skip_replay
			= find_widget<ttoggle_button>(&window, "skip_replay", false);
	skip_replay.set_value(preferences::skip_mp_replay());
	skip_replay.set_callback_state_change(
			std::bind(&tlobby_main::skip_replay_changed_callback, this, _1));

	filter_friends_ = find_widget<ttoggle_button>(&window, "filter_with_friends", false, true);
	filter_ignored_ = find_widget<ttoggle_button>(&window, "filter_without_ignored", false, true);
	filter_slots_   = find_widget<ttoggle_button>(&window, "filter_vacant_slots", false, true);
	filter_invert_  = find_widget<ttoggle_button>(&window, "filter_invert", false, true);
	filter_text_    = find_widget<ttext_box>(&window, "filter_text", false, true);

	filter_friends_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_ignored_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_slots_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_invert_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	connect_signal_pre_key_press(
			*filter_text_,
			std::bind(&tlobby_main::game_filter_keypress_callback, this, _5));

	room_window_open("lobby", true);
	active_window_changed();
	game_filter_reload();

	// Force first update to be directly.
	tlobby_main::network_handler();
	lobby_update_timer_ = add_timer(
		game_config::lobby_network_timer, std::bind(&tlobby_main::network_handler, this), true);
}
void tsystem::pre_show(CVideo& /*video*/, twindow& window)
{
	play_controller* controller = resources::controller;

	if (controller->is_replaying()) {
		find_widget<tbutton>(&window, "save", false).set_active(false);
		find_widget<tbutton>(&window, "savereplay", false).set_active(false);
	} else {
		connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "save", false)
			, boost::bind(
				&tsystem::set_retval
				, this
				, boost::ref(window)
				, (int)SAVE));
		connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "savereplay", false)
			, boost::bind(
				&tsystem::set_retval
				, this
				, boost::ref(window)
				, (int)SAVEREPLAY));
	}
/*
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "savemap", false)
		, boost::bind(
			&tsystem::set_retval
			, this
			, boost::ref(window)
			, (int)SAVEMAP));
*/
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "load", false)
		, boost::bind(
			&tsystem::set_retval
			, this
			, boost::ref(window)
			, (int)LOAD));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "preferences", false)
		, boost::bind(
			&tsystem::set_retval
			, this
			, boost::ref(window)
			, (int)PREFERENCES));
	if (game_config::tiny_gui) {
		find_widget<tbutton>(&window, "help", false).set_visible(twidget::INVISIBLE);
	} else {
		connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "help", false)
			, boost::bind(
				&tsystem::set_retval
				, this
				, boost::ref(window)
				, (int)HELP));
	}
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "quit", false)
		, boost::bind(
			&tsystem::set_retval
			, this
			, boost::ref(window)
			, (int)QUIT));
}
Example #10
0
void tlobby_main::pre_show(twindow& window)
{
	SCOPE_LB;

	gamelistbox_ = find_widget<tlistbox>(&window, "game_list", false, true);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(
			*gamelistbox_,
			std::bind(&tlobby_main::gamelist_change_callback, *this, std::ref(window)));
#else
	gamelistbox_->set_callback_value_change(
			dialog_callback<tlobby_main, &tlobby_main::gamelist_change_callback>);
#endif

	window.keyboard_capture(gamelistbox_);

	player_list_.init(window);

	player_list_.sort_by_name->set_value(preferences::playerlist_sort_name());
	player_list_.sort_by_relation->set_value(preferences::playerlist_sort_relation());
	player_list_.update_sort_icons();

	player_list_.sort_by_name->set_callback_state_change(
			std::bind(&tlobby_main::player_filter_callback, this, _1));
	player_list_.sort_by_relation->set_callback_state_change(
			std::bind(&tlobby_main::player_filter_callback, this, _1));

	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

	// A new key handler to deal with escape in a different manner.
	window.connect_signal<event::SDL_KEY_DOWN>(
		std::bind(&tlobby_main::signal_handler_key_down, this, _5, _3, _4),
		event::tdispatcher::front_pre_child);

	window_ = &window;

	chatbox_ = find_widget<tchatbox>(&window, "chat", false, true);
	chatbox_->set_lobby_info(lobby_info_);
	chatbox_->set_wesnothd_connection(wesnothd_connection_);
	chatbox_->set_active_window_changed_callback([this]() { player_list_dirty_ = true; });

	find_widget<tbutton>(&window, "create", false).set_retval(CREATE);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "refresh", false),
		std::bind(&tlobby_main::refresh_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "show_preferences", false),
		std::bind(&tlobby_main::show_preferences_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "join_global", false),
		std::bind(&tlobby_main::join_global_button_callback, this, std::ref(window)));

	find_widget<tbutton>(&window, "join_global", false).set_active(false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "observe_global", false),
		std::bind(&tlobby_main::observe_global_button_callback, this, std::ref(window)));

	find_widget<tbutton>(&window, "observe_global", false).set_active(false);

	tmenu_button& replay_options = find_widget<tmenu_button>(&window, "replay_options", false);

	if(preferences::skip_mp_replay()) {
		replay_options.set_selected(1);
	}

	if(preferences::blindfold_replay()) {
		replay_options.set_selected(2);
	}

	replay_options.connect_click_handler(
			std::bind(&tlobby_main::skip_replay_changed_callback, this, std::ref(window)));

	filter_friends_ = find_widget<ttoggle_button>(&window, "filter_with_friends", false, true);
	filter_ignored_ = find_widget<ttoggle_button>(&window, "filter_without_ignored", false, true);
	filter_slots_   = find_widget<ttoggle_button>(&window, "filter_vacant_slots", false, true);
	filter_invert_  = find_widget<ttoggle_button>(&window, "filter_invert", false, true);
	filter_text_    = find_widget<ttext_box>(&window, "filter_text", false, true);

	filter_friends_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_ignored_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_slots_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_invert_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	connect_signal_pre_key_press(
			*filter_text_,
			std::bind(&tlobby_main::game_filter_keypress_callback, this, _5));

	chatbox_->room_window_open("lobby", true);
	chatbox_->active_window_changed();
	game_filter_reload();

	// Force first update to be directly.
	tlobby_main::network_handler();
	lobby_update_timer_ = add_timer(
		game_config::lobby_network_timer, std::bind(&tlobby_main::network_handler, this), true);

	// Set up Lua plugin context
	plugins_context_.reset(new plugins_context("Multiplayer Lobby"));

	plugins_context_->set_callback("join",    [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), false)) {
			window.set_retval(JOIN);
		}
	}, true);

	plugins_context_->set_callback("observe", [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), true)) {
			window.set_retval(OBSERVE);
		}
	}, true);

	plugins_context_->set_callback("create", [this, &window](const config&) { window.set_retval(CREATE); }, true);
	plugins_context_->set_callback("quit", [&window](const config&) { window.set_retval(twindow::CANCEL); }, false);

	plugins_context_->set_callback("chat", [this](const config& cfg) { chatbox_->send_chat_message(cfg["message"], false); }, true);
	plugins_context_->set_callback("select_game", [this](const config& cfg) {
		selected_game_id_ = cfg.has_attribute("id") ? cfg["id"].to_int() : lobby_info_.games()[cfg["index"].to_int()]->id;
	}, true);

	plugins_context_->set_accessor("game_list",   [this](const config&) { return lobby_info_.gamelist(); });
	plugins_context_->set_accessor("game_config", [this](const config&) { return game_config_; });
}
void mp_options_helper::display_custom_options(const std::string& type, int node_position, const config& cfg)
{
	// Needed since some compilers don't like passing just {}
	static const std::map<std::string, string_map> empty_map;

	// This ensures that any game, era, or mod with no options doesn't get an entry in the visible_options_
	// vector and prevents invalid options from different games, era, or mods being created when the options
	// config is created.
	if(!cfg.has_child("options")) {
		return;
	}

	visible_options_.push_back({type, cfg["id"]});

	// Get the node vector for this specific source type
	node_vector& type_node_vector = node_data_map_[type].nodes;

	for(const auto& options : cfg.child_range("options")) {
		std::map<std::string, string_map> data;
		string_map item;

		item["label"] = cfg["name"];
		data.emplace("tree_view_node_label", item);

		tree_view_node& option_node = options_tree_.add_node("option_node", data, node_position);
		type_node_vector.push_back(&option_node);

		for(const config::any_child& opt : options.all_children_range()) {
			data.clear();
			item.clear();

			const config& option_cfg = opt.cfg;

			const auto add_name = [&](const std::string& id) {
				item["label"] = option_cfg["name"];
				data.emplace(id, item);
			};

			config::attribute_value val;

			if(opt.key == "checkbox") {
				add_name("option_checkbox");

				toggle_button* checkbox;
				std::tie(checkbox, val) = add_node_and_get_widget<toggle_button>(option_node, "option_checkbox", data, option_cfg);

				checkbox->set_value(val.to_bool());

				connect_signal_notify_modified(*checkbox,
					std::bind(&mp_options_helper::update_options_data_map<toggle_button>, this, checkbox, visible_options_.back()));

			} else if(opt.key == "spacer") {
				option_node.add_child("options_spacer_node", empty_map);

			} else if(opt.key == "choice" || opt.key == "combo") {
				if(opt.key == "combo") {
					deprecated_message("combo", DEP_LEVEL::FOR_REMOVAL, {1, 15, 0}, "Use [choice] instead.");
				}

				if(!option_cfg.has_child("item")) {
					continue;
				}

				add_name("menu_button_label");

				std::vector<config> combo_items;
				std::vector<std::string> combo_values;

				for(auto i : option_cfg.child_range("item")) {
					// Comboboxes expect this key to be 'label' not 'name'
					i["label"] = i["name"];

					combo_items.push_back(i);
					combo_values.push_back(i["value"]);
				}

				menu_button* menu;
				std::tie(menu, val) = add_node_and_get_widget<menu_button>(option_node, "option_menu_button", data, option_cfg);

				// Needs to be called before set_selected
				menu->set_values(combo_items);

				auto iter = std::find(combo_values.begin(), combo_values.end(), val.str());

				if(iter != combo_values.end()) {
					menu->set_selected(std::distance(combo_values.begin(), iter));
				}

				connect_signal_notify_modified(*menu,
					std::bind(&mp_options_helper::update_options_data_map_menu_button, this, menu, visible_options_.back(), option_cfg));

			} else if(opt.key == "slider") {
				add_name("slider_label");

				slider* slide;
				std::tie(slide, val) = add_node_and_get_widget<slider>(option_node, "option_slider", data, option_cfg);

				slide->set_value_range(option_cfg["min"].to_int(), option_cfg["max"].to_int());
				slide->set_step_size(option_cfg["step"].to_int(1));
				slide->set_value(val.to_int());

				connect_signal_notify_modified(*slide,
					std::bind(&mp_options_helper::update_options_data_map<slider>, this, slide, visible_options_.back()));

			} else if(opt.key == "entry") {
				add_name("text_entry_label");

				text_box* textbox;
				std::tie(textbox, val) = add_node_and_get_widget<text_box>(option_node, "option_text_entry", data, option_cfg);

				textbox->set_value(val.str());
				textbox->set_text_changed_callback(
					std::bind(&mp_options_helper::update_options_data_map<text_box>, this, textbox, visible_options_.back()));
			}
		}

		// Add the Defaults button at the end
		tree_view_node& node = option_node.add_child("options_default_button", empty_map);

		connect_signal_mouse_left_click(find_widget<button>(&node, "reset_option_values", false),
			std::bind(&mp_options_helper::reset_options_data, this, visible_options_.back(),
				std::placeholders::_3, std::placeholders::_4));
	}
}
void tlobby_player_info::pre_show(CVideo& /*video*/, twindow& window)
{
	relation_ = find_widget<tlabel>(&window, "relation_info", false, true);
	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "start_whisper", false)
			, boost::bind(
				  &tlobby_player_info::start_whisper_button_callback
				, this
				, boost::ref(window)));

	add_to_friends_ = &find_widget<tbutton>(&window, "add_to_friends", false);
	connect_signal_mouse_left_click(*add_to_friends_, boost::bind(
				  &tlobby_player_info::add_to_friends_button_callback
				, this
				, boost::ref(window)));

	add_to_ignores_ = &find_widget<tbutton>(&window, "add_to_ignores", false);
	connect_signal_mouse_left_click(*add_to_ignores_, boost::bind(
				  &tlobby_player_info::add_to_ignores_button_callback
				, this
				, boost::ref(window)));

	remove_from_list_ = &find_widget<tbutton>(&window, "remove_from_list", false);
	connect_signal_mouse_left_click(*remove_from_list_, boost::bind(
				  &tlobby_player_info::remove_from_list_button_callback
				, this
				, boost::ref(window)));

	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "check_status", false)
			, boost::bind(
				  &tlobby_player_info::check_status_button_callback
				, this
				, boost::ref(window)));

	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "kick", false)
			, boost::bind(
				  &tlobby_player_info::kick_button_callback
				, this
				, boost::ref(window)));

	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "kick_ban", false)
			, boost::bind(
				  &tlobby_player_info::kick_ban_button_callback
				, this
				, boost::ref(window)));

	find_widget<tlabel>(&window, "player_name", false)
			.set_label(info_.name);

	std::stringstream loc;
	const game_info* game = lobby_info_.get_game_by_id(info_.game_id);
	if (game != NULL) {
		loc << _("In game:") << " " << game->name << " ";
		if (info_.observing) {
			loc << _("(observing)");
		} else {
			loc << _("(playing)");
		}
	} else {
		loc << _("In lobby");
	}

	find_widget<tlabel>(&window, "location_info", false).set_label(loc.str());

	update_relation(window);

	if (!preferences::is_authenticated()) {
		twidget* aw = window.find("admin", false);
		aw->set_visible(twidget::INVISIBLE);
	}
}
Example #13
0
void tgame_version::pre_show(twindow& window)
{
	string_map i18n_syms;

	//
	// General information.
	//

	tcontrol& version_label = find_widget<tcontrol>(&window, "version", false);
	i18n_syms["version"] = game_config::revision;
	version_label.set_label(VGETTEXT("Version $version", i18n_syms));

	tcontrol& os_label = find_widget<tcontrol>(&window, "os", false);
	i18n_syms["os"] = desktop::os_version();
	os_label.set_label(VGETTEXT("Running on $os", i18n_syms));

	tbutton& copy_all = find_widget<tbutton>(&window, "copy_all", false);
	connect_signal_mouse_left_click(
			copy_all,
			std::bind(&tgame_version::report_copy_callback, this));

	//
	// Game paths tab.
	//

	for(const auto & path_ent : path_map_)
	{
		const std::string& path_id = path_ent.first;
		const std::string& path_path = path_ent.second;

		ttext_& path_w
				= find_widget<ttext_>(&window, path_wid_stem_ + path_id, false);
		tbutton& copy_w = find_widget<tbutton>(
				&window, copy_wid_stem_ + path_id, false);
		tbutton& browse_w = find_widget<tbutton>(
				&window, browse_wid_stem_ + path_id, false);

		path_w.set_value(path_path);
		path_w.set_active(false);

		connect_signal_mouse_left_click(
				copy_w,
				std::bind(&tgame_version::copy_to_clipboard_callback,
							this,
							path_path));
		connect_signal_mouse_left_click(
				browse_w,
				std::bind(&tgame_version::browse_directory_callback,
							this,
							path_path));

		if(!desktop::open_object_is_supported()) {
			// No point in displaying these on platforms that can't do
			// open_object().
			browse_w.set_visible(tcontrol::tvisible::invisible);
		}

		if(!desktop::clipboard::available()) {
			copy_w.set_active(false);
			copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
		}
	}

#ifndef _WIN32
	tgrid& w32_options_grid
			= find_widget<tgrid>(&window, "win32_paths", false);
	w32_options_grid.set_visible(twidget::tvisible::invisible);
#else
	tbutton& stderr_button
			= find_widget<tbutton>(&window, "open_stderr", false);
	connect_signal_mouse_left_click(
			stderr_button,
			std::bind(&tgame_version::browse_directory_callback,
						this,
						log_path_));
	stderr_button.set_active(!log_path_.empty());
#endif

	//
	// Build info tab.
	//

	std::map<std::string, string_map> list_data;

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

	for(const auto & dep : deps_)
	{
		list_data["dep_name"]["label"] = dep[0];

		list_data["dep_build_version"]["label"] = dep[1];

		// The build version is always known, but runtime version isn't, esp.
		// for header-only libraries like Boost for which the concept does not
		// apply.
		if(!dep[2].empty()) {
			list_data["dep_rt_version"]["label"] = dep[2];
		} else {
			list_data["dep_rt_version"]["label"] = _("version^N/A");
		}

		deps_listbox.add_row(list_data);
	}

	deps_listbox.select_row(0);
	list_data.clear();

	//
	// Features tab.
	//

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

	for(const auto & opt : opts_)
	{
		list_data["opt_name"]["label"] = opt.name;

		if(opt.enabled) {
			list_data["opt_status"]["label"] = text_feature_on;
		} else {
			list_data["opt_status"]["label"] = text_feature_off;
		}
		list_data["opt_status"]["use_markup"] = "true";

		opts_listbox.add_row(list_data);
	}

	opts_listbox.select_row(0);
	list_data.clear();

	//
	// Set-up page stack and auxiliary controls last.
	//

	tstacked_widget& pager
			= find_widget<tstacked_widget>(&window, "tabs_container", false);
	pager.select_layer(0);

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

	window.keyboard_capture(&tab_bar);

	const unsigned tab_count = tab_bar.get_item_count();
	VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");

#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(tab_bar,
		std::bind(&tgame_version::tab_switch_callback, *this, std::ref(window)));
#else
	tab_bar.set_callback_value_change(
		dialog_callback<tgame_version, &tgame_version::tab_switch_callback>);
#endif
}
Example #14
0
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
	window_ = &window;

	set_restore(false);
	window.set_click_dismiss(false);
	window.set_escape_disabled(true);

	std::stringstream strstr;
	std::string color = game_config::local_only? "red": "green";

	strstr.str("");
	tlabel* label = find_widget<tlabel>(&window, "coin", true, true);
	strstr << tintegrate::generate_format(group.coin(), color, 17);
	label->set_label(strstr.str());

	strstr.str("");
	label = find_widget<tlabel>(&window, "score", true, true);
	strstr << tintegrate::generate_format(group.score(), color, 17);
	label->set_label(strstr.str());

	strstr.str("");
	label = find_widget<tlabel>(&window, "signin_data", true, true);
	if (!game_config::local_only) {
		strstr << tintegrate::generate_format(group.signin().continue_days, "green", 17) << "/";
		if (!group.signin().break_days) {
			color = "green";
		} else if (group.signin().break_days < game_config::max_breaks) {
			color = "yellow";
		} else {
			color = "red";
		}
		strstr << tintegrate::generate_format(group.signin().break_days, color, 17);
	} else {
		strstr << tintegrate::generate_format("---/-", "white", 17);
	}
	label->set_label(strstr.str());

	tcontrol* control = find_widget<tcontrol>(&window, "icon_vip", true, true);
	if (!preferences::vip2()) {
		control->set_visible(twidget::INVISIBLE);
	}

	// Set the version number
	control = find_widget<tcontrol>(&window, "revision_number", false, false);
	if (control) {
		// control->set_label(_("V") + game_config::version);
		// control->set_label(_("V") + game_config::version + "-alpha");
		// control->set_label(_("v") + game_config::version + "-beta");
		control->set_label(_("v") + game_config::version + "-beta4");
	}
	window.canvas()[0].set_variable("revision_number", variant(_("Version") + std::string(" ") + game_config::version));

	if (!game_config::images::game_title.empty()) {
		window.canvas()[0].set_variable("background_image",	variant(game_config::images::game_title));
	}

	/***** Set the logo *****/
	tcontrol* logo = find_widget<tcontrol>(&window, "logo", false, false);
	if (logo) {
		logo->set_label(game_config::logo_png);
	}

	label = find_widget<tlabel>(&window, "player_name", false, true);
	label->set_label(player_hero_.name());

	tbutton* b;
	for (int item = 0; item < nb_items; item ++) {
		b = find_widget<tbutton>(&window, menu_items[item], false, false);
		if (!b) {
			continue;
		}
		std::string str;
		if (!strcmp(menu_items[item], "player")) {
			str = player_hero_.image(true);

		} else if (!strcmp(menu_items[item], "signin")) {
			if (group.signin().today) {
				str = std::string("icons/") + "signin-ok" + ".png";
			} else {
				str = std::string("icons/") + "signin" + ".png";
			}

		} else {
			if (!strcmp(menu_items[item], "message")) {
				if (group.message_count()) {
					b->set_label("misc/red-dot12.png");
				}
			}
			str = std::string("icons/") + menu_items[item] + ".png";
		}

		for (int i = 0; i < 4; i ++) {
			b->canvas()[i].set_variable("image", variant(str));
		}
	}

	if (game_config::tiny_gui) {
		b = find_widget<tbutton>(&window, "design", false, false);
		if (b) {
			b->set_visible(twidget::INVISIBLE);
		}
		b = find_widget<tbutton>(&window, "editor", false, false);
		if (b) {
			b->set_visible(twidget::INVISIBLE);
		}

	} else if (!preferences::developer()) {
		b = find_widget<tbutton>(&window, "design", false, false);
		if (b) {
			b->set_visible(twidget::INVISIBLE);
		}
	}

#if defined(__APPLE__) && TARGET_OS_IPHONE
	b = find_widget<tbutton>(&window, "quit", false, false);
	if (b) {
		b->set_visible(twidget::INVISIBLE);
	}
#endif

	for (int item = 0; item < nb_items; item ++) {
		std::string id = menu_items[item];
		int retval = twindow::NONE;
		if (id == "editor") {
			retval = START_MAP_EDITOR;
		} else if (id == "quit") {
			retval = QUIT_GAME;
		} else if (id == "help") {
			retval = HELP;
		} else if (id == "campaign") {
			retval = NEW_CAMPAIGN;
		} else if (id == "player") {
			retval = PLAYER;
		} else if (id == "side") {
			retval = PLAYER_SIDE;
		} else if (id == "multiplayer") {
			retval = MULTIPLAYER;
		} else if (id == "load") {
			retval = LOAD_GAME;
		} else if (id == "report") {
			retval = REPORT;
		} else if (id == "language") {
			retval = CHANGE_LANGUAGE;
		} else if (id == "message") {
			retval = MESSAGE;
		} else if (id == "preferences") {
			retval = EDIT_PREFERENCES;
		} else if (id == "signin") {
			retval = SIGNIN;
		} else if (id == "shop") {
			retval = INAPP_PURCHASE;
		}

		connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, id, false)
			, boost::bind(
				&ttitle_screen::set_retval
				, this
				, boost::ref(window)
				, retval));
	}

	tlobby::thandler::join();

	config cfg;
	cfg["id"] = anim2::rfind(anim2::TITLE_SCREEN);
	cfg["width"] = 1600;
	cfg["height"] = 900;
	window.insert_animation(cfg, false);
}
Example #15
0
void tduel::pre_show(CVideo& /*video*/, twindow& window)
{
	// Override the user value, to make sure it's set properly.
	window.set_click_dismiss(false);

	// ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
	window.canvas(1).set_variable("left_image", variant(left_.image(true)));
	window.canvas(1).set_variable("right_image", variant(right_.image(true)));
	window.canvas(1).set_variable("center_image", variant(""));
	
	window.canvas(1).set_variable("hp_left", variant("misc/hp-blue.png"));
	window.canvas(1).set_variable("hp_right", variant("misc/hp-red.png"));
	window.canvas(1).set_variable("percentage", variant((hp_ * 100) / TOTAL_HP));

	std::stringstream str;

	tbutton* b = find_widget<tbutton>(&window, "endturn", false, false);
	for (int i = 0; i < 4; i ++) {
		b->canvas()[i].set_variable("image", variant("misc/ok.png"));
	}

	find_widget<tcontrol>(&window, "lname", false, false)->set_label(left_.name());
	find_widget<tcontrol>(&window, "rname", false, false)->set_label(right_.name());

	tcontrol* control = find_widget<tcontrol>(&window, "lforce", false, false);
	str.str("");
	str << setting_[0].force_ << "(" << hero::adaptability_str2(left_.skill_[hero_skill_hero]).c_str() << ")";
	control->set_label(str.str());

	control = find_widget<tcontrol>(&window, "rforce", false, false);
	str.str("");
	str << setting_[1].force_ << "(" << hero::adaptability_str2(right_.skill_[hero_skill_hero]).c_str() << ")";;
	control->set_label(str.str());

	endturn_ = find_widget<tbutton>(&window, "endturn", false, false);
	connect_signal_mouse_left_click(
		*endturn_
		, boost::bind(
			&tduel::end_turn
			, this
			, boost::ref(window)));
	endturn_->set_sound_button_click("hatchet.wav");
	
	lskill0_ = find_widget<ttoggle_button>(&window, "lskill0", false, false);
	connect_signal_mouse_left_click(
		 *lskill0_
		, boost::bind(
		  &tduel::on_deadfight
		, this
		, boost::ref(window)));

	lskill1_ = find_widget<ttoggle_button>(&window, "lskill1", false, false);
	connect_signal_mouse_left_click(
		 *lskill1_
		, boost::bind(
		  &tduel::on_fightback
		, this
		, boost::ref(window)));
	
	find_widget<ttoggle_button>(&window, "lturn0", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn0_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<tlabel>(&window, "turn0", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn0", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn0_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn1", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn1_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<tlabel>(&window, "turn1", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn1", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn1_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn2", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn2_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<tlabel>(&window, "turn2", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn2", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn2_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn3", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn3_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<tlabel>(&window, "turn3", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn3", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn3_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn4", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "lturn4_skill", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<tlabel>(&window, "turn4", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn4", false, false)->set_visible(twidget::INVISIBLE);
	find_widget<ttoggle_button>(&window, "rturn4_skill", false, false)->set_visible(twidget::INVISIBLE);

	reset_turn(window);
}
Example #16
0
	/** Inherited from tclickable. */
	void connect_click_handler(const event::tsignal_function& signal)
	{
		connect_signal_mouse_left_click(*this, signal);
	}
Example #17
0
void teditor_settings::pre_show(CVideo& /*video*/, twindow& window)
{
	assert(!tods_.empty());
	current_tod_label_ = find_widget<tlabel>(
			&window, "current_tod", false, true);
	current_tod_image_ = find_widget<tlabel>(
			&window, "current_tod_image", false, true);
	custom_tod_toggle_ = find_widget<ttoggle_button>(
			&window, "custom_tod_toggle", false, true);
	custom_tod_auto_refresh_ = find_widget<ttoggle_button>(
			&window, "custom_tod_auto_refresh", false, true);

	tbutton& next_tod_button = find_widget<tbutton>(
			&window, "next_tod", false);
	connect_signal_mouse_left_click(next_tod_button, boost::bind(
			  &teditor_settings::do_next_tod
			, this
			, boost::ref(window)));


	tbutton& apply_button = find_widget<tbutton>(
			&window, "apply", false);
	connect_signal_mouse_left_click(apply_button, boost::bind(
			  &teditor_settings::update_tod_display
			, this
			, boost::ref(window)));

	custom_tod_toggle_->set_callback_state_change(
			dialog_callback<teditor_settings
				, &teditor_settings::update_selected_tod_info>);

	connect_signal_notify_modified(*(custom_tod_red_field_->widget())
			, boost::bind(
				  &teditor_settings::slider_update_callback
				, this
				, boost::ref(window)));

	connect_signal_notify_modified(*(custom_tod_green_field_->widget())
			, boost::bind(
				  &teditor_settings::slider_update_callback
				, this
				, boost::ref(window)));

	connect_signal_notify_modified(*(custom_tod_blue_field_->widget())
			, boost::bind(
				  &teditor_settings::slider_update_callback
				, this
				, boost::ref(window)));

	for (size_t i = 0; i < tods_.size(); ++i) {

		time_of_day& tod = tods_[i];
		const int r = custom_tod_red_field_->get_widget_value(window);
		const int g = custom_tod_green_field_->get_widget_value(window);
		const int b = custom_tod_blue_field_->get_widget_value(window);
		if (tod.color.r == r && tod.color.g == g && tod.color.b == b) {
			current_tod_ = i;
			custom_tod_toggle_->set_value(false);
			update_selected_tod_info(window);
			can_update_display_ = true;
			return;
		}
	}

	/* custom tod */
	custom_tod_toggle_->set_value(true);

	update_selected_tod_info(window);

	can_update_display_ = true;
}
Example #18
0
void ttitle_screen::pre_show(twindow& window)
{
	set_restore(false);
	window.set_click_dismiss(false);
	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

#ifdef DEBUG_TOOLTIP
	window.connect_signal<event::SDL_MOUSE_MOTION>(
			std::bind(debug_tooltip, std::ref(window), _3, _5),
			event::tdispatcher::front_child);
#endif

	/**** Set the version number ****/
	if(tcontrol* control
	   = find_widget<tcontrol>(&window, "revision_number", false, false)) {

		control->set_label(_("Version ") + game_config::revision);
	}
	window.canvas()[0].set_variable(
			"revision_number",
			variant(_("Version") + std::string(" ") + game_config::revision));

	/**** Set the tip of the day ****/
	tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);

	std::vector<ttip> tips(settings::get_tips());
	if(tips.empty()) {
		WRN_CF << "There are not tips of day available." << std::endl;
	}

	for(const auto & tip : tips)
	{

		string_map widget;
		std::map<std::string, string_map> page;

		widget["label"] = tip.text();
		widget["use_markup"] = "true";
		page["tip"] = widget;

		widget["label"] = tip.source();
		widget["use_markup"] = "true";
		page["source"] = widget;

		tip_pages.add_page(page);
	}

	update_tip(window, true);

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "next_tip", false),
			std::bind(&ttitle_screen::update_tip,
						this,
						std::ref(window),
						true));

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "previous_tip", false),
			std::bind(&ttitle_screen::update_tip,
						this,
						std::ref(window),
						false));

	if(game_config::images::game_title.empty()) {
		ERR_CF << "No title image defined" << std::endl;
	} else {
		window.canvas()[0].set_variable(
				"title_image", variant(game_config::images::game_title));
	}

	if(game_config::images::game_title_background.empty()) {
		ERR_CF << "No title background image defined" << std::endl;
	} else {
		window.canvas()[0].set_variable(
				"background_image",
				variant(game_config::images::game_title_background));
	}

	/***** Logo *****/
	find_widget<timage>(&window, "logo", false).set_image("misc/logo.png");

	/***** About dialog button *****/
	tbutton& about = find_widget<tbutton>(&window, "about", false);
	connect_signal_mouse_left_click(
			about,
			std::bind(&tgame_version::display, std::ref(window.video())));

	/***** Set the clock button. *****/
	tbutton& clock = find_widget<tbutton>(&window, "clock", false);
	clock.set_visible(show_debug_clock_button ? twidget::tvisible::visible
											  : twidget::tvisible::invisible);

	connect_signal_mouse_left_click(
			clock,
			std::bind(&ttitle_screen::show_debug_clock_window,
						this,
						std::ref(window.video())));
}
Example #19
0
void thero_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	max_checked_size_ = 1;

	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);

	catalog_page(window, OWNERSHIP_PAGE, false);

	hero_table_->set_callback_value_change(dialog_callback<thero_selection, &thero_selection::hero_changed>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ownership", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)OWNERSHIP_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ability", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)ABILITY_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "feature", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)FEATURE_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "adaptability", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)ADAPTABILITY_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "command", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)COMMAND_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "personal", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)PERSONAL_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "relation", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)RELATION_PAGE
			, true));

	tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
	ok->set_active(false);
}
Example #20
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);
}
Example #21
0
void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
{
	ttoggle_button& male_toggle
			= find_widget<ttoggle_button>(&window, "male_toggle", false);
	ttoggle_button& female_toggle
			= find_widget<ttoggle_button>(&window, "female_toggle", false);
	tlistbox& list = find_widget<tlistbox>(&window, "unit_type_list", false);

	ttext_box* filter
			= find_widget<ttext_box>(&window, "filter_box", false, true);

	filter->set_text_changed_callback(
			boost::bind(&tunit_create::filter_text_changed, this, _1, _2));

#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(*list,
								   boost::bind(&tunit_create::list_item_clicked,
											   *this,
											   boost::ref(window)));
#else
	list.set_callback_value_change(
			dialog_callback<tunit_create, &tunit_create::list_item_clicked>);
#endif

	window.keyboard_capture(&list);

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "type_profile", false),
			boost::bind(&tunit_create::profile_button_callback,
						this,
						boost::ref(window)));

	male_toggle.set_callback_state_change(
			dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);

	female_toggle.set_callback_state_change(
			dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);

	update_male_female_toggles(male_toggle, female_toggle, gender_);

	list.clear();

	FOREACH(const AUTO & i, unit_types.types())
	{
		if(i.second.do_not_list())
			continue;

		// Make sure this unit type is built with the data we need.
		unit_types.build_unit_type(i.second, unit_type::WITHOUT_ANIMATIONS);

		units_.push_back(&i.second);

		std::map<std::string, string_map> row_data;
		string_map column;

		column["label"] = units_.back()->race()->plural_name();
		row_data.insert(std::make_pair("race", column));
		column["label"] = units_.back()->type_name();
		row_data.insert(std::make_pair("unit_type", column));

		list.add_row(row_data);

		// Select the previous choice, if any.
		if(choice_.empty() != true && choice_ == i.first) {
			list.select_row(list.get_item_count() - 1);
		}
	}

	if(units_.empty()) {
		ERR_GUI_G << "no unit types found for unit create dialog; not good"
				  << std::endl;
	}

	std::vector<tgenerator_::torder_func> order_funcs(2);
	order_funcs[0] = boost::bind(&tunit_create::compare_race, this, _1, _2);
	order_funcs[1] = boost::bind(&tunit_create::compare_race_rev, this, _1, _2);
	list.set_column_order(0, order_funcs);
	order_funcs[0] = boost::bind(&tunit_create::compare_type, this, _1, _2);
	order_funcs[1] = boost::bind(&tunit_create::compare_type_rev, this, _1, _2);
	list.set_column_order(1, order_funcs);

	list_item_clicked(window);
}