本文整理汇总了C++中DynamicRibbonWidget::setSelection方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicRibbonWidget::setSelection方法的具体用法?C++ DynamicRibbonWidget::setSelection怎么用?C++ DynamicRibbonWidget::setSelection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicRibbonWidget
的用法示例。
在下文中一共展示了DynamicRibbonWidget::setSelection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setFocusOnTrack
void ArenasScreen::setFocusOnTrack(const std::string& trackName)
{
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("tracks");
assert( w != NULL );
w->setSelection(trackName, PLAYER_ID_GAME_MASTER, true);
} // setFOxuOnTrack
示例2: init
void ArenasScreen::init()
{
Screen::init();
buildTrackList();
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("tracks");
// select something by default for the game master
assert( w != NULL );
w->setSelection(w->getItems()[0].m_code_name, PLAYER_ID_GAME_MASTER, true);
} // init
示例3: selectTrack
// -----------------------------------------------------------------------------
void EditTrackScreen::selectTrack(const std::string& id)
{
DynamicRibbonWidget* tracks = getWidget<DynamicRibbonWidget>("tracks");
assert(tracks != NULL);
LabelWidget* selected_track = getWidget<LabelWidget>("selected_track");
assert(selected_track != NULL);
SpinnerWidget* laps = getWidget<SpinnerWidget>("laps");
assert(laps != NULL);
LabelWidget* label_reverse = getWidget<LabelWidget>("reverse_label");
assert(label_reverse != NULL);
CheckBoxWidget* reverse = getWidget<CheckBoxWidget>("reverse");
assert(reverse != NULL);
ButtonWidget* ok_button = getWidget<ButtonWidget>("ok");
assert(ok_button != NULL);
m_track = track_manager->getTrack(id);
if (m_track != NULL)
{
tracks->setSelection(m_track->getIdent(), PLAYER_ID_GAME_MASTER, true);
selected_track->setText(m_track->getName(), true);
laps->setValue(m_laps);
reverse->setVisible(m_track->reverseAvailable());
label_reverse->setVisible(m_track->reverseAvailable());
ok_button->setActivated();
}
else
{
tracks->setSelection("", PLAYER_ID_GAME_MASTER, true);
selected_track->setText(_("Select a track"), true);
// We can't set a better default for number of laps. On the other
// hand, if a track is selected, the number of laps will be updated.
laps->setValue(3);
reverse->setVisible(true);
reverse->setState(false);
ok_button->setDeactivated();
}
}
示例4: onSelectionChanged
// ------------------------------------------------------------------------
void KartHoverListener::onSelectionChanged(DynamicRibbonWidget* theWidget,
const std::string& selectionID,
const irr::core::stringw& selectionText,
const int player_id)
{
assert(m_magic_number == 0xCAFEC001);
// Check if this player has a kart
if (m_parent->m_kart_widgets.size() <= unsigned(player_id))
{
GUIEngine::focusNothingForPlayer(player_id);
return;
}
// Don't allow changing the selection after confirming it
if (m_parent->m_kart_widgets[player_id].isReady())
{
// discard events sent when putting back to the right kart
if (selectionID ==
m_parent->m_kart_widgets[player_id].m_kartInternalName) return;
DynamicRibbonWidget* w =
m_parent->getWidget<DynamicRibbonWidget>("karts");
assert(w != NULL);
w->setSelection(m_parent->m_kart_widgets[player_id]
.m_kartInternalName, player_id, true);
return;
}
if (m_parent->m_kart_widgets[player_id].getKartInternalName() == selectionID)
return; // already selected
m_parent->updateKartWidgetModel(player_id, selectionID, selectionText);
m_parent->m_kart_widgets[player_id].setKartInternalName(selectionID);
m_parent->updateKartStats(player_id, selectionID);
m_parent->validateKartChoices();
} // onSelectionChanged
示例5: eventCallback
/**
* Callback handling events from the kart selection menu
*/
void KartSelectionScreen::eventCallback(Widget* widget,
const std::string& name,
const int player_id)
{
// don't allow changing group after someone confirmed
if (name == "kartgroups" && !m_game_master_confirmed)
{
RibbonWidget* tabs = getWidget<RibbonWidget>("kartgroups");
assert(tabs != NULL);
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
assert(w != NULL);
setKartsFromCurrentGroup();
const std::string &selected_kart_group =
tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER);
UserConfigParams::m_last_used_kart_group = selected_kart_group;
RandomGenerator random;
const int num_players = m_kart_widgets.size();
for (int n=0; n<num_players; n++)
{
// The game master is the one that can change the groups, leave
// his focus on the tabs for others, remove focus from kart that
// might no more exist in this tab.
if (n != PLAYER_ID_GAME_MASTER)
GUIEngine::focusNothingForPlayer(n);
if (!m_kart_widgets[n].isReady())
{
// try to preserve the same kart for each player (except for
// game master, since it's the one that can change the
// groups, so focus for this player must remain on the tabs)
const std::string& selected_kart =
m_kart_widgets[n].getKartInternalName();
if (!w->setSelection( selected_kart, n,
n != PLAYER_ID_GAME_MASTER))
{
// if we get here, it means one player "lost" his kart in
// the tab switch
if (UserConfigParams::logGUI())
Log::info("KartSelectionScreen", "Player %u"
" lost their selection when switching tabs!!!",n);
// Select a random kart in this case
const int count = (int) w->getItems().size();
if (count > 0)
{
// FIXME: two players may be given the same kart by
// the use of random
const int random_id = random.get( count );
// select kart for players > 0 (player 0 is the one
// that can change the groups, so focus for player 0
// must remain on the tabs)
const bool success =
w->setSelection( random_id, n,
n != PLAYER_ID_GAME_MASTER );
if (!success)
Log::warn("KartSelectionScreen",
"setting kart of player %u failed");
}
else
{
Log::warn("KartSelectionScreen", " 0 items "
"in the ribbon");
}
}
}
} // end for
}
else if (name == "karts")
{
if (m_kart_widgets.size() > unsigned(player_id))
playerConfirm(player_id);
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
else
{
// Transmit to all subwidgets, maybe *they* care about this event
const int amount = m_kart_widgets.size();
for (int n=0; n<amount; n++)
{
m_kart_widgets[n].transmitEvent(widget, name, player_id);
}
// those events may mean that a player selection changed, so
// validate again
validateIdentChoices();
validateKartChoices();
}
} // eventCallback
示例6: playerQuit
bool KartSelectionScreen::playerQuit(StateManager::ActivePlayer* player)
{
int player_id = -1;
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
if (w == NULL)
{
Log::error("KartSelectionScreen", "playerQuit() called "
"outside of kart selection screen, "
"or the XML file for this screen was changed without "
"adapting the code accordingly");
return false;
}
// If last player quits, return to main menu
if (m_kart_widgets.size() <= 1)
{
StateManager::get()->escapePressed();
return true;
}
std::map<PlayerKartWidget*, std::string> selections;
// Find the player ID associated to this player
for (unsigned int n=0; n<m_kart_widgets.size(); n++)
{
if (m_kart_widgets[n].getAssociatedPlayer() == player)
{
// Check that this player has not already confirmed,
// then they can't back out
if (m_kart_widgets[n].isReady())
{
SFXManager::get()->quickSound( "anvil" );
return true;
}
player_id = n;
}
else
{
selections[m_kart_widgets.get(n)] =
m_kart_widgets[n].getKartInternalName();
}
}
if (player_id == -1)
{
Log::warn("KartSelectionScreen", "playerQuit cannot find "
"passed player");
return false;
}
if(UserConfigParams::logGUI())
Log::info("KartSelectionScreen", "playerQuit(%d)", player_id);
// Just a cheap way to check if there is any discrepancy
// between m_kart_widgets and the active player array
assert( m_kart_widgets.size() == StateManager::get()->activePlayerCount());
// unset selection of this player
GUIEngine::focusNothingForPlayer(player_id);
// delete a previous removed widget that didn't have time to fully shrink
// yet.
// TODO: handle multiple shrinking widgets gracefully?
if (m_removed_widget != NULL)
{
manualRemoveWidget(m_removed_widget);
delete m_removed_widget;
m_removed_widget = NULL;
}
// keep the removed kart a while, for the 'disappear' animation
// to take place
m_removed_widget = m_kart_widgets.remove(player_id);
// Tell the StateManager to remove this player
StateManager::get()->removeActivePlayer(player_id);
addMultiplayerMessage();
// Karts count changed, maybe order too, so renumber them.
renumberKarts();
// Tell the removed widget to perform the shrinking animation (which will
// be updated in onUpdate, and will stop when the widget has disappeared)
Widget* fullarea = getWidget("playerskarts");
m_removed_widget->move(m_removed_widget->m_x + m_removed_widget->m_w/2,
fullarea->m_y + fullarea->m_h, 0, 0);
// update selections
const unsigned int amount = m_kart_widgets.size();
for (unsigned int n=0; n<amount; n++)
{
const std::string& selectedKart = selections[m_kart_widgets.get(n)];
if (selectedKart.size() > 0)
{
//std::cout << m_kart_widgets[n].getAssociatedPlayer()
// ->getProfile()->getName() << " selected "
// << selectedKart.c_str() << "\n";
const bool success = w->setSelection(selectedKart, n, true);
//.........这里部分代码省略.........
示例7: joinPlayer
//.........这里部分代码省略.........
Log::error("KartSelectionScreen", "joinPlayer(): Received null "
"device pointer");
return false;
}
if (StateManager::get()->activePlayerCount() >= MAX_PLAYER_COUNT)
{
Log::error("KartSelectionScreen", "Maximum number of players "
"reached");
SFXManager::get()->quickSound( "anvil" );
return false;
}
// ---- Create new active player
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
// Make sure enough guest character exists. At this stage this player has
// not been added, so the number of guests requested for the first player
// is 0 --> forcing at least one real player.
PlayerManager::get()->createGuestPlayers(
StateManager::get()->activePlayerCount());
if (!first_player)
{
// Give each player a different start profile
const int num_active_players = StateManager::get()->activePlayerCount();
profile_to_use = PlayerManager::get()->getPlayer(num_active_players);
removeMultiplayerMessage();
}
const int new_player_id =
StateManager::get()->createActivePlayer(profile_to_use, device);
StateManager::ActivePlayer* aplayer =
StateManager::get()->getActivePlayer(new_player_id);
RibbonWidget* tabs = getWidget<RibbonWidget>("kartgroups");
assert(tabs != NULL);
std::string selected_kart_group =
tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER);
// ---- Get available area for karts
// make a copy of the area, ands move it to be outside the screen
Widget* kartsAreaWidget = getWidget("playerskarts");
// start at the rightmost of the screen
const int shift = irr_driver->getFrameSize().Width;
core::recti kartsArea(kartsAreaWidget->m_x + shift,
kartsAreaWidget->m_y,
kartsAreaWidget->m_x + shift + kartsAreaWidget->m_w,
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
// ---- Create player/kart widget
PlayerKartWidget* newPlayerWidget =
new PlayerKartWidget(this, aplayer, NULL, kartsArea, m_kart_widgets.size(),
selected_kart_group);
manualAddWidget(newPlayerWidget);
m_kart_widgets.push_back(newPlayerWidget);
newPlayerWidget->add();
// ---- Divide screen space among all karts
const int amount = m_kart_widgets.size();
Widget* fullarea = getWidget("playerskarts");
// in this special case, leave room for a message on the right
if (m_multiplayer && first_player)
{
addMultiplayerMessage();
const int splitWidth = fullarea->m_w / 2;
m_kart_widgets[0].move( fullarea->m_x, fullarea->m_y, splitWidth,
fullarea->m_h );
}
else
{
const int splitWidth = fullarea->m_w / amount;
for (int n=0; n<amount; n++)
{
m_kart_widgets[n].move( fullarea->m_x + splitWidth * n,
fullarea->m_y, splitWidth, fullarea->m_h);
}
}
// select something (anything) in the ribbon; by default, only the
// game master has something selected. Thus, when a new player joins,
// we need to select something for them
w->setSelection(new_player_id, new_player_id, true);
newPlayerWidget->m_player_ident_spinner
->setFocusForPlayer(new_player_id);
if (!m_multiplayer)
{
input_manager->getDeviceManager()->setSinglePlayer(StateManager::get()
->getActivePlayer(0));
}
return true;
} // joinPlayer
示例8: init
void KartSelectionScreen::init()
{
m_instance_ptr = this;
Screen::init();
m_must_delete_on_back = false;
RibbonWidget* tabs = getWidget<RibbonWidget>("kartgroups");
assert( tabs != NULL );
tabs->select(UserConfigParams::m_last_used_kart_group,
PLAYER_ID_GAME_MASTER);
Widget* placeholder = getWidget("playerskarts");
assert(placeholder != NULL);
// FIXME : The reserved id value is -1 when we switch from KSS to NKSS and vice-versa
m_dispatcher->setRootID(placeholder->m_reserved_id);
g_root_id = placeholder->m_reserved_id;
if (!m_widgets.contains(m_dispatcher))
{
m_widgets.push_back(m_dispatcher);
// this is only needed if the dispatcher wasn't already in
// the list of widgets. If it already was, it was added along
// other widgets.
m_dispatcher->add();
}
m_game_master_confirmed = false;
tabs->setActive(true);
m_kart_widgets.clearAndDeleteAll();
StateManager::get()->resetActivePlayers();
input_manager->getDeviceManager()->setAssignMode(DETECT_NEW);
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
KartHoverListener* karthoverListener = new KartHoverListener(this);
w->registerHoverListener(karthoverListener);
// Build kart list (it is built everytime, to account for .g. locking)
setKartsFromCurrentGroup();
/*
TODO: Ultimately, it'd be nice to *not* clear m_kart_widgets so that
when players return to the kart selection screen, it will appear as
it did when they left (at least when returning from the track menu).
Rebuilding the screen is a little tricky.
*/
/*
if (m_kart_widgets.size() > 0)
{
// trying to rebuild the screen
for (int n = 0; n < m_kart_widgets.size(); n++)
{
PlayerKartWidget *pkw;
pkw = m_kart_widgets.get(n);
manualAddWidget(pkw);
pkw->add();
}
}
else */
// For now this is what will happen
if (!m_multiplayer)
{
joinPlayer(input_manager->getDeviceManager()->getLatestUsedDevice());
w->updateItemDisplay();
// Player 0 select default kart
if (!w->setSelection(UserConfigParams::m_default_kart, 0, true))
{
// if kart from config not found, select the first instead
w->setSelection(0, 0, true);
}
} else
// Add multiplayer message
addMultiplayerMessage();
// This flag will cause that a 'fire' event will be mapped to 'select' (if
// 'fire' is not assigned to a GUI event). This is done to support the old
// way of player joining by pressing 'fire' instead of 'select'.
input_manager->getDeviceManager()->mapFireToSelect(true);
} // init
示例9: init
//.........这里部分代码省略.........
r.height = modes[n].getHeight();
resolutions.push_back(r);
if (r.width == UserConfigParams::m_width &&
r.height == UserConfigParams::m_height)
{
found_config_res = true;
}
if (r.width == 1024 && r.height == 768)
{
found_1024_768 = true;
}
}
if (!found_config_res)
{
r.width = UserConfigParams::m_width;
r.height = UserConfigParams::m_height;
resolutions.push_back(r);
if (r.width == 1024 && r.height == 768)
{
found_1024_768 = true;
}
} // next found resolution
// Add default resolutions that were not found by irrlicht
if (!found_1024_768)
{
r.width = 1024;
r.height = 768;
resolutions.push_back(r);
}
// Sort resolutions by size
std::sort(resolutions.begin(), resolutions.end());
// Add resolutions list
for(std::vector<Resolution>::iterator it = resolutions.begin();
it != resolutions.end(); it++)
{
const float ratio = it->getRatio();
char name[32];
sprintf(name, "%ix%i", it->width, it->height);
core::stringw label;
label += it->width;
label += L"\u00D7";
label += it->height;
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if (ABOUT_EQUAL( ratio, (5.0f/4.0f) ))
res->addItem(label, name, "/gui/screen54.png");
else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) ))
res->addItem(label, name, "/gui/screen43.png");
else if (ABOUT_EQUAL( ratio, (16.0f/10.0f)))
res->addItem(label, name, "/gui/screen1610.png");
else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) ))
res->addItem(label, name, "/gui/screen53.png");
else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) ))
res->addItem(label, name, "/gui/screen32.png");
else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) ))
res->addItem(label, name, "/gui/screen169.png");
else
res->addItem(label, name, "/gui/screen_other.png");
#undef ABOUT_EQUAL
} // add next resolution
} // end if not inited
res->updateItemDisplay();
// ---- select current resolution every time
char searching_for[32];
snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_width,
(int)UserConfigParams::m_height);
if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER,
false /* focus it */, true /* even if deactivated*/))
{
Log::error("OptionsScreenVideo", "Cannot find resolution %s", searching_for);
}
// --- set gfx settings values
updateGfxSlider();
// ---- forbid changing resolution or animation settings from in-game
// (we need to disable them last because some items can't be edited when
// disabled)
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
res->setActive(!in_game);
full->setActive(!in_game);
applyBtn->setActive(!in_game);
gfx->setActive(!in_game);
getWidget<ButtonWidget>("custom")->setActive(!in_game);
} // init
示例10: init
//.........这里部分代码省略.........
const float ratio = (float)w / h;
if (w == 800 && h == 600)
{
#ifdef DEBUG
found_800_600 = true;
#endif
}
else if (w == 1024 && h == 640)
{
found_1024_640 = true;
}
else if (w == 1024 && h == 768)
{
found_1024_768 = true;
}
char name[32];
sprintf( name, "%ix%i", w, h );
core::stringw label;
label += w;
label += L"\u00D7";
label += h;
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if (ABOUT_EQUAL( ratio, (5.0f/4.0f) ))
res->addItem(label, name, "/gui/screen54.png");
else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) ))
res->addItem(label, name, "/gui/screen43.png");
else if (ABOUT_EQUAL( ratio, (16.0f/10.0f) ))
res->addItem(label, name, "/gui/screen1610.png");
else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) ))
res->addItem(label, name, "/gui/screen53.png");
else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) ))
res->addItem(label, name, "/gui/screen32.png");
else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) ))
res->addItem(label, name, "/gui/screen169.png");
else
res->addItem(label, name, "/gui/screen_other.png");
#undef ABOUT_EQUAL
}
#ifdef DEBUG
if (!found_800_600)
{
res->addItem(L"800\u00D7600", "800x600", "/gui/screen43.png");
}
#endif
if (!found_1024_640)
{
res->addItem(L"1024\u00D7640", "1024x640", "/gui/screen1610.png");
}
if (!found_1024_768)
{
res->addItem(L"1024\u00D7768", "1024x768", "/gui/screen43.png");
}
} // end if not inited
res->updateItemDisplay();
// ---- select current resolution every time
char searching_for[32];
snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_width,
(int)UserConfigParams::m_height);
if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER,
false /* focus it */, true /* even if deactivated*/))
{
Log::error("OptionsScreenVideo", "Cannot find resolution %s", searching_for);
}
// --- set gfx settings values
updateGfxSlider();
// ---- forbid changing resolution or animation settings from in-game
// (we need to disable them last because some items can't be edited when
// disabled)
if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
{
res->setDeactivated();
full->setDeactivated();
applyBtn->setDeactivated();
gfx->setDeactivated();
getWidget<ButtonWidget>("custom")->setDeactivated();
}
else
{
// Enable back widgets if they were visited in-game previously
res->setActivated();
full->setActivated();
applyBtn->setActivated();
gfx->setActivated();
getWidget<ButtonWidget>("custom")->setActivated();
}
} // init