示例#1
0
void tside_list::catalog_page(twindow& window, int catalog, bool swap)
{
	if (catalog < MIN_PAGE || catalog > MAX_PAGE) {
		return;
	}
	int index = catalog - MIN_PAGE;

	if (window.alternate_index() == index) {
		// desired page is the displaying page, do nothing.
		return;
	}
	
	int selected_row = 0;
	if (swap) {
		selected_row = hero_table_->get_selected_row();
	}

	window.alternate_uh(hero_table_, index);

	fill_table(catalog);

	if (swap) {
		window.alternate_bh(hero_table_, index);
		hero_table_->select_row(selected_row);
	} else {
		hero_changed(window);
	}
}
示例#2
0
void tdata_manage::pre_show(CVideo& /*video*/, twindow& window)
{
	assert(txtFilter_);

	ttext_box* filter
			= find_widget<ttext_box>(&window, "txtFilter", false, true);
	window.keyboard_capture(filter);
	filter->set_text_changed_callback(
			boost::bind(&tdata_manage::filter_text_changed, this, _1, _2));

	tlistbox& list = find_widget<tlistbox>(&window, "persist_list", false);
	window.keyboard_capture(&list);

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

	{
		cursor::setter cur(cursor::WAIT);
		games_ = savegame::get_saves_list();
	}
	fill_game_list(window, games_);

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "clear", false),
			boost::bind(&tdata_manage::delete_button_callback,
						this,
						boost::ref(window)));
}
示例#3
0
void tcombo_box::pre_show(CVideo& /*video*/, twindow& window)
{
	window.set_canvas_variable("border", variant("default-border"));

	tlabel* title = find_widget<tlabel>(&window, "title", false, true);
	if (type_ == EXTRACT) {
		title->set_label(_("Extract hero"));
	} else {
		title->set_visible(twidget::INVISIBLE);
		find_widget<twidget>(&window, "ok", false, true)->set_visible(twidget::INVISIBLE);
		find_widget<twidget>(&window, "cancel", false, true)->set_visible(twidget::INVISIBLE);
	}
	tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
	window.keyboard_capture(&list);

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

	int item_index = 0;
	for (std::vector<tval_str>::const_iterator it = items_.begin(); it != items_.end(); ++ it) {
		const tval_str& item = *it;
		
		data["label"]["label"] = item.str;
		list.add_row(data);

		item_index ++;
	}
	list.set_callback_value_change(dialog_callback3<tcombo_box, tlistbox, &tcombo_box::item_selected>);

	if (index_ != -1) {
		list.select_row(index_);
	}
}
void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	window.set_canvas_variable("border", variant("default-border"));

	tlistbox& list = find_widget<tlistbox>(&window, "language_list", false);
	window.keyboard_capture(&list);

	const std::vector<language_def>& languages = get_languages();
	const language_def& current_language = get_language();
	std::stringstream strstr;
	int number = hero::number_normal_min;
	BOOST_FOREACH (const language_def& lang, languages) {
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		strstr.str("");
		strstr << "hero-64/" << number << ".png";
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("icon", list_item));

		list_item["label"] = lang.language;
		list_item_item.insert(std::make_pair("name", list_item));

		list.add_row(list_item_item);

		if (lang == current_language) {
			list.select_row(list.get_item_count() - 1);
		}
		number ++;
	}
