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();
e35cd386 Poul Sander 2023-11-29 20:33 31
}
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
static void testMusic() {
e35cd386 Poul Sander 2023-11-29 20:33 35
	static bool highbeatNext = false;
e35cd386 Poul Sander 2023-11-29 20:33 36
	int musicVolume = Config::getInstance()->getInt("volume_music");
e35cd386 Poul Sander 2023-11-29 20:33 37
	std::string music_name = "bgmusic";
e35cd386 Poul Sander 2023-11-29 20:33 38
	if (highbeatNext) {
e35cd386 Poul Sander 2023-11-29 20:33 39
		music_name = "highbeat";
e35cd386 Poul Sander 2023-11-29 20:33 40
	}
e35cd386 Poul Sander 2023-11-29 20:33 41
	Mix_PlayMusic(globalData.spriteHolder->GetDataHolder().getMusicHandler(music_name.c_str()).get(), 1);
e35cd386 Poul Sander 2023-11-29 20:33 42
	Mix_VolumeMusic(musicVolume);
e35cd386 Poul Sander 2023-11-29 20:33 43
	highbeatNext = !highbeatNext; //Toggle between standard and highbeat
e35cd386 Poul Sander 2023-11-29 20:33 44
}
e35cd386 Poul Sander 2023-11-29 20:33 45
7602f86d Poul Sander 2024-01-10 21:39 46
7602f86d Poul Sander 2024-01-10 21:39 47
e35cd386 Poul Sander 2023-11-29 20:33 48
class ThemesMenu : public Menu {
7602f86d Poul Sander 2024-01-10 21:39 49
public:
e35cd386 Poul Sander 2023-11-29 20:33 50
	std::shared_ptr<BlockGameSdl> game;
e35cd386 Poul Sander 2023-11-29 20:33 51
	sago::SagoTextField themeTitle;
7602f86d Poul Sander 2024-01-10 21:39 52
e35cd386 Poul Sander 2023-11-29 20:33 53
	ThemesMenu(SDL_Renderer* screen, const std::string& title, bool submenu) : Menu(screen, title, submenu) {
e35cd386 Poul Sander 2023-11-29 20:33 54
		game = std::make_shared<BlockGameSdl>(globalData.xsize-450,100,&globalData.spriteHolder->GetDataHolder());
7bb13b4e Poul Sander 2024-02-25 11:05 55
		game->name = "Player 1";
e35cd386 Poul Sander 2023-11-29 20:33 56
		game->putSampleBlocks();
e35cd386 Poul Sander 2023-11-29 20:33 57
		sagoTextSetBlueFont(themeTitle);
e35cd386 Poul Sander 2023-11-29 20:33 58
	}
e35cd386 Poul Sander 2023-11-29 20:33 59
e35cd386 Poul Sander 2023-11-29 20:33 60
	void placeButtons() override {
e35cd386 Poul Sander 2023-11-29 20:33 61
		int nextY = 100;
e35cd386 Poul Sander 2023-11-29 20:33 62
		int X = 10;
e35cd386 Poul Sander 2023-11-29 20:33 63
		for (Button* it : buttons) {
e35cd386 Poul Sander 2023-11-29 20:33 64
			it->x = X;
e35cd386 Poul Sander 2023-11-29 20:33 65
			it->y = nextY;
e35cd386 Poul Sander 2023-11-29 20:33 66
			nextY += it->standardButton.ysize+10;
e35cd386 Poul Sander 2023-11-29 20:33 67
		}
e35cd386 Poul Sander 2023-11-29 20:33 68
		exit.x = X;
e35cd386 Poul Sander 2023-11-29 20:33 69
		exit.y = nextY;
e35cd386 Poul Sander 2023-11-29 20:33 70
	}
e35cd386 Poul Sander 2023-11-29 20:33 71
e35cd386 Poul Sander 2023-11-29 20:33 72
	void Draw(SDL_Renderer* target) override {
e35cd386 Poul Sander 2023-11-29 20:33 73
		Menu::Draw(target);
e35cd386 Poul Sander 2023-11-29 20:33 74
		game->DoPaintJob();
e35cd386 Poul Sander 2023-11-29 20:33 75
		themeTitle.SetText(fmt::format(_("Theme: {}"), globalData.theme.theme_name));
e35cd386 Poul Sander 2023-11-29 20:33 76
		themeTitle.Draw(target, 10, globalData.ysize-50,sago::SagoTextField::Alignment::left);
e35cd386 Poul Sander 2023-11-29 20:33 77
	}
e35cd386 Poul Sander 2023-11-29 20:33 78
};
e35cd386 Poul Sander 2023-11-29 20:33 79
66d6174b Poul Sander 2024-01-13 22:45 80
static Theme themeBackup;
66d6174b Poul Sander 2024-01-13 22:45 81
static Theme themeToEdit;
66d6174b Poul Sander 2024-01-13 22:45 82
66d6174b Poul Sander 2024-01-13 22:45 83
static void themesEditSwitchBackground() {
66d6174b Poul Sander 2024-01-13 22:45 84
	themeToEdit.background = ThemesGetNextBackground(themeToEdit.background.name);
66d6174b Poul Sander 2024-01-13 22:45 85
	globalData.theme = themeToEdit;
66d6174b Poul Sander 2024-01-13 22:45 86
}
7602f86d Poul Sander 2024-01-10 21:39 87
de41f458 Poul Sander 2024-01-29 20:53 88
static void themesEditSwitchBoardBackground() {
de41f458 Poul Sander 2024-01-29 20:53 89
	themeToEdit.back_board = ThemesGetNextBoardBackground(themeToEdit.back_board);
de41f458 Poul Sander 2024-01-29 20:53 90
	globalData.theme = themeToEdit;
de41f458 Poul Sander 2024-01-29 20:53 91
}
de41f458 Poul Sander 2024-01-29 20:53 92
5d5a5e92 Poul Sander 2024-03-06 21:41 93
static void themesEditSwitchBorder() {
5d5a5e92 Poul Sander 2024-03-06 21:41 94
	themeToEdit.border = ThemesGetNextBorder(themeToEdit.border.name);
5d5a5e92 Poul Sander 2024-03-06 21:41 95
	globalData.theme = themeToEdit;
5d5a5e92 Poul Sander 2024-03-06 21:41 96
}
5d5a5e92 Poul Sander 2024-03-06 21:41 97
c8e0251f Poul Sander 2024-02-07 21:38 98
static void themesEditSlot(int slot) {
c8e0251f Poul Sander 2024-02-07 21:38 99
	ThemesMenu tem(globalData.screen, fmt::format(_("Edit custom theme {}"), slot), true);
c8e0251f Poul Sander 2024-02-07 21:38 100
	size_t theme_index = ThemeGetNumber(fmt::format("custom_slot_{}", slot));
7602f86d Poul Sander 2024-01-10 21:39 101
	if (theme_index == 0) {
7602f86d Poul Sander 2024-01-10 21:39 102
		// Theme not found
7602f86d Poul Sander 2024-01-10 21:39 103
		return;
7602f86d Poul Sander 2024-01-10 21:39 104
	}
66d6174b Poul Sander 2024-01-13 22:45 105
	Button bSwitchBackground;
66d6174b Poul Sander 2024-01-13 22:45 106
	bSwitchBackground.setLabel(_("Switch background"));
66d6174b Poul Sander 2024-01-13 22:45 107
	bSwitchBackground.setAction(&themesEditSwitchBackground);
66d6174b Poul Sander 2024-01-13 22:45 108
	tem.addButton(&bSwitchBackground);
de41f458 Poul Sander 2024-01-29 20:53 109
	Button bSwitchBoardBackground;
de41f458 Poul Sander 2024-01-29 20:53 110
	bSwitchBoardBackground.setLabel(_("Switch board background"));
de41f458 Poul Sander 2024-01-29 20:53 111
	bSwitchBoardBackground.setAction(&themesEditSwitchBoardBackground);
de41f458 Poul Sander 2024-01-29 20:53 112
	tem.addButton(&bSwitchBoardBackground);
5d5a5e92 Poul Sander 2024-03-06 21:41 113
	Button bSwitchBorder;
5d5a5e92 Poul Sander 2024-03-06 21:41 114
	bSwitchBorder.setLabel(_("Switch border"));
5d5a5e92 Poul Sander 2024-03-06 21:41 115
	bSwitchBorder.setAction(&themesEditSwitchBorder);
5d5a5e92 Poul Sander 2024-03-06 21:41 116
	tem.addButton(&bSwitchBorder);
66d6174b Poul Sander 2024-01-13 22:45 117
	themeBackup = globalData.theme;
66d6174b Poul Sander 2024-01-13 22:45 118
	themeToEdit = ThemesGet(theme_index);
66d6174b Poul Sander 2024-01-13 22:45 119
	globalData.theme = themeToEdit;
7602f86d Poul Sander 2024-01-10 21:39 120
	RunGameState(tem);
66d6174b Poul Sander 2024-01-13 22:45 121
	ThemesAddOrReplace(themeToEdit);
66d6174b Poul Sander 2024-01-13 22:45 122
	globalData.theme = themeBackup;
c8e0251f Poul Sander 2024-02-07 21:38 123
	ThemesSaveCustomSlots();
c8e0251f Poul Sander 2024-02-07 21:38 124
}
c8e0251f Poul Sander 2024-02-07 21:38 125
c8e0251f Poul Sander 2024-02-07 21:38 126
static void themesEditSlot1() {
c8e0251f Poul Sander 2024-02-07 21:38 127
	themesEditSlot(1);
c8e0251f Poul Sander 2024-02-07 21:38 128
}
c8e0251f Poul Sander 2024-02-07 21:38 129
c8e0251f Poul Sander 2024-02-07 21:38 130
static void themesEditSlot2() {
c8e0251f Poul Sander 2024-02-07 21:38 131
	themesEditSlot(2);
7602f86d Poul Sander 2024-01-10 21:39 132
}
7602f86d Poul Sander 2024-01-10 21:39 133
7602f86d Poul Sander 2024-01-10 21:39 134
e35cd386 Poul Sander 2023-11-29 20:33 135
void OpenThemesMenu() {
e35cd386 Poul Sander 2023-11-29 20:33 136
	ThemesMenu tm(globalData.screen, _("Themes"), true);
e35cd386 Poul Sander 2023-11-29 20:33 137
	Button bSwitchTheme;
e35cd386 Poul Sander 2023-11-29 20:33 138
	bSwitchTheme.setLabel(_("Switch theme"));
e35cd386 Poul Sander 2023-11-29 20:33 139
	bSwitchTheme.setAction(&switchTheme);
e35cd386 Poul Sander 2023-11-29 20:33 140
	tm.addButton(&bSwitchTheme);
7602f86d Poul Sander 2024-01-10 21:39 141
	Button bEditTheme1;
c8e0251f Poul Sander 2024-02-07 21:38 142
	bEditTheme1.setLabel(fmt::format(_("Edit custom theme {}"), 1));
7602f86d Poul Sander 2024-01-10 21:39 143
	bEditTheme1.setAction(&themesEditSlot1);
7602f86d Poul Sander 2024-01-10 21:39 144
	tm.addButton(&bEditTheme1);
c8e0251f Poul Sander 2024-02-07 21:38 145
	Button bEditTheme2;
c8e0251f Poul Sander 2024-02-07 21:38 146
	bEditTheme2.setLabel(fmt::format(_("Edit custom theme {}"), 2));
c8e0251f Poul Sander 2024-02-07 21:38 147
	bEditTheme2.setAction(&themesEditSlot2);
c8e0251f Poul Sander 2024-02-07 21:38 148
	tm.addButton(&bEditTheme2);
e35cd386 Poul Sander 2023-11-29 20:33 149
	if (!globalData.NoSound) {
e35cd386 Poul Sander 2023-11-29 20:33 150
		Button bTestMusic;
e35cd386 Poul Sander 2023-11-29 20:33 151
		bTestMusic.setLabel(_("Test music"));
e35cd386 Poul Sander 2023-11-29 20:33 152
		bTestMusic.setAction(&testMusic);
e35cd386 Poul Sander 2023-11-29 20:33 153
		tm.addButton(&bTestMusic);
e35cd386 Poul Sander 2023-11-29 20:33 154
	}
e35cd386 Poul Sander 2023-11-29 20:33 155
	RunGameState(tm);
e35cd386 Poul Sander 2023-11-29 20:33 156
}
1970-01-01 00:00 157