git repos / blockattack-game

blame: source/code/ScoresDisplay.cpp

normal view · raw

c3b697c6 sago007 2016-02-07 17:30 1
/*
7a956470 sago007 2016-02-14 17:09 2
===========================================================================
7a956470 sago007 2016-02-14 17:09 3
blockattack - Block Attack - Rise of the Blocks
7a956470 sago007 2016-02-14 17:09 4
Copyright (C) 2005-2016 Poul Sander
c3b697c6 sago007 2016-02-07 17:30 5
7a956470 sago007 2016-02-14 17:09 6
This program is free software: you can redistribute it and/or modify
7a956470 sago007 2016-02-14 17:09 7
it under the terms of the GNU General Public License as published by
7a956470 sago007 2016-02-14 17:09 8
the Free Software Foundation, either version 2 of the License, or
7a956470 sago007 2016-02-14 17:09 9
(at your option) any later version.
7a956470 sago007 2016-02-14 17:09 10
7a956470 sago007 2016-02-14 17:09 11
This program is distributed in the hope that it will be useful,
7a956470 sago007 2016-02-14 17:09 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
7a956470 sago007 2016-02-14 17:09 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7a956470 sago007 2016-02-14 17:09 14
GNU General Public License for more details.
7a956470 sago007 2016-02-14 17:09 15
7a956470 sago007 2016-02-14 17:09 16
You should have received a copy of the GNU General Public License
7a956470 sago007 2016-02-14 17:09 17
along with this program.  If not, see http://www.gnu.org/licenses/
7a956470 sago007 2016-02-14 17:09 18
7a956470 sago007 2016-02-14 17:09 19
Source information and contacts persons can be found at
7a956470 sago007 2016-02-14 17:09 20
http://www.blockattack.net
7a956470 sago007 2016-02-14 17:09 21
===========================================================================
7a956470 sago007 2016-02-14 17:09 22
*/
c3b697c6 sago007 2016-02-07 17:30 23
c3b697c6 sago007 2016-02-07 17:30 24
#include "ScoresDisplay.hpp"
c3b697c6 sago007 2016-02-07 17:30 25
#include "global.hpp"
c3b697c6 sago007 2016-02-07 17:30 26
#include "common.h"
c3b697c6 sago007 2016-02-07 17:30 27
#include "stats.h"
d21782d4 sago007 2016-03-13 11:17 28
#include "MenuSystem.h"
16476649 Poul Sander 2022-01-09 10:29 29
#include <fmt/core.h>
c3b697c6 sago007 2016-02-07 17:30 30
aa7d74c5 Poul Sander 2019-05-08 17:14 31
const int buttonOffsetX = 140;
aa7d74c5 Poul Sander 2019-05-08 17:14 32
const int buttonOffsetY = 180;
aa7d74c5 Poul Sander 2019-05-08 17:14 33
extern sago::SagoSprite bExit;
aa7d74c5 Poul Sander 2019-05-08 17:14 34
d2ba3cf5 sago007 2018-05-13 15:00 35
static void setButtonFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
34ab7861 sago007 2018-03-28 14:47 36
	field.SetHolder(holder);
34ab7861 sago007 2018-03-28 14:47 37
	field.SetFont("freeserif");
34ab7861 sago007 2018-03-28 14:47 38
	field.SetColor({255,255,255,255});
34ab7861 sago007 2018-03-28 14:47 39
	field.SetFontSize(24);
d8fe60bd sago007 2018-04-02 16:15 40
	field.SetOutline(1, {128,128,128,255});
34ab7861 sago007 2018-03-28 14:47 41
	field.SetText(text);
