Removed old player management screen.

This commit is contained in:
hiker
2014-05-16 08:50:10 +10:00
parent 1102702f5b
commit 629ecc8ecb
6 changed files with 2 additions and 667 deletions

View File

@@ -24,7 +24,6 @@
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/options_screen_players.hpp"
#include "states_screens/options_screen_input.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/cpp2011.h"

View File

@@ -1,312 +0,0 @@
// 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.
#include "states_screens/dialogs/player_info_dialog.hpp"
#include <IGUIStaticText.h>
#include <IGUIEnvironment.h>
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player_manager.hpp"
#include "config/player_profile.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "states_screens/options_screen_players.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
using namespace irr::gui;
using namespace irr::core;
// -----------------------------------------------------------------------------
/** Creates a modal dialog with given percentage of screen width and height.
*/
PlayerInfoDialog::PlayerInfoDialog(PlayerProfile* player, const float w,
const float h)
: ModalDialog(w, h)
{
m_player = player;
doInit();
showRegularDialog();
} // PlayerInfoDialog
// -----------------------------------------------------------------------------
/** When the dialog is finished, select the just edited player again in the
* option screen.
*/
PlayerInfoDialog::~PlayerInfoDialog()
{
if (m_player != NULL)
{
OptionsScreenPlayers::getInstance()->selectPlayer(
translations->fribidize(m_player->getName()) );
}
} // ~PlayerInfoDialog
// -----------------------------------------------------------------------------
/** Show the current data of this player.
*/
void PlayerInfoDialog::showRegularDialog()
{
if (m_irrlicht_window)
clearWindow();
const int y1 = m_area.getHeight()/6;
const int y2 = m_area.getHeight()*2/6;
const int y3 = m_area.getHeight()*3/6;
const int y4 = m_area.getHeight()*5/6;
ScalableFont* font = GUIEngine::getFont();
const int textHeight = GUIEngine::getFontHeight();
const int buttonHeight = textHeight + 10;
{
textCtrl = new TextBoxWidget();
textCtrl->m_properties[PROP_ID] = "newname";
textCtrl->setText(m_player->getName());
textCtrl->m_x = 50;
textCtrl->m_y = y1 - textHeight/2;
textCtrl->m_w = m_area.getWidth()-100;
textCtrl->m_h = textHeight + 5;
textCtrl->setParent(m_irrlicht_window);
m_widgets.push_back(textCtrl);
textCtrl->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "renameplayer";
//I18N: In the player info dialog
widget->setText( _("Rename") );
const int textWidth =
font->getDimension( widget->getText().c_str() ).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y2;
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_widgets.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "cancel";
widget->setText( _("Cancel") );
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y3;
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_widgets.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "removeplayer";
//I18N: In the player info dialog
widget->setText( _("Remove"));
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y4;
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_widgets.push_back(widget);
widget->add();
}
textCtrl->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
} // showRegularDialog
// -----------------------------------------------------------------------------
/** Changes this dialog to confirm the changes.
*/
void PlayerInfoDialog::showConfirmDialog()
{
clearWindow();
IGUIFont* font = GUIEngine::getFont();
const int textHeight = GUIEngine::getFontHeight();
const int buttonHeight = textHeight + 10;
irr::core::stringw message =
//I18N: In the player info dialog (when deleting)
_("Do you really want to delete player '%s' ?", m_player->getName());
if (PlayerManager::getCurrentPlayer() == m_player)
{
message = _("You cannot delete this player "
"because it is currently in use.");
}
core::rect< s32 > area_left(5, 0, m_area.getWidth()-5, m_area.getHeight()/2);
// When there is no need to tab through / click on images/labels,
// we can add irrlicht labels directly
// (more complicated uses require the use of our widget set)
IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( message.c_str(),
area_left, false /* border */,
true /* word wrap */,
m_irrlicht_window);
a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
if (PlayerManager::getCurrentPlayer() != m_player)
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "confirmremove";
//I18N: In the player info dialog (when deleting)
widget->setText( _("Confirm Remove") );
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = m_area.getHeight()/2;
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_widgets.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "cancelremove";
//I18N: In the player info dialog (when deleting)
widget->setText( _("Cancel Remove") );
const int textWidth =
font->getDimension( widget->getText().c_str() ).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = m_area.getHeight()*3/4;
widget->m_w = textWidth;
widget->m_h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_widgets.push_back(widget);
widget->add();
widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
}
} // showConfirmDialog
// -----------------------------------------------------------------------------
void PlayerInfoDialog::onEnterPressedInternal()
{
} // onEnterPressedInternal
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation
PlayerInfoDialog::processEvent(const std::string& eventSource)
{
if (eventSource == "renameplayer")
{
// accept entered name
stringw player_name = textCtrl->getText().trim();
const int player_amount = PlayerManager::get()->getNumPlayers();
for(int n=0; n<player_amount; n++)
{
const PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player == m_player) continue;
if (player->getName() == player_name)
{
ButtonWidget* label = getWidget<ButtonWidget>("renameplayer");
label->setBadge(BAD_BADGE);
sfx_manager->quickSound( "anvil" );
return GUIEngine::EVENT_BLOCK;
}
}
if (player_name.size() <= 0) return GUIEngine::EVENT_BLOCK;
OptionsScreenPlayers::getInstance()->renamePlayer(player_name,m_player);
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
dismiss();
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "removeplayer")
{
showConfirmDialog();
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "confirmremove")
{
OptionsScreenPlayers::getInstance()->deletePlayer( m_player );
m_player = NULL;
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
return GUIEngine::EVENT_BLOCK;
}
else if(eventSource == "cancelremove")
{
showRegularDialog();
return GUIEngine::EVENT_BLOCK;
}
else if(eventSource == "cancel")
{
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
return GUIEngine::EVENT_BLOCK;
}
return GUIEngine::EVENT_LET;
} // processEvent
// -----------------------------------------------------------------------------

