Very eary first version of a new login screen.

This commit is contained in:
hiker 2014-04-28 07:54:09 +10:00
parent b3291caea2
commit 2f17264f39
3 changed files with 142 additions and 59 deletions

View File

@ -2,25 +2,29 @@
<div x="2%" y="2%" width="96%" height="97%" layout="vertical-row" >
<header text_align="center" width="80%" align="center" text="Select a Player"/>
<spacer height="15" width="10"/>
<header text_align="center" width="80%" align="center" text="Select a Local Player"/>
<spacer height="15" width="10"/>
<box proportion="6" width="75%" align="center" layout="vertical-row" padding="8">
<list id="gameslots" x="0" y="0" width="100%" height="100%"/>
</box>
<scrollable_toolbar id="local" height="175" y="10" x="10" width="98%" align="center" label_location="each"
square_items="true" child_width="160" child_height="120" />
<header text_align="center" width="80%" align="center" text="Select an Online Player"/>
<spacer height="15" width="10"/>
<scrollable_toolbar id="online" height="175" y="10" x="10" width="98%" align="center" label_location="each"
square_items="true" child_width="160" child_height="120" />
<spacer width="20" height="25"/>
<div layout="horizontal-row" align="center" width="70%" height="fit">
<checkbox id="rememberme" />
<label text="Remember me" height="100%"/>
</div>
<spacer width="20" height="15"/>
<button id="creategame" x="20"
I18N="In story mode 'select a game slot' menu"
text="Create a new player" align="center"/>
<buttonbar id="options" width="90%" height="13%" align="bottom">
<icon-button id="ok" width="64" height="64" icon="gui/green_check.png"
I18N="Login dialog" text="OK" label_location="bottom"/>
<icon-button id="ok_and_save" width="64" height="64" icon="gui/main_help.png"
I18N="Login dialog" text="OK and Save" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_help.png"
I18N="Login dialog" text="Cancel" label_location="bottom"/>
</buttonbar>
<spacer width="20" height="15"/>
</div>

View File

