Added Screen::push() function to shorten the calls to pushScreen().

This commit is contained in:
hiker 2014-09-23 16:43:50 +10:00
parent 596cc44dfa
commit aa64f31f83
25 changed files with 584 additions and 65 deletions

View File

@ -93,6 +93,15 @@ void Screen::init()
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
} // init
// -----------------------------------------------------------------------------
/** Displays this screen bu pushing it onto the stack of screen
* in the state manager.
*/
void Screen::push()
{
StateManager::get()->pushScreen(this);
} // push
// -----------------------------------------------------------------------------
/** Prepares removal of this screen. If necessary this will unpause the
* race (so this means that if you have several consecutive screens while

View File

@ -228,6 +228,10 @@ namespace GUIEngine
*/
virtual void init();
/** Displays this screen bu pushing it onto the stack of screen
* in the state manager. */
void push();
/**
* \brief Callback invoked before leaving this menu.
*

View File

@ -1300,16 +1300,16 @@ int main(int argc, char *argv[] )
if(PlayerManager::getCurrentPlayer() && !
UserConfigParams::m_always_show_login_screen)
{
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
MainMenuScreen::getInstance()->push();
}
else
{
StateManager::get()->pushScreen(UserScreen::getInstance());
UserScreen::getInstance()->push();
// If there is no player, push the RegisterScreen on top of
// the login screen. This way on first start players are
// forced to create a player.
if(PlayerManager::get()->getNumPlayers()==0)
StateManager::get()->pushScreen(RegisterScreen::getInstance());
RegisterScreen::getInstance()->push();
}
#ifdef ENABLE_WIIUSE
// Show a dialog to allow connection of wiimotes. */

View File

@ -408,7 +408,7 @@ void CutsceneWorld::enterRaceOverState()
GUIEngine::Screen* newStack[] = { mainMenu, credits, NULL };
race_manager->exitRace();
StateManager::get()->resetAndSetStack(newStack);
StateManager::get()->pushScreen(credits);
credits->push();
}
// TODO: remove hardcoded knowledge of cutscenes, replace with scripting probably
else if (m_parts.size() == 1 && m_parts[0] == "gpwin")
@ -525,7 +525,7 @@ void CutsceneWorld::enterRaceOverState()
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
s->setMultiplayer(false);
s->setGoToOverworldNext();
StateManager::get()->pushScreen( s );
s->push();
}
}
// TODO: remove hardcoded knowledge of cutscenes, replace with scripting probably

View File

@ -548,7 +548,7 @@ void World::terminateRace()
results->clearHighscores();
}
StateManager::get()->pushScreen(results);
results->push();
WorldStatus::terminateRace();
} // terminateRace

View File

@ -245,7 +245,7 @@ void ClientLobbyRoomProtocol::update()
case KART_SELECTION:
{
NetworkKartSelectionScreen* screen = NetworkKartSelectionScreen::getInstance();
StateManager::get()->pushScreen(screen);
screen->push();
m_state = SELECTING_KARTS;
}
break;

View File