View File

@@ -1,53 +0,0 @@
// 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.
#ifndef HEADER_PLAYERINFO_DIALOG_HPP
#define HEADER_PLAYERINFO_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
class PlayerProfile;
namespace GUIEngine
{
class TextBoxWidget;
}
/**
* \brief Dialog that allows renaming and deleting players
* \ingroup states_screens
*/
class PlayerInfoDialog : public GUIEngine::ModalDialog
{
GUIEngine::TextBoxWidget* textCtrl;
PlayerProfile* m_player;
void showRegularDialog();
void showConfirmDialog();
public:
PlayerInfoDialog(PlayerProfile* PlayerInfoDialog,
const float percentWidth, const float percentHeight);
virtual ~PlayerInfoDialog();
void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
};
#endif

View File

@@ -32,10 +32,10 @@
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/options_screen_audio.hpp"
#include "states_screens/options_screen_input.hpp"
#include "states_screens/options_screen_players.hpp"
#include "states_screens/options_screen_video.hpp"
#include "states_screens/options_screen_ui.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/user_screen.hpp"
#include "utils/translation.hpp"
#include <iostream>
@@ -442,7 +442,7 @@ void OptionsScreenInput2::eventCallback(Widget* widget,
else if (selection == "tab_video")
sm->replaceTopMostScreen(OptionsScreenVideo::getInstance());
else if (selection == "tab_players")
sm->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
sm->replaceTopMostScreen(UserScreen::getInstance());
else if (selection == "tab_ui")
sm->replaceTopMostScreen(OptionsScreenUI::getInstance());
else if (selection == "tab_controls") {}

View File

@@ -1,228 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-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.
#include "states_screens/options_screen_players.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/device_config.hpp"
#include "config/player_manager.hpp"
#include "config/player_profile.hpp"
#include "config/user_config.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "states_screens/options_screen_audio.hpp"
#include "states_screens/options_screen_input.hpp"
#include "states_screens/options_screen_video.hpp"
#include "states_screens/options_screen_ui.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/user_screen.hpp"
#include <IGUIButton.h>
#include <iostream>
#include <sstream>
using namespace GUIEngine;
using namespace irr::core;
using namespace irr::gui;
DEFINE_SCREEN_SINGLETON( OptionsScreenPlayers );
// -----------------------------------------------------------------------------
OptionsScreenPlayers::OptionsScreenPlayers() : Screen("options_players.stkgui")
{
} // OptionsScreenPlayers
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::loadedFromFile()
{
} // loadedFromFile
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::init()
{
Screen::init();
RibbonWidget* tabBar = this->getWidget<RibbonWidget>("options_choice");
if (tabBar != NULL) tabBar->select( "tab_players", PLAYER_ID_GAME_MASTER );
tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") );
tabBar->getRibbonChildren()[1].setTooltip( _("Audio") );
tabBar->getRibbonChildren()[2].setTooltip( _("User Interface") );
tabBar->getRibbonChildren()[4].setTooltip( _("Controls") );
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
refreshPlayerList();
ButtonWidget* you = getWidget<ButtonWidget>("playername");
unsigned int playerID = PlayerManager::getCurrentPlayer()->getUniqueID();
core::stringw player_name = L"-";
const PlayerProfile* curr = PlayerManager::get()->getPlayerById(playerID);
if(curr)
player_name = curr->getName();
you->setText( player_name );
((gui::IGUIButton*)you->getIrrlichtElement())->setOverrideFont( GUIEngine::getSmallFont() );
if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
{
players->setDeactivated();
you->setDeactivated();
}
else
{
players->setActivated();
you->setActivated();
}
} // init
// -----------------------------------------------------------------------------
bool OptionsScreenPlayers::renamePlayer(const stringw& newName, PlayerProfile* player)
{
player->setName( newName );
refreshPlayerList();
return true;
} // renamePlayer
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::onNewPlayerWithName(const stringw& newName)
{
ListWidget* players = this->getWidget<ListWidget>("players");
if (players != NULL)
{
core::stringc newNameC(newName.c_str());
players->addItem( newNameC.c_str(), translations->fribidize(newName) );
}
}
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::deletePlayer(PlayerProfile* player)
{
PlayerManager::get()->deletePlayer(player);
refreshPlayerList();
} // deletePlayer
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::tearDown()
{
Screen::tearDown();
user_config->saveConfig();
} // tearDown
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name, const int playerID)
{
if (name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str();
if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance());
else if (selection == "tab_video") StateManager::get()->replaceTopMostScreen(OptionsScreenVideo::getInstance());
else if (selection == "tab_players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
else if (selection == "tab_controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
else if (selection == "tab_ui") StateManager::get()->replaceTopMostScreen(OptionsScreenUI::getInstance());
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
else if (name == "addplayer")
{
new EnterPlayerNameDialog(this, 0.5f, 0.4f);
}
else if (name == "players")
{
// Find which player in the list was clicked
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
core::stringw selectedPlayer = players->getSelectionLabel();
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int i=0; i<player_amount; i++)
{
PlayerProfile *player = PlayerManager::get()->getPlayer(i);
if (selectedPlayer == translations->fribidize(player->getName()))
{
if (!(player->isGuestAccount()))
{
new PlayerInfoDialog( player, 0.5f, 0.6f );
}
return;
}
} // end for
}
else if (name == "playername")
{
race_manager->clearKartLastPositionOnOverworld();
PlayerManager::get()->setCurrentPlayer(NULL);
StateManager::get()->pushScreen(UserScreen::getInstance());
}
} // eventCallback
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::selectPlayer(const irr::core::stringw& name)
{
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
players->selectItemWithLabel(name);
players->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
// ----------------------------------------------------------------------------
/** Refreshes the list of players.
*/
bool OptionsScreenPlayers::refreshPlayerList()
{
ListWidget* players = this->getWidget<ListWidget>("players");
if (players == NULL) return false;
// Get rid of previous
players->clear();
// Rebuild it
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int i = 0; i < player_amount; i++)
{
// FIXME: Using a truncated ASCII string for internal ID. Let's cross
// our fingers and hope no one enters two player names that,
// when stripped down to ASCII, give the same identifier...
const PlayerProfile *player = PlayerManager::get()->getPlayer(i);
players->addItem(
core::stringc(player->getName().c_str()).c_str(),
translations->fribidize(player->getName()));
}
return true;
}

View File

@@ -1,71 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-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.
#ifndef __HEADER_OPTIONS_SCREEN_PLAYERS_HPP__
#define __HEADER_OPTIONS_SCREEN_PLAYERS_HPP__
#include <string>
#include <irrString.h>
#include "guiengine/screen.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
namespace GUIEngine { class Widget; }
struct Input;
class PlayerProfile;
/**
* \brief Player management options screen
* \ingroup states_screens
*/
class OptionsScreenPlayers : public GUIEngine::Screen, public EnterPlayerNameDialog::INewPlayerListener,
public GUIEngine::ScreenSingleton<OptionsScreenPlayers>
{
private:
OptionsScreenPlayers();
bool refreshPlayerList();
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenPlayers>;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
const int playerID) OVERRIDE;
/**
* \brief Adds a new player (if 'player' is NULL) or renames an existing player (if 'player' is not NULL)
* \return whether adding was successful (can fail e.g. if trying to add a duplicate)
*/
bool renamePlayer(const irr::core::stringw& newName, PlayerProfile* player=NULL);
void deletePlayer(PlayerProfile* player);
void selectPlayer(const irr::core::stringw& name);
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void init() OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void tearDown() OVERRIDE;
/** \brief implement callback from EnterPlayerNameDialog::INewPlayerListener */
virtual void onNewPlayerWithName(const irr::core::stringw& newName);
};
#endif