git repos / blockattack-game

blame: source/code/menudef_themes.cpp

normal view · raw

e35cd386 Poul Sander 2023-11-29 20:33 1
/*
e35cd386 Poul Sander 2023-11-29 20:33 2
===========================================================================
e35cd386 Poul Sander 2023-11-29 20:33 3
blockattack - Block Attack - Rise of the Blocks
e35cd386 Poul Sander 2023-11-29 20:33 4
Copyright (C) 2005-2013 Poul Sander
e35cd386 Poul Sander 2023-11-29 20:33 5
e35cd386 Poul Sander 2023-11-29 20:33 6
This program is free software: you can redistribute it and/or modify
e35cd386 Poul Sander 2023-11-29 20:33 7
it under the terms of the GNU General Public License as published by
e35cd386 Poul Sander 2023-11-29 20:33 8
the Free Software Foundation, either version 2 of the License, or
e35cd386 Poul Sander 2023-11-29 20:33 9
(at your option) any later version.
e35cd386 Poul Sander 2023-11-29 20:33 10
e35cd386 Poul Sander 2023-11-29 20:33 11
This program is distributed in the hope that it will be useful,
e35cd386 Poul Sander 2023-11-29 20:33 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
e35cd386 Poul Sander 2023-11-29 20:33 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e35cd386 Poul Sander 2023-11-29 20:33 14
GNU General Public License for more details.
e35cd386 Poul Sander 2023-11-29 20:33 15
e35cd386 Poul Sander 2023-11-29 20:33 16
You should have received a copy of the GNU General Public License
e35cd386 Poul Sander 2023-11-29 20:33 17
along with this program.  If not, see http://www.gnu.org/licenses/
e35cd386 Poul Sander 2023-11-29 20:33 18
e35cd386 Poul Sander 2023-11-29 20:33 19
Source information and contacts persons can be found at
e35cd386 Poul Sander 2023-11-29 20:33 20
http://blockattack.net
e35cd386 Poul Sander 2023-11-29 20:33 21
===========================================================================
e35cd386 Poul Sander 2023-11-29 20:33 22
*/
e35cd386 Poul Sander 2023-11-29 20:33 23
#include "global.hpp"
e35cd386 Poul Sander 2023-11-29 20:33 24
#include "menudef_themes.hpp"
e35cd386 Poul Sander 2023-11-29 20:33 25
#include "MenuSystem.h"
e35cd386 Poul Sander 2023-11-29 20:33 26
#include "BlockGameSdl.hpp"
e35cd386 Poul Sander 2023-11-29 20:33 27
#include <fmt/core.h>
e35cd386 Poul Sander 2023-11-29 20:33 28
e35cd386 Poul Sander 2023-11-29 20:33 29
static void switchTheme() {
e35cd386 Poul Sander 2023-11-29 20:33 30
	globalData.theme = ThemesGetNext();
f45790f5 Poul Sander 2024-04-14 19:29 31
	Config::getInstance()->setString("theme", globalData.theme.theme_name);
e35cd386 Poul Sander 2023-11-29 20:33 32
}
e35cd386 Poul Sander 2023-11-29 20:33 33
e35cd386 Poul Sander 2023-11-29 20:33 34
e35cd386 Poul Sander 2023-11-29 20:33 35
static void testMusic() {
e35cd386 Poul Sander 2023-11-29 20:33 36
	static bool highbeatNext = false;
e35cd386 Poul Sander 2023-11-29 20:33 37
	int musicVolume = Config::getInstance()->getInt("volume_music");
e35cd386 Poul Sander 2023-11-29 20:33 38
	std::string music_name = "bgmusic";
e35cd386 Poul Sander 2023-11-29 20:33 39
	if (highbeatNext) {
e35cd386 Poul Sander 2023-11-29 20:33 40
		music_name = "highbeat";
e35cd386 Poul Sander 2023-11-29 20:33 41
	}
e35cd386 Poul Sander 2023-11-29 20:33 42
	Mix_PlayMusic(globalData.spriteHolder->GetDataHolder().getMusicHandler(music_name.c_str()).get(), 1);
e35cd386 Poul Sander 2023-11-29 20:33 43
	Mix_VolumeMusic(musicVolume);
e35cd386 Poul Sander 2023-11-29 20:33 44
	highbeatNext = !highbeatNext; //Toggle between standard and highbeat
e35cd386 Poul Sander 2023-11-29 20:33 45
}
e35cd386 Poul Sander 2023-11-29 20:33 46
7602f86d Poul Sander 2024-01-10 21:39 47
7602f86d Poul Sander 2024-01-10 21:39 48
e35cd386 Poul Sander 2023-11-29 20:33 49
class ThemesMenu : public Menu {
7602f86d Poul Sander 2024-01-10 21:39 50
public:
e35cd386 Poul Sander 2023-11-29 20:33 51
	std::shared_ptr<BlockGameSdl> game;
e35cd386 Poul Sander 2023-11-29 20:33 52
	sago::SagoTextField themeTitle;
7602f86d Poul Sander 2024-01-10 21:39 53
e35cd386 Poul Sander 2023-11-29 20:33 54
	ThemesMenu(SDL_Renderer* screen, const std::string& title, bool submenu) : Menu(screen, title, submenu) {
e35cd386 Poul Sander 2023-11-29 20:33 55
		game = std::make_shared<BlockGameSdl>(globalData.xsize-450,100,&globalData.spriteHolder->GetDataHolder());
7bb13b4e Poul Sander 2024-02-25 11:05 56
		game->name = "Player 1";
e35cd386 Poul Sander 2023-11-29 20:33 57
		game->putSampleBlocks();
e35cd386 Poul Sander 2023-11-29 20:33 58
		sagoTextSetBlueFont(themeTitle);
e35cd386 Poul Sander 2023-11-29 20:33 59
	}
e35cd386 Poul Sander 2023-11-29 20:33 60
e35cd386 Poul Sander 2023-11-29 20:33 61
	void placeButtons() override {
e35cd386 Poul Sander 2023-11-29 20:33 62
		int nextY = 100;
e35cd386 Poul Sander 2023-11-29 20:33 63
		int X = 10;
e35cd386 Poul Sander 2023-11-29 20:33 64
		for (Button* it : buttons) {
e35cd386 Poul Sander 2023-11-29 20:33 65
			it->x = X;
e35cd386 Poul Sander 2023-11-29 20:33 66
			it->y = nextY;
e35cd386 Poul Sander 2023-11-29 20:33 67
			nextY += it->standardButton.ysize+10;
e35cd386 Poul Sander 2023-11-29 20:33 68
		}
e35cd386 Poul Sander 2023-11-29 20:33 69
		exit.x = X;
e35cd386 Poul Sander 2023-11-29 20:33 70
		exit.y = nextY;
e35cd386 Poul Sander 2023-11-29 20:33 71
	}
e35cd386 Poul Sander 2023-11-29 20:33 72
e35cd386 Poul Sander 2023-11-29 20:33 73
	void Draw(SDL_Renderer* target) override {
e35cd386 Poul Sander 2023-11-29 20:33 74
		Menu::Draw(target);
e35cd386 Poul Sander 2023-11-29 20:33 75
		game->DoPaintJob();
e35cd386 Poul Sander 2023-11-29 20:33 76
		themeTitle.SetText(fmt::format(_("Theme: {}"), globalData.theme.theme_name));
e35cd386 Poul Sander 2023-11-29 20:33 77
		themeTitle.Draw(target, 10, globalData.ysize-50,sago::SagoTextField::Alignment::left);
e35cd386 Poul Sander 2023-11-29 20:33 78
	}
e35cd386 Poul Sander 2023-11-29 20:33 79
};
e35cd386 Poul Sander 2023-11-29 20:33 80
66d6174b Poul Sander 2024-01-13 22:45 81
static Theme themeBackup;
66d6174b Poul Sander 2024-01-13 22:45 82
static Theme themeToEdit;
66d6174b Poul Sander 2024-01-13 22:45 83
66d6174b Poul Sander 2024-01-13 22:45 84
static void themesEditSwitchBackground() {
66d6174b Poul Sander 2024-01-13 22:45 85
	themeToEdit.background = ThemesGetNextBackground(themeToEdit.background.name);
66d6174b Poul Sander 2024-01-13 22:45 86
	globalData.theme = themeToEdit;
66d6174b Poul Sander 2024-01-13 22:45 87
}
7602f86d Poul Sander 2024-01-10 21:39 88
de41f458 Poul Sander 2024-01-29 20:53 89
static void themesEditSwitchBoardBackground() {
de41f458 Poul Sander 2024-01-29 20:53 90
	themeToEdit.back_board = ThemesGetNextBoardBackground(themeToEdit.back_board);
de41f458 Poul Sander 2024-01-29 20:53 91
	globalData.theme = themeToEdit;
de41f458 Poul Sander 2024-01-29 20:53 92
}
de41f458 Poul Sander 2024-01-29 20:53 93
5d5a5e92 Poul Sander 2024-03-06 21:41 94
static void themesEditSwitchBorder() {
5d5a5e92 Poul Sander 2024-03-06 21:41 95
	themeToEdit.border = ThemesGetNextBorder(themeToEdit.border.name);
5d5a5e92 Poul Sander 2024-03-06 21:41 96
	globalData.theme = themeToEdit;
5d5a5e92 Poul Sander 2024-03-06 21:41 97
}
5d5a5e92 Poul Sander 2024-03-06 21:41 98
c8e0251f Poul Sander 2024-02-07 21:38 99
static void themesEditSlot(int slot) {
c8e0251f Poul Sander 2024-02-07 21:38 100
	ThemesMenu tem(globalData.screen, fmt::format(_("Edit custom theme {}"), slot), true);
f45790f5 Poul Sander 2024-04-14 19:29 101
	size_t theme_index = ThemesGetNumber(fmt::format("custom_slot_{}", slot));
7602f86d Poul Sander 2024-01-10 21:39 102
	if (theme_index == 0) {
7602f86d Poul Sander 2024-01-10 21:39 103
		// Theme not found
7602f86d Poul Sander 2024-01-10 21:39 104
		return;
7602f86d Poul Sander 2024-01-10 21:39 105
	}
66d6174b Poul Sander 2024-01-13 22:45 106
	Button bSwitchBackground;
66d6174b Poul Sander 2024-01-13 22:45 107
	bSwitchBackground.setLabel(_("Switch background"));
66d6174b Poul Sander 2024-01-13 22:45 108
	bSwitchBackground.setAction(&themesEditSwitchBackground);
66d6174b Poul Sander 2024-01-13 22:45 109
	tem.addButton(&bSwitchBackground);
de41f458 Poul Sander 2024-01-29 20:53 110
	Button bSwitchBoardBackground;
de41f458 Poul Sander 2024-01-29 20:53 111
	bSwitchBoardBackground.setLabel(_("Switch board background"));
de41f458 Poul Sander 2024-01-29 20:53 112
	bSwitchBoardBackground.setAction(&themesEditSwitchBoardBackground);
de41f458 Poul Sander 2024-01-29 20:53 113
	tem.addButton(&bSwitchBoardBackground);
5d5a5e92 Poul Sander 2024-03-06 21:41 114
	Button bSwitchBorder;
5d5a5e92 Poul Sander 2024-03-06 21:41 115
	bSwitchBorder.setLabel(_("Switch border"));
5d5a5e92 Poul Sander 2024-03-06 21:41 116
	bSwitchBorder.setAction(&themesEditSwitchBorder);
5d5a5e92 Poul Sander 2024-03-06 21:41 117
	tem.addButton(&bSwitchBorder);
66d6174b Poul Sander 2024-01-13 22:45 118
	themeBackup = globalData.theme;
66d6174b Poul Sander 2024-01-13 22:45 119
	themeToEdit = ThemesGet(theme_index);
66d6174b Poul Sander 2024-01-13 22:45 120
	globalData.theme = themeToEdit;
7602f86d Poul Sander 2024-01-10 21:39 121
	RunGameState(tem);
66d6174b Poul Sander 2024-01-13 22:45 122
	ThemesAddOrReplace(themeToEdit);
66d6174b Poul Sander 2024-01-13 22:45 123
	globalData.theme = themeBackup;
c8e0251f Poul Sander 2024-02-07 21:38 124
	ThemesSaveCustomSlots();
c8e0251f Poul Sander 2024-02-07 21:38 125
}
c8e0251f Poul Sander 2024-02-07 21:38 126
c8e0251f Poul Sander 2024-02-07 21:38 127
static void themesEditSlot1() {
c8e0251f Poul Sander 2024-02-07 21:38 128
	themesEditSlot(1);
c8e0251f Poul Sander 2024-02-07 21:38 129
}
c8e0251f Poul Sander 2024-02-07 21:38 130
c8e0251f Poul Sander 2024-02-07 21:38 131
static void themesEditSlot2() {
c8e0251f Poul Sander 2024-02-07 21:38 132
	themesEditSlot(2);
7602f86d Poul Sander 2024-01-10 21:39 133
}
7602f86d Poul Sander 2024-01-10 21:39 134
7602f86d Poul Sander 2024-01-10 21:39 135
e35cd386 Poul Sander 2023-11-29 20:33 136
void OpenThemesMenu() {
e35cd386 Poul Sander 2023-11-29 20:33 137
	ThemesMenu tm(globalData.screen, _("Themes"), true);
e35cd386 Poul Sander 2023-11-29 20:33 138
	Button bSwitchTheme;
e35cd386 Poul Sander 2023-11-29 20:33 139
	bSwitchTheme.setLabel(_("Switch theme"));
e35cd386 Poul Sander 2023-11-29 20:33 140
	bSwitchTheme.setAction(&switchTheme);
e35cd386 Poul Sander 2023-11-29 20:33 141
	tm.addButton(&bSwitchTheme);
7602f86d Poul Sander 2024-01-10 21:39 142
	Button bEditTheme1;
c8e0251f Poul Sander 2024-02-07 21:38 143
	bEditTheme1.setLabel(fmt::format(_("Edit custom theme {}"), 1));
7602f86d Poul Sander 2024-01-10 21:39 144
	bEditTheme1.setAction(&themesEditSlot1);
7602f86d Poul Sander 2024-01-10 21:39 145
	tm.addButton(&bEditTheme1);
c8e0251f Poul Sander 2024-02-07 21:38 146
	Button bEditTheme2;
c8e0251f Poul Sander 2024-02-07 21:38 147
	bEditTheme2.setLabel(fmt::format(_("Edit custom theme {}"), 2));
c8e0251f Poul Sander 2024-02-07 21:38 148
	bEditTheme2.setAction(&themesEditSlot2);
c8e0251f Poul Sander 2024-02-07 21:38 149
	tm.addButton(&bEditTheme2);
e35cd386 Poul Sander 2023-11-29 20:33 150
	if (!globalData.NoSound) {
e35cd386 Poul Sander 2023-11-29 20:33 151
		Button bTestMusic;
e35cd386 Poul Sander 2023-11-29 20:33 152
		bTestMusic.setLabel(_("Test music"));
e35cd386 Poul Sander 2023-11-29 20:33 153
		bTestMusic.setAction(&testMusic);
e35cd386 Poul Sander 2023-11-29 20:33 154
		tm.addButton(&bTestMusic);
e35cd386 Poul Sander 2023-11-29 20:33 155
	}
e35cd386 Poul Sander 2023-11-29 20:33 156
	RunGameState(tm);
e35cd386 Poul Sander 2023-11-29 20:33 157
}
1970-01-01 00:00 158