1 // SuperTuxKart - a fun racing game with go-kart 2 // 3 // Copyright (C) 2006-2015 SuperTuxKart-Team 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 3 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 #ifndef PLAYER_KART_WIDGET_HPP 20 #define PLAYER_KART_WIDGET_HPP 21 22 #include "guiengine/widgets/spinner_widget.hpp" 23 #include "states_screens/state_manager.hpp" 24 #include <IGUIStaticText.h> 25 #include <IGUIImage.h> 26 #include <string> 27 28 29 class KartSelectionScreen; 30 31 namespace GUIEngine 32 { 33 class PlayerNameSpinner; 34 class KartStatsWidget; 35 class ModelViewWidget; 36 class LabelWidget; 37 38 /** A widget representing the kart selection for a player (i.e. the player's 39 * number, name, the kart view, the kart's name) */ 40 class PlayerKartWidget : public GUIEngine::Widget, 41 public GUIEngine::SpinnerWidget::ISpinnerConfirmListener 42 { 43 /** Whether this player confirmed their selection */ 44 bool m_ready; 45 /** If the player is handicapped. */ 46 HandicapLevel m_handicap; 47 48 /** widget coordinates */ 49 int player_name_x, player_name_y, player_name_w, player_name_h; 50 int model_x, model_y, model_w, model_h; 51 int kart_name_x, kart_name_y, kart_name_w, kart_name_h; 52 int m_kart_stats_x, m_kart_stats_y, m_kart_stats_w, m_kart_stats_h; 53 54 /** A reserved ID for this widget if any, -1 otherwise. (If no ID is 55 * reserved, widget will not be in the regular tabbing order */ 56 int m_irrlicht_widget_id; 57 58 /** For animation purposes (see method 'move') */ 59 int target_x, target_y, target_w, target_h; 60 float x_speed, y_speed, w_speed, h_speed; 61 62 /** Object representing this player */ 63 /** Local info about the player. */ 64 StateManager::ActivePlayer* m_associated_player; 65 int m_player_id; 66 67 /** Internal name of the spinner; useful to interpret spinner events, 68 * which contain the name of the activated object */ 69 std::string spinnerID; 70 71 #ifdef DEBUG 72 long m_magic_number; 73 #endif 74 75 public: 76 77 LEAK_CHECK() 78 79 /** Sub-widgets created by this widget */ 80 PlayerNameSpinner* m_player_ident_spinner; 81 KartStatsWidget* m_kart_stats; 82 ModelViewWidget* m_model_view; 83 LabelWidget* m_kart_name; 84 85 KartSelectionScreen* m_parent_screen; 86 87 irr::gui::IGUIStaticText* m_ready_text; 88 89 core::stringw deviceName; 90 std::string m_kart_internal_name; 91 92 bool m_not_updated_yet; 93 94 PlayerKartWidget(KartSelectionScreen* parent, 95 StateManager::ActivePlayer* associated_player, 96 core::recti area, const int player_id, 97 std::string kart_group, 98 const int irrlicht_idget_id=-1); 99 // ------------------------------------------------------------------------ 100 101 ~PlayerKartWidget(); 102 103 // ------------------------------------------------------------------------ 104 /** Called when players are renumbered (changes the player ID) */ 105 void setPlayerID(const int newPlayerID); 106 // ------------------------------------------------------------------------ getPlayerNameSpinner() const107 PlayerNameSpinner* getPlayerNameSpinner() const 108 { return m_player_ident_spinner; } 109 // ------------------------------------------------------------------------ 110 /** Returns the ID of this player */ 111 int getPlayerID() const; 112 113 // ------------------------------------------------------------------------ 114 /** Add the widgets to the current screen */ 115 virtual void add(); 116 117 // ------------------------------------------------------------------------ 118 /** Get the associated ActivePlayer object*/ 119 StateManager::ActivePlayer* getAssociatedPlayer(); 120 121 // ------------------------------------------------------------------------ 122 /** Starts a 'move/resize' animation, by simply passing destination coords. 123 * The animation will then occur on each call to 'onUpdate'. */ 124 void move(const int x, const int y, const int w, const int h); 125 126 // ------------------------------------------------------------------------ 127 /** Call when player confirmed his identity and kart */ 128 void markAsReady(); 129 130 // ------------------------------------------------------------------------ 131 /** \return Whether this player confirmed his kart and indent selection */ 132 bool isReady(); 133 134 // ------------------------------------------------------------------------ 135 /** \return handicap */ 136 HandicapLevel getHandicap(); 137 138 // ------------------------------------------------------------------------- 139 /** Updates the animation (moving/shrinking/etc.) */ 140 void onUpdate(float delta); 141 142 // ------------------------------------------------------------------------- 143 /** Event callback */ 144 virtual GUIEngine::EventPropagation transmitEvent( 145 GUIEngine::Widget* w, 146 const std::string& originator, 147 const int m_player_id); 148 149 // ------------------------------------------------------------------------- 150 /** Sets the size of the widget as a whole, and placed children widgets 151 * inside itself */ 152 void setSize(const int x, const int y, const int w, const int h); 153 154 // ------------------------------------------------------------------------- 155 156 /** Sets which kart was selected for this player */ 157 void setKartInternalName(const std::string& whichKart); 158 159 // ------------------------------------------------------------------------- 160 161 const std::string& getKartInternalName() const; 162 163 // ------------------------------------------------------------------------- 164 165 /** \brief Event callback from ISpinnerConfirmListener */ 166 virtual GUIEngine::EventPropagation onSpinnerConfirmed(); 167 // ------------------------------------------------------------------------- 168 void enableHandicapForNetwork(); 169 }; // PlayerKartWidget 170 } 171 172 #endif 173 174