@ -12,7 +12,6 @@
#include "network/protocols/synchronization_protocol.hpp"
#include "online/online_profile.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/network_kart_selection.hpp"
#include "utils/log.hpp"
@ -159,7 +158,7 @@ void StartGameProtocol::update()
KartSelectionScreen* s = KartSelectionScreen::getInstance();
s->setMultiplayer(false);
s->setFromOverworld(false);
StateManager::get()->pushScreen( s );*/
s->push();*/
}
else if (m_state == SYNCHRONIZATION_WAIT)
{

View File

@ -692,14 +692,14 @@ void RaceManager::exitRace(bool delete_world)
{
race_manager->startSingleRace("gpwin", 999, false);
GrandPrixWin* scene = GrandPrixWin::getInstance();
StateManager::get()->pushScreen(scene);
scene->push();
scene->setKarts(winners);
}
else
{
race_manager->startSingleRace("gplose", 999, false);
GrandPrixLose* scene = GrandPrixLose::getInstance();
StateManager::get()->pushScreen(scene);
scene->push();
if (humanLosers.size() >= 1)
{

View File

@ -167,7 +167,7 @@ void ArenasScreen::eventCallback(Widget* widget, const std::string& name, const
if (clicked_track != NULL)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
}
}
@ -184,7 +184,7 @@ void ArenasScreen::eventCallback(Widget* widget, const std::string& name, const
if (clicked_track != NULL)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
} // clickedTrack != NULL
} // if random_track

View File

@ -139,12 +139,12 @@ void NotificationDialog::onUpdate(float dt)
if(type == T_Friends)
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileFriends::getInstance());
OnlineProfileFriends::getInstance()->push();
}
else if (type == T_Achievements)
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileAchievements::getInstance());
OnlineProfileAchievements::getInstance()->push();
}
}
return;

View File

@ -134,13 +134,13 @@ GUIEngine::EventPropagation
else if (selection == "help")
{
dismiss();
StateManager::get()->pushScreen(HelpScreen1::getInstance());
HelpScreen1::getInstance()->push();
return GUIEngine::EVENT_BLOCK;
}
else if (selection == "options")
{
dismiss();
StateManager::get()->pushScreen(OptionsScreenVideo::getInstance());
OptionsScreenVideo::getInstance()->push();
return GUIEngine::EVENT_BLOCK;
}
else if (selection == "restart")

View File

@ -64,7 +64,7 @@ ServerInfoDialog::ServerInfoDialog(uint32_t server_id, uint32_t host_id, bool fr
assert(m_cancel_widget != NULL);
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
} // ServerInfoDialog
// -----------------------------------------------------------------------------
ServerInfoDialog::~ServerInfoDialog()
@ -72,7 +72,8 @@ ServerInfoDialog::~ServerInfoDialog()
if (m_server_join_request)
delete m_server_join_request;
m_server_join_request = NULL;
}
} // ~ServerInfoDialog
// -----------------------------------------------------------------------------
void ServerInfoDialog::requestJoin()
{
@ -81,9 +82,9 @@ void ServerInfoDialog::requestJoin()
Online::ServersManager::get()->setJoinedServer(m_server_id);
ProtocolManager::getInstance()->requestStart(new ConnectToServer(m_server_id, m_host_id));
ModalDialog::dismiss();
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
NetworkingLobby::getInstance()->push();
//Online::CurrentUser::release();
}
} // requestJoin
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation ServerInfoDialog::processEvent(const std::string& eventSource)
@ -104,7 +105,7 @@ GUIEngine::EventPropagation ServerInfoDialog::processEvent(const std::string& ev
}
}
return GUIEngine::EVENT_LET;
}
} // processEvent
// -----------------------------------------------------------------------------
@ -116,7 +117,7 @@ void ServerInfoDialog::onEnterPressedInternal()
if (GUIEngine::isFocusedForPlayer(m_options_widget, playerID))
return;
requestJoin();
}
} // onEnterPressedInternal
// -----------------------------------------------------------------------------
@ -125,7 +126,7 @@ bool ServerInfoDialog::onEscapePressed()
if (m_cancel_widget->isActivated())
m_self_destroy = true;
return false;
}
} // onEscapePressed
// -----------------------------------------------------------------------------
@ -166,7 +167,7 @@ void ServerInfoDialog::onUpdate(float dt)
if (m_from_server_creation)
StateManager::get()->popMenu();
if (m_enter_lobby)
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
NetworkingLobby::getInstance()->push();
return;
}
}
} // onUpdate

View File

@ -86,7 +86,7 @@ void EasterEggScreen::eventCallback(Widget* widget, const std::string& name, con
if (clicked_track != NULL)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
}
}
@ -100,7 +100,7 @@ void EasterEggScreen::eventCallback(Widget* widget, const std::string& name, con
if (clicked_track != NULL)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
}
}
}

