2009-07-04 13:24:09 -04:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2013-12-01 23:27:55 -05:00
|
|
|
//
|
|
|
|
// Copyright (C) 2006-2013 SuperTuxKart-Team
|
2009-07-04 13:24:09 -04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2013-07-31 14:03:11 -04:00
|
|
|
#ifndef KART_SELECTION_INCLUDED
|
|
|
|
#define KART_SELECTION_INCLUDED
|
|
|
|
|
2009-07-04 13:24:09 -04:00
|
|
|
#include <string>
|
2009-10-04 19:59:05 -04:00
|
|
|
#include "guiengine/screen.hpp"
|
2013-07-31 14:03:11 -04:00
|
|
|
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
|
|
|
#include "guiengine/widgets/label_widget.hpp"
|
|
|
|
#include "guiengine/widgets/model_view_widget.hpp"
|
|
|
|
#include "guiengine/widgets/spinner_widget.hpp"
|
2010-02-18 16:28:32 -05:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2013-07-31 14:03:11 -04:00
|
|
|
#include <IGUIImage.h>
|
2009-07-04 13:24:09 -04:00
|
|
|
|
|
|
|
namespace GUIEngine
|
|
|
|
{
|
|
|
|
class Widget;
|
2011-01-23 16:40:19 -05:00
|
|
|
class BubbleWidget;
|
2013-07-31 14:03:11 -04:00
|
|
|
enum EventPropagation;
|
2009-07-04 13:24:09 -04:00
|
|
|
}
|
2013-08-01 15:49:57 -04:00
|
|
|
namespace Online
|
|
|
|
{
|
|
|
|
class User;
|
|
|
|
}
|
2009-07-04 16:00:18 -04:00
|
|
|
class InputDevice;
|
2009-10-29 20:51:58 -04:00
|
|
|
class PlayerKartWidget;
|
|
|
|
class KartHoverListener;
|
2009-07-04 13:24:09 -04:00
|
|
|
|
2010-04-23 16:48:56 -04:00
|
|
|
/**
|
|
|
|
* \brief screen where players can choose their kart
|
|
|
|
* \ingroup states_screens
|
|
|
|
*/
|
2013-07-31 14:03:11 -04:00
|
|
|
class KartSelectionScreen : public GUIEngine::Screen
|
2009-07-04 13:24:09 -04:00
|
|
|
{
|
2009-10-29 20:51:58 -04:00
|
|
|
friend class KartHoverListener;
|
|
|
|
friend class PlayerNameSpinner;
|
2009-10-30 20:32:18 -04:00
|
|
|
friend class FocusDispatcher;
|
2013-07-31 14:03:11 -04:00
|
|
|
protected:
|
2013-05-30 15:47:39 -04:00
|
|
|
/** Contains the custom widget shown for every player. (ref only since
|
|
|
|
* we're adding them to a Screen, and the Screen will take ownership
|
2011-09-29 21:10:23 -04:00
|
|
|
* of these widgets)
|
|
|
|
*/
|
2011-02-03 17:20:53 -05:00
|
|
|
PtrVector<PlayerKartWidget, REF> m_kart_widgets;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2009-10-04 19:59:05 -04:00
|
|
|
friend class GUIEngine::ScreenSingleton<KartSelectionScreen>;
|
2010-09-25 14:34:04 -04:00
|
|
|
friend class PlayerKartWidget;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-01-23 16:40:19 -05:00
|
|
|
bool m_multiplayer;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-02-05 14:32:17 -05:00
|
|
|
/** Whether this screen is being visited from overworld or not */
|
|
|
|
bool m_from_overworld;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-11-14 19:09:36 -05:00
|
|
|
bool m_go_to_overworld_next;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2013-07-31 14:03:11 -04:00
|
|
|
bool m_must_delete_on_back; //!< To delete the screen if back is pressed
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2013-09-15 05:45:22 -04:00
|
|
|
KartSelectionScreen(const char* filename);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
/** Stores whether any player confirmed their choice; then, some things
|
2011-09-29 21:10:23 -04:00
|
|
|
* are "frozen", for instance the selected kart group tab
|
2010-03-02 19:48:31 -05:00
|
|
|
*/
|
2011-08-27 21:13:58 -04:00
|
|
|
bool m_game_master_confirmed;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-06-24 14:28:20 -04:00
|
|
|
PlayerKartWidget* m_removed_widget;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-01-23 16:40:19 -05:00
|
|
|
/** Message shown in multiplayer mode */
|
|
|
|
GUIEngine::BubbleWidget* m_multiplayer_message;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2009-10-28 19:04:38 -04:00
|
|
|
/** Called when all players selected their kart */
|
|
|
|
void allPlayersDone();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
/** Called when number/order of karts changed, so that all will keep
|
2011-09-29 21:10:23 -04:00
|
|
|
* an up-to-date ID */
|
2009-10-28 19:04:38 -04:00
|
|
|
void renumberKarts();
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** Checks identities chosen by players, making sure no duplicates are
|
2011-09-29 21:10:23 -04:00
|
|
|
* used.
|
2010-03-02 19:48:31 -05:00
|
|
|
* \return Whether all choices are ok
|
|
|
|
*/
|
2009-10-29 14:30:29 -04:00
|
|
|
bool validateIdentChoices();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-01-04 13:59:07 -05:00
|
|
|
/** Checks karts chosen by players, making sure no duplicates are used.
|
2010-03-02 19:48:31 -05:00
|
|
|
* \return Whether all choices are ok
|
|
|
|
*/
|
2010-01-04 13:59:07 -05:00
|
|
|
bool validateKartChoices();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-03-03 14:40:49 -05:00
|
|
|
/** Fill the ribbon with the karts from the currently selected group */
|
|
|
|
void setKartsFromCurrentGroup();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2013-08-01 07:51:23 -04:00
|
|
|
virtual void playerConfirm(const int playerID);
|
2013-08-06 15:10:33 -04:00
|
|
|
/** updates model of a kart widget, to have the good selection when the user validates */
|
|
|
|
void updateKartWidgetModel(uint8_t widget_id,
|
|
|
|
const std::string& selection,
|
|
|
|
const irr::core::stringw& selectionText);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2013-07-31 14:03:11 -04:00
|
|
|
/** Stores a pointer to the current selection screen */
|
|
|
|
static KartSelectionScreen* m_instance_ptr;
|
2009-10-04 19:59:05 -04:00
|
|
|
public:
|
2013-07-31 14:03:11 -04:00
|
|
|
/** Returns the current instance */
|
|
|
|
static KartSelectionScreen* getRunningInstance();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-05-01 15:16:38 -04:00
|
|
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void loadedFromFile() OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-01-23 16:40:19 -05:00
|
|
|
void setMultiplayer(bool multiplayer);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-02-05 14:32:17 -05:00
|
|
|
/** \brief Set whether this screen is being visited from overworld or not */
|
|
|
|
void setFromOverworld(bool from_overworld) { m_from_overworld = from_overworld; }
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-11-14 19:09:36 -05:00
|
|
|
void setGoToOverworldNext() { m_go_to_overworld_next = true; }
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
/** \brief Called when a player hits 'fire'/'select' on his device to
|
2011-09-29 21:10:23 -04:00
|
|
|
* join the game */
|
2009-08-26 16:05:51 -04:00
|
|
|
bool playerJoin(InputDevice* device, bool firstPlayer);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-09-25 14:34:04 -04:00
|
|
|
/**
|
2013-05-30 15:47:39 -04:00
|
|
|
* \brief Called when a player hits 'rescue'/'cancel' on his device
|
2011-09-29 21:10:23 -04:00
|
|
|
* to leave the game
|
2010-09-25 14:34:04 -04:00
|
|
|
* \return true if event was handled succesfully
|
|
|
|
*/
|
2010-02-18 16:28:32 -05:00
|
|
|
bool playerQuit(StateManager::ActivePlayer* player);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-05-01 15:16:38 -04:00
|
|
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void init() OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void beforeAddingWidget() OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-05-01 15:16:38 -04:00
|
|
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void tearDown() OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-05-01 15:16:38 -04:00
|
|
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
|
|
|
|
const int playerID) OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-05-01 15:16:38 -04:00
|
|
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE;
|
2010-06-26 13:19:12 -04:00
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** \brief implement optional callback from parent
|
2011-09-29 21:10:23 -04:00
|
|
|
* class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual void unloaded() OVERRIDE;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
/** \brief implement optional callback from parent
|
2012-02-05 14:32:17 -05:00
|
|
|
* class GUIEngine::Screen */
|
2012-05-13 20:04:26 -04:00
|
|
|
virtual bool onEscapePressed() OVERRIDE;
|
2012-12-06 05:58:04 -05:00
|
|
|
|
2012-12-06 18:43:09 -05:00
|
|
|
}; // KartSelectionScreen
|
2013-07-31 14:03:11 -04:00
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------
|
|
|
|
//! FocusDispatcher :
|
|
|
|
/** Currently, navigation for multiple players at the same time is implemented
|
|
|
|
in a somewhat clunky way. An invisible "dispatcher" widget is added above
|
|
|
|
kart icons. When a player moves up, he focuses the dispatcher, which in
|
|
|
|
turn moves the selection to the appropriate spinner. "tabbing roots" are
|
|
|
|
used to make navigation back down possible. (FIXME: maybe find a cleaner
|
|
|
|
way?) */
|
|
|
|
class FocusDispatcher : public GUIEngine::Widget
|
|
|
|
{
|
|
|
|
KartSelectionScreen* m_parent;
|
|
|
|
int m_reserved_id;
|
|
|
|
|
|
|
|
bool m_is_initialised;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
LEAK_CHECK()
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
FocusDispatcher(KartSelectionScreen* parent);
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
void setRootID(const int reservedID);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
virtual void add();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
virtual GUIEngine::EventPropagation focused(const int playerID);
|
|
|
|
}; // FocusDispatcher
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------
|
|
|
|
//! PlayerNameSpinner :
|
|
|
|
/** A small extension to the spinner widget to add features like player ID
|
|
|
|
* management or badging */
|
|
|
|
class PlayerNameSpinner : public GUIEngine::SpinnerWidget
|
|
|
|
{
|
|
|
|
int m_playerID;
|
|
|
|
bool m_incorrect;
|
|
|
|
irr::gui::IGUIImage* m_red_mark_widget;
|
|
|
|
KartSelectionScreen* m_parent;
|
|
|
|
|
|
|
|
//virtual EventPropagation focused(const int m_playerID) ;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PlayerNameSpinner(KartSelectionScreen* parent, const int playerID);
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
void setID(const int m_playerID);
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Add a red mark on the spinner to mean "invalid choice" */
|
|
|
|
void markAsIncorrect();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Remove any red mark set with 'markAsIncorrect' */
|
|
|
|
void markAsCorrect();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A widget representing the kart selection for a player (i.e. the player's
|
|
|
|
* number, name, the kart view, the kart's name) */
|
|
|
|
class PlayerKartWidget : public GUIEngine::Widget,
|
|
|
|
public GUIEngine::SpinnerWidget::ISpinnerConfirmListener
|
|
|
|
{
|
|
|
|
/** Whether this player confirmed their selection */
|
|
|
|
bool m_ready;
|
|
|
|
|
|
|
|
/** widget coordinates */
|
|
|
|
int player_id_x, player_id_y, player_id_w, player_id_h;
|
|
|
|
int player_name_x, player_name_y, player_name_w, player_name_h;
|
|
|
|
int model_x, model_y, model_w, model_h;
|
|
|
|
int kart_name_x, kart_name_y, kart_name_w, kart_name_h;
|
|
|
|
|
|
|
|
/** A reserved ID for this widget if any, -1 otherwise. (If no ID is
|
|
|
|
* reserved, widget will not be in the regular tabbing order */
|
|
|
|
int m_irrlicht_widget_ID;
|
|
|
|
|
|
|
|
/** For animation purposes (see method 'move') */
|
|
|
|
int target_x, target_y, target_w, target_h;
|
|
|
|
float x_speed, y_speed, w_speed, h_speed;
|
|
|
|
|
|
|
|
/** Object representing this player */
|
2013-08-01 15:49:57 -04:00
|
|
|
StateManager::ActivePlayer* m_associatedPlayer; // local info
|
2013-07-31 14:03:11 -04:00
|
|
|
int m_playerID;
|
2013-08-26 21:02:41 -04:00
|
|
|
Online::Profile* m_associated_user; // network info
|
2013-07-31 14:03:11 -04:00
|
|
|
|
|
|
|
/** Internal name of the spinner; useful to interpret spinner events,
|
|
|
|
* which contain the name of the activated object */
|
|
|
|
std::string spinnerID;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
long m_magic_number;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
LEAK_CHECK()
|
|
|
|
|
|
|
|
/** Sub-widgets created by this widget */
|
|
|
|
//LabelWidget* m_player_ID_label;
|
|
|
|
PlayerNameSpinner* m_player_ident_spinner;
|
|
|
|
GUIEngine::ModelViewWidget* m_model_view;
|
|
|
|
GUIEngine::LabelWidget* m_kart_name;
|
|
|
|
|
|
|
|
KartSelectionScreen* m_parent_screen;
|
|
|
|
|
|
|
|
irr::gui::IGUIStaticText* m_ready_text;
|
|
|
|
|
|
|
|
//LabelWidget *getPlayerIDLabel() {return m_player_ID_label;}
|
|
|
|
core::stringw deviceName;
|
|
|
|
std::string m_kartInternalName;
|
|
|
|
|
|
|
|
bool m_not_updated_yet;
|
|
|
|
|
|
|
|
PlayerKartWidget(KartSelectionScreen* parent,
|
|
|
|
StateManager::ActivePlayer* associatedPlayer,
|
2013-08-26 21:02:41 -04:00
|
|
|
Online::Profile* associatedUser,
|
2013-07-31 14:03:11 -04:00
|
|
|
core::recti area, const int playerID,
|
|
|
|
std::string kartGroup,
|
|
|
|
const int irrlichtWidgetID=-1);
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
~PlayerKartWidget();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Called when players are renumbered (changes the player ID) */
|
|
|
|
void setPlayerID(const int newPlayerID);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the ID of this player */
|
|
|
|
int getPlayerID() const;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Add the widgets to the current screen */
|
|
|
|
virtual void add();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Get the associated ActivePlayer object*/
|
|
|
|
StateManager::ActivePlayer* getAssociatedPlayer();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Starts a 'move/resize' animation, by simply passing destination coords.
|
|
|
|
* The animation will then occur on each call to 'onUpdate'. */
|
|
|
|
void move(const int x, const int y, const int w, const int h);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Call when player confirmed his identity and kart */
|
|
|
|
void markAsReady();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** \return Whether this player confirmed his kart and indent selection */
|
|
|
|
bool isReady();
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
/** Updates the animation (moving/shrinking/etc.) */
|
|
|
|
void onUpdate(float delta);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
/** Event callback */
|
|
|
|
virtual GUIEngine::EventPropagation transmitEvent(
|
|
|
|
GUIEngine::Widget* w,
|
|
|
|
const std::string& originator,
|
|
|
|
const int m_playerID);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
/** Sets the size of the widget as a whole, and placed children widgets
|
|
|
|
* inside itself */
|
|
|
|
void setSize(const int x, const int y, const int w, const int h);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** Sets which kart was selected for this player */
|
|
|
|
void setKartInternalName(const std::string& whichKart);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const std::string& getKartInternalName() const;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** \brief Event callback from ISpinnerConfirmListener */
|
|
|
|
virtual GUIEngine::EventPropagation onSpinnerConfirmed();
|
|
|
|
}; // PlayerKartWidget
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------
|
|
|
|
//! KartHoverListener :
|
|
|
|
|
|
|
|
class KartHoverListener : public GUIEngine::DynamicRibbonHoverListener
|
|
|
|
{
|
|
|
|
KartSelectionScreen* m_parent;
|
|
|
|
public:
|
|
|
|
unsigned int m_magic_number;
|
|
|
|
|
|
|
|
KartHoverListener(KartSelectionScreen* parent);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
virtual ~KartHoverListener();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
void onSelectionChanged(GUIEngine::DynamicRibbonWidget* theWidget,
|
|
|
|
const std::string& selectionID,
|
|
|
|
const irr::core::stringw& selectionText,
|
|
|
|
const int playerID);
|
|
|
|
}; // KartHoverListener
|
|
|
|
|
|
|
|
#endif
|