34ab7861 sago007 2018-03-28 14:47 42
}
e1b2e653 sago007 2017-11-28 18:10 43
69d8f1dc sago007 2018-03-31 16:19 44
sago::SagoTextField* ScoresDisplay::getCachedText(const std::string& text) {
69d8f1dc sago007 2018-03-31 16:19 45
	std::shared_ptr<sago::SagoTextField> ptr = fieldCache[text];
69d8f1dc sago007 2018-03-31 16:19 46
	if (!ptr) {
69d8f1dc sago007 2018-03-31 16:19 47
		std::shared_ptr<sago::SagoTextField> newText = std::make_shared<sago::SagoTextField>();
69d8f1dc sago007 2018-03-31 16:19 48
		sagoTextSetBlueFont(*newText.get());
0b8fb137 sago007 2018-03-31 19:53 49
		newText->SetText(text);
69d8f1dc sago007 2018-03-31 16:19 50
		fieldCache[text] = newText;
69d8f1dc sago007 2018-03-31 16:19 51
	}
69d8f1dc sago007 2018-03-31 16:19 52
	return fieldCache[text].get();
69d8f1dc sago007 2018-03-31 16:19 53
}
69d8f1dc sago007 2018-03-31 16:19 54
69d8f1dc sago007 2018-03-31 16:19 55
void ScoresDisplay::Write(SDL_Renderer* target, int x, int y, const char* text) {
69d8f1dc sago007 2018-03-31 16:19 56
	getCachedText(text)->Draw(target, x, y);
c3b697c6 sago007 2016-02-07 17:30 57
}
c3b697c6 sago007 2016-02-07 17:30 58
16476649 Poul Sander 2022-01-09 10:29 59
16476649 Poul Sander 2022-01-09 10:29 60
void ScoresDisplay::Write(SDL_Renderer* target, int x, int y, const std::string& text) {
16476649 Poul Sander 2022-01-09 10:29 61
	Write(target, x, y, text.c_str());
16476649 Poul Sander 2022-01-09 10:29 62
}
16476649 Poul Sander 2022-01-09 10:29 63
79d552fa sago007 2019-02-12 17:17 64
const int numberOfPages = 7;
c3b697c6 sago007 2016-02-07 17:30 65
13476fc2 sago007 2016-09-28 18:34 66
void ScoresDisplay::DrawBackgroundAndCalcPlacements() {
72383a9e sago007 2016-10-30 11:56 67
	DrawBackground(globalData.screen);
72383a9e sago007 2016-10-30 11:56 68
	nextX = globalData.xsize-buttonXsize-20;
72383a9e sago007 2016-10-30 11:56 69
	backY = globalData.ysize-buttonYsize-20;
13476fc2 sago007 2016-09-28 18:34 70
	nextY = backY;
13476fc2 sago007 2016-09-28 18:34 71
}
13476fc2 sago007 2016-09-28 18:34 72
c3b697c6 sago007 2016-02-07 17:30 73
//Draws the highscores
79d552fa sago007 2019-02-12 17:17 74
void ScoresDisplay::DrawHighscores(int x, int y, bool endless, int level = 0) {
13476fc2 sago007 2016-09-28 18:34 75
	DrawBackgroundAndCalcPlacements();
c3b697c6 sago007 2016-02-07 17:30 76
	if (endless) {
47515b6a Poul Sander 2019-02-13 18:16 77
		std::string header;
47515b6a Poul Sander 2019-02-13 18:16 78
		switch (level) {
9c7fa9a1 sago007 2020-06-27 22:09 79
		case 1:
9c7fa9a1 sago007 2020-06-27 22:09 80
			header = _("Endless (Fast):");
9c7fa9a1 sago007 2020-06-27 22:09 81
			break;
9c7fa9a1 sago007 2020-06-27 22:09 82
		case 2:
9c7fa9a1 sago007 2020-06-27 22:09 83
			header = _("Endless (Faster):");
9c7fa9a1 sago007 2020-06-27 22:09 84
			break;
9c7fa9a1 sago007 2020-06-27 22:09 85
		case 3:
9c7fa9a1 sago007 2020-06-27 22:09 86
			header = _("Endless (Even faster):");
9c7fa9a1 sago007 2020-06-27 22:09 87
			break;
9c7fa9a1 sago007 2020-06-27 22:09 88
		case 4:
9c7fa9a1 sago007 2020-06-27 22:09 89
			header = _("Endless (Fastest):");
9c7fa9a1 sago007 2020-06-27 22:09 90
			break;
9c7fa9a1 sago007 2020-06-27 22:09 91
		default:
9c7fa9a1 sago007 2020-06-27 22:09 92
			header = _("Endless:");
47515b6a Poul Sander 2019-02-13 18:16 93
		};
79d552fa sago007 2019-02-12 17:17 94
		Write(globalData.screen, x+100,y+100, header.c_str() );
c3b697c6 sago007 2016-02-07 17:30 95
	}
c3b697c6 sago007 2016-02-07 17:30 96
	else {
69d8f1dc sago007 2018-03-31 16:19 97
		Write(globalData.screen, x+100,y+100, _("Time Trial:") );
c3b697c6 sago007 2016-02-07 17:30 98
	}
c3b697c6 sago007 2016-02-07 17:30 99
	for (int i =0; i<10; i++) {
7a956470 sago007 2016-02-14 17:09 100
		record r;
c3b697c6 sago007 2016-02-07 17:30 101
		if (endless) {
9c7fa9a1 sago007 2020-06-27 22:09 102
			switch (level) {
9c7fa9a1 sago007 2020-06-27 22:09 103
			case 1:
9c7fa9a1 sago007 2020-06-27 22:09 104
				r = theTopScoresEndless1.getScoreNumber(i);
9c7fa9a1 sago007 2020-06-27 22:09 105
				break;
9c7fa9a1 sago007 2020-06-27 22:09 106
			case 2:
9c7fa9a1 sago007 2020-06-27 22:09 107
				r = theTopScoresEndless2.getScoreNumber(i);
9c7fa9a1 sago007 2020-06-27 22:09 108
				break;
9c7fa9a1 sago007 2020-06-27 22:09 109
			case 3:
9c7fa9a1 sago007 2020-06-27 22:09 110
				r = theTopScoresEndless3.getScoreNumber(i);
9c7fa9a1 sago007 2020-06-27 22:09 111
				break;
9c7fa9a1 sago007 2020-06-27 22:09 112
			case 4:
9c7fa9a1 sago007 2020-06-27 22:09 113
				r = theTopScoresEndless4.getScoreNumber(i);
9c7fa9a1 sago007 2020-06-27 22:09 114
				break;
9c7fa9a1 sago007 2020-06-27 22:09 115
			default:
9c7fa9a1 sago007 2020-06-27 22:09 116
				r = theTopScoresEndless0.getScoreNumber(i);
79d552fa sago007 2019-02-12 17:17 117
			}
c3b697c6 sago007 2016-02-07 17:30 118
		}
c3b697c6 sago007 2016-02-07 17:30 119
		else {
905de2a2 sago007 2019-02-08 18:46 120
			r = theTopScoresTimeTrial.getScoreNumber(i);
c3b697c6 sago007 2016-02-07 17:30 121
		}
7a956470 sago007 2016-02-14 17:09 122
		char playerScore[32];
7a956470 sago007 2016-02-14 17:09 123
		char playerName[32];
7a956470 sago007 2016-02-14 17:09 124
		snprintf(playerScore, sizeof(playerScore), "%i", r.score);
7a956470 sago007 2016-02-14 17:09 125
		snprintf(playerName, sizeof(playerName), "%s", r.name.c_str());
69d8f1dc sago007 2018-03-31 16:19 126
		Write(globalData.screen, x+420,y+150+i*35, playerScore);
69d8f1dc sago007 2018-03-31 16:19 127
		Write(globalData.screen, x+60,y+150+i*35, playerName);
c3b697c6 sago007 2016-02-07 17:30 128
	}
c3b697c6 sago007 2016-02-07 17:30 129
}
c3b697c6 sago007 2016-02-07 17:30 130
c3b697c6 sago007 2016-02-07 17:30 131
void ScoresDisplay::DrawStats() {
13476fc2 sago007 2016-09-28 18:34 132
	DrawBackgroundAndCalcPlacements();
c3b697c6 sago007 2016-02-07 17:30 133
	int y = 5;
c3b697c6 sago007 2016-02-07 17:30 134
	const int y_spacing = 30;
69d8f1dc sago007 2018-03-31 16:19 135
	Write(globalData.screen, 10,y,_("Stats") );
c3b697c6 sago007 2016-02-07 17:30 136
	y+=y_spacing*2;
69d8f1dc sago007 2018-03-31 16:19 137
	Write(globalData.screen, 10,y,_("Chains") );
c3b697c6 sago007 2016-02-07 17:30 138
	for (int i=2; i<13; i++) {
c3b697c6 sago007 2016-02-07 17:30 139
		y+=y_spacing;
69d8f1dc sago007 2018-03-31 16:19 140
		Write(globalData.screen, 10,y,(std::to_string(i)+"X").c_str());
e373cd75 Poul Sander 2018-11-07 19:21 141
		std::string numberAsString = std::to_string(Stats::getInstance()->getNumberOf("chainX"+std::to_string(i)));
69d8f1dc sago007 2018-03-31 16:19 142
		Write(globalData.screen, 300,y,numberAsString.c_str());
c3b697c6 sago007 2016-02-07 17:30 143
	}
c3b697c6 sago007 2016-02-07 17:30 144
	y+=y_spacing*2;
69d8f1dc sago007 2018-03-31 16:19 145
	Write(globalData.screen, 10,y,_("Lines Pushed: ") );
e373cd75 Poul Sander 2018-11-07 19:21 146
	std::string numberAsString = std::to_string(Stats::getInstance()->getNumberOf("linesPushed"));
69d8f1dc sago007 2018-03-31 16:19 147
	Write(globalData.screen, 300,y,numberAsString.c_str());
c3b697c6 sago007 2016-02-07 17:30 148
c3b697c6 sago007 2016-02-07 17:30 149
	y+=y_spacing;
69d8f1dc sago007 2018-03-31 16:19 150
	Write(globalData.screen, 10,y, _("Puzzles solved: ") );
549ecfae sago007 2016-10-09 08:37 151
	numberAsString = std::to_string(Stats::getInstance()->getNumberOf("puzzlesSolved"));
69d8f1dc sago007 2018-03-31 16:19 152
	Write(globalData.screen, 300,y,numberAsString.c_str());
c3b697c6 sago007 2016-02-07 17:30 153
c3b697c6 sago007 2016-02-07 17:30 154
	y+=y_spacing*2;
69d8f1dc sago007 2018-03-31 16:19 155
	Write(globalData.screen, 10,y, _("Run time: ") );
c3b697c6 sago007 2016-02-07 17:30 156
	commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
c3b697c6 sago007 2016-02-07 17:30 157
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 158
	Write(globalData.screen, 10, y, fmt::format( _("Days: {}"), ct.days) );
c3b697c6 sago007 2016-02-07 17:30 159
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 160
	Write(globalData.screen, 10, y, fmt::format( _("Hours: {:02}"), ct.hours) );
c3b697c6 sago007 2016-02-07 17:30 161
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 162
	Write(globalData.screen, 10, y, fmt::format( _("Minutes: {:02}"), ct.minutes) );
c3b697c6 sago007 2016-02-07 17:30 163
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 164
	Write(globalData.screen, 10, y, fmt::format( _("Seconds: {:02}"), ct.seconds) );
c3b697c6 sago007 2016-02-07 17:30 165
c3b697c6 sago007 2016-02-07 17:30 166
	y-=y_spacing*4; //Four rows back
72383a9e sago007 2016-10-30 11:56 167
	const int x_offset3 = globalData.xsize/3+10; //Ofset for three rows
69d8f1dc sago007 2018-03-31 16:19 168
	Write(globalData.screen, x_offset3,y, _("Play time: ") );
c3b697c6 sago007 2016-02-07 17:30 169
	ct = TimeHandler::getTime("playTime");
c3b697c6 sago007 2016-02-07 17:30 170
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 171
	Write(globalData.screen, x_offset3, y, fmt::format( _("Days: {}"), ct.days) );
c3b697c6 sago007 2016-02-07 17:30 172
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 173
	Write(globalData.screen, x_offset3, y, fmt::format( _("Hours: {:02}"), ct.hours) );
c3b697c6 sago007 2016-02-07 17:30 174
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 175
	Write(globalData.screen, x_offset3, y, fmt::format( _("Minutes: {:02}"), ct.minutes) );
c3b697c6 sago007 2016-02-07 17:30 176
	y+=y_spacing;
16476649 Poul Sander 2022-01-09 10:29 177
	Write(globalData.screen, x_offset3, y, fmt::format( _("Seconds: {:02}"), ct.seconds) );
c3b697c6 sago007 2016-02-07 17:30 178
72383a9e sago007 2016-10-30 11:56 179
	const int x_offset = globalData.xsize/2+10;
c3b697c6 sago007 2016-02-07 17:30 180
	y = 5+y_spacing*2;
69d8f1dc sago007 2018-03-31 16:19 181
	Write(globalData.screen, x_offset,y, _("VS CPU (win/loss)") );
c3b697c6 sago007 2016-02-07 17:30 182
	for (int i=0; i<7; i++) {
c3b697c6 sago007 2016-02-07 17:30 183
		y += y_spacing;
e373cd75 Poul Sander 2018-11-07 19:21 184
		Write(globalData.screen, x_offset,y,std::string("AI "+std::to_string(i+1)).c_str());
549ecfae sago007 2016-10-09 08:37 185
		numberAsString = std::to_string(Stats::getInstance()->getNumberOf("defeatedAI"+std::to_string(i)));
e373cd75 Poul Sander 2018-11-07 19:21 186
		std::string numberAsString2 = std::to_string(Stats::getInstance()->getNumberOf("defeatedByAI"+std::to_string(i)));
e373cd75 Poul Sander 2018-11-07 19:21 187
		std::string toPrint = numberAsString + "/" + numberAsString2;
69d8f1dc sago007 2018-03-31 16:19 188
		Write(globalData.screen, x_offset+230,y,toPrint.c_str());
c3b697c6 sago007 2016-02-07 17:30 189
	}
c3b697c6 sago007 2016-02-07 17:30 190
}
c3b697c6 sago007 2016-02-07 17:30 191
c3b697c6 sago007 2016-02-07 17:30 192
ScoresDisplay::ScoresDisplay() {
c3b697c6 sago007 2016-02-07 17:30 193
}
c3b697c6 sago007 2016-02-07 17:30 194
c3b697c6 sago007 2016-02-07 17:30 195
ScoresDisplay::~ScoresDisplay() {
c3b697c6 sago007 2016-02-07 17:30 196
}
c3b697c6 sago007 2016-02-07 17:30 197
c3b697c6 sago007 2016-02-07 17:30 198
bool ScoresDisplay::IsActive() {
c3b697c6 sago007 2016-02-07 17:30 199
	return isActive;
c3b697c6 sago007 2016-02-07 17:30 200
}
c3b697c6 sago007 2016-02-07 17:30 201
647f12da sago007 2016-09-12 20:07 202
void ScoresDisplay::Draw(SDL_Renderer*) {
c3b697c6 sago007 2016-02-07 17:30 203
	switch (page) {
9c7fa9a1 sago007 2020-06-27 22:09 204
	case 0:
9c7fa9a1 sago007 2020-06-27 22:09 205
	case 1:
9c7fa9a1 sago007 2020-06-27 22:09 206
	case 2:
9c7fa9a1 sago007 2020-06-27 22:09 207
	case 3:
9c7fa9a1 sago007 2020-06-27 22:09 208
	case 4:
9c7fa9a1 sago007 2020-06-27 22:09 209
		//Highscores, endless
9c7fa9a1 sago007 2020-06-27 22:09 210
		DrawHighscores(100,100,true, page);
9c7fa9a1 sago007 2020-06-27 22:09 211
		break;
9c7fa9a1 sago007 2020-06-27 22:09 212
	case 5:
9c7fa9a1 sago007 2020-06-27 22:09 213
		//Highscores, Time Trial
9c7fa9a1 sago007 2020-06-27 22:09 214
		DrawHighscores(100,100,false);
9c7fa9a1 sago007 2020-06-27 22:09 215
		break;
9c7fa9a1 sago007 2020-06-27 22:09 216
	case 6:
9c7fa9a1 sago007 2020-06-27 22:09 217
	default:
9c7fa9a1 sago007 2020-06-27 22:09 218
		DrawStats();
c3b697c6 sago007 2016-02-07 17:30 219
	};
c3b697c6 sago007 2016-02-07 17:30 220
34ab7861 sago007 2018-03-28 14:47 221
	const sago::SagoDataHolder* holder = &globalData.spriteHolder->GetDataHolder();
c3b697c6 sago007 2016-02-07 17:30 222
	//Draw buttons:
aa7d74c5 Poul Sander 2019-05-08 17:14 223
	bExit.Draw(globalData.screen, SDL_GetTicks(), globalData.xsize-buttonOffsetX, globalData.ysize-buttonOffsetY);
72383a9e sago007 2016-10-30 11:56 224
	globalData.bBack.Draw(globalData.screen, 0, backX, backY);
34ab7861 sago007 2018-03-28 14:47 225
	static sago::SagoTextField backLabel;
34ab7861 sago007 2018-03-28 14:47 226
	setButtonFont(holder, backLabel, _("Back"));
34ab7861 sago007 2018-03-28 14:47 227
	backLabel.Draw(globalData.screen, backX+60,backY+10, sago::SagoTextField::Alignment::center);
72383a9e sago007 2016-10-30 11:56 228
	globalData.bNext.Draw(globalData.screen, 0, nextX, nextY);
34ab7861 sago007 2018-03-28 14:47 229
	static sago::SagoTextField nextLabel;
34ab7861 sago007 2018-03-28 14:47 230
	setButtonFont(holder, nextLabel, _("Next"));
34ab7861 sago007 2018-03-28 14:47 231
	nextLabel.Draw(globalData.screen, nextX+60, nextY+10, sago::SagoTextField::Alignment::center);
c3b697c6 sago007 2016-02-07 17:30 232
c3b697c6 sago007 2016-02-07 17:30 233
	//Draw page number
16476649 Poul Sander 2022-01-09 10:29 234
	std::string pageXofY = fmt::format(_("Page {} of {}"), page+1, numberOfPages);
c9a65d81 sago007 2018-03-31 16:22 235
	getCachedText(pageXofY)->Draw(globalData.screen,  globalData.xsize/2, globalData.ysize-60, sago::SagoTextField::Alignment::center);
c3b697c6 sago007 2016-02-07 17:30 236
}
c3b697c6 sago007 2016-02-07 17:30 237
58a2d7e1 sago007 2016-02-12 18:53 238
void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
c7f2082f sago007 2016-03-13 11:48 239
20d77c6e sago007 2016-11-12 16:28 240
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
092bdebe sago007 2017-03-19 14:39 241
79d552fa sago007 2019-02-12 17:17 242
	if (isRightEvent(event)) {
d21782d4 sago007 2016-03-13 11:17 243
		page++;
d21782d4 sago007 2016-03-13 11:17 244
		if (page>=numberOfPages) {
d21782d4 sago007 2016-03-13 11:17 245
			page = 0;
c3b697c6 sago007 2016-02-07 17:30 246
		}
647f12da sago007 2016-09-12 20:07 247
		processed = true;
d21782d4 sago007 2016-03-13 11:17 248
	}
