SuperTuxKart
tracks_screen.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2009-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef HEADER_TRACKS_SCREEN_HPP
19 #define HEADER_TRACKS_SCREEN_HPP
20 
21 #include "guiengine/screen.hpp"
22 
23 #include <deque>
24 #include <limits>
25 #include <string>
26 #include <vector>
27 
28 class PeerVote;
29 class Track;
30 
31 namespace GUIEngine
32 {
33  class CheckBoxWidget;
34  class CheckBoxWidget;
35  class ListWidget;
36  class SpinnerWidget;
37  class ProgressBarWidget;
38 }
39 
40 namespace irr
41 {
42  namespace gui
43  {
44  class STKModifiedSpriteBank;
45  }
46 }
47 
53  public GUIEngine::ScreenSingleton<TracksScreen>
54 {
56 
57 private:
58 
59  Track* m_selected_track = NULL;
60  GUIEngine::CheckBoxWidget* m_reversed;
62  GUIEngine::ListWidget* m_vote_list;
63 
67 
68  irr::gui::STKModifiedSpriteBank* m_track_icons;
69 
70  bool m_network_tracks, m_quit_server;
71 
72  int m_bottom_box_height;
73 
75  uint32_t m_winning_index;
76 
79  std::vector<uint32_t> m_index_to_hostid;
80 
81  std::deque<std::string> m_random_track_list;
82 
84  void buildTrackList();
85 
86  void voteForPlayer();
87 
88  TracksScreen() : Screen("tracks.stkgui")
89  {
90  m_network_tracks = false;
91  m_quit_server = false;
92  m_bottom_box_height = -1;
93  m_track_icons = NULL;
94  m_timer = NULL;
95  m_winning_index = std::numeric_limits<uint32_t>::max();
96  m_vote_list = NULL;
97  m_reversed = NULL;
98  m_laps = NULL;
99  }
100  // ------------------------------------------------------------------------
101  void updateProgressBarText();
102 
103 public:
104 
105  void addVote(uint32_t host_id, const PeerVote& vote);
106  void removeVote(uint32_t host_id);
107  void setResult(uint32_t winner_host, const PeerVote& winner_vote);
108 
110  virtual void loadedFromFile() OVERRIDE;
111 
113  virtual void eventCallback(GUIEngine::Widget* widget,
114  const std::string& name,
115  const int playerID) OVERRIDE;
116 
118  virtual void init() OVERRIDE;
119 
121  virtual void beforeAddingWidget() OVERRIDE;
122 
124  virtual void tearDown() OVERRIDE;
125 
127  virtual bool onEscapePressed() OVERRIDE;
128 
130  virtual void onUpdate(float dt) OVERRIDE;
131 
133  virtual void unloaded() OVERRIDE;
134  // ------------------------------------------------------------------------
135  void setFocusOnTrack(const std::string& trackName);
136  // ------------------------------------------------------------------------
137  void setNetworkTracks() { m_network_tracks = true; }
138  // ------------------------------------------------------------------------
139  void setQuitServer() { m_quit_server = true; }
140  // ------------------------------------------------------------------------
143  void resetVote()
144  {
145  m_winning_index = std::numeric_limits<uint32_t>::max();
146  m_index_to_hostid.clear();
147  }
148  // ------------------------------------------------------------------------
149  void updatePlayerVotes();
150 };
151 
152 #endif
A spinner or gauge widget (to select numbers / percentages).
Definition: spinner_widget.hpp:39
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:187
void addVote(uint32_t host_id, const PeerVote &vote)
Selects in which part of the vote list the new host is being shown and stores this information in the...
Definition: tracks_screen.cpp:701
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
void removeVote(uint32_t host_id)
Removes a vote, which is triggered when a client disconnects.
Definition: tracks_screen.cpp:728
void buildTrackList()
adds the tracks from the current track group into the tracks ribbon
Definition: tracks_screen.cpp:541
void resetVote()
Called at the beginning of the voting process to reset any previous data fields.
Definition: tracks_screen.hpp:143
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:367
A simple structure to store a vote from a client: track name, number of laps and reverse or not.
Definition: peer_vote.hpp:29
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:197
A checkbox widget.
Definition: check_box_widget.hpp:33
virtual void beforeAddingWidget() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:217
virtual void onUpdate(float dt) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:674
virtual void eventCallback(GUIEngine::Widget *widget, const std::string &name, const int playerID) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:59
virtual void unloaded() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:205
uint32_t m_winning_index
Id of the winning peer.
Definition: tracks_screen.hpp:75
GUIEngine::ProgressBarWidget * m_timer
Pointer to progress bar widget which is used as a timer (going backwards).
Definition: tracks_screen.hpp:66
A vertical list widget with text entries.
Definition: list_widget.hpp:49
Represents a single GUI screen.
Definition: screen.hpp:94
Declares a class to be a singleton.
Definition: screen.hpp:57
Screen(bool pause_race=true)
Creates a dummy incomplete object; only use to override behaviour in sub-class.
Definition: screen.cpp:68
virtual bool onEscapePressed() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:170
void setResult(uint32_t winner_host, const PeerVote &winner_vote)
Received the winning vote.
Definition: tracks_screen.cpp:747
Definition: track.hpp:96
A progress bar widget.
Definition: progress_bar_widget.hpp:35
std::vector< uint32_t > m_index_to_hostid
This stores which vote (hostid) is shown at which index in the vote overview list.
Definition: tracks_screen.hpp:79
screen where the user can select a track
Definition: tracks_screen.hpp:52