git repos / blockattack-game

blame: source/code/menudef.cpp

normal view · raw

593aeae4 sago007 2011-06-25 22:42 1
/*
af35c39d sago007 2013-11-16 16:37 2
===========================================================================
af35c39d sago007 2013-11-16 16:37 3
blockattack - Block Attack - Rise of the Blocks
af35c39d sago007 2013-11-16 16:37 4
Copyright (C) 2005-2013 Poul Sander
af35c39d sago007 2013-11-16 16:37 5
af35c39d sago007 2013-11-16 16:37 6
This program is free software: you can redistribute it and/or modify
af35c39d sago007 2013-11-16 16:37 7
it under the terms of the GNU General Public License as published by
af35c39d sago007 2013-11-16 16:37 8
the Free Software Foundation, either version 2 of the License, or
af35c39d sago007 2013-11-16 16:37 9
(at your option) any later version.
af35c39d sago007 2013-11-16 16:37 10
af35c39d sago007 2013-11-16 16:37 11
This program is distributed in the hope that it will be useful,
af35c39d sago007 2013-11-16 16:37 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
af35c39d sago007 2013-11-16 16:37 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
af35c39d sago007 2013-11-16 16:37 14
GNU General Public License for more details.
af35c39d sago007 2013-11-16 16:37 15
af35c39d sago007 2013-11-16 16:37 16
You should have received a copy of the GNU General Public License
af35c39d sago007 2013-11-16 16:37 17
along with this program.  If not, see http://www.gnu.org/licenses/
af35c39d sago007 2013-11-16 16:37 18
af35c39d sago007 2013-11-16 16:37 19
Source information and contacts persons can be found at
021de090 sago007 2015-12-30 18:56 20
http://blockattack.net
af35c39d sago007 2013-11-16 16:37 21
===========================================================================
593aeae4 sago007 2011-06-25 22:42 22
*/
26ddb424 sago007 2011-06-09 20:06 23
#include "global.hpp"
26ddb424 sago007 2011-06-09 20:06 24
#include <iostream>
26ddb424 sago007 2011-06-09 20:06 25
#include <stdlib.h>
26ddb424 sago007 2011-06-09 20:06 26
#include "MenuSystem.h"
c9dd376f sago007 2012-01-20 17:13 27
#include "common.h"
d8fe60bd sago007 2018-04-02 16:15 28
#include "HelpHowtoState.hpp"
bfb4fed7 Poul Sander 2022-02-14 19:35 29
#include "HelpModInfoState.hpp"
54d2d583 sago007 2018-04-05 17:52 30
#include "HelpGamepadState.hpp"
5147de4e Poul Sander 2018-05-06 12:59 31
#include "HelpAboutState.hpp"
0471a1d3 sago007 2018-05-19 10:26 32
#include "ShowFileState.hpp"
16476649 Poul Sander 2022-01-09 10:29 33
#include <fmt/core.h>
5f4ad77b Poul Sander 2023-11-29 21:01 34
#include "menudef_themes.hpp"
26ddb424 sago007 2011-06-09 20:06 35
26ddb424 sago007 2011-06-09 20:06 36
3838c95c sago007 2016-01-23 10:47 37
#if 0
26ddb424 sago007 2011-06-09 20:06 38
//Menu
ecef5838 sago007 2015-11-24 20:01 39
static void PrintHi(Button* b) {
161a010c sago007 2016-05-06 14:00 40
	cout << "Hi" <<"\n";
26ddb424 sago007 2011-06-09 20:06 41
}
3838c95c sago007 2016-01-23 10:47 42
#endif
26ddb424 sago007 2011-06-09 20:06 43
593aeae4 sago007 2011-06-25 22:42 44
//Stores the controls
ecef5838 sago007 2015-11-24 20:01 45
struct control {
1d2e2129 sago007 2015-12-23 15:41 46
	SDL_Keycode up;
1d2e2129 sago007 2015-12-23 15:41 47
	SDL_Keycode down;
1d2e2129 sago007 2015-12-23 15:41 48
	SDL_Keycode left;
1d2e2129 sago007 2015-12-23 15:41 49
	SDL_Keycode right;
1d2e2129 sago007 2015-12-23 15:41 50
	SDL_Keycode change;
1d2e2129 sago007 2015-12-23 15:41 51
	SDL_Keycode push;
593aeae4 sago007 2011-06-25 22:42 52
};
593aeae4 sago007 2011-06-25 22:42 53
26ddb424 sago007 2011-06-09 20:06 54
void OpenScoresDisplay();
593aeae4 sago007 2011-06-25 22:42 55
extern control keySettings[3];
593aeae4 sago007 2011-06-25 22:42 56
593aeae4 sago007 2011-06-25 22:42 57
//Function to return the name of a key, to be displayed...
97546fef Poul Sander 2020-08-08 17:21 58
std::string getKeyName(SDL_Keycode key) {
97546fef Poul Sander 2020-08-08 17:21 59
	std::string keyname(SDL_GetKeyName(key));
d82fedb9 Poul Sander 2018-06-20 16:48 60
	if (key == SDLK_UP) {
d82fedb9 Poul Sander 2018-06-20 16:48 61
		keyname = _("Up arrow");
d82fedb9 Poul Sander 2018-06-20 16:48 62
	}
d82fedb9 Poul Sander 2018-06-20 16:48 63
	if (key == SDLK_DOWN) {
d82fedb9 Poul Sander 2018-06-20 16:48 64
		keyname = _("Down arrow");
d82fedb9 Poul Sander 2018-06-20 16:48 65
	}
d82fedb9 Poul Sander 2018-06-20 16:48 66
	if (key == SDLK_LEFT) {
d82fedb9 Poul Sander 2018-06-20 16:48 67
		keyname = _("Left arrow");
d82fedb9 Poul Sander 2018-06-20 16:48 68
	}
d82fedb9 Poul Sander 2018-06-20 16:48 69
	if (key == SDLK_RIGHT) {
d82fedb9 Poul Sander 2018-06-20 16:48 70
		keyname = _("Right arrow");
d82fedb9 Poul Sander 2018-06-20 16:48 71
	}
d82fedb9 Poul Sander 2018-06-20 16:48 72
	if (key == SDLK_RCTRL) {
d82fedb9 Poul Sander 2018-06-20 16:48 73
		keyname = _("Right Ctrl");
d82fedb9 Poul Sander 2018-06-20 16:48 74
	}
d82fedb9 Poul Sander 2018-06-20 16:48 75
	if (key == SDLK_LCTRL) {
d82fedb9 Poul Sander 2018-06-20 16:48 76
		keyname = _("Left Ctrl");
d82fedb9 Poul Sander 2018-06-20 16:48 77
	}
d82fedb9 Poul Sander 2018-06-20 16:48 78
	if (key == SDLK_RSHIFT) {
d82fedb9 Poul Sander 2018-06-20 16:48 79
		keyname = _("Right shift");
d82fedb9 Poul Sander 2018-06-20 16:48 80
	}
d82fedb9 Poul Sander 2018-06-20 16:48 81
	if (key == SDLK_LSHIFT) {
d82fedb9 Poul Sander 2018-06-20 16:48 82
		keyname = _("Left shift");
d82fedb9 Poul Sander 2018-06-20 16:48 83
	}
d82fedb9 Poul Sander 2018-06-20 16:48 84
	if (key == SDLK_RALT) {
d82fedb9 Poul Sander 2018-06-20 16:48 85
		keyname = _("Right alt");
d82fedb9 Poul Sander 2018-06-20 16:48 86
	}
d82fedb9 Poul Sander 2018-06-20 16:48 87
	if (key == SDLK_LALT) {
d82fedb9 Poul Sander 2018-06-20 16:48 88
		keyname = _("Left alt");
d82fedb9 Poul Sander 2018-06-20 16:48 89
	}
d82fedb9 Poul Sander 2018-06-20 16:48 90
	if (key == SDLK_RETURN) {
d82fedb9 Poul Sander 2018-06-20 16:48 91
		keyname = _("Return");
d82fedb9 Poul Sander 2018-06-20 16:48 92
	}
d82fedb9 Poul Sander 2018-06-20 16:48 93
	if (key == SDLK_SPACE) {
d82fedb9 Poul Sander 2018-06-20 16:48 94
		keyname = _("Space");
d82fedb9 Poul Sander 2018-06-20 16:48 95
	}
72383a9e sago007 2016-10-30 11:56 96
	if (globalData.verboseLevel) {
b1f06489 Poul Sander 2020-08-08 17:19 97
		std::cout << key << " translated to " << keyname << "\n";
acd79baf sago007 2015-11-22 19:37 98
	}
c53e6443 sago007 2012-04-17 11:04 99
	return keyname;
593aeae4 sago007 2011-06-25 22:42 100
}
593aeae4 sago007 2011-06-25 22:42 101
ecef5838 sago007 2015-11-24 20:01 102
class Button_changekey : public Button {
593aeae4 sago007 2011-06-25 22:42 103
private:
1d2e2129 sago007 2015-12-23 15:41 104
	SDL_Keycode* m_key2change;
97546fef Poul Sander 2020-08-08 17:21 105
	std::string m_keyname;
593aeae4 sago007 2011-06-25 22:42 106
public:
7192940a Poul Sander 2020-08-08 17:18 107
	Button_changekey(SDL_Keycode* key, const char* keyname);
5f8ce673 Poul Sander 2021-06-05 22:18 108
	virtual void doAction() override;
593aeae4 sago007 2011-06-25 22:42 109
};
593aeae4 sago007 2011-06-25 22:42 110
6710d462 sago007 2012-05-12 17:23 111
7192940a Poul Sander 2020-08-08 17:18 112
Button_changekey::Button_changekey(SDL_Keycode* key, const char* keyname)
3674f7f0 sago007 2020-07-12 12:16 113
	: m_key2change{key}, m_keyname{keyname} {
c53e6443 sago007 2012-04-17 11:04 114
	setLabel(m_keyname+" : "+getKeyName(*m_key2change));
593aeae4 sago007 2011-06-25 22:42 115
}
593aeae4 sago007 2011-06-25 22:42 116
ecef5838 sago007 2015-11-24 20:01 117
void Button_changekey::doAction() {
c53e6443 sago007 2012-04-17 11:04 118
	SDL_Event event;
c53e6443 sago007 2012-04-17 11:04 119
c53e6443 sago007 2012-04-17 11:04 120
	bool finnish = false;
ecef5838 sago007 2015-11-24 20:01 121
	while (!finnish) {
c53e6443 sago007 2012-04-17 11:04 122
		SDL_Delay(10);
ecef5838 sago007 2015-11-24 20:01 123
		while ( SDL_PollEvent(&event) ) {
ecef5838 sago007 2015-11-24 20:01 124
			if (event.type == SDL_KEYDOWN) {
acd79baf sago007 2015-11-22 19:37 125
				if (event.key.keysym.sym != SDLK_ESCAPE) {
c53e6443 sago007 2012-04-17 11:04 126
					*m_key2change = event.key.keysym.sym;
acd79baf sago007 2015-11-22 19:37 127
				}
c53e6443 sago007 2012-04-17 11:04 128
				finnish = true;
c53e6443 sago007 2012-04-17 11:04 129
			}
c53e6443 sago007 2012-04-17 11:04 130
		}
c53e6443 sago007 2012-04-17 11:04 131
	}
c53e6443 sago007 2012-04-17 11:04 132
	setLabel(m_keyname+" : "+getKeyName(*m_key2change));
593aeae4 sago007 2011-06-25 22:42 133
}
26ddb424 sago007 2011-06-09 20:06 134
c99935b0 Poul Sander 2021-08-28 13:13 135
class Button_confirmVolume : public Button {
55e33610 Poul Sander 2022-01-09 11:45 136
private:
c99935b0 Poul Sander 2021-08-28 13:13 137
	std::string cvar="";
c99935b0 Poul Sander 2021-08-28 13:13 138
	mutable std::string volumeLabel; /*used for cache*/
55e33610 Poul Sander 2022-01-09 11:45 139
public:
493079d1 Poul Sander 2021-10-20 21:03 140
	explicit Button_confirmVolume(const char* cvar);
c99935b0 Poul Sander 2021-08-28 13:13 141
	virtual void doAction() override { /*Do nothing. Equal to choose "back". */ };
c99935b0 Poul Sander 2021-08-28 13:13 142
	virtual const std::string& getLabel() const override;
c99935b0 Poul Sander 2021-08-28 13:13 143
};
c99935b0 Poul Sander 2021-08-28 13:13 144
c99935b0 Poul Sander 2021-08-28 13:13 145
Button_confirmVolume::Button_confirmVolume(const char* cvar) : cvar{cvar} {
c99935b0 Poul Sander 2021-08-28 13:13 146
	this->setPopOnRun(true);
c99935b0 Poul Sander 2021-08-28 13:13 147
}
c99935b0 Poul Sander 2021-08-28 13:13 148
c99935b0 Poul Sander 2021-08-28 13:13 149
const std::string& Button_confirmVolume::getLabel() const {
c99935b0 Poul Sander 2021-08-28 13:13 150
	int volumePct = Config::getInstance()->getInt(cvar)*100.0/MIX_MAX_VOLUME;
16476649 Poul Sander 2022-01-09 10:29 151
	this->volumeLabel = fmt::format(_("Volume: {}%"), volumePct); //  std::string(_("Volume: "))+ std::to_string(volumePct)+"%" ;
c99935b0 Poul Sander 2021-08-28 13:13 152
	return volumeLabel;
c99935b0 Poul Sander 2021-08-28 13:13 153
}
5f8ce673 Poul Sander 2021-06-05 22:18 154
c99935b0 Poul Sander 2021-08-28 13:13 155
class Button_increaseVolume : public Button {
55e33610 Poul Sander 2022-01-09 11:45 156
private:
c99935b0 Poul Sander 2021-08-28 13:13 157
	std::string cvar="";
c99935b0 Poul Sander 2021-08-28 13:13 158
	int incrementValue = 1;
c99935b0 Poul Sander 2021-08-28 13:13 159
	int lowerLimit = 0;
c99935b0 Poul Sander 2021-08-28 13:13 160
	int upperLimit = MIX_MAX_VOLUME;
55e33610 Poul Sander 2022-01-09 11:45 161
public:
c99935b0 Poul Sander 2021-08-28 13:13 162
	Button_increaseVolume(const char* cvar, int incrementValue);
5f8ce673 Poul Sander 2021-06-05 22:18 163
	virtual void doAction() override;
5f8ce673 Poul Sander 2021-06-05 22:18 164
};
5f8ce673 Poul Sander 2021-06-05 22:18 165
c99935b0 Poul Sander 2021-08-28 13:13 166
Button_increaseVolume::Button_increaseVolume(const char* cvar, int incrementValue)
c99935b0 Poul Sander 2021-08-28 13:13 167
	: cvar{cvar},incrementValue{incrementValue} {
55e33610 Poul Sander 2022-01-09 11:45 168
	char prefix = '+';
55e33610 Poul Sander 2022-01-09 11:45 169
	double value = incrementValue;
55e33610 Poul Sander 2022-01-09 11:45 170
	if (incrementValue<0) {
55e33610 Poul Sander 2022-01-09 11:45 171
		prefix = '-';
55e33610 Poul Sander 2022-01-09 11:45 172
		value = -incrementValue;
55e33610 Poul Sander 2022-01-09 11:45 173
	}
55e33610 Poul Sander 2022-01-09 11:45 174
	value = value*100.0/MIX_MAX_VOLUME;
55e33610 Poul Sander 2022-01-09 11:45 175
	setLabel(fmt::format("{}{:.2f}", prefix, value));
c99935b0 Poul Sander 2021-08-28 13:13 176
}
c99935b0 Poul Sander 2021-08-28 13:13 177
c99935b0 Poul Sander 2021-08-28 13:13 178
void Button_increaseVolume::doAction() {
c99935b0 Poul Sander 2021-08-28 13:13 179
	int newValue = Config::getInstance()->getInt(cvar)+incrementValue;
c99935b0 Poul Sander 2021-08-28 13:13 180
	if (newValue<lowerLimit) {
c99935b0 Poul Sander 2021-08-28 13:13 181
		newValue = lowerLimit;
5f8ce673 Poul Sander 2021-06-05 22:18 182
	}
c99935b0 Poul Sander 2021-08-28 13:13 183
	if (newValue>upperLimit) {
c99935b0 Poul Sander 2021-08-28 13:13 184
		newValue = upperLimit;
5f8ce673 Poul Sander 2021-06-05 22:18 185
	}
c99935b0 Poul Sander 2021-08-28 13:13 186
	Config::getInstance()->setInt(cvar, newValue);
5f8ce673 Poul Sander 2021-06-05 22:18 187
}
5f8ce673 Poul Sander 2021-06-05 22:18 188
c99935b0 Poul Sander 2021-08-28 13:13 189
class Button_testSound : public Button {
55e33610 Poul Sander 2022-01-09 11:45 190
public:
c99935b0 Poul Sander 2021-08-28 13:13 191
	Button_testSound();
c99935b0 Poul Sander 2021-08-28 13:13 192
	virtual void doAction() override;
c99935b0 Poul Sander 2021-08-28 13:13 193
};
c99935b0 Poul Sander 2021-08-28 13:13 194
c99935b0 Poul Sander 2021-08-28 13:13 195
Button_testSound::Button_testSound() {
c99935b0 Poul Sander 2021-08-28 13:13 196
	setLabel(_("Test sound"));
c99935b0 Poul Sander 2021-08-28 13:13 197
}
c99935b0 Poul Sander 2021-08-28 13:13 198
c99935b0 Poul Sander 2021-08-28 13:13 199
void Button_testSound::doAction() {
c99935b0 Poul Sander 2021-08-28 13:13 200
	sago::SoundHandler testSound = globalData.spriteHolder->GetDataHolder().getSoundHandler("pop");
c99935b0 Poul Sander 2021-08-28 13:13 201
	Mix_VolumeChunk(testSound.get(), Config::getInstance()->getInt("volume_sound"));
c99935b0 Poul Sander 2021-08-28 13:13 202
	Mix_PlayChannel(1, testSound.get(), 0);
c99935b0 Poul Sander 2021-08-28 13:13 203
}
c99935b0 Poul Sander 2021-08-28 13:13 204
c99935b0 Poul Sander 2021-08-28 13:13 205
class Button_testMusic : public Button {
55e33610 Poul Sander 2022-01-09 11:45 206
public:
c99935b0 Poul Sander 2021-08-28 13:13 207
	Button_testMusic();
c99935b0 Poul Sander 2021-08-28 13:13 208
	virtual void doAction() override;
c99935b0 Poul Sander 2021-08-28 13:13 209
};
c99935b0 Poul Sander 2021-08-28 13:13 210
c99935b0 Poul Sander 2021-08-28 13:13 211
Button_testMusic::Button_testMusic() {
c99935b0 Poul Sander 2021-08-28 13:13 212
	setLabel(_("Test music"));
c99935b0 Poul Sander 2021-08-28 13:13 213
}
c99935b0 Poul Sander 2021-08-28 13:13 214
c99935b0 Poul Sander 2021-08-28 13:13 215
void Button_testMusic::doAction() {
c99935b0 Poul Sander 2021-08-28 13:13 216
	Mix_VolumeMusic(Config::getInstance()->getInt("volume_music"));
c99935b0 Poul Sander 2021-08-28 13:13 217
	sago::MusicHandler bgMusic = globalData.spriteHolder->GetDataHolder().getMusicHandler("bgmusic");
c99935b0 Poul Sander 2021-08-28 13:13 218
	Mix_PlayMusic(bgMusic.get(), -1);
5f8ce673 Poul Sander 2021-06-05 22:18 219
}
5f8ce673 Poul Sander 2021-06-05 22:18 220
517ed886 Poul Sander 2025-12-14 14:38 221
// Sound volume button with adjustment controls
517ed886 Poul Sander 2025-12-14 14:38 222
class Button_soundVolume : public ButtonWithAdjustment {
517ed886 Poul Sander 2025-12-14 14:38 223
private:
517ed886 Poul Sander 2025-12-14 14:38 224
	mutable std::string volumeLabel;
517ed886 Poul Sander 2025-12-14 14:38 225
	int incrementValue = 5;
517ed886 Poul Sander 2025-12-14 14:38 226
public:
517ed886 Poul Sander 2025-12-14 14:38 227
	Button_soundVolume();
517ed886 Poul Sander 2025-12-14 14:38 228
	virtual void doAction() override;
517ed886 Poul Sander 2025-12-14 14:38 229
	virtual void doLeft() override;
517ed886 Poul Sander 2025-12-14 14:38 230
	virtual void doRight() override;
517ed886 Poul Sander 2025-12-14 14:38 231
	virtual const std::string& getLabel() const override;
517ed886 Poul Sander 2025-12-14 14:38 232
};
517ed886 Poul Sander 2025-12-14 14:38 233
517ed886 Poul Sander 2025-12-14 14:38 234
Button_soundVolume::Button_soundVolume() {
517ed886 Poul Sander 2025-12-14 14:38 235
	standardButton.setSurfaces();
517ed886 Poul Sander 2025-12-14 14:38 236
}
517ed886 Poul Sander 2025-12-14 14:38 237
517ed886 Poul Sander 2025-12-14 14:38 238
void Button_soundVolume::doAction() {
517ed886 Poul Sander 2025-12-14 14:38 239
	// Test sound
517ed886 Poul Sander 2025-12-14 14:38 240
	sago::SoundHandler testSound = globalData.spriteHolder->GetDataHolder().getSoundHandler("pop");
517ed886 Poul Sander 2025-12-14 14:38 241
	Mix_VolumeChunk(testSound.get(), Config::getInstance()->getInt("volume_sound"));
517ed886 Poul Sander 2025-12-14 14:38 242
	Mix_PlayChannel(1, testSound.get(), 0);
517ed886 Poul Sander 2025-12-14 14:38 243
}
517ed886 Poul Sander 2025-12-14 14:38 244
517ed886 Poul Sander 2025-12-14 14:38 245
void Button_soundVolume::doLeft() {
517ed886 Poul Sander 2025-12-14 14:38 246
	// Decrease volume
517ed886 Poul Sander 2025-12-14 14:38 247
	int newValue = Config::getInstance()->getInt("volume_sound") - incrementValue;
517ed886 Poul Sander 2025-12-14 14:38 248
	if (newValue < 0) {
517ed886 Poul Sander 2025-12-14 14:38 249
		newValue = 0;
517ed886 Poul Sander 2025-12-14 14:38 250
	}
517ed886 Poul Sander 2025-12-14 14:38 251
	Config::getInstance()->setInt("volume_sound", newValue);
c4ae70b7 Poul Sander 2025-12-14 15:05 252
	leftButtonMarkTime = SDL_GetTicks();
517ed886 Poul Sander 2025-12-14 14:38 253
}
517ed886 Poul Sander 2025-12-14 14:38 254
517ed886 Poul Sander 2025-12-14 14:38 255
void Button_soundVolume::doRight() {
517ed886 Poul Sander 2025-12-14 14:38 256
	// Increase volume
517ed886 Poul Sander 2025-12-14 14:38 257
	int newValue = Config::getInstance()->getInt("volume_sound") + incrementValue;
517ed886 Poul Sander 2025-12-14 14:38 258
	if (newValue > MIX_MAX_VOLUME) {
517ed886 Poul Sander 2025-12-14 14:38 259
		newValue = MIX_MAX_VOLUME;
517ed886 Poul Sander 2025-12-14 14:38 260
	}
517ed886 Poul Sander 2025-12-14 14:38 261
	Config::getInstance()->setInt("volume_sound", newValue);
c4ae70b7 Poul Sander 2025-12-14 15:05 262
	rightButtonMarkTime = SDL_GetTicks();
517ed886 Poul Sander 2025-12-14 14:38 263
}
517ed886 Poul Sander 2025-12-14 14:38 264
517ed886 Poul Sander 2025-12-14 14:38 265
const std::string& Button_soundVolume::getLabel() const {
517ed886 Poul Sander 2025-12-14 14:38 266
	int volumePct = Config::getInstance()->getInt("volume_sound")*100.0/MIX_MAX_VOLUME;
517ed886 Poul Sander 2025-12-14 14:38 267
	volumeLabel = fmt::format(_("Sound: {}"), volumePct)+"%";
517ed886 Poul Sander 2025-12-14 14:38 268
	return volumeLabel;
517ed886 Poul Sander 2025-12-14 14:38 269
}
517ed886 Poul Sander 2025-12-14 14:38 270
517ed886 Poul Sander 2025-12-14 14:38 271
// Music volume button with adjustment controls
517ed886 Poul Sander 2025-12-14 14:38 272
class Button_musicVolume : public ButtonWithAdjustment {
517ed886 Poul Sander 2025-12-14 14:38 273
private:
517ed886 Poul Sander 2025-12-14 14:38 274
	mutable std::string volumeLabel;
517ed886 Poul Sander 2025-12-14 14:38 275
	int incrementValue = 5;
517ed886 Poul Sander 2025-12-14 14:38 276
public:
517ed886 Poul Sander 2025-12-14 14:38 277
	Button_musicVolume();
517ed886 Poul Sander 2025-12-14 14:38 278
	virtual void doAction() override;
517ed886 Poul Sander 2025-12-14 14:38 279
	virtual void doLeft() override;
517ed886 Poul Sander 2025-12-14 14:38 280
	virtual void doRight() override;
517ed886 Poul Sander 2025-12-14 14:38 281
	virtual const std::string& getLabel() const override;
517ed886 Poul Sander 2025-12-14 14:38 282
};
517ed886 Poul Sander 2025-12-14 14:38 283
517ed886 Poul Sander 2025-12-14 14:38 284
Button_musicVolume::Button_musicVolume() {
517ed886 Poul Sander 2025-12-14 14:38 285
	standardButton.setSurfaces();
517ed886 Poul Sander 2025-12-14 14:38 286
}
517ed886 Poul Sander 2025-12-14 14:38 287
517ed886 Poul Sander 2025-12-14 14:38 288
void Button_musicVolume::doAction() {
517ed886 Poul Sander 2025-12-14 14:38 289
	// Test music
517ed886 Poul Sander 2025-12-14 14:38 290
	Mix_VolumeMusic(Config::getInstance()->getInt("volume_music"));
517ed886 Poul Sander 2025-12-14 14:38 291
	sago::MusicHandler bgMusic = globalData.spriteHolder->GetDataHolder().getMusicHandler("bgmusic");
517ed886 Poul Sander 2025-12-14 14:38 292
	Mix_PlayMusic(bgMusic.get(), -1);
517ed886 Poul Sander 2025-12-14 14:38 293
}
517ed886 Poul Sander 2025-12-14 14:38 294
517ed886 Poul Sander 2025-12-14 14:38 295
void Button_musicVolume::doLeft() {
517ed886 Poul Sander 2025-12-14 14:38 296
	// Decrease volume
517ed886 Poul Sander 2025-12-14 14:38 297
	int newValue = Config::getInstance()->getInt("volume_music") - incrementValue;
517ed886 Poul Sander 2025-12-14 14:38 298
	if (newValue < 0) {
517ed886 Poul Sander 2025-12-14 14:38 299
		newValue = 0;
517ed886 Poul Sander 2025-12-14 14:38 300
	}
517ed886 Poul Sander 2025-12-14 14:38 301
	Config::getInstance()->setInt("volume_music", newValue);
c4ae70b7 Poul Sander 2025-12-14 15:05 302
	leftButtonMarkTime = SDL_GetTicks();
517ed886 Poul Sander 2025-12-14 14:38 303
}
517ed886 Poul Sander 2025-12-14 14:38 304
517ed886 Poul Sander 2025-12-14 14:38 305
void Button_musicVolume::doRight() {
517ed886 Poul Sander 2025-12-14 14:38 306
	// Increase volume
517ed886 Poul Sander 2025-12-14 14:38 307
	int newValue = Config::getInstance()->getInt("volume_music") + incrementValue;
517ed886 Poul Sander 2025-12-14 14:38 308
	if (newValue > MIX_MAX_VOLUME) {
517ed886 Poul Sander 2025-12-14 14:38 309
		newValue = MIX_MAX_VOLUME;
517ed886 Poul Sander 2025-12-14 14:38 310
	}
517ed886 Poul Sander 2025-12-14 14:38 311
	Config::getInstance()->setInt("volume_music", newValue);
c4ae70b7 Poul Sander 2025-12-14 15:05 312
	rightButtonMarkTime = SDL_GetTicks();
517ed886 Poul Sander 2025-12-14 14:38 313
}
517ed886 Poul Sander 2025-12-14 14:38 314
517ed886 Poul Sander 2025-12-14 14:38 315
const std::string& Button_musicVolume::getLabel() const {
517ed886 Poul Sander 2025-12-14 14:38 316
	int volumePct = Config::getInstance()->getInt("volume_music")*100.0/MIX_MAX_VOLUME;
517ed886 Poul Sander 2025-12-14 14:38 317
	volumeLabel = fmt::format(_("Music: {}"), volumePct)+"%";
517ed886 Poul Sander 2025-12-14 14:38 318
	return volumeLabel;
517ed886 Poul Sander 2025-12-14 14:38 319
}
517ed886 Poul Sander 2025-12-14 14:38 320
26ddb424 sago007 2011-06-09 20:06 321
4379ec19 Poul Sander 2019-01-30 18:27 322
static void runSinglePlayerEndless0() {
de81e07d sago007 2016-07-10 20:22 323
	runGame(Gametype::SinglePlayerEndless, 0);
26ddb424 sago007 2011-06-09 20:06 324
}
26ddb424 sago007 2011-06-09 20:06 325
4379ec19 Poul Sander 2019-01-30 18:27 326
static void runSinglePlayerEndless1() {
4379ec19 Poul Sander 2019-01-30 18:27 327
	runGame(Gametype::SinglePlayerEndless, 1);
4379ec19 Poul Sander 2019-01-30 18:27 328
}
4379ec19 Poul Sander 2019-01-30 18:27 329
4379ec19 Poul Sander 2019-01-30 18:27 330
static void runSinglePlayerEndless2() {
4379ec19 Poul Sander 2019-01-30 18:27 331
	runGame(Gametype::SinglePlayerEndless, 2);
4379ec19 Poul Sander 2019-01-30 18:27 332
}
4379ec19 Poul Sander 2019-01-30 18:27 333
4379ec19 Poul Sander 2019-01-30 18:27 334
static void runSinglePlayerEndless3() {
4379ec19 Poul Sander 2019-01-30 18:27 335
	runGame(Gametype::SinglePlayerEndless, 3);
4379ec19 Poul Sander 2019-01-30 18:27 336
}
4379ec19 Poul Sander 2019-01-30 18:27 337
4379ec19 Poul Sander 2019-01-30 18:27 338
static void runSinglePlayerEndless4() {
4379ec19 Poul Sander 2019-01-30 18:27 339
	runGame(Gametype::SinglePlayerEndless, 4);
4379ec19 Poul Sander 2019-01-30 18:27 340
}
4379ec19 Poul Sander 2019-01-30 18:27 341
4379ec19 Poul Sander 2019-01-30 18:27 342
static void runSinglePlayerEndless() {
4379ec19 Poul Sander 2019-01-30 18:27 343
	Menu sp(globalData.screen,_("Single Player Endless"),true);
4379ec19 Poul Sander 2019-01-30 18:27 344
	Button d0,d1,d2,d3,d4;
4379ec19 Poul Sander 2019-01-30 18:27 345
	d0.setPopOnRun(true);
4379ec19 Poul Sander 2019-01-30 18:27 346
	d1.setPopOnRun(true);
4379ec19 Poul Sander 2019-01-30 18:27 347
	d2.setPopOnRun(true);
4379ec19 Poul Sander 2019-01-30 18:27 348
	d3.setPopOnRun(true);
4379ec19 Poul Sander 2019-01-30 18:27 349
	d4.setPopOnRun(true);
4379ec19 Poul Sander 2019-01-30 18:27 350
	d0.setLabel(_("Slow"));
4379ec19 Poul Sander 2019-01-30 18:27 351
	d1.setLabel(_("Fast"));
4379ec19 Poul Sander 2019-01-30 18:27 352
	d2.setLabel(_("Faster"));
4379ec19 Poul Sander 2019-01-30 18:27 353
	d3.setLabel(_("Even faster"));
4379ec19 Poul Sander 2019-01-30 18:27 354
	d4.setLabel(_("Fastest"));
4379ec19 Poul Sander 2019-01-30 18:27 355
	d0.setAction(runSinglePlayerEndless0);
4379ec19 Poul Sander 2019-01-30 18:27 356
	d1.setAction(runSinglePlayerEndless1);
4379ec19 Poul Sander 2019-01-30 18:27 357
	d2.setAction(runSinglePlayerEndless2);
4379ec19 Poul Sander 2019-01-30 18:27 358
	d3.setAction(runSinglePlayerEndless3);
4379ec19 Poul Sander 2019-01-30 18:27 359
	d4.setAction(runSinglePlayerEndless4);
4379ec19 Poul Sander 2019-01-30 18:27 360
	sp.addButton(&d0);
4379ec19 Poul Sander 2019-01-30 18:27 361
	sp.addButton(&d1);
4379ec19 Poul Sander 2019-01-30 18:27 362
	sp.addButton(&d2);
4379ec19 Poul Sander 2019-01-30 18:27 363
	sp.addButton(&d3);
4379ec19 Poul Sander 2019-01-30 18:27 364
	sp.addButton(&d4);
4379ec19 Poul Sander 2019-01-30 18:27 365
	RunGameState(sp);
4379ec19 Poul Sander 2019-01-30 18:27 366
}
4379ec19 Poul Sander 2019-01-30 18:27 367
29edda2d sago007 2016-10-08 18:06 368
static void runSinglePlayerTimeTrial() {
de81e07d sago007 2016-07-10 20:22 369
	runGame(Gametype::SinglePlayerTimeTrial, 0);
26ddb424 sago007 2011-06-09 20:06 370
}
26ddb424 sago007 2011-06-09 20:06 371
29edda2d sago007 2016-10-08 18:06 372
static void runStageClear() {
de81e07d sago007 2016-07-10 20:22 373
	runGame(Gametype::StageClear, 0);
aede0664 sago007 2012-04-19 19:45 374
}
aede0664 sago007 2012-04-19 19:45 375
29edda2d sago007 2016-10-08 18:06 376
static void runSinglePlayerPuzzle() {
de81e07d sago007 2016-07-10 20:22 377
	runGame(Gametype::Puzzle, 0);
26ddb424 sago007 2011-06-09 20:06 378
}
26ddb424 sago007 2011-06-09 20:06 379
29edda2d sago007 2016-10-08 18:06 380
class RunSinglePlayerVsButton : public Button {
29edda2d sago007 2016-10-08 18:06 381
	virtual void doAction() override {
29edda2d sago007 2016-10-08 18:06 382
		runGame(Gametype::SinglePlayerVs, iGeneric1);
29edda2d sago007 2016-10-08 18:06 383
	}
29edda2d sago007 2016-10-08 18:06 384
};
26ddb424 sago007 2011-06-09 20:06 385
29edda2d sago007 2016-10-08 18:06 386
static void runTwoPlayerTimeTrial() {
de81e07d sago007 2016-07-10 20:22 387
	runGame(Gametype::TwoPlayerTimeTrial, 0);
b0222eff sago007 2012-04-22 15:06 388
}
b0222eff sago007 2012-04-22 15:06 389
29edda2d sago007 2016-10-08 18:06 390
static void runTwoPlayerVs() {
de81e07d sago007 2016-07-10 20:22 391
	runGame(Gametype::TwoPlayerVs, 0);
b0222eff sago007 2012-04-22 15:06 392
}
b0222eff sago007 2012-04-22 15:06 393
1029dfed Poul Sander 2019-03-13 17:22 394
static void SetAlwaysSoftwareLabel(Button* b) {
1029dfed Poul Sander 2019-03-13 17:22 395
	b->setLabel(Config::getInstance()->getInt("always-software")?
9c7fa9a1 sago007 2020-06-27 22:09 396
	            _("Always use software render: On")
9c7fa9a1 sago007 2020-06-27 22:09 397
	            : _("Always use software render: Off"));
1029dfed Poul Sander 2019-03-13 17:22 398
}
1029dfed Poul Sander 2019-03-13 17:22 399
5f8ce673 Poul Sander 2021-06-05 22:18 400
static void runSetMusicVolume(const char* cvar, const char* header) {
5f8ce673 Poul Sander 2021-06-05 22:18 401
	Menu volumeMenu(globalData.screen, header, true);
c99935b0 Poul Sander 2021-08-28 13:13 402
	Button_confirmVolume bConfirm(cvar);
c99935b0 Poul Sander 2021-08-28 13:13 403
	Button_increaseVolume plus5(cvar, 5);
c99935b0 Poul Sander 2021-08-28 13:13 404
	Button_increaseVolume minus5(cvar, -5);
c99935b0 Poul Sander 2021-08-28 13:13 405
	Button_increaseVolume plus1(cvar, 1);
c99935b0 Poul Sander 2021-08-28 13:13 406
	Button_increaseVolume minus1(cvar, -1);
c99935b0 Poul Sander 2021-08-28 13:13 407
	volumeMenu.addButton(&bConfirm);
c99935b0 Poul Sander 2021-08-28 13:13 408
	volumeMenu.addButton(&plus5);
c99935b0 Poul Sander 2021-08-28 13:13 409
	volumeMenu.addButton(&minus5);
c99935b0 Poul Sander 2021-08-28 13:13 410
	volumeMenu.addButton(&plus1);
c99935b0 Poul Sander 2021-08-28 13:13 411
	volumeMenu.addButton(&minus1);
c99935b0 Poul Sander 2021-08-28 13:13 412
	Button_testSound bTestSound;
c99935b0 Poul Sander 2021-08-28 13:13 413
	volumeMenu.addButton(&bTestSound);
c99935b0 Poul Sander 2021-08-28 13:13 414
	Button_testMusic bTestMusic;
c99935b0 Poul Sander 2021-08-28 13:13 415
	volumeMenu.addButton(&bTestMusic);
5f8ce673 Poul Sander 2021-06-05 22:18 416
	RunGameState(volumeMenu);
5f8ce673 Poul Sander 2021-06-05 22:18 417
}
5f8ce673 Poul Sander 2021-06-05 22:18 418
e17d4be2 Poul Sander 2019-03-13 17:29 419
static void SetMusicLabel (Button* b) {
4482071a Poul Sander 2021-06-05 15:07 420
	if (globalData.MusicEnabled) {
4482071a Poul Sander 2021-06-05 15:07 421
		double volume = Config::getInstance()->getInt("volume_music");
4482071a Poul Sander 2021-06-05 15:07 422
		int volumePct = volume*100.0/MIX_MAX_VOLUME;
4482071a Poul Sander 2021-06-05 15:07 423
		b->setLabel(std::string(_("Music: "))+ std::to_string(volumePct)+"%" );
4482071a Poul Sander 2021-06-05 15:07 424
	}
4482071a Poul Sander 2021-06-05 15:07 425
	else {
4482071a Poul Sander 2021-06-05 15:07 426
		b->setLabel(_("Music: Off") );
4482071a Poul Sander 2021-06-05 15:07 427
	}
e17d4be2 Poul Sander 2019-03-13 17:29 428
}
e17d4be2 Poul Sander 2019-03-13 17:29 429
e17d4be2 Poul Sander 2019-03-13 17:29 430
static void SetSoundLabel (Button* b) {
4482071a Poul Sander 2021-06-05 15:07 431
	if (globalData.SoundEnabled) {
4482071a Poul Sander 2021-06-05 15:07 432
		double volume = Config::getInstance()->getInt("volume_sound");
4482071a Poul Sander 2021-06-05 15:07 433
		int volumePct = volume*100.0/MIX_MAX_VOLUME;
4482071a Poul Sander 2021-06-05 15:07 434
		b->setLabel(std::string(_("Sound: "))+ std::to_string(volumePct)+"%" );
4482071a Poul Sander 2021-06-05 15:07 435
	}
4482071a Poul Sander 2021-06-05 15:07 436
	else {
4482071a Poul Sander 2021-06-05 15:07 437
		b->setLabel(_("Sound: Off") );
4482071a Poul Sander 2021-06-05 15:07 438
	}
e17d4be2 Poul Sander 2019-03-13 17:29 439
}
e17d4be2 Poul Sander 2019-03-13 17:29 440
e17d4be2 Poul Sander 2019-03-13 17:29 441
static void SetFullscreenLabel (Button* b) {
e17d4be2 Poul Sander 2019-03-13 17:29 442
	b->setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
e17d4be2 Poul Sander 2019-03-13 17:29 443
}
e17d4be2 Poul Sander 2019-03-13 17:29 444
1b403c4a Poul Sander 2024-04-14 14:57 445
static void SetBlockVariationLabel (Button* b) {
1b403c4a Poul Sander 2024-04-14 14:57 446
	b->setLabel(_("Block variants: ")+std::to_string(Config::getInstance()->getInt("basic_block_variants", 6)) );
1b403c4a Poul Sander 2024-04-14 14:57 447
}
1b403c4a Poul Sander 2024-04-14 14:57 448
1029dfed Poul Sander 2019-03-13 17:22 449
class AlwaysSoftwareRenderButton : public Button {
1029dfed Poul Sander 2019-03-13 17:22 450
	virtual void doAction() override {
1029dfed Poul Sander 2019-03-13 17:22 451
		Config::getInstance()->setInt("always-software", !Config::getInstance()->getInt("always-software"));
1029dfed Poul Sander 2019-03-13 17:22 452
		SetAlwaysSoftwareLabel(this);
1029dfed Poul Sander 2019-03-13 17:22 453
	}
1029dfed Poul Sander 2019-03-13 17:22 454
};
1029dfed Poul Sander 2019-03-13 17:22 455
29edda2d sago007 2016-10-08 18:06 456
class MusicButton : public Button {
29edda2d sago007 2016-10-08 18:06 457
	virtual void doAction() override {
5f8ce673 Poul Sander 2021-06-05 22:18 458
		runSetMusicVolume("volume_music", _("Music volume"));
5f8ce673 Poul Sander 2021-06-05 22:18 459
		globalData.MusicEnabled = (Config::getInstance()->getInt("volume_music") != 0);
e17d4be2 Poul Sander 2019-03-13 17:29 460
		SetMusicLabel(this);
29edda2d sago007 2016-10-08 18:06 461
	}
29edda2d sago007 2016-10-08 18:06 462
};
26ddb424 sago007 2011-06-09 20:06 463
29edda2d sago007 2016-10-08 18:06 464
class SoundButton : public Button {
29edda2d sago007 2016-10-08 18:06 465
	virtual void doAction() override {
5f8ce673 Poul Sander 2021-06-05 22:18 466
		runSetMusicVolume("volume_sound", _("Sound volume"));
5f8ce673 Poul Sander 2021-06-05 22:18 467
		globalData.MusicEnabled = (Config::getInstance()->getInt("volume_sound") != 0);
e17d4be2 Poul Sander 2019-03-13 17:29 468
		SetSoundLabel(this);
29edda2d sago007 2016-10-08 18:06 469
	}
29edda2d sago007 2016-10-08 18:06 470
};
29edda2d sago007 2016-10-08 18:06 471
29edda2d sago007 2016-10-08 18:06 472
class FullscreenButton : public Button {
29edda2d sago007 2016-10-08 18:06 473
	virtual void doAction() override {
72383a9e sago007 2016-10-30 11:56 474
		globalData.bFullscreen = !globalData.bFullscreen;
e17d4be2 Poul Sander 2019-03-13 17:29 475
		SetFullscreenLabel(this);
29edda2d sago007 2016-10-08 18:06 476
		ResetFullscreen();
29edda2d sago007 2016-10-08 18:06 477
	}
29edda2d sago007 2016-10-08 18:06 478
};
26ddb424 sago007 2011-06-09 20:06 479
1b403c4a Poul Sander 2024-04-14 14:57 480
class BlockVariantButton : public Button {
1b403c4a Poul Sander 2024-04-14 14:57 481
	virtual void doAction() override {
1b403c4a Poul Sander 2024-04-14 14:57 482
		int blockVariation = Config::getInstance()->getInt("basic_block_variants", 6);
1b403c4a Poul Sander 2024-04-14 14:57 483
		blockVariation++;
1b403c4a Poul Sander 2024-04-14 14:57 484
		if (blockVariation>6) {
1b403c4a Poul Sander 2024-04-14 14:57 485
			blockVariation = 5;
1b403c4a Poul Sander 2024-04-14 14:57 486
		}
1b403c4a Poul Sander 2024-04-14 14:57 487
		Config::getInstance()->setInt("basic_block_variants", blockVariation);
1b403c4a Poul Sander 2024-04-14 14:57 488
		SetBlockVariationLabel(this);
1b403c4a Poul Sander 2024-04-14 14:57 489
	}
1b403c4a Poul Sander 2024-04-14 14:57 490
};
1b403c4a Poul Sander 2024-04-14 14:57 491
29edda2d sago007 2016-10-08 18:06 492
static void buttonActionPlayer1Name() {
72383a9e sago007 2016-10-30 11:56 493
	if ( OpenDialogbox(200, 100, globalData.player1name, _("Enter player 1 name:")) ) {
acd79baf sago007 2015-11-22 19:37 494
		return;    //must save if true
acd79baf sago007 2015-11-22 19:37 495
	}
26ddb424 sago007 2011-06-09 20:06 496
}
26ddb424 sago007 2011-06-09 20:06 497
29edda2d sago007 2016-10-08 18:06 498
static void buttonActionPlayer2Name() {
72383a9e sago007 2016-10-30 11:56 499
	if ( OpenDialogbox(200, 100, globalData.player2name, _("Enter player 2 name:")) ) {
acd79baf sago007 2015-11-22 19:37 500
		return;    //must save if true
acd79baf sago007 2015-11-22 19:37 501
	}
26ddb424 sago007 2011-06-09 20:06 502
}
26ddb424 sago007 2011-06-09 20:06 503
29edda2d sago007 2016-10-08 18:06 504
static void buttonActionHighscores() {
c53e6443 sago007 2012-04-17 11:04 505
	OpenScoresDisplay();
26ddb424 sago007 2011-06-09 20:06 506
}
26ddb424 sago007 2011-06-09 20:06 507
ecef5838 sago007 2015-11-24 20:01 508
static void ChangeKeysMenu(long playernumber) {
72383a9e sago007 2016-10-30 11:56 509
	Menu km(globalData.screen,_("Change key bindings"),true);
c53e6443 sago007 2012-04-17 11:04 510
	Button_changekey bLeft(&keySettings[playernumber].left,_("Left") );
c53e6443 sago007 2012-04-17 11:04 511
	Button_changekey bRight(&keySettings[playernumber].right,_("Right") );
c53e6443 sago007 2012-04-17 11:04 512
	Button_changekey bUp(&keySettings[playernumber].up,_("Up") );
c53e6443 sago007 2012-04-17 11:04 513
	Button_changekey bDown(&keySettings[playernumber].down,_("Down") );
c53e6443 sago007 2012-04-17 11:04 514
	Button_changekey bPush(&keySettings[playernumber].push,_("Push") );
c53e6443 sago007 2012-04-17 11:04 515
	Button_changekey bSwitch(&keySettings[playernumber].change,_("Change") );
c53e6443 sago007 2012-04-17 11:04 516
	km.addButton(&bLeft);
c53e6443 sago007 2012-04-17 11:04 517
	km.addButton(&bRight);
c53e6443 sago007 2012-04-17 11:04 518
	km.addButton(&bUp);
c53e6443 sago007 2012-04-17 11:04 519
	km.addButton(&bDown);
c53e6443 sago007 2012-04-17 11:04 520
	km.addButton(&bPush);
c53e6443 sago007 2012-04-17 11:04 521
	km.addButton(&bSwitch);
20d77c6e sago007 2016-11-12 16:28 522
	RunGameState(km);
c53e6443 sago007 2012-04-17 11:04 523
}
c53e6443 sago007 2012-04-17 11:04 524
29edda2d sago007 2016-10-08 18:06 525
static void ChangeKeysMenu1() {
c53e6443 sago007 2012-04-17 11:04 526
	ChangeKeysMenu(0);
593aeae4 sago007 2011-06-25 22:42 527
}
593aeae4 sago007 2011-06-25 22:42 528
29edda2d sago007 2016-10-08 18:06 529
static void ChangeKeysMenu2() {
c53e6443 sago007 2012-04-17 11:04 530
	ChangeKeysMenu(2);
593aeae4 sago007 2011-06-25 22:42 531
}
fc8e3d6a sago007 2011-06-25 16:31 532
3affd2d6 Poul Sander 2020-12-27 15:56 533
static void PlayerConfigMenu() {
3affd2d6 Poul Sander 2020-12-27 15:56 534
	Menu pcm(globalData.screen,_("Player configuration"),true);
3affd2d6 Poul Sander 2020-12-27 15:56 535
	Button bPlayer1Name, bPlayer2Name;
3affd2d6 Poul Sander 2020-12-27 15:56 536
	Button bPlayer1Keys, bPlayer2Keys;
3affd2d6 Poul Sander 2020-12-27 15:56 537
	bPlayer1Name.setAction(buttonActionPlayer1Name);
3affd2d6 Poul Sander 2020-12-27 15:56 538
	bPlayer1Name.setLabel(_("Change player 1's name") );
3affd2d6 Poul Sander 2020-12-27 15:56 539
	bPlayer2Name.setAction(buttonActionPlayer2Name);
3affd2d6 Poul Sander 2020-12-27 15:56 540
	bPlayer2Name.setLabel(_("Change player 2's name") );
3affd2d6 Poul Sander 2020-12-27 15:56 541
	bPlayer1Keys.setAction(ChangeKeysMenu1);
3affd2d6 Poul Sander 2020-12-27 15:56 542
	bPlayer1Keys.setLabel(_("Change player 1's keys") );
3affd2d6 Poul Sander 2020-12-27 15:56 543
	bPlayer2Keys.setAction(ChangeKeysMenu2);
3affd2d6 Poul Sander 2020-12-27 15:56 544
	bPlayer2Keys.setLabel(_("Change player 2's keys") );
3affd2d6 Poul Sander 2020-12-27 15:56 545
	pcm.addButton(&bPlayer1Name);
3affd2d6 Poul Sander 2020-12-27 15:56 546
	pcm.addButton(&bPlayer2Name);
3affd2d6 Poul Sander 2020-12-27 15:56 547
	pcm.addButton(&bPlayer1Keys);
3affd2d6 Poul Sander 2020-12-27 15:56 548
	pcm.addButton(&bPlayer2Keys);
3affd2d6 Poul Sander 2020-12-27 15:56 549
	RunGameState(pcm);
3affd2d6 Poul Sander 2020-12-27 15:56 550
}
3affd2d6 Poul Sander 2020-12-27 15:56 551
4ba5514b Poul Sander 2023-10-09 18:59 552
29edda2d sago007 2016-10-08 18:06 553
static void ConfigureMenu() {
72383a9e sago007 2016-10-30 11:56 554
	Menu cm(globalData.screen,_("Configuration"),true);
1029dfed Poul Sander 2019-03-13 17:22 555
	AlwaysSoftwareRenderButton bSoftware;
517ed886 Poul Sander 2025-12-14 14:38 556
	Button_musicVolume bMusic;
517ed886 Poul Sander 2025-12-14 14:38 557
	Button_soundVolume bSound;
29edda2d sago007 2016-10-08 18:06 558
	FullscreenButton buttonFullscreen;
1b403c4a Poul Sander 2024-04-14 14:57 559
	BlockVariantButton bBlockVariant;
3affd2d6 Poul Sander 2020-12-27 15:56 560
	Button bPlayerConfig;
3affd2d6 Poul Sander 2020-12-27 15:56 561
	bPlayerConfig.setLabel(_("Player configuration") );
3affd2d6 Poul Sander 2020-12-27 15:56 562
	bPlayerConfig.setAction(PlayerConfigMenu);
4ba5514b Poul Sander 2023-10-09 18:59 563
	Button bThemes;
4ba5514b Poul Sander 2023-10-09 18:59 564
	bThemes.setLabel(_("Themes"));
4ba5514b Poul Sander 2023-10-09 18:59 565
	bThemes.setAction(OpenThemesMenu);
1029dfed Poul Sander 2019-03-13 17:22 566
	SetAlwaysSoftwareLabel(&bSoftware);
e17d4be2 Poul Sander 2019-03-13 17:29 567
	SetFullscreenLabel(&buttonFullscreen);
1b403c4a Poul Sander 2024-04-14 14:57 568
	SetBlockVariationLabel(&bBlockVariant);
c53e6443 sago007 2012-04-17 11:04 569
	cm.addButton(&bMusic);
c53e6443 sago007 2012-04-17 11:04 570
	cm.addButton(&bSound);
1029dfed Poul Sander 2019-03-13 17:22 571
	cm.addButton(&bSoftware);
c53e6443 sago007 2012-04-17 11:04 572
	cm.addButton(&buttonFullscreen);
1b403c4a Poul Sander 2024-04-14 14:57 573
	cm.addButton(&bBlockVariant);
3affd2d6 Poul Sander 2020-12-27 15:56 574
	cm.addButton(&bPlayerConfig);
4ba5514b Poul Sander 2023-10-09 18:59 575
	cm.addButton(&bThemes);
20d77c6e sago007 2016-11-12 16:28 576
	RunGameState(cm);
26ddb424 sago007 2011-06-09 20:06 577
}
26ddb424 sago007 2011-06-09 20:06 578
29edda2d sago007 2016-10-08 18:06 579
static void SinglePlayerVsMenu() {
72383a9e sago007 2016-10-30 11:56 580
	Menu spvs(globalData.screen,_("Single player VS"),true);
29edda2d sago007 2016-10-08 18:06 581
	RunSinglePlayerVsButton d1,d2,d3,d4,d5,d6,d7;
67a32395 sago007 2012-04-19 18:40 582
	d1.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 583
	d2.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 584
	d3.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 585
	d4.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 586
	d5.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 587
	d6.setPopOnRun(true);
67a32395 sago007 2012-04-19 18:40 588
	d7.setPopOnRun(true);
e68d08eb sago007 2013-11-15 22:33 589
	d1.iGeneric1 = 0;
e68d08eb sago007 2013-11-15 22:33 590
	d2.iGeneric1 = 1;
e68d08eb sago007 2013-11-15 22:33 591
	d3.iGeneric1 = 2;
e68d08eb sago007 2013-11-15 22:33 592
	d4.iGeneric1 = 3;
e68d08eb sago007 2013-11-15 22:33 593
	d5.iGeneric1 = 4;
e68d08eb sago007 2013-11-15 22:33 594
	d6.iGeneric1 = 5;
e68d08eb sago007 2013-11-15 22:33 595
	d7.iGeneric1 = 6;
67a32395 sago007 2012-04-19 18:40 596
	d1.setLabel(_("Very easy"));
67a32395 sago007 2012-04-19 18:40 597
	d2.setLabel(_("Easy"));
67a32395 sago007 2012-04-19 18:40 598
	d3.setLabel(_("Below normal"));
67a32395 sago007 2012-04-19 18:40 599
	d4.setLabel(_("Normal"));
67a32395 sago007 2012-04-19 18:40 600
	d5.setLabel(_("Above normal"));
67a32395 sago007 2012-04-19 18:40 601
	d6.setLabel(_("Hard"));
67a32395 sago007 2012-04-19 18:40 602
	d7.setLabel(_("Hardest"));
67a32395 sago007 2012-04-19 18:40 603
	spvs.addButton(&d1);
67a32395 sago007 2012-04-19 18:40 604
	spvs.addButton(&d2);
67a32395 sago007 2012-04-19 18:40 605
	spvs.addButton(&d3);
67a32395 sago007 2012-04-19 18:40 606
	spvs.addButton(&d4);
67a32395 sago007 2012-04-19 18:40 607
	spvs.addButton(&d5);
67a32395 sago007 2012-04-19 18:40 608
	spvs.addButton(&d6);
67a32395 sago007 2012-04-19 18:40 609
	spvs.addButton(&d7);
20d77c6e sago007 2016-11-12 16:28 610
	RunGameState(spvs);
67a32395 sago007 2012-04-19 18:40 611
}
67a32395 sago007 2012-04-19 18:40 612
29edda2d sago007 2016-10-08 18:06 613
static void MultiplayerMenu() {
72383a9e sago007 2016-10-30 11:56 614
	Menu mm(globalData.screen,_("Multiplayer"),true);
de81e07d sago007 2016-07-10 20:22 615
	Button bTT, bVs;
b0222eff sago007 2012-04-22 15:06 616
	bTT.setLabel(_("Two player - time trial"));
b0222eff sago007 2012-04-22 15:06 617
	bTT.setAction(runTwoPlayerTimeTrial);
b0222eff sago007 2012-04-22 15:06 618
	bVs.setLabel(_("Two player - vs"));
b0222eff sago007 2012-04-22 15:06 619
	bVs.setAction(runTwoPlayerVs);
b0222eff sago007 2012-04-22 15:06 620
	mm.addButton(&bTT);
b0222eff sago007 2012-04-22 15:06 621
	mm.addButton(&bVs);
20d77c6e sago007 2016-11-12 16:28 622
	RunGameState(mm);
b0222eff sago007 2012-04-22 15:06 623
}
b0222eff sago007 2012-04-22 15:06 624
d8fe60bd sago007 2018-04-02 16:15 625
static void runHowto() {
d8fe60bd sago007 2018-04-02 16:15 626
	HelpHowtoState howto;
d8fe60bd sago007 2018-04-02 16:15 627
	RunGameState(howto);
d8fe60bd sago007 2018-04-02 16:15 628
}
d8fe60bd sago007 2018-04-02 16:15 629
bfb4fed7 Poul Sander 2022-02-14 19:35 630
static void runHelpModInfo() {
bfb4fed7 Poul Sander 2022-02-14 19:35 631
	HelpModInfoState modInfo;
bfb4fed7 Poul Sander 2022-02-14 19:35 632
	RunGameState(modInfo);
bfb4fed7 Poul Sander 2022-02-14 19:35 633
}
bfb4fed7 Poul Sander 2022-02-14 19:35 634
54d2d583 sago007 2018-04-05 17:52 635
static void runHelpGamepad() {
54d2d583 sago007 2018-04-05 17:52 636
	HelpGamepadState helpGamepad;
54d2d583 sago007 2018-04-05 17:52 637
	RunGameState(helpGamepad);
54d2d583 sago007 2018-04-05 17:52 638
}
54d2d583 sago007 2018-04-05 17:52 639
5147de4e Poul Sander 2018-05-06 12:59 640
static void runHelpAbout() {
5147de4e Poul Sander 2018-05-06 12:59 641
	HelpAboutState helpAbout;
5147de4e Poul Sander 2018-05-06 12:59 642
	RunGameState(helpAbout);
5147de4e Poul Sander 2018-05-06 12:59 643
}
5147de4e Poul Sander 2018-05-06 12:59 644
0471a1d3 sago007 2018-05-19 10:26 645
static void runCredits() {
0471a1d3 sago007 2018-05-19 10:26 646
	ShowFileState creditsFile;
0471a1d3 sago007 2018-05-19 10:26 647
	creditsFile.SetData("misc/AUTHORS", _("Credits"));
0471a1d3 sago007 2018-05-19 10:26 648
	RunGameState(creditsFile);
0471a1d3 sago007 2018-05-19 10:26 649
}
0471a1d3 sago007 2018-05-19 10:26 650
d8fe60bd sago007 2018-04-02 16:15 651
static void HelpMenu() {
d8fe60bd sago007 2018-04-02 16:15 652
	Menu m(globalData.screen, _("Help"), true);
d8fe60bd sago007 2018-04-02 16:15 653
	Button bHowto;
d8fe60bd sago007 2018-04-02 16:15 654
	bHowto.setLabel(_("How to"));
d8fe60bd sago007 2018-04-02 16:15 655
	bHowto.setAction(runHowto);
d8fe60bd sago007 2018-04-02 16:15 656
	m.addButton(&bHowto);
54d2d583 sago007 2018-04-05 17:52 657
	Button bGamepad;
54d2d583 sago007 2018-04-05 17:52 658
	bGamepad.setLabel(_("Gamepad"));
54d2d583 sago007 2018-04-05 17:52 659
	bGamepad.setAction(runHelpGamepad);
54d2d583 sago007 2018-04-05 17:52 660
	m.addButton(&bGamepad);
bfb4fed7 Poul Sander 2022-02-14 19:35 661
	Button bModInfo;
bfb4fed7 Poul Sander 2022-02-14 19:35 662
	bModInfo.setLabel(_("Mod info"));
bfb4fed7 Poul Sander 2022-02-14 19:35 663
	bModInfo.setAction(runHelpModInfo);
bfb4fed7 Poul Sander 2022-02-14 19:35 664
	m.addButton(&bModInfo);
0471a1d3 sago007 2018-05-19 10:26 665
	Button bCredits;
0471a1d3 sago007 2018-05-19 10:26 666
	bCredits.setLabel(_("Credits"));
0471a1d3 sago007 2018-05-19 10:26 667
	bCredits.setAction(runCredits);
0471a1d3 sago007 2018-05-19 10:26 668
	m.addButton(&bCredits);
5147de4e Poul Sander 2018-05-06 12:59 669
	Button bAbout;
5147de4e Poul Sander 2018-05-06 12:59 670
	bAbout.setLabel(_("About"));
5147de4e Poul Sander 2018-05-06 12:59 671
	bAbout.setAction(runHelpAbout);
5147de4e Poul Sander 2018-05-06 12:59 672
	m.addButton(&bAbout);
d8fe60bd sago007 2018-04-02 16:15 673
	RunGameState(m);
d8fe60bd sago007 2018-04-02 16:15 674
}
d8fe60bd sago007 2018-04-02 16:15 675
2f331f0c sago007 2017-08-19 16:17 676
static void SinglePlayerMenu() {
2f331f0c sago007 2017-08-19 16:17 677
	Menu m(globalData.screen, _("Single player"), true);
2f331f0c sago007 2017-08-19 16:17 678
	Button bHi,bTimetrial1, bStageClear, bPuzzle, bVs1;
c53e6443 sago007 2012-04-17 11:04 679
	bHi.setLabel(_("Single player - endless") );
c53e6443 sago007 2012-04-17 11:04 680
	bHi.setAction(runSinglePlayerEndless);
c53e6443 sago007 2012-04-17 11:04 681
	bTimetrial1.setLabel(_("Single player - time trial") );
c53e6443 sago007 2012-04-17 11:04 682
	bTimetrial1.setAction(runSinglePlayerTimeTrial);
aede0664 sago007 2012-04-19 19:45 683
	bStageClear.setLabel(_("Single player - stage clear") );
aede0664 sago007 2012-04-19 19:45 684
	bStageClear.setAction(runStageClear);
c53e6443 sago007 2012-04-17 11:04 685
	bPuzzle.setLabel(_("Single player - puzzle mode") );
c53e6443 sago007 2012-04-17 11:04 686
	bPuzzle.setAction(runSinglePlayerPuzzle);
c53e6443 sago007 2012-04-17 11:04 687
	bVs1.setLabel(_("Single player - vs") );
67a32395 sago007 2012-04-19 18:40 688
	bVs1.setAction(SinglePlayerVsMenu);
2f331f0c sago007 2017-08-19 16:17 689
	m.addButton(&bHi);
2f331f0c sago007 2017-08-19 16:17 690
	m.addButton(&bTimetrial1);
2f331f0c sago007 2017-08-19 16:17 691
	m.addButton(&bStageClear);
2f331f0c sago007 2017-08-19 16:17 692
	m.addButton(&bPuzzle);
2f331f0c sago007 2017-08-19 16:17 693
	m.addButton(&bVs1);
2f331f0c sago007 2017-08-19 16:17 694
	RunGameState(m);
2f331f0c sago007 2017-08-19 16:17 695
}
2f331f0c sago007 2017-08-19 16:17 696
ccee1ad0 Poul Sander 2019-03-13 18:39 697
void SafeModeMenu() {
ccee1ad0 Poul Sander 2019-03-13 18:39 698
	if (Config::getInstance()->getInt("always-software")) {
ccee1ad0 Poul Sander 2019-03-13 18:39 699
		return;
ccee1ad0 Poul Sander 2019-03-13 18:39 700
	}
ccee1ad0 Poul Sander 2019-03-13 18:39 701
	Menu safeMode(globalData.screen, _("Game did not shutdown as it should"), true);
ccee1ad0 Poul Sander 2019-03-13 18:39 702
	Button bOnce;
ccee1ad0 Poul Sander 2019-03-13 18:39 703
	Button bAlways;
ccee1ad0 Poul Sander 2019-03-13 18:39 704
	bOnce.setLabel(_("Use software renderer this time"));
ccee1ad0 Poul Sander 2019-03-13 18:39 705
	bAlways.setLabel(_("Always use software renderer"));
ccee1ad0 Poul Sander 2019-03-13 18:39 706
	bOnce.setPopOnRun(true);
9c7fa9a1 sago007 2020-06-27 22:09 707
	bAlways.setAction([]() {
9c7fa9a1 sago007 2020-06-27 22:09 708
		Config::getInstance()->setInt("always-software", 1);
9c7fa9a1 sago007 2020-06-27 22:09 709
	});
ccee1ad0 Poul Sander 2019-03-13 18:39 710
	bAlways.setPopOnRun(true);
ccee1ad0 Poul Sander 2019-03-13 18:39 711
	safeMode.addButton(&bOnce);
ccee1ad0 Poul Sander 2019-03-13 18:39 712
	safeMode.addButton(&bAlways);
ccee1ad0 Poul Sander 2019-03-13 18:39 713
	RunGameState(safeMode);
ccee1ad0 Poul Sander 2019-03-13 18:39 714
}
ccee1ad0 Poul Sander 2019-03-13 18:39 715
2f331f0c sago007 2017-08-19 16:17 716
void MainMenu() {
2f331f0c sago007 2017-08-19 16:17 717
	Menu m(globalData.screen,_("Block Attack - Rise of the blocks"),false);
d8fe60bd sago007 2018-04-02 16:15 718
	Button bHi, bMulti, bConfigure, bHighscore, bHelp;
2f331f0c sago007 2017-08-19 16:17 719
	bHi.setLabel(_("Single player") );
2f331f0c sago007 2017-08-19 16:17 720
	bHi.setAction(SinglePlayerMenu);
b0222eff sago007 2012-04-22 15:06 721
	bMulti.setLabel(_("Multi player") );
b0222eff sago007 2012-04-22 15:06 722
	bMulti.setAction(MultiplayerMenu);
c53e6443 sago007 2012-04-17 11:04 723
	bConfigure.setLabel(_("Configure") );
c53e6443 sago007 2012-04-17 11:04 724
	bConfigure.setAction(ConfigureMenu);
c53e6443 sago007 2012-04-17 11:04 725
	bHighscore.setLabel(_("Highscores") );
c53e6443 sago007 2012-04-17 11:04 726
	bHighscore.setAction(buttonActionHighscores);
d8fe60bd sago007 2018-04-02 16:15 727
	bHelp.setLabel(_("Help"));
d8fe60bd sago007 2018-04-02 16:15 728
	bHelp.setAction(HelpMenu);
c53e6443 sago007 2012-04-17 11:04 729
	m.addButton(&bHi);
b0222eff sago007 2012-04-22 15:06 730
	m.addButton(&bMulti);
c53e6443 sago007 2012-04-17 11:04 731
	m.addButton(&bConfigure);
c53e6443 sago007 2012-04-17 11:04 732
	m.addButton(&bHighscore);
d8fe60bd sago007 2018-04-02 16:15 733
	m.addButton(&bHelp);
95ab6b0d sago007 2016-11-12 16:11 734
	RunGameState(m);
593aeae4 sago007 2011-06-25 22:42 735
}
1970-01-01 00:00 736