8e3fb7e1 sago007 2016-03-13 11:26 249
79d552fa sago007 2019-02-12 17:17 250
	if (isLeftEvent(event)) {
d21782d4 sago007 2016-03-13 11:17 251
		page--;
d21782d4 sago007 2016-03-13 11:17 252
		if (page<0) {
d21782d4 sago007 2016-03-13 11:17 253
			page = numberOfPages-1;
c3b697c6 sago007 2016-02-07 17:30 254
		}
647f12da sago007 2016-09-12 20:07 255
		processed = true;
c3b697c6 sago007 2016-02-07 17:30 256
	}
8e3fb7e1 sago007 2016-03-13 11:26 257
d21782d4 sago007 2016-03-13 11:17 258
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
d21782d4 sago007 2016-03-13 11:17 259
		isActive = false;
647f12da sago007 2016-09-12 20:07 260
		processed = true;
d21782d4 sago007 2016-03-13 11:17 261
	}
c3b697c6 sago007 2016-02-07 17:30 262
}
c3b697c6 sago007 2016-02-07 17:30 263
c3b697c6 sago007 2016-02-07 17:30 264
void ScoresDisplay::Update() {
c3b697c6 sago007 2016-02-07 17:30 265
	// If the mouse button is released, make bMouseUp equal true
08c44684 sago007 2016-10-30 09:19 266
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
c3b697c6 sago007 2016-02-07 17:30 267
		bMouseUp=true;
c3b697c6 sago007 2016-02-07 17:30 268
	}