示例#5
0
void tcustom_tod::update_tod_display(twindow& window)
{
	image::set_color_adjustment(tod_red_field_->get_value(),
								tod_green_field_->get_value(),
								tod_blue_field_->get_value());

	if(!display_) {
		return;
	}

	// Prevent a floating slice of window appearing alone over the
	// theme UI sidebar after redrawing tiles and before we have a
	// chance to redraw the rest of this window.
	window.undraw();

	// NOTE: We only really want to re-render the gamemap tiles here.
	// Redrawing everything is a significantly more expensive task.
	// At this time, tiles are the only elements on which ToD tint is
	// meant to have a visible effect. This is very strongly tied to
	// the image caching mechanism.
	//
	// If this ceases to be the case in the future, you'll need to call
	// redraw_everything() instead.

	// invalidate all tiles so they are redrawn with the new ToD tint next
	display_->invalidate_all();

	// redraw tiles
	display_->draw(false);

	window.invalidate_layout();
}
void tstory_screen::pre_show(CVideo& video, twindow& window)
{
	// set_restore(false);
	window.set_click_dismiss(false);
	window.set_enter_disabled(true);
	window.set_escape_disabled(true);


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

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

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

}
示例#7
0
void tmessage::pre_show(CVideo& /*video*/, twindow& window)
{
	// ***** Validate the required buttons ***** ***** ***** *****
	tmessage_implementation::
			init_button(window, buttons_[left_1], "left_side");
	tmessage_implementation::
			init_button(window, buttons_[cancel], "cancel");
	tmessage_implementation::
			init_button(window, buttons_[ok] ,"ok");
	tmessage_implementation::
			init_button(window, buttons_[right_1], "right_side");

	// ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
	if(!title_.empty()) {
		find_widget<tlabel>(&window, "title", false).set_label(title_);
	}

	if(!image_.empty()) {
		find_widget<timage>(&window, "image", false).set_label(image_);
	}

	tcontrol& label = find_widget<tcontrol>(&window, "label", false);
	label.set_label(message_);

	// The label might not always be a scroll_label but the capturing
	// shouldn't hurt.
	window.keyboard_capture(&label);

	// Override the user value, to make sure it's set properly.
	window.set_click_dismiss(auto_close_);
}
示例#8
0
void ttreasure_list::catalog_page(twindow& window, int catalog, bool swap)
{
	if (catalog < MIN_PAGE || catalog > MAX_PAGE) {
		return;
	}
	int index = catalog - MIN_PAGE;

	if (window.alternate_index() == index) {
		// desired page is the displaying page, do nothing.
		return;
	}
	
	unsigned int selected_row = 0;
	if (swap) {
		// because sort, order is changed.
		selected_row = hero_table_->get_selected_row();
		tgrid* grid_ptr = hero_table_->get_row_grid(hero_table_->get_selected_row());
		selected_row = dynamic_cast<ttoggle_panel*>(grid_ptr->find("_toggle", true))->get_data();
	}

	window.alternate_uh(hero_table_, index);

	fill_table(catalog);

	if (swap) {
		window.alternate_bh(hero_table_, index);
		hero_table_->select_row(selected_row);
		// swap to other page, there is no sorted column.
		sorting_widget_ = NULL;
	} else {
		hero_changed(window);
	}

	// in order to support sortable, form relative data.
	std::vector<tbutton*> widgets;
	if (catalog == OWNERSHIP_PAGE) {
		widgets.push_back(&find_widget<tbutton>(&window, "button_name", false));
		widgets.back()->set_active(false);
		widgets.push_back(&find_widget<tbutton>(&window, "button_feature", false));
		widgets.back()->set_active(false);
		widgets.push_back(&find_widget<tbutton>(&window, "button_side", false));
		widgets.back()->set_active(false);
		widgets.push_back(&find_widget<tbutton>(&window, "button_hero", false));
		widgets.back()->set_active(false);
	}
	for (std::vector<tbutton*>::iterator i = widgets.begin(); i != widgets.end(); ++ i) {
		tbutton& widget = **i;
		connect_signal_mouse_left_click(
			widget
			, boost::bind(
				&ttreasure_list::sort_column
				, this
				, boost::ref(window)
				, boost::ref(widget)));
	}
	sorting_widgets_[catalog] = widgets;

	// speeden compare_row, remember this catalog.
	current_page_ = catalog;
}
示例#9
0
void taddon_connect::pre_show(CVideo& /*video*/, twindow& window)
{
	ttext_box* host_widget = dynamic_cast<ttext_box*>(window.find_widget("host_name", false));
	VALIDATE(host_widget, missing_widget("host_name"));

	host_widget->set_value(host_name_);
	window.keyboard_capture(host_widget);
}
示例#10
0
void tlobby_main::post_build(twindow& window)
{
	/** @todo Should become a global hotkey after 1.8, then remove it here. */
	window.register_hotkey(hotkey::HOTKEY_FULLSCREEN, std::bind(fullscreen, std::ref(window.video())));

	/*** Local hotkeys. ***/
	window.register_hotkey(hotkey::HOTKEY_PREFERENCES, [this](event::tdispatcher& win, hotkey::HOTKEY_COMMAND)->bool {
		show_preferences_button_callback(dynamic_cast<twindow&>(win));
		return true;
	});
}
示例#11
0
void tmp_method_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	user_name_ = preferences::login();
	ttext_box* user_widget = find_widget<ttext_box>(
			&window, "user_name", false, true);
	user_widget->set_value(user_name_);
	user_widget->set_maximum_length(mp::max_login_size);
	window.keyboard_capture(user_widget);

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

	window.add_to_keyboard_chain(list);
}
示例#12
0
void tinapp_purchase::quit(twindow& window)
{
	if (operating_anim_ == twidget::npos) {
		window.set_retval(twindow::OK);
		return;
	}
	
	std::string message = _("System is processing inapp-purchase request, and force to quit maybe result data not integrated. Do you want to Quit?");
	int res = gui2::show_message(disp_.video(), "", message, gui2::tmessage::yes_no_buttons);
	if (res != gui2::twindow::OK) {
		return;
	}
	window.set_retval(twindow::OK);
}
示例#13
0
void tdialog::init_fields(twindow& window)
{
	for(auto field : fields_)
	{
		field->attach_to_window(window);
		field->widget_init(window);
	}

	if(!focus_.empty()) {
		if(twidget* widget = window.find(focus_, false)) {
			window.keyboard_capture(widget);
		}
	}
}
void tmp_cmd_wrapper::post_show(twindow& window)
{
	ttext_box* message =
		dynamic_cast<ttext_box*>(window.find("message", false));
	message_ = message ? message_ = message->get_value() : "";

	ttext_box* reason =
		dynamic_cast<ttext_box*>(window.find("reason", false));
	reason_ = reason ? reason_ = reason->get_value() : "";

	ttext_box* time =
		dynamic_cast<ttext_box*>(window.find("time", false));
	time_ = time ? time_ = time->get_value() : "";

}
void teditor_set_starting_position::pre_show(CVideo& /*video*/, twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
	window.keyboard_capture(&list);

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

	column["label"] = _("player^None");
	data.insert(std::make_pair("player", column));
	list.add_row(data);

	for(unsigned i = 0; i < starting_positions_.size(); ++i) {
		const map_location& player_pos = starting_positions_[i];

		data.clear();

		utils::string_map symbols;
		symbols["player_number"] = str_cast(i + 1);

		column["label"] = utils::interpolate_variables_into_string(_("Player $player_number"), &symbols);
		data.insert(std::make_pair("player", column));

		if(player_pos.valid()) {
			column["label"] = (formatter() << "(" << player_pos.x + 1 << ", " << player_pos.y + 1 << ")").str();
			data.insert(std::make_pair("location", column));
		}

		list.add_row(data);
	}

	list.select_row(selection_);
}
示例#16
0
void tlobby_player_info::update_relation(twindow& w)
{
	add_to_friends_->set_active(false);
	add_to_ignores_->set_active(false);
	remove_from_list_->set_active(false);
	switch(info_.relation) {
		case user_info::FRIEND:
			relation_->set_label(_("On friends list"));
			add_to_ignores_->set_active(true);
			remove_from_list_->set_active(true);
			break;
		case user_info::IGNORED:
			relation_->set_label(_("On ignores list"));
			add_to_friends_->set_active(true);
			remove_from_list_->set_active(true);
			break;
		case user_info::NEUTRAL:
			relation_->set_label(_("Neither a friend nor ignored"));
			add_to_friends_->set_active(true);
			add_to_ignores_->set_active(true);
			break;
		case user_info::ME:
			relation_->set_label(_("You"));
			break;
		default:
			relation_->set_label(_("Error"));
	}
	w.invalidate_layout();
}
示例#17
0
void tnetdiag::pre_show(CVideo& /*video*/, twindow& window)
{
	window.set_canvas_variable("border", variant("default-border"));

	log_ = &find_widget<tscroll_label>(&window, "log", false);
	log_->set_label(lobby->format_log_str());
	log_->set_scroll_to_end(true);

	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "connect", false)
			, boost::bind(
				  &tnetdiag::connect_button_callback
				, this
				, boost::ref(window)));
	find_widget<tbutton>(&window, "connect", false).set_active(false);

	connect_signal_mouse_left_click(
			  find_widget<tbutton>(&window, "clear", false)
			, boost::bind(
				  &tnetdiag::clear_button_callback
				, this
				, boost::ref(window)));

	join();
}
示例#18
0
void tstacked_widget::child_populate_dirty_list(twindow& caller,
		const std::vector<twidget*>& call_stack)
{
	std::vector<twidget*> layers;
	for (size_t n = 0; n < generator_->get_item_count(); ++ n) {
		std::vector<tdirty_list>& dirty_list = caller.dirty_list();
		size_t dirty_size = dirty_list.size();

		// tgrid <==> [layer]
		tgrid& grid = generator_->item(n);
		if (grid.get_visible() != twidget::VISIBLE) {
			continue;
		}
		std::vector<twidget*> child_call_stack = call_stack;
		if (n > 0) {
			child_call_stack.insert(child_call_stack.end(), layers.begin(), layers.end());
		}
		grid.populate_dirty_list(caller, child_call_stack);
	
		if (n > 0 && dirty_list.size() != dirty_size) {
			std::vector<tdirty_list>::iterator it = dirty_list.begin();
			for (std::advance(it, dirty_size); it != dirty_list.end(); ++ it) {
				it->children = layers;
			}
		}
		layers.push_back(&grid);
	}
}
示例#19
0
 void pre_show(twindow& window)
 {
     LOG_CHAT_LOG << "Entering tchat_log::view::pre_show" << std::endl;
     controller_.update_view_from_model(true);
     window.invalidate_layout(); // workaround for assertion failure
     LOG_CHAT_LOG << "Exiting tchat_log::view::pre_show" << std::endl;
 }