@ -38,12 +38,6 @@ void PlayerManager::create()
{
assert(!m_player_manager);
m_player_manager = new PlayerManager();
if(m_player_manager->getNumPlayers() == 0)
{
m_player_manager->addDefaultPlayer();
m_player_manager->save();
}
} // create
// ----------------------------------------------------------------------------
@ -211,9 +205,11 @@ void PlayerManager::load()
m_all_online_ids.clear();
m_current_player = NULL;
for(unsigned int i=0; i<m_player_data->getNumNodes(); i++)
std::vector<XMLNode*> player_list;
m_player_data->getNodes("player", player_list);
for(unsigned int i=0; i<player_list.size(); i++)
{
const XMLNode *player_xml = m_player_data->getNode(i);
const XMLNode *player_xml = player_list[i];
PlayerProfile *player = new Online::OnlinePlayerProfile(player_xml);
m_all_players.push_back(player);
if(player->isDefault())
@ -231,6 +227,11 @@ void PlayerManager::load()
*/
void PlayerManager::initRemainingData()
{
// Filter the player nodes out (there is one additional node 'online-ids'
// which makes this necessary), otherwise the index of m_all_players
// is not identical with the index in the xml file.
std::vector<XMLNode*> player_nodes;
m_player_data->getNodes("player", player_nodes);
for (unsigned int i = 0; i<m_all_players.size(); i++)
{
// On the first time STK is run, there is no player data,
@ -239,7 +240,7 @@ void PlayerManager::initRemainingData()
if (!m_player_data)
m_all_players[i].initRemainingData();
else // not a first time start, load remaining data
m_all_players[i].loadRemainingData(m_player_data->getNode(i));
m_all_players[i].loadRemainingData(player_nodes[i]);
}
delete m_player_data;

View File

@ -19,8 +19,8 @@
#include "challenges/unlock_manager.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/main_menu_screen.hpp"
@ -48,33 +48,67 @@ void StoryModeLobbyScreen::loadedFromFile()
void StoryModeLobbyScreen::init()
{
Screen::init();
PlayerProfile *player = PlayerManager::getCurrentPlayer();
if (player)
{
//StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
//return;
}
CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
cb->setState(false);
//CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
//cb->setState(false);
ListWidget* list = getWidget<ListWidget>("gameslots");
list->clear();
PlayerProfile *player = PlayerManager::getCurrentPlayer();
if(player)
//PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
#if 0
if (UserConfigParams::m_default_player.toString().size() > 0)
{
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
for (unsigned int n=0; n<players.size(); n++)
{
if (players[n].getName() == UserConfigParams::m_default_player.toString())
{
unlock_manager->setCurrentSlot(players[n].getUniqueID());
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
}
}.
#endif
DynamicRibbonWidget* local = getWidget<DynamicRibbonWidget>("local");
assert( local != NULL );
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
const PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player->isGuestAccount()) continue;
// FIXME: we're using a trunacted ascii version of the player name as
// identifier, let's hope this causes no issues...
list->addItem(core::stringc(player->getName().c_str()).c_str(),
player->getName() );
std::string s = StringUtils::toString(n);
local->addItem(player->getName(), s, "", 0, IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
}
list->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
list->setSelectionID(0);
local->addItem("Create new user", "local_new",
"karts/sara/icon-sara.png", 0,
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
local->updateItemDisplay();
DynamicRibbonWidget* online = this->getWidget<DynamicRibbonWidget>("online");
assert( online != NULL );
const std::vector<core::stringw> &online_ids =
PlayerManager::get()->getAllOnlineIds();
for (unsigned int i = 0; i < online_ids.size(); i++)
{
std::string s = StringUtils::toString(i);
online->addItem(online_ids[i], s, "karts/nolok/nolokicon.png", 0,
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
}
online->addItem("Create new online user", "online_new",
"karts/sara/icon-sara.png", 0,
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
online->updateItemDisplay();
} // init
@ -91,6 +125,35 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
const std::string& name,
const int player_id)
{
if (name == "local")
{
// FIXME nothing to do
}
else if (name == "options")
{
const std::string &button =
getWidget<RibbonWidget>("options")->getSelectionIDString(player_id);
if (button == "ok" || button == "ok_and_save")
{
DynamicRibbonWidget *local = getWidget<DynamicRibbonWidget>("local");
const std::string &name = local->getSelectionIDString(player_id);
if (name == "local_new")
{
// create new local player
return;
}
unsigned int id;
StringUtils::fromString(name, id);
PlayerProfile *profile = PlayerManager::get()->getPlayer(id);
PlayerManager::get()->setCurrentPlayer(profile, button=="ok_and_save");
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
return;
} // button==ok || ok_and_save
} // options
return;
if (name == "back")
{
StateManager::get()->escapePressed();
@ -103,27 +166,35 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
{
ListWidget* list = getWidget<ListWidget>("gameslots");
PlayerProfile *player = PlayerManager::get()
->getPlayer(list->getSelectionLabel());
if(player)
bool slot_found = false;
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
player->computeActive();
CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
PlayerManager::get()->setCurrentPlayer(player,cb->getState());
PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (list->getSelectionLabel() == player->getName())
{
PlayerManager::get()->setCurrentPlayer(player, false);
slot_found = true;
break;
}
}
else
if (!slot_found)
{
Log::error("StoryModeLobby",
"Cannot find player corresponding to slot '%s'.",
core::stringc(list->getSelectionLabel().c_str()).c_str());
}
else
{
// CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
// if (cb->getState())
{
// UserConfigParams::m_default_player = list->getSelectionLabel();
}
}
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
// Since only now the current player is defined, we have to request
// a login (if an online login was saved). If the current player was
// saved, this request will be started much earlier in the startup
// sequence from the RequestManager.
PlayerManager::resumeSavedSession();
}
} // eventCallback
@ -135,19 +206,26 @@ void StoryModeLobbyScreen::unloaded()
// ----------------------------------------------------------------------------
void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name)
void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& newName)
{
PlayerProfile *player = PlayerManager::get()->getPlayer(new_name);
if(player)
bool slot_found = false;
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
PlayerManager::get()->setCurrentPlayer(player,false);
player->computeActive();
PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player->getName() == newName)
{
PlayerManager::get()->setCurrentPlayer(player, false);
slot_found = true;
break;
}
}
else
if (!slot_found)
{
Log::error("StoryModeLobbyScreen",
"Cannot find player corresponding to slot '%s'.",
core::stringc(new_name.c_str()).c_str());
core::stringc(newName.c_str()).c_str());
}
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());