SuperTuxKart
Loading...
Searching...
No Matches
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
29class PeerVote;
30class Track;
31
32namespace GUIEngine
33{
34 class CheckBoxWidget;
35 class CheckBoxWidget;
36 class ListWidget;
37 class SpinnerWidget;
38 class ProgressBarWidget;
39}
40
41namespace irr
42{
43 namespace gui
44 {
45 class STKModifiedSpriteBank;
46 }
47}
48
54 public GUIEngine::ScreenSingleton<TracksScreen>,
56{
58
59private:
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
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
106public:
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 // ------------------------------------------------------------------------
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 checkbox widget.
Definition: check_box_widget.hpp:34
Definition: text_box_widget.hpp:42
A vertical list widget with text entries.
Definition: list_widget.hpp:50
A progress bar widget.
Definition: progress_bar_widget.hpp:36
Declares a class to be a singleton.
Definition: screen.hpp:59
Represents a single GUI screen.
Definition: screen.hpp:97
Screen(bool pause_race=true)
Creates a dummy incomplete object; only use to override behaviour in sub-class.
Definition: screen.cpp:68
A spinner or gauge widget (to select numbers / percentages).
Definition: spinner_widget.hpp:41
A text field widget.
Definition: text_box_widget.hpp:53
A simple structure to store a vote from a client: track name, number of laps and reverse or not.
Definition: peer_vote.hpp:30
Definition: track.hpp:114
screen where the user can select a track
Definition: tracks_screen.hpp:56
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:197
void removeVote(uint32_t host_id)
Removes a vote, which is triggered when a client disconnects.
Definition: tracks_screen.cpp:762
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:187
GUIEngine::ProgressBarWidget * m_timer
Pointer to progress bar widget which is used as a timer (going backwards).
Definition: tracks_screen.hpp:69
void buildTrackList()
adds the tracks from the current track group into the tracks ribbon
Definition: tracks_screen.cpp:566
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
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
virtual void onUpdate(float dt) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:708
virtual void beforeAddingWidget() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:217
void setResult(uint32_t winner_host, const PeerVote &winner_vote)
Received the winning vote.
Definition: tracks_screen.cpp:781
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:735
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:382
uint32_t m_winning_index
Id of the winning peer.
Definition: tracks_screen.hpp:78
virtual void unloaded() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:205
virtual bool onEscapePressed() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: tracks_screen.cpp:170
void resetVote()
Called at the beginning of the voting process to reset any previous data fields.
Definition: tracks_screen.hpp:146
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33