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
c8e0251f Poul Sander 2024-02-07 21:38 93
static void themesEditSlot(int slot) {
c8e0251f Poul Sander 2024-02-07 21:38 94
	ThemesMenu tem(globalData.screen, fmt::format(_("Edit custom theme {}"), slot), true);
c8e0251f Poul Sander 2024-02-07 21:38 95
	size_t theme_index = ThemeGetNumber(fmt::format("custom_slot_{}", slot));
7602f86d Poul Sander 2024-01-10 21:39 96
	if (theme_index == 0) {
7602f86d Poul Sander 2024-01-10 21:39 97
		// Theme not found
7602f86d Poul Sander 2024-01-10 21:39 98
		return;
7602f86d Poul Sander 2024-01-10 21:39 99
	}
66d6174b Poul Sander 2024-01-13 22:45 100
	Button bSwitchBackground;
66d6174b Poul Sander 2024-01-13 22:45 101
	bSwitchBackground.setLabel(_("Switch background"));
66d6174b Poul Sander 2024-01-13 22:45 102
	bSwitchBackground.setAction(&themesEditSwitchBackground);
66d6174b Poul Sander 2024-01-13 22:45 103
	tem.addButton(&bSwitchBackground);
de41f458 Poul Sander 2024-01-29 20:53 104
	Button bSwitchBoardBackground;
de41f458 Poul Sander 2024-01-29 20:53 105
	bSwitchBoardBackground.setLabel(_("Switch board background"));
de41f458 Poul Sander 2024-01-29 20:53 106
	bSwitchBoardBackground.setAction(&themesEditSwitchBoardBackground);
de41f458 Poul Sander 2024-01-29 20:53 107
	tem.addButton(&bSwitchBoardBackground);
66d6174b Poul Sander 2024-01-13 22:45 108
	themeBackup = globalData.theme;
66d6174b Poul Sander 2024-01-13 22:45 109
	themeToEdit = ThemesGet(theme_index);
66d6174b Poul Sander 2024-01-13 22:45 110
	globalData.theme = themeToEdit;
7602f86d Poul Sander 2024-01-10 21:39 111
	RunGameState(tem);
66d6174b Poul Sander 2024-01-13 22:45 112
	ThemesAddOrReplace(themeToEdit);
66d6174b Poul Sander 2024-01-13 22:45 113
	globalData.theme = themeBackup;
c8e0251f Poul Sander 2024-02-07 21:38 114
	ThemesSaveCustomSlots();
c8e0251f Poul Sander 2024-02-07 21:38 115
}
c8e0251f Poul Sander 2024-02-07 21:38 116
c8e0251f Poul Sander 2024-02-07 21:38 117
static void themesEditSlot1() {
c8e0251f Poul Sander 2024-02-07 21:38 118
	themesEditSlot(1);
c8e0251f Poul Sander 2024-02-07 21:38 119
}
c8e0251f Poul Sander 2024-02-07 21:38 120
c8e0251f Poul Sander 2024-02-07 21:38 121
static void themesEditSlot2() {
c8e0251f Poul Sander 2024-02-07 21:38 122
	themesEditSlot(2);
7602f86d Poul Sander 2024-01-10 21:39 123
}
7602f86d Poul Sander 2024-01-10 21:39 124
7602f86d Poul Sander 2024-01-10 21:39 125
e35cd386 Poul Sander 2023-11-29 20:33 126
void OpenThemesMenu() {
e35cd386 Poul Sander 2023-11-29 20:33 127
	ThemesMenu tm(globalData.screen, _("Themes"), true);
e35cd386 Poul Sander 2023-11-29 20:33 128
	Button bSwitchTheme;
e35cd386 Poul Sander 2023-11-29 20:33 129
	bSwitchTheme.setLabel(_("Switch theme"));
e35cd386 Poul Sander 2023-11-29 20:33 130
	bSwitchTheme.setAction(&switchTheme);
e35cd386 Poul Sander 2023-11-29 20:33 131
	tm.addButton(&bSwitchTheme);
7602f86d Poul Sander 2024-01-10 21:39 132
	Button bEditTheme1;
c8e0251f Poul Sander 2024-02-07 21:38 133
	bEditTheme1.setLabel(fmt::format(_("Edit custom theme {}"), 1));
7602f86d Poul Sander 2024-01-10 21:39 134
	bEditTheme1.setAction(&themesEditSlot1);
7602f86d Poul Sander 2024-01-10 21:39 135
	tm.addButton(&bEditTheme1);
c8e0251f Poul Sander 2024-02-07 21:38 136
	Button bEditTheme2;
c8e0251f Poul Sander 2024-02-07 21:38 137
	bEditTheme2.setLabel(fmt::format(_("Edit custom theme {}"), 2));
c8e0251f Poul Sander 2024-02-07 21:38 138
	bEditTheme2.setAction(&themesEditSlot2);
c8e0251f Poul Sander 2024-02-07 21:38 139
	tm.addButton(&bEditTheme2);
e35cd386 Poul Sander 2023-11-29 20:33 140
	if (!globalData.NoSound) {
e35cd386 Poul Sander 2023-11-29 20:33 141
		Button bTestMusic;
e35cd386 Poul Sander 2023-11-29 20:33 142
		bTestMusic.setLabel(_("Test music"));
e35cd386 Poul Sander 2023-11-29 20:33 143
		bTestMusic.setAction(&testMusic);
e35cd386 Poul Sander 2023-11-29 20:33 144
		tm.addButton(&bTestMusic);
e35cd386 Poul Sander 2023-11-29 20:33 145
	}
e35cd386 Poul Sander 2023-11-29 20:33 146
	RunGameState(tm);
e35cd386 Poul Sander 2023-11-29 20:33 147
}
1970-01-01 00:00 148