View File

@ -113,7 +113,7 @@ void EditGPScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
assert(edit != NULL);
//By default, 3 laps and no reversing
edit->setSelection(NULL, 3, false);
StateManager::get()->pushScreen(edit);
edit->push();
}
else if (m_action == "remove")
{
@ -301,7 +301,7 @@ void EditGPScreen::edit()
m_gp->getTrackId(m_selected)),
m_gp->getLaps((unsigned int)m_selected),
m_gp->getReverse((unsigned int)m_selected));
StateManager::get()->pushScreen(edit_screen);
edit_screen->push();
}
}

View File

@ -248,7 +248,7 @@ void GrandPrixEditorScreen::showEditScreen(GrandPrixData* gp)
assert(gp != NULL);
EditGPScreen* edit = EditGPScreen::getInstance();
edit->setSelectedGP(gp);
StateManager::get()->pushScreen(edit);
edit->push();
}
// -----------------------------------------------------------------------------

View File

@ -1887,7 +1887,7 @@ void KartSelectionScreen::allPlayersDone()
}
else
{
StateManager::get()->pushScreen( RaceSetupScreen::getInstance() );
RaceSetupScreen::getInstance()->push();
}
} // allPlayersDone

View File

@ -251,7 +251,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("gpwin", 999, false);
GrandPrixWin* scene = GrandPrixWin::getInstance();
StateManager::get()->pushScreen(scene);
scene->push();
const std::string winners[] = { "elephpant", "nolok", "pidgin" };
scene->setKarts(winners);
}
@ -264,7 +264,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("gplose", 999, false);
GrandPrixLose* scene = GrandPrixLose::getInstance();
StateManager::get()->pushScreen(scene);
scene->push();
std::vector<std::string> losers;
losers.push_back("nolok");
losers.push_back("elephpant");
@ -305,7 +305,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
L"You unlocked <actual text would go here...>"
);
scene->addUnlockedTrack(track_manager->getTrack("lighthouse"));
StateManager::get()->pushScreen(scene);
scene->push();
}
else if (selection == "test_unlocked2")
{
@ -325,7 +325,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
scene->addUnlockedPictures(textures, 4.0, 3.0, L"You unlocked <actual text would go here...>");
StateManager::get()->pushScreen(scene);
scene->push();
}
}
else
@ -335,18 +335,18 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); //FIXME : that was for tests
s->setMultiplayer(false);
s->setFromOverworld(false);
StateManager::get()->pushScreen( s );
s->push();
}
else if (selection == "multiplayer")
{
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
s->setMultiplayer(true);
s->setFromOverworld(false);
StateManager::get()->pushScreen( s );
s->push();
}
else if (selection == "options")
{
StateManager::get()->pushScreen( OptionsScreenVideo::getInstance() );
OptionsScreenVideo::getInstance()->push();
}
else if (selection == "quit")
{
@ -355,11 +355,11 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (selection == "about")
{
StateManager::get()->pushScreen(CreditsScreen::getInstance());
CreditsScreen::getInstance()->push();
}
else if (selection == "help")
{
StateManager::get()->pushScreen(HelpScreen1::getInstance());
HelpScreen1::getInstance()->push();
}
else if (selection == "startTutorial")
{
@ -440,11 +440,12 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
return;
}
if (PlayerManager::getCurrentOnlineId())
StateManager::get()->pushScreen(OnlineScreen::getInstance());
{
OnlineScreen::getInstance()->push();
}
else
{
BaseUserScreen *login = UserScreen::getInstance();
StateManager::get()->pushScreen(login);
UserScreen::getInstance()->push();
}
}
else if (selection == "addons")
@ -460,11 +461,11 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
"\"Allow STK to connect to the Internet\"."));
return;
}
StateManager::get()->pushScreen(AddonsScreen::getInstance());
AddonsScreen::getInstance()->push();
}
else if (selection == "gpEditor")
{
StateManager::get()->pushScreen(GrandPrixEditorScreen::getInstance());
GrandPrixEditorScreen::getInstance()->push();
}
} // eventCallback

