本文整理汇总了C++中game_display类的典型用法代码示例。如果您正苦于以下问题:C++ game_display类的具体用法?C++ game_display怎么用?C++ game_display使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了game_display类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
statistics_dialog::statistics_dialog(game_display &disp,
const std::string& title,
const unsigned int team,
const std::string& team_id,
const std::string& player) :
dialog(disp.video(), title, "", gui::NULL_DIALOG),
detail_btn_(new gui::standard_dialog_button(disp.video(), _("Details"), 0 , false)),
toggle_btn_(new gui::dialog_button(disp.video(), "", gui::button::TYPE_PRESS, BUTTON_TOGGLE)),
scene_btn_(new gui::dialog_button(disp.video(), _("Select Scenario"), gui::button::TYPE_PRESS, BUTTON_SCENE)),
player_name_(player),
campaign_(statistics::calculate_stats(team_id)),
scenarios_(statistics::level_stats(team_id)),
scenario_index_(scenarios_.size() - 1), // current scenario
team_num_(team),
unit_count_(5,0)
{
if ( scenarios_.size() > 1 ) {
add_button(scene_btn_, gui::dialog::BUTTON_EXTRA_LEFT);
add_button(toggle_btn_, gui::dialog::BUTTON_EXTRA_LEFT);
}
add_button(detail_btn_, gui::dialog::BUTTON_EXTRA);
add_button(new gui::standard_dialog_button(disp.video(), _("Close"), 1, true),
gui::dialog::BUTTON_STANDARD);
// Initialize the displayed data.
if ( use_campaign_ || scenarios_.size() == 1 )
display_stats(use_campaign_);
else {
// Starting with the scenario stats, but we need to make sure the
// window is wide enough for the campaign stats.
display_stats(true);
layout();
display_stats(false);
}
}
示例2: fade_logo
/**
* Fade-in the wesnoth-logo.
*
* Animation-effect: scroll-in from right. \n
* Used only once, after the game is started.
*
* @param screen surface to operate on
* @param xpos x-position of logo
* @param ypos y-position of logo
*
* @return Result of running the routine
* @retval true operation finished (successful or not)
* @retval false operation failed (because modeChanged), need to retry
*/
static bool fade_logo(game_display& screen, int xpos, int ypos)
{
const surface logo(image::get_image(game_config::game_logo));
if(logo == NULL) {
ERR_DP << "Could not find game logo\n";
return true;
}
surface const fb = screen.video().getSurface();
if(fb == NULL || xpos < 0 || ypos < 0 || xpos + logo->w > fb->w || ypos + logo->h > fb->h) {
return true;
}
// Only once, when the game is first started, the logo fades in unless
// it was disabled in adv. preferences
static bool faded_in = !preferences::startup_effect();
// static bool faded_in = true; // for faster startup: mark logo as 'has already faded in'
CKey key;
bool last_button = key[SDLK_ESCAPE] || key[SDLK_SPACE];
LOG_DP << "fading logo in....\n";
LOG_DP << "logo size: " << logo->w << "," << logo->h << "\n";
for(int x = 0; x != logo->w; ++x) {
SDL_Rect srcrect = {x,0,1,logo->h};
SDL_Rect dstrect = {xpos+x,ypos,1,logo->h};
SDL_BlitSurface(logo,&srcrect,fb,&dstrect);
update_rect(dstrect);
if(!faded_in && (x%5) == 0) {
const bool new_button = key[SDLK_ESCAPE] || key[SDLK_SPACE] ||
key[SDLK_RETURN] || key[SDLK_KP_ENTER] ;
if(new_button && !last_button) {
faded_in = true;
}
last_button = new_button;
screen.update_display();
screen.delay(10);
events::pump();
if(screen.video().modeChanged()) {
faded_in = true;
return false;
}
}
}
LOG_DP << "logo faded in\n";
faded_in = true;
return true;
}
示例3:
wait::wait(game_display& disp, const config& cfg,
mp::chat& c, config& gamelist) :
ui(disp, _("Game Lobby"), cfg, c, gamelist),
cancel_button_(disp.video(), _("Cancel")),
start_label_(disp.video(), _("Waiting for game to start..."), font::SIZE_SMALL, font::LOBBY_COLOR),
game_menu_(disp.video(), std::vector<std::string>(), false, -1, -1, NULL, &gui::menu::bluebg_style),
level_(),
state_(),
stop_updates_(false)
{
game_menu_.set_numeric_keypress_selection(false);
gamelist_updated();
}
示例4: switch
void floating_textbox::tab(std::vector<team>& teams, const unit_map& /*units*/, game_display& gui)
{
if(active() == false) {
return;
}
switch(mode_) {
case gui::TEXTBOX_SEARCH:
case gui::TEXTBOX_COMMAND:
case gui::TEXTBOX_MESSAGE:
{
std::string text = box_->text();
std::vector<std::string> matches;
// Add players
for(size_t n = 0; n != teams.size(); ++n) {
if(teams[n].is_empty()) continue;
matches.push_back(teams[n].current_player());
}
// Add observers
const std::set<std::string>& observers = gui.observers();
for(std::set<std::string>::const_iterator i = observers.begin();
i != observers.end(); ++i)
{
matches.push_back(*i);
}
// Remove duplicates.
std::sort<std::vector<std::string>::iterator>
(matches.begin(), matches.end());
matches.erase(std::unique(matches.begin(), matches.end()), matches.end());
// Exclude own nick from tab-completion.
if (mode_ == gui::TEXTBOX_MESSAGE) {
matches.erase(std::remove(matches.begin(), matches.end(),
preferences::login()), matches.end());
}
const bool line_start = utils::word_completion(text, matches);
if (matches.empty()) return;
if (matches.size() == 1 && mode_ == gui::TEXTBOX_MESSAGE) {
text.append(line_start ? ": " : " ");
} else {
std::string completion_list = utils::join(matches, ' ');
gui.add_chat_message(time(NULL), "", 0, completion_list,
game_display::MESSAGE_PRIVATE, false);
}
box_->set_text(text);
break;
}
default:
LOG_STREAM(err, display) << "unknown textbox mode\n";
}
}
示例5: enter_create_mode
static void enter_create_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist, mp::controller default_controller, bool local_players_only)
{
if (0 && gui2::new_widgets) {
gui2::tmp_create_game dlg(game_config);
dlg.show(disp.video());
network::send_data(config("refresh_lobby"), 0, true);
} else {
mp::ui::result res;
mp_game_settings params;
int num_turns;
{
mp::create ui(disp, game_config, chat, gamelist);
run_lobby_loop(disp, ui);
res = ui.get_result();
params = ui.get_parameters();
num_turns = ui.num_turns();
}
switch (res) {
case mp::ui::CREATE:
enter_connect_mode(disp, game_config, chat, gamelist, params, num_turns, default_controller, local_players_only);
break;
case mp::ui::QUIT:
default:
//update lobby content
network::send_data(config("refresh_lobby"), 0, true);
break;
}
}
}
示例6: show
void floating_textbox::show(gui::TEXTBOX_MODE mode, const std::string& label,
const std::string& check_label, bool checked, game_display& gui)
{
close(gui);
label_string_ = label;
mode_ = mode;
if(check_label != "") {
check_.assign(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK));
check_->set_check(checked);
}
box_.assign(new gui::textbox(gui.video(),100,"",true,256,0.8,0.6));
update_location(gui);
}
示例7:
create_engine::create_engine(game_display& disp, saved_game& state) :
current_level_type_(),
current_level_index_(0),
current_era_index_(0),
current_mod_index_(0),
level_name_filter_(),
player_count_filter_(1),
scenarios_(),
user_maps_(),
user_scenarios_(),
campaigns_(),
sp_campaigns_(),
random_maps_(),
user_map_names_(),
user_scenario_names_(),
eras_(),
mods_(),
state_(state),
dependency_manager_(resources::config_manager->game_config(), disp.video()),
generator_(NULL)
{
DBG_MP << "restoring game config\n";
// Restore game config for multiplayer.
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;
resources::config_manager->
load_game_config_for_game(state_.classification());
//TODO the editor dir is already configurable, is the preferences value
get_files_in_dir(get_user_data_dir() + "/editor/maps", &user_map_names_,
NULL, FILE_NAME_ONLY);
get_files_in_dir(get_user_data_dir() + "/editor/scenarios", &user_scenario_names_,
NULL, FILE_NAME_ONLY);
DBG_MP << "initializing all levels, eras and mods\n";
init_all_levels();
init_extras(ERA);
init_extras(MOD);
state_.mp_settings().saved_game = false;
BOOST_FOREACH (const std::string& str, preferences::modifications()) {
if (resources::config_manager->
game_config().find_child("modification", "id", str))
state_.mp_settings().active_mods.push_back(str);
}
if (current_level_type_ != level::CAMPAIGN &&
current_level_type_ != level::SP_CAMPAIGN) {
dependency_manager_.try_modifications(state_.mp_settings().active_mods, true);
}
reset_level_filters();
}
示例8:
wait::wait(game_display& disp, const config& cfg, saved_game& state,
mp::chat& c, config& gamelist, const bool first_scenario) :
ui(disp, _("Game Lobby"), cfg, c, gamelist),
cancel_button_(disp.video(), first_scenario ? _("Cancel") : _("Quit")),
start_label_(disp.video(), _("Waiting for game to start..."), font::SIZE_SMALL, font::LOBBY_COLOR),
game_menu_(disp.video(), std::vector<std::string>(), false, -1, -1, NULL, &gui::menu::bluebg_style),
level_(),
state_(state),
first_scenario_(first_scenario),
stop_updates_(false)
{
game_menu_.set_numeric_keypress_selection(false);
gamelist_updated();
plugins_context_.reset(new plugins_context("Multiplayer Wait"));
//These structure initializers create a lobby::process_data_event
plugins_context_->set_callback("quit", boost::bind(&wait::process_event_impl, this, true), false);
plugins_context_->set_callback("chat", boost::bind(&wait::send_chat_message, this, boost::bind(get_str, _1, "message"), false), true);
}
示例9: enter_create_mode
static void enter_create_mode(game_display& disp, const config& game_config,
game_state& state, bool local_players_only)
{
DBG_MP << "entering create mode" << std::endl;
bool configure_canceled;
bool connect_canceled;
do {
configure_canceled = false;
connect_canceled = false;
if (gui2::new_widgets) {
gui2::tmp_create_game dlg(game_config);
dlg.show(disp.video());
network::send_data(config("refresh_lobby"), 0);
} else {
mp::ui::result res;
mp_game_settings new_params;
{
mp::create ui(disp, game_config, state, gamechat, gamelist);
run_lobby_loop(disp, ui);
res = ui.get_result();
new_params = ui.get_parameters();
}
switch (res) {
case mp::ui::CREATE:
configure_canceled = !enter_configure_mode(disp, game_config,
state, new_params, local_players_only);
break;
case mp::ui::LOAD_GAME:
connect_canceled = !enter_connect_mode(disp, game_config,
state, new_params, local_players_only);
break;
case mp::ui::QUIT:
default:
//update lobby content
network::send_data(config("refresh_lobby"), 0);
break;
}
}
} while(configure_canceled || connect_canceled);
}
示例10: update_location
void floating_textbox::update_location(game_display& gui)
{
if (box_ == NULL)
return;
const SDL_Rect& area = gui.map_outside_area();
const int border_size = 10;
const int ypos = area.y+area.h-30 - (check_ != NULL ? check_->height() + border_size : 0);
if (label_ != 0)
font::remove_floating_label(label_);
font::floating_label flabel(label_string_);
flabel.set_color(font::YELLOW_COLOR);
flabel.set_position(area.x + border_size, ypos);
flabel.set_alignment(font::LEFT_ALIGN);
flabel.set_clip_rect(area);
label_ = font::add_floating_label(flabel);
if (label_ == 0)
return;
const SDL_Rect& label_area = font::get_floating_label_rect(label_);
const int textbox_width = area.w - label_area.w - border_size*3;
if(textbox_width <= 0) {
font::remove_floating_label(label_);
return;
}
if(box_ != NULL) {
box_->set_volatile(true);
const SDL_Rect rect = create_rect(
area.x + label_area.w + border_size * 2
, ypos
, textbox_width
, box_->height());
box_->set_location(rect);
}
if(check_ != NULL) {
check_->set_volatile(true);
check_->set_location(box_->location().x,box_->location().y + box_->location().h + border_size);
}
}
示例11: close
void floating_textbox::close(game_display& gui)
{
if(!active()) {
return;
}
if(check_ != NULL) {
if(mode_ == TEXTBOX_MESSAGE) {
preferences::set_message_private(check_->checked());
}
}
box_.assign(NULL);
check_.assign(NULL);
font::remove_floating_label(label_);
mode_ = TEXTBOX_NONE;
gui.invalidate_all();
}
示例12: do_preferences_dialog
static void do_preferences_dialog(game_display& disp, const config& game_config)
{
const preferences::display_manager disp_manager(&disp);
preferences::show_preferences_dialog(disp,game_config);
/**
* The screen size might have changed force an update of the size.
*
* @todo This might no longer be needed when gui2 is done.
*/
const SDL_Rect rect = screen_area();
preferences::set_resolution(disp.video(), rect.w, rect.h);
gui2::settings::gamemap_width += rect.w - gui2::settings::screen_width ;
gui2::settings::gamemap_height += rect.h - gui2::settings::screen_height ;
gui2::settings::screen_width = rect.w;
gui2::settings::screen_height = rect.h;
}
示例13: update_location
void floating_textbox::update_location(game_display& gui)
{
if (box_ == NULL)
return;
const SDL_Rect& area = gui.map_outside_area();
const int border_size = 10;
const int ypos = area.y+area.h-30 - (check_ != NULL ? check_->height() + border_size : 0);
if (label_ != 0)
font::remove_floating_label(label_);
label_ = font::add_floating_label(label_string_,font::SIZE_NORMAL,
font::YELLOW_COLOUR,area.x+border_size,ypos,0,0,-1, area,font::LEFT_ALIGN);
if (label_ == 0)
return;
const SDL_Rect& label_area = font::get_floating_label_rect(label_);
const int textbox_width = area.w - label_area.w - border_size*3;
if(textbox_width <= 0) {
font::remove_floating_label(label_);
return;
}
if(box_ != NULL) {
box_->set_volatile(true);
const SDL_Rect rect = {
area.x + label_area.w + border_size*2, ypos,
textbox_width, box_->height()
};
box_->set_location(rect);
}
if(check_ != NULL) {
check_->set_volatile(true);
check_->set_location(box_->location().x,box_->location().y + box_->location().h + border_size);
}
}
示例14: error
create::create(game_display& disp, const config& cfg, saved_game& state,
chat& c, config& gamelist) :
ui(disp, _("Create Game"), cfg, c, gamelist),
tooltip_manager_(disp.video()),
era_selection_(-1),
mod_selection_(-1),
level_selection_(-1),
eras_menu_(disp.video(), std::vector<std::string>()),
levels_menu_(disp.video(), std::vector<std::string>()),
mods_menu_(disp.video(), std::vector<std::string>()),
filter_name_label_(disp.video(), _("Filter:"), font::SIZE_SMALL, font::LOBBY_COLOR),
filter_num_players_label_(disp.video(), _("Number of players: any"), font::SIZE_SMALL, font::LOBBY_COLOR),
map_generator_label_(disp.video(), _("Random map options:"), font::SIZE_SMALL, font::LOBBY_COLOR),
era_label_(disp.video(), _("Era:"), font::SIZE_SMALL, font::LOBBY_COLOR),
no_era_label_(disp.video(), _("No eras available\nfor this game."),
font::SIZE_SMALL, font::LOBBY_COLOR),
mod_label_(disp.video(), _("Modifications:"), font::SIZE_SMALL, font::LOBBY_COLOR),
map_size_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOR),
num_players_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOR),
level_type_label_(disp.video(), "Game type:", font::SIZE_SMALL, font::LOBBY_COLOR),
launch_game_(disp.video(), _("Next")),
cancel_game_(disp.video(), _("Cancel")),
regenerate_map_(disp.video(), _("Regenerate")),
generator_settings_(disp.video(), _("Settings...")),
load_game_(disp.video(), _("Load Game...")),
level_type_combo_(disp, std::vector<std::string>()),
filter_num_players_slider_(disp.video()),
description_(disp.video(), 100, "", false),
filter_name_(disp.video(), 100, "", true, 256, font::SIZE_SMALL),
image_restorer_(NULL),
image_rect_(null_rect),
available_level_types_(),
engine_(disp, state)
{
filter_num_players_slider_.set_min(1);
filter_num_players_slider_.set_max(9);
filter_num_players_slider_.set_increment(1);
DBG_MP << "constructing multiplayer create dialog" << std::endl;
levels_menu_.set_numeric_keypress_selection(false);
typedef std::pair<ng::level::TYPE, std::string> level_type_info;
std::vector<level_type_info> all_level_types;
all_level_types.push_back(std::make_pair(ng::level::TYPE::SCENARIO, _("Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::CAMPAIGN, _("Campaigns")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::USER_MAP, _("User Maps")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::USER_SCENARIO, _("User Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::RANDOM_MAP, _("Random Maps")));
if (game_config::debug) {
all_level_types.push_back(std::make_pair(ng::level::TYPE::SP_CAMPAIGN,
"SP Campaigns"));
}
std::vector<std::string> combo_level_names;
BOOST_FOREACH(level_type_info type_info, all_level_types) {
if (!engine_.get_levels_by_type_unfiltered(type_info.first).empty()) {
available_level_types_.push_back(type_info.first);
combo_level_names.push_back(type_info.second);
}
}
if (available_level_types_.empty()) {
gui2::show_transient_message(disp.video(), "", _("No games found."));
throw game::error(_("No games found."));
}
level_type_combo_.set_items(combo_level_names);
size_t combo_new_selection = 0;
size_t level_new_selection = 0;
// Set level selection according to the preferences, if possible.
size_t type_index = 0;
BOOST_FOREACH(ng::level::TYPE type, available_level_types_) {
if (preferences::level_type() == type.cast<int>()) {
break;
}
type_index++;
}
if (type_index < available_level_types_.size()) {
combo_new_selection = type_index;
int level_index = engine_.find_level_by_id(preferences::level());
if (level_index != -1) {
level_new_selection = level_index;
}
}
level_type_combo_.set_selected(combo_new_selection);
init_level_type_changed(level_new_selection);
const std::vector<std::string>& era_names =
engine_.extras_menu_item_names(ng::create_engine::ERA);
if(era_names.empty()) {
gui2::show_transient_message(disp.video(), "", _("No eras found."));
throw config::error(_("No eras found"));
}
//.........这里部分代码省略.........
示例15: enter_lobby_mode
static void enter_lobby_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist)
{
mp::ui::result res;
while (true) {
const config &cfg = game_config.child("lobby_music");
if (cfg) {
foreach (const config &i, cfg.child_range("music")) {
sound::play_music_config(i);
}
sound::commit_music_changes();
} else {
sound::empty_playlist();
sound::stop_music();
}
lobby_info li(game_config);
gui2::tlobby_main dlg(game_config, li, disp);
dlg.set_preferences_callback(
boost::bind(do_preferences_dialog,
boost::ref(disp), boost::ref(game_config)));
dlg.show(disp.video());
//ugly kludge for launching other dialogs like the old lobby
switch (dlg.get_legacy_result()) {
case gui2::tlobby_main::CREATE:
res = mp::ui::CREATE;
break;
case gui2::tlobby_main::JOIN:
res = mp::ui::JOIN;
break;
case gui2::tlobby_main::OBSERVE:
res = mp::ui::OBSERVE;
break;
default:
res = mp::ui::QUIT;
}
switch (res) {
case mp::ui::JOIN:
try {
enter_wait_mode(disp, game_config, chat, gamelist, false);
} catch(config::error& error) {
if(!error.message.empty()) {
gui2::show_error_message(disp.video(), error.message);
}
//update lobby content
network::send_data(config("refresh_lobby"), 0, true);
}
break;
case mp::ui::OBSERVE:
try {
enter_wait_mode(disp, game_config, chat, gamelist, true);
} catch(config::error& error) {
if(!error.message.empty()) {
gui2::show_error_message(disp.video(), error.message);
}
}
// update lobby content unconditionally because we might have left only after the
// game ended in which case we ignored the gamelist and need to request it again
network::send_data(config("refresh_lobby"), 0, true);
break;
case mp::ui::CREATE:
try {
enter_create_mode(disp, game_config, chat, gamelist, mp::CNTR_NETWORK);
} catch(config::error& error) {
if (!error.message.empty())
gui2::show_error_message(disp.video(), error.message);
//update lobby content
network::send_data(config("refresh_lobby"), 0, true);
}
break;
case mp::ui::QUIT:
return;
case mp::ui::PREFERENCES:
{
do_preferences_dialog(disp, game_config);
//update lobby content
network::send_data(config("refresh_lobby"), 0, true);
}
break;
default:
return;
}
}