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 #include "guiengine/widgets/text_box_widget.hpp"
23 
24 #include <deque>
25 #include <limits>
26 #include <string>
27 #include <vector>
28 
29 class PeerVote;
30 class Track;
31 
32 namespace GUIEngine
33 {
34  class CheckBoxWidget;
35  class CheckBoxWidget;
36  class ListWidget;
37  class SpinnerWidget;
38  class ProgressBarWidget;
39 }
40 
41 namespace irr
42 {
43  namespace gui
44  {
45  class STKModifiedSpriteBank;
46  }
47 }
48 
54  public GUIEngine::ScreenSingleton<TracksScreen>,
56 {
57  friend class GUIEngine::ScreenSingleton<TracksScreen>;
58 
59 private:
60 
61  Track* m_selected_track = NULL;
62  GUIEngine::CheckBoxWidget* m_reversed;
64  GUIEngine::ListWidget* m_vote_list;
65  GUIEngine::TextBoxWidget* m_search_track;
66 
70 
71  irr::gui::STKModifiedSpriteBank* m_track_icons;
72 
73  bool m_network_tracks, m_quit_server;
74 
75  int m_bottom_box_height;
76 
78  uint32_t m_winning_index;
79 
82  std::vector<uint32_t> m_index_to_hostid;
83 
84  std::deque<std::string> m_random_track_list;
85 
87  void buildTrackList();
88 
89  void voteForPlayer();
90 
91  TracksScreen() : Screen("tracks.stkgui")
92  {
93  m_network_tracks = false;
94  m_quit_server = false;
95  m_bottom_box_height = -1;
96  m_track_icons = NULL;
97  m_timer = NULL;
98  m_winning_index = std::numeric_limits<uint32_t>::max();
99  m_vote_list = NULL;
100  m_reversed = NULL;
101  m_laps = NULL;
102  }
103  // ------------------------------------------------------------------------
104  void updateProgressBarText();
105 
106 public:
107 
108  void addVote(uint32_t host_id, const PeerVote& vote);
109  void removeVote(uint32_t host_id);
110  void setResult(uint32_t winner_host, const PeerVote& winner_vote);
111 
113  virtual void loadedFromFile() OVERRIDE;
114 
116  virtual void eventCallback(GUIEngine::Widget* widget,
117  const std::string& name,
118  const int playerID) OVERRIDE;
119 
121  virtual void init() OVERRIDE;
122 
124  virtual void beforeAddingWidget() OVERRIDE;
125 
127  virtual void tearDown() OVERRIDE;
128 
130  virtual bool onEscapePressed() OVERRIDE;
131 
133  virtual void onUpdate(float dt) OVERRIDE;
134 
136  virtual void unloaded() OVERRIDE;
137  // ------------------------------------------------------------------------
138  void setFocusOnTrack(const std::string& trackName);
139  // ------------------------------------------------------------------------
140  void setNetworkTracks() { m_network_tracks = true; }
141  // ------------------------------------------------------------------------
142  void setQuitServer() { m_quit_server = true; }
143  // ------------------------------------------------------------------------
146  void resetVote()
147  {
148  m_winning_index = std::numeric_limits<uint32_t>::max();
149  m_index_to_hostid.clear();
150  }
151  // ------------------------------------------------------------------------
152  void updatePlayerVotes();
153  // ------------------------------------------------------------------------
154  virtual void onTextUpdated() OVERRIDE
155  {
156  eventCallback(m_search_track, "trackgroups", 0);
157  }
158 };
159 
160 #endif
A spinner or gauge widget (to select numbers / percentages).
Definition: spinner_widget.hpp:40
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
A text field widget.
Definition: text_box_widget.hpp:52
void resetVote()
Called at the beginning of the voting process to reset any previous data fields.
Definition: tracks_screen.hpp:146
Definition: three_d_animation.hpp:32
A simple structure to store a vote from a client: track name, number of laps and reverse or not...
Definition: peer_vote.hpp:29
A checkbox widget.
Definition: check_box_widget.hpp:33
uint32_t m_winning_index
Id of the winning peer.
Definition: tracks_screen.hpp:78
GUIEngine::ProgressBarWidget * m_timer
Pointer to progress bar widget which is used as a timer (going backwards).
Definition: tracks_screen.hpp:69
A vertical list widget with text entries.
Definition: list_widget.hpp:49
Definition: script_track.cpp:52
Represents a single GUI screen.
Definition: screen.hpp:96
Definition: text_box_widget.hpp:41
Declares a class to be a singleton.
Definition: screen.hpp:58
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:82
screen where the user can select a track
Definition: tracks_screen.hpp:53