c3b697c6 sago007 2016-02-07 17:30 269
c3b697c6 sago007 2016-02-07 17:30 270
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
c3b697c6 sago007 2016-02-07 17:30 271
		bMouseUp = false;
c3b697c6 sago007 2016-02-07 17:30 272
aa7d74c5 Poul Sander 2019-05-08 17:14 273
		//The Exit button:
aa7d74c5 Poul Sander 2019-05-08 17:14 274
		if ((globalData.mousex>globalData.xsize-buttonOffsetX) && (globalData.mousex<globalData.xsize-buttonOffsetX+bExit.GetWidth())
aa7d74c5 Poul Sander 2019-05-08 17:14 275
		        && (globalData.mousey>globalData.ysize-buttonOffsetY) && (globalData.mousey<globalData.ysize-buttonOffsetY+bExit.GetHeight())) {
c3b697c6 sago007 2016-02-07 17:30 276
			isActive = false;
c3b697c6 sago007 2016-02-07 17:30 277
		}
c3b697c6 sago007 2016-02-07 17:30 278
c3b697c6 sago007 2016-02-07 17:30 279
		//The back button:
20d77c6e sago007 2016-11-12 16:28 280
		if ((globalData.mousex>backX) && (globalData.mousex<backX+buttonXsize) && (globalData.mousey>backY) && (globalData.mousey<backY+buttonYsize)) {
c3b697c6 sago007 2016-02-07 17:30 281
			page--;
c3b697c6 sago007 2016-02-07 17:30 282
			if (page<0) {
c3b697c6 sago007 2016-02-07 17:30 283
				page = numberOfPages-1;
c3b697c6 sago007 2016-02-07 17:30 284
			}
c3b697c6 sago007 2016-02-07 17:30 285
		}
c3b697c6 sago007 2016-02-07 17:30 286
c3b697c6 sago007 2016-02-07 17:30 287
		//The next button:
20d77c6e sago007 2016-11-12 16:28 288
		if ((globalData.mousex>nextX) && (globalData.mousex<nextX+buttonXsize) && (globalData.mousey>nextY) && (globalData.mousey<nextY+buttonYsize)) {
c3b697c6 sago007 2016-02-07 17:30 289
			page++;
c3b697c6 sago007 2016-02-07 17:30 290
			if (page>=numberOfPages) {
c3b697c6 sago007 2016-02-07 17:30 291
				page = 0;
c3b697c6 sago007 2016-02-07 17:30 292
			}
c3b697c6 sago007 2016-02-07 17:30 293
		}
c3b697c6 sago007 2016-02-07 17:30 294
	}
16476649 Poul Sander 2022-01-09 10:29 295
}
1970-01-01 00:00 296