View File

@ -198,7 +198,7 @@ void OnlineScreen::doQuickPlay()
if (join_request->isSuccess())
{
delete join_request;
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
NetworkingLobby::getInstance()->push();
ConnectToServer *cts = new ConnectToServer(server->getServerId(),
server->getHostId());
ProtocolManager::getInstance()->requestStart(cts);
@ -233,15 +233,15 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
else if (selection == m_profile_widget->m_properties[PROP_ID])
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileOverview::getInstance());
OnlineProfileOverview::getInstance()->push();
}
else if (selection == m_find_server_widget->m_properties[PROP_ID])
{
StateManager::get()->pushScreen(ServerSelection::getInstance());
ServerSelection::getInstance()->push();
}
else if (selection == m_create_server_widget->m_properties[PROP_ID])
{
StateManager::get()->pushScreen(CreateServerScreen::getInstance());
CreateServerScreen::getInstance()->push();
}
else if (selection == m_quick_play_widget->m_properties[PROP_ID])
{

View File

@ -295,7 +295,7 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
UserConfigParams::m_language = selection.c_str();
user_config->saveConfig();
GUIEngine::getStateManager()->pushScreen(OptionsScreenUI::getInstance());
OptionsScreenUI::getInstance()->push();
}
} // eventCallback

View File

@ -289,7 +289,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
scene->addTrophy(race_manager->getDifficulty());
scene->findWhatWasUnlocked(race_manager->getDifficulty());
StateManager::get()->pushScreen(scene);
scene->push();
race_manager->setAIKartOverride("");
std::vector<std::string> parts;

View File

@ -76,13 +76,13 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
UserConfigParams::m_game_mode = CONFIG_CODE_NORMAL;
StateManager::get()->pushScreen( TracksScreen::getInstance() );
TracksScreen::getInstance()->push();
}
else if (selectedMode == IDENT_TTRIAL)
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
UserConfigParams::m_game_mode = CONFIG_CODE_TIMETRIAL;
StateManager::get()->pushScreen( TracksScreen::getInstance() );
TracksScreen::getInstance()->push();
}
else if (selectedMode == IDENT_FTL)
{
@ -92,21 +92,21 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
race_manager->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
UserConfigParams::m_game_mode = CONFIG_CODE_FTL;
StateManager::get()->pushScreen( TracksScreen::getInstance() );
TracksScreen::getInstance()->push();
}
else if (selectedMode == IDENT_STRIKES)
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
UserConfigParams::m_game_mode = CONFIG_CODE_3STRIKES;
race_manager->setNumKarts( race_manager->getNumLocalPlayers() ); // no AI karts;
StateManager::get()->pushScreen( ArenasScreen::getInstance() );
ArenasScreen::getInstance()->push();
}
else if (selectedMode == IDENT_EASTER)
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_EASTER_EGG);
UserConfigParams::m_game_mode = CONFIG_CODE_EASTER;
race_manager->setNumKarts( race_manager->getNumLocalPlayers() ); // no AI karts;
StateManager::get()->pushScreen( EasterEggScreen::getInstance() );
EasterEggScreen::getInstance()->push();
}
else if (selectedMode == IDENT_SOCCER)
{
@ -115,9 +115,9 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
race_manager->setNumKarts( race_manager->getNumLocalPlayers() ); // no AI karts;
// 1 player -> no need to choose a team or determine when the match ends
if(race_manager->getNumLocalPlayers() <= 1)
StateManager::get()->pushScreen( ArenasScreen::getInstance() );
ArenasScreen::getInstance()->push();
else
StateManager::get()->pushScreen( SoccerSetupScreen::getInstance() );
SoccerSetupScreen::getInstance()->push();
}
else if (selectedMode == "locked")
{

View File

@ -383,7 +383,7 @@ void SoccerSetupScreen::onUpdate(float delta)
return;
}
m_schedule_continue = false;
StateManager::get()->pushScreen( ArenasScreen::getInstance() );
ArenasScreen::getInstance()->push();
}
} // onUPdate

