File: event_select.cpp

package info (click to toggle)
ppracer 0.3.1-11
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,916 kB
  • ctags: 3,049
  • sloc: cpp: 24,190; sh: 3,544; tcl: 2,450; makefile: 612; lisp: 87
file content (234 lines) | stat: -rw-r--r-- 5,834 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* 
 * PPRacer 
 * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
 * 
 * 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 2
 * 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.
 */

#include "event_select.h"

#include "ppgltk/audio/audio.h"

#include "course_load.h"
#include "textures.h"
#include "joystick.h"

#include "player.h"
#include "game_mgr.h"
	
EventSelect::EventSelect()
{
	if(GameMode::prevmode==EVENT_RACE_SELECT){
		m_curEvent = gameMgr->currentEvent;
		m_curCup = gameMgr->currentCup;
		if(players[0].isCupComplete((*m_curEvent).name,(*m_curCup).name)){
			if(m_curCup != --(*m_curEvent).cupList.end()){
				m_curCup++;
			}				
		}
	}else{
		m_curEvent = eventList.begin();
		m_curCup = (*m_curEvent).cupList.begin();
	}
		
	pp::Vec2d pos( getparam_x_resolution()/2,
				   getparam_y_resolution()/2+150);
	
	mp_titleLbl = new pp::Label(pos,"menu_label",_("Select event and cup"));
	mp_titleLbl->alignment.center();
	
	
	pos.x-=200;
	pos.y-=60;
	mp_eventLbl = new pp::Label(pos,"event_and_cup_label",_("Event:"));	
	
	pos.y-=50;
	mp_eventListbox = new pp::Listbox<EventData>( pos,
				   pp::Vec2d(400, 40),
				   "listbox_item",
				   eventList);
	mp_eventListbox->setCurrentItem( m_curEvent );
	mp_eventListbox->signalChange.Connect(pp::CreateSlot(this,&EventSelect::eventChanged));
	
	pos.y-=40;
	mp_cupLbl = new pp::Label(pos,"event_and_cup_label",_("Cup:"));
		
	pos.y-=50;
	mp_cupListbox = new pp::Listbox<CupData>( pos,
				   pp::Vec2d(400, 40),
				   "listbox_item",
				   (*m_curEvent).cupList );
	mp_cupListbox->setCurrentItem( m_curCup );	
    mp_cupListbox->signalChange.Connect(pp::CreateSlot(this,&EventSelect::cupChanged));

	pos.y-=30;
	mp_statusLbl = new pp::Label( pp::Vec2d(pos.x+200,pos.y),
								  "cup_status","");
	mp_statusLbl->alignment.center();

    pos.y-=120;
	pos.x-=50;	
	mp_backBtn = new pp::Button( pos,
			      pp::Vec2d(150, 40), 
			      "button_label", 
			      _("Back") );
    mp_backBtn->setHilitFontBinding( "button_label_hilit" );
    mp_backBtn->signalClicked.Connect(pp::CreateSlot(this,&EventSelect::back));

	pos.x+=350;	
	mp_continueBtn = new pp::Button( pos,
			       pp::Vec2d(150, 40),
			       "button_label",
			       _("Continue") );
    mp_continueBtn->setHilitFontBinding( "button_label_hilit" );
    mp_continueBtn->setDisabledFontBinding( "button_label_disabled" );
    mp_continueBtn->signalClicked.Connect(pp::CreateSlot(this,&EventSelect::apply));
	
	updateCupStates();
	updateButtonEnabledStates();
}

EventSelect::~EventSelect()
{
	delete mp_backBtn;
	delete mp_continueBtn;	
	delete mp_eventListbox;
	delete mp_cupListbox;
	
	delete mp_titleLbl;
	delete mp_eventLbl;
	delete mp_cupLbl;	
	delete mp_statusLbl;
}

void
EventSelect::loop(float timeStep)
{
    update_audio();
    set_gl_options( GUI );
    clear_rendering_context();
    UIMgr.setupDisplay();
	drawSnow(timeStep);
    theme.drawMenuDecorations();
    UIMgr.draw();
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    winsys_swap_buffers();
}

void
EventSelect::updateCupStates()
{
	m_curCupComplete=false;
	m_curCupPlayable=false;
	
	if ( players[0].isCupComplete( (*m_curEvent).name, (*m_curCup).name) ) {
		m_curCupComplete=true;
		m_curCupPlayable=true;
    } else if ( players[0].isFirstIncompleteCup( m_curEvent, m_curCup ) ) {
		m_curCupPlayable=true;
    }
	
	const char* string;
	if(m_curCupComplete){
		string = _("You've won this cup!");
	}else if (m_curCupPlayable){
		string = _("You must complete this cup next");
	}else{
		string = _("You cannot enter this cup yet"); 
	}
	mp_statusLbl->setText(string);
}

void
EventSelect::updateButtonEnabledStates()
{
	if(m_curCupPlayable){
		mp_continueBtn->setSensitive(true);
	}else{
		mp_continueBtn->setSensitive(false);
	}
}

void
EventSelect::cupChanged()
{
	m_curCup = mp_cupListbox->getCurrentItem();
	updateCupStates();
	updateButtonEnabledStates();
}

void
EventSelect::eventChanged()
{
	m_curEvent = mp_eventListbox->getCurrentItem();
	m_curCup = (*m_curEvent).cupList.begin();
	updateCupStates();
	updateButtonEnabledStates();
}

void
EventSelect::back()
{
	set_game_mode( GAME_TYPE_SELECT );
	UIMgr.setDirty();
}

void
EventSelect::apply()
{
    m_curEvent = mp_eventListbox->getCurrentItem();
	m_curCup = mp_cupListbox->getCurrentItem();

	gameMgr->setupEventAndCup(	m_curEvent,
								m_curCup );

	if(!getparam_always_save_event_race_data()){	
		if(!players[0].isCupComplete((*m_curEvent).name, (*m_curCup).name )){
			players[0].clearCupData((*m_curEvent).name, (*m_curCup).name);
		}
	}
	players[0].resetLives();
    set_game_mode( EVENT_RACE_SELECT );
    UIMgr.setDirty();
}

bool
EventSelect::keyPressEvent(SDLKey key)
{
	switch (key){
		case SDLK_UP:
			mp_cupListbox->gotoPrevItem();
	    	return true;
		case SDLK_DOWN:
			mp_cupListbox->gotoNextItem();
	    	return true;
		case SDLK_LEFT:
			mp_eventListbox->gotoPrevItem();
	    	return true;
		case SDLK_RIGHT:
			mp_eventListbox->gotoPrevItem();
	    	return true;
		case SDLK_RETURN: 
	    	mp_continueBtn->simulateMouseClick();
			UIMgr.setDirty();
			return true;
		case SDLK_ESCAPE: 
	    	mp_backBtn->simulateMouseClick();
			UIMgr.setDirty();
			return true;
		default:
			return false;
	}	
}