示例#20
0
void ttheme_list::pre_show(twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "themes", false);
	window.keyboard_capture(&list);

	for(const auto & t : themes_)
	{
		std::map<std::string, string_map> data;
		string_map column;

		std::string theme_name = t.name;
		if(theme_name.empty()) {
			theme_name = t.id;
		}

		column["label"] = theme_name;
		data.emplace("name", column);
		column["label"] = t.description;
		data.emplace("description", column);

		list.add_row(data);
	}

	if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
		list.select_row(index_);
	}

	index_ = -1;
}
void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& window)
{
	window.set_canvas_variable("border", variant("default-border"));

	assert(!map_generators_.empty());
	assert(gui_);

	current_generator_label_ =
			&find_widget<tlabel>(&window, "current_generator", false);

	tbutton& settings_button =
			find_widget<tbutton>(&window, "settings", false);
	connect_signal_mouse_left_click(settings_button, boost::bind(
			  &teditor_generate_map::do_settings
			, this
			, boost::ref(window)));

	tbutton& next_generator_button =
			find_widget<tbutton>(&window, "next_generator", false);
	connect_signal_mouse_left_click(next_generator_button, boost::bind(
			  &teditor_generate_map::do_next_generator
			, this
			, boost::ref(window)));

	update_current_generator_label(window);
}
示例#22
0
void tlobby_main::join_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), false)) {
		legacy_result_ = JOIN;
		window.close();
	}
}
示例#23
0
void tlobby_main::observe_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), true)) {
		legacy_result_ = OBSERVE;
		window.close();
	}
}
示例#24
0
void ttitle_screen::update_tip(twindow& window, const bool previous)
{
	tmulti_page& tips = find_widget<tmulti_page>(&window, "tips", false);
	if(tips.get_page_count() == 0) {
		return;
	}

	int page = tips.get_selected_page();
	if(previous) {
		if(page <= 0) {
			page = tips.get_page_count();
		}
		--page;
	} else {
		++page;
		if(static_cast<unsigned>(page) >= tips.get_page_count()) {
			page = 0;
		}
	}

	tips.select_page(page);
	/**
	 * @todo Look for a proper fix.
	 *
	 * This dirtying is required to avoid the blurring to be rendered wrong.
	 * Not entirely sure why, but since we plan to move to SDL2 that change
	 * will probably fix this issue automatically.
	 */
	window.set_is_dirty(true);
}
示例#25
0
void tcampaign_difficulty::pre_show(CVideo& /*video*/, twindow& window)
{
	tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
	window.keyboard_capture(&list);

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

	BOOST_FOREACH(const config &d, difficulties_.child_range("difficulty"))
	{
		data["icon"]["label"] = d["image"];
		data["label"]["label"] = d["label"];
		data["label"]["use_markup"] = "true";
		data["description"]["label"] = d["old_markup"].to_bool() || d["description"].empty() ? d["description"]
			: std::string("(") + d["description"] + std::string(")");
		data["description"]["use_markup"] = "true";

		list.add_row(data);

		const int this_row = list.get_item_count() - 1;

		if(d["default"].to_bool(false)) {
			list.select_row(this_row);
		}

		tgrid* grid = list.get_row_grid(this_row);
		assert(grid);

		twidget *widget = grid->find("victory", false);
		if (widget && !preferences::is_campaign_completed(campaign_id_, d["define"])) {
			widget->set_visible(twidget::tvisible::hidden);
		}
	}
}
void teditor_settings::update_tod_display(twindow& window)
{
	redraw_callback_(custom_tod_red_->get_value(),
		custom_tod_green_->get_value(),
		custom_tod_blue_->get_value());
	window.set_dirty(true);
}
void teditor_settings::update_selected_tod_info(twindow& window)
{
	bool custom = custom_tod_toggle_->get_value();
	if (custom) {
		current_tod_label_->set_label(_("Custom setting"));
	} else {
		std::stringstream ss;
		ss << (current_tod_ + 1);
		ss << "/" << tods_.size();
		ss << ": " << get_selected_tod().name;
		current_tod_label_->set_label(ss.str());
		/**
		 * @todo Implement the showing of the ToD icon.
		 *
		 * Note at the moment the icon is a label widget, should become an
		 * image widget.
		 */
		//current_tod_image_->set_icon_name(get_selected_tod().image);
		custom_tod_red_->set_value(get_selected_tod().red);
		custom_tod_green_->set_value(get_selected_tod().green);
		custom_tod_blue_->set_value(get_selected_tod().blue);
		custom_tod_red_field_->set_cache_value(get_selected_tod().red);
		custom_tod_green_field_->set_cache_value(get_selected_tod().green);
		custom_tod_blue_field_->set_cache_value(get_selected_tod().blue);
	}
	custom_tod_red_->set_active(custom);
	custom_tod_green_->set_active(custom);
	custom_tod_blue_->set_active(custom);
	current_tod_label_->set_active(!custom);
	update_tod_display(window);
	window.invalidate_layout();
}
示例#28
0
void ttip::pre_show(CVideo& /*video*/, twindow& window)
{
	find_widget<tcontrol>(&window, "label", false).set_label(message_);

	window.set_variable("mouse_x", variant(mouse_.x));
	window.set_variable("mouse_y", variant(mouse_.y));
}
示例#29
0
void tgame_load::delete_button_callback(twindow& window)
{
	if (current_page_ != LOCAL_PAGE) {
		return;
	}
	tlistbox& list = *lists_[current_page_];

	const size_t index = size_t(list.get_selected_row());
	if (index < games_.size()) {

		// See if we should ask the user for deletion confirmation
		if (preferences::ask_delete_saves()) {
			if(!gui2::tgame_delete::execute(window.video())) {
				return;
			}
		}

		// Delete the file
		savegame::manager::delete_game(games_[index].name);

		// Remove it from the list of saves
		games_.erase(games_.begin() + index);
		list.remove_row(index);

		display_savegame(window, list);
	}
}
示例#30
0
void trecruit::switch_type_internal(twindow& window)
{
    int side_num = city_.side();
    std::stringstream str;
    int gold = current_team_.gold();

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

    const std::vector<const unit_type*>& recruits = city_.recruits(game_config::current_level);
    for (std::vector<const unit_type*>::const_iterator it = recruits.begin(); it != recruits.end(); ++it) {
        /*** Add list item ***/
        const unit_type* type = *it;
        VALIDATE(type, std::string("could not find unit type ") + type->id());

        string_map list_item;
        std::map<std::string, string_map> list_item_item;

        if (gold >= type->cost() * cost_exponent_ / 100) {
            list_item["label"] = type->image() + "~RC(" + type->flag_rgb() + ">" + team::get_side_color_index(side_num) + ")";
        } else {
            list_item["label"] = type->image() + "~GS()";
        }

        list_item_item.insert(std::make_pair("icon", list_item));

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

        str.str("");
        str << type->cost() * cost_exponent_ / 100 << " " << sngettext("unit^Gold", "Gold", type->cost() * cost_exponent_ / 100);
        list_item["label"] = str.str();
        list_item_item.insert(std::make_pair("cost", list_item));

        list->add_row(list_item_item);

        tgrid* grid_ptr = list->get_row_grid(unit_types_.size());
        twidget* widget = grid_ptr->find("leader", false);
        widget->set_visible(type->leader()? twidget::VISIBLE: twidget::INVISIBLE);

        unit_types_.push_back(type);
    }
    window.invalidate_layout();
    if (type_index_ >= (int)list->get_item_count()) {
        type_index_ = list->get_item_count() - 1;
    }
    list->select_row(type_index_);

    tbutton* prev = find_widget<tbutton>(&window, "prev", false, true);
    prev->set_active(game_config::current_level != game_config::min_level);
    tbutton* next = find_widget<tbutton>(&window, "next", false, true);
    next->set_active(game_config::current_level != game_config::max_level);

    str.str("");
    str << "misc/digit-big.png~CROP(" << 30 * game_config::current_level << ", 0, 30, 45)";
    find_widget<tcontrol>(&window, "level", false, false)->set_label(str.str());

    type_selected(window);
}