View File

@ -81,7 +81,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
if (clicked_track)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
} // if clicked_track
} // selection=="random_track"
@ -98,7 +98,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
if (clicked_track)
{
TrackInfoScreen::getInstance()->setTrack(clicked_track);
StateManager::get()->pushScreen(TrackInfoScreen::getInstance());
TrackInfoScreen::getInstance()->push();
}
}
} // name=="tracks"
@ -117,7 +117,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
GPInfoScreen *gpis = GPInfoScreen::getInstance();
gpis->setGP( selection == "Random Grand Prix" ? "random"
: selection);
StateManager::get()->pushScreen(gpis);
gpis->push();
}
}
else if (name == "trackgroups")

View File

@ -273,7 +273,7 @@ void BaseUserScreen::eventCallback(Widget* widget,
} // button==ok
else if (button == "new_user")
{
StateManager::get()->pushScreen(RegisterScreen::getInstance());
RegisterScreen::getInstance()->push();
// Make sure the new user will have an empty online name field
// that can also be edited.
m_username_tb->setText("");
@ -292,7 +292,7 @@ void BaseUserScreen::eventCallback(Widget* widget,
{
PlayerProfile *cp = getSelectedPlayer();
RegisterScreen::getInstance()->setRename(cp);
StateManager::get()->pushScreen(RegisterScreen::getInstance());
RegisterScreen::getInstance()->push();
// Init will automatically be called, which
// refreshes the player list
}

505
src/states_screens/xx.cpp Normal file
View File

@ -0,0 +1,505 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009-2013 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DEBUG_MENU_ITEM 0
#include "states_screens/main_menu_screen.hpp"
#include "addons/news_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "main_loop.hpp"
#include "modes/cutscene_world.hpp"
#include "modes/overworld.hpp"
#include "modes/demo_world.hpp"
#include "online/request_manager.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/credits.hpp"
#include "states_screens/grand_prix_editor_screen.hpp"
#include "states_screens/help_screen_1.hpp"
#include "states_screens/offline_kart_selection.hpp"
#include "states_screens/online_screen.hpp"
#include "states_screens/online_profile_overview.hpp"
#include "states_screens/options_screen_video.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/user_screen.hpp"
#if DEBUG_MENU_ITEM
#include "states_screens/feature_unlocked.hpp"
#include "states_screens/grand_prix_lose.hpp"
#include "states_screens/grand_prix_win.hpp"
#endif
#include "states_screens/dialogs/message_dialog.hpp"
#include "tracks/track_manager.hpp"
#include "tracks/track.hpp"
#include "utils/string_utils.hpp"
#include <string>
using namespace GUIEngine;
using namespace Online;
DEFINE_SCREEN_SINGLETON( MainMenuScreen );
bool MainMenuScreen::m_enable_online = false;
// ----------------------------------------------------------------------------
MainMenuScreen::MainMenuScreen() : Screen("main.stkgui")
{
} // MainMenuScreen
// ----------------------------------------------------------------------------
void MainMenuScreen::loadedFromFile()
{
LabelWidget* w = getWidget<LabelWidget>("info_addons");
w->setScrollSpeed(15);
#if DEBUG_MENU_ITEM != 1
RibbonWidget* rw = getWidget<RibbonWidget>("menu_bottomrow");
rw->removeChildNamed("test_gpwin");
rw->removeChildNamed("test_gplose");
rw->removeChildNamed("test_unlocked");
rw->removeChildNamed("test_unlocked2");
#endif
} // loadedFromFile
// ----------------------------------------------------------------------------
//
void MainMenuScreen::init()
{
Screen::init();
// reset in case we're coming back from a race
StateManager::get()->resetActivePlayers();
input_manager->getDeviceList()->setAssignMode(NO_ASSIGN);
input_manager->getDeviceList()->setSinglePlayer( NULL );
input_manager->setMasterPlayerOnly(false);
// Avoid incorrect behaviour in certain race circumstances:
// If a multi-player game is played with two keyboards, the 2nd
// player selects his kart last, and only the keyboard is used
// to select all other settings - then if the next time the kart
// selection screen comes up, the default device will still be
// the 2nd player. So if the first player presses 'select', it
// will instead add a second player (so basically the key
// binding for the second player become the default, so pressing
// select will add a new player). See bug 3090931
// To avoid this, we will clean the last used device, making
// the key bindings for the first player the default again.
input_manager->getDeviceList()->clearLatestUsedDevice();
if (addons_manager->isLoading())
{
IconButtonWidget* w = getWidget<IconButtonWidget>("addons");
w->setDeactivated();
w->resetAllBadges();
w->setBadge(LOADING_BADGE);
}
m_online = getWidget<IconButtonWidget>("online");
if(!m_enable_online)
m_online->setDeactivated();
LabelWidget* w = getWidget<LabelWidget>("info_addons");
const core::stringw &news_text = NewsManager::get()->getNextNewsMessage();
w->setText(news_text, true);
w->update(0.01f);
RibbonWidget* r = getWidget<RibbonWidget>("menu_bottomrow");
// FIXME: why do I need to do this manually
((IconButtonWidget*)r->getChildren().get(0))->unfocused(PLAYER_ID_GAME_MASTER, NULL);
((IconButtonWidget*)r->getChildren().get(1))->unfocused(PLAYER_ID_GAME_MASTER, NULL);
((IconButtonWidget*)r->getChildren().get(2))->unfocused(PLAYER_ID_GAME_MASTER, NULL);
r = getWidget<RibbonWidget>("menu_toprow");
r->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
DemoWorld::resetIdleTime();
#if _IRR_MATERIAL_MAX_TEXTURES_ < 8
getWidget<IconButtonWidget>("logo")->setImage("gui/logo_broken.png",
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
#endif
} // init
// ----------------------------------------------------------------------------
void MainMenuScreen::onUpdate(float delta)
{
if(PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_GUEST ||
PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN)
{
m_online->setActivated();
m_online->setLabel( _("Online"));
}
else if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_OUT)
{
m_online->setActivated();
m_online->setLabel( _("Login" ));
}
else // now must be either logging in or logging out
m_online->setDeactivated();
m_online->setLabel(PlayerManager::getCurrentOnlineId() ? _("Online")
: _("Login" ) );
IconButtonWidget* addons_icon = getWidget<IconButtonWidget>("addons");
if (addons_icon != NULL)
{
if (addons_manager->wasError())
{
addons_icon->setActivated();
addons_icon->resetAllBadges();
addons_icon->setBadge(BAD_BADGE);
}
else if (addons_manager->isLoading() && UserConfigParams::m_internet_status
== Online::RequestManager::IPERM_ALLOWED)
{
// Addons manager is still initialising/downloading.
addons_icon->setDeactivated();
addons_icon->resetAllBadges();
addons_icon->setBadge(LOADING_BADGE);
}
else
{
addons_icon->setActivated();
addons_icon->resetAllBadges();
}
// maybe add a new badge when not allowed to access the net
}
LabelWidget* w = getWidget<LabelWidget>("info_addons");
w->update(delta);
if(w->scrolledOff())
{
const core::stringw &news_text = NewsManager::get()->getNextNewsMessage();
w->setText(news_text, true);
}
} // onUpdate
// ----------------------------------------------------------------------------
void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
// most interesting stuff is in the ribbons, so start there
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return; // what's that event??
// ---- A ribbon icon was clicked
std::string selection =
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
/*
if (selection == "story")
{
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts( 0 );
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("endcutscene", 999, false);
std::vector<std::string> parts;
parts.push_back("introcutscene");
parts.push_back("introcutscene2");
((CutsceneWorld*)World::getWorld())->setParts(parts);
//race_manager->startSingleRace("introcutscene2", 999, false);
return;
}
*/
#if DEBUG_MENU_ITEM
if (selection == "test_gpwin")
{
StoryModeStatus* sms = PlayerManager::getCurrentPlayer()->getStoryModeStatus();
sms->unlockFeature(const_cast<ChallengeStatus*>(sms->getChallengeStatus("gp1")),
RaceManager::DIFFICULTY_HARD);
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts(0);
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("gpwin", 999, false);
GrandPrixWin* scene = GrandPrixWin::getInstance();
scene->push();
const std::string winners[] = { "elephpant", "nolok", "pidgin" };
scene->setKarts(winners);
}
else if (selection == "test_gplose")
{
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts(0);
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("gplose", 999, false);
GrandPrixLose* scene = GrandPrixLose::getInstance();
scene->push();
std::vector<std::string> losers;
losers.push_back("nolok");
losers.push_back("elephpant");
//losers.push_back("wilber");
//losers.push_back("tux");
scene->setKarts(losers);
}
else if (selection == "test_unlocked" || selection == "test_unlocked2")
{
StoryModeStatus* sms = PlayerManager::getCurrentPlayer()->getStoryModeStatus();
sms->unlockFeature(const_cast<ChallengeStatus*>(sms->getChallengeStatus("gp1")),
RaceManager::DIFFICULTY_HARD);
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts(0);
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("featunlocked", 999, false);
FeatureUnlockedCutScene* scene =
FeatureUnlockedCutScene::getInstance();
std::vector<std::string> parts;
parts.push_back("featunlocked");
((CutsceneWorld*)World::getWorld())->setParts(parts);
scene->addTrophy(RaceManager::DIFFICULTY_EASY);
if (selection == "test_unlocked")
{
// the passed kart will not be modified, that's why I allow myself
// to use const_cast
scene->addUnlockedKart(
const_cast<KartProperties*>(
kart_properties_manager->getKart("tux")
),
L"You unlocked <actual text would go here...>"
);
scene->addUnlockedTrack(track_manager->getTrack("lighthouse"));
scene->push();
}
else if (selection == "test_unlocked2")
{
std::vector<video::ITexture*> textures;
textures.push_back(irr_driver->getTexture(
track_manager->getTrack("lighthouse")
->getScreenshotFile().c_str()));
textures.push_back(irr_driver->getTexture(
track_manager->getTrack("startrack")
->getScreenshotFile().c_str()));
textures.push_back(irr_driver->getTexture(
track_manager->getTrack("sandtrack")
->getScreenshotFile().c_str()));
textures.push_back(irr_driver->getTexture(
track_manager->getTrack("snowmountain")
->getScreenshotFile().c_str()));
scene->addUnlockedPictures(textures, 4.0, 3.0, L"You unlocked <actual text would go here...>");
scene->push();
}
}
else
#endif
if (selection == "new")
{
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); //FIXME : that was for tests
s->setMultiplayer(false);
s->setFromOverworld(false);
s->push();
}
else if (selection == "multiplayer")
{
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
s->setMultiplayer(true);
s->setFromOverworld(false);
s->push();
}
else if (selection == "options")
{
OptionsScreenVideo::getInstance()->push();
}
else if (selection == "quit")
{
StateManager::get()->popMenu();
return;
}
else if (selection == "about")
{
StateManager::get()->pushScreen(CreditsScreen::getInstance());
}
else if (selection == "help")
{
StateManager::get()->pushScreen(HelpScreen1::getInstance());
}
else if (selection == "startTutorial")
{
race_manager->setNumLocalPlayers(1);
race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
race_manager->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
race_manager->setNumKarts( 1 );
race_manager->setTrack( "tutorial" );
race_manager->setDifficulty(RaceManager::DIFFICULTY_EASY);
race_manager->setReverseTrack(false);
// Use keyboard 0 by default (FIXME: let player choose?)
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
// Create player and associate player with keyboard
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
device);
if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{
Log::warn("MainMenuScreen", "Cannot find kart '%s', will revert to default",
UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults();
}
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
// ASSIGN should make sure that only input from assigned devices
// is read.
input_manager->getDeviceList()->setAssignMode(ASSIGN);
input_manager->getDeviceList()
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
StateManager::get()->enterGameState();
race_manager->setupPlayerKartInfo();
race_manager->startNew(false);
}
else if (selection == "story")
{
PlayerProfile *player = PlayerManager::getCurrentPlayer();
if (player->isFirstTime())
{
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts( 0 );
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
race_manager->startSingleRace("introcutscene", 999, false);
std::vector<std::string> parts;
parts.push_back("introcutscene");
parts.push_back("introcutscene2");
((CutsceneWorld*)World::getWorld())->setParts(parts);
//race_manager->startSingleRace("introcutscene2", 999, false);
return;
}
else
{
const std::string default_kart = UserConfigParams::m_default_kart;
if (player->isLocked(default_kart))
{
KartSelectionScreen *next = OfflineKartSelectionScreen::getInstance();
next->setGoToOverworldNext();
next->setMultiplayer(false);
StateManager::get()->resetAndGoToScreen(next);
return;
}
OverWorld::enterOverWorld();
}
}
else if (selection == "online")
{
if(UserConfigParams::m_internet_status!=RequestManager::IPERM_ALLOWED)
{
new MessageDialog(_("You can not play online without internet access. "
"If you want to play online, go to options, select "
" tab 'User Interface', and edit "
"\"Allow STK to connect to the Internet\"."));
return;
}
if (PlayerManager::getCurrentOnlineId())
{
// For 0.8.2 disable the server menu, instead go to online profile
// StateManager::get()->pushScreen(OnlineScreen::getInstance());
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
OnlineProfileOverview::getInstance()->push();
}
else
{
UserScreen::getInstance()->push();
}
}
else if (selection == "addons")
{
// Don't go to addons if there is no internet, unless some addons are
// already installed (so that you can delete addons without being online).
if(UserConfigParams::m_internet_status!=RequestManager::IPERM_ALLOWED &&
!addons_manager->anyAddonsInstalled())
{
new MessageDialog(_("You can not download addons without internet access. "
"If you want to download addons, go to options, select "
" tab 'User Interface', and edit "
"\"Allow STK to connect to the Internet\"."));
return;
}
AddonsScreen::getInstance()->push();
}
else if (selection == "gpEditor")
{
GrandPrixEditorScreen::getInstance()->push();
}
} // eventCallback
// ----------------------------------------------------------------------------
void MainMenuScreen::tearDown()
{
} // tearDown
// ----------------------------------------------------------------------------
void MainMenuScreen::onDisabledItemClicked(const std::string& item)
{
if (item == "addons")
{
if (UserConfigParams::m_internet_status != RequestManager::IPERM_ALLOWED)
{
new MessageDialog( _("The add-ons module is currently disabled in "
"the Options screen") );
}
else if (addons_manager->wasError())
{
new MessageDialog( _("Sorry, an error occurred while contacting "
"the add-ons website. Make sure you are "
"connected to the Internet and that "
"SuperTuxKart is not blocked by a firewall"));
}
else if (addons_manager->isLoading())
{
new MessageDialog( _("Please wait while the add-ons are loading"));
}
}
} // onDisabledItemClicked