| 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()); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
55 |
game->putSampleBlocks(); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
56 |
sagoTextSetBlueFont(themeTitle); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
57 |
} |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
58 |
|
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
59 |
void placeButtons() override { |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
60 |
int nextY = 100; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
61 |
int X = 10; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
62 |
for (Button* it : buttons) { |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
63 |
it->x = X; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
64 |
it->y = nextY; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
65 |
nextY += it->standardButton.ysize+10; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
66 |
} |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
67 |
exit.x = X; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
68 |
exit.y = nextY; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
69 |
} |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
70 |
|
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
71 |
void Draw(SDL_Renderer* target) override { |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
72 |
Menu::Draw(target); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
73 |
game->DoPaintJob(); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
74 |
themeTitle.SetText(fmt::format(_("Theme: {}"), globalData.theme.theme_name)); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
75 |
themeTitle.Draw(target, 10, globalData.ysize-50,sago::SagoTextField::Alignment::left); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
76 |
} |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
77 |
}; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
78 |
|
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
79 |
static Theme themeBackup; |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
80 |
static Theme themeToEdit; |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
81 |
|
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
82 |
static void themesEditSwitchBackground() { |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
83 |
themeToEdit.background = ThemesGetNextBackground(themeToEdit.background.name); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
84 |
globalData.theme = themeToEdit; |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
85 |
} |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
86 |
|
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
87 |
static void themesEditSwitchBoardBackground() { |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
88 |
themeToEdit.back_board = ThemesGetNextBoardBackground(themeToEdit.back_board); |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
89 |
globalData.theme = themeToEdit; |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
90 |
} |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
91 |
|
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
92 |
static void themesEditSlot1() { |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
93 |
ThemesMenu tem(globalData.screen, _("Edit custom theme 1"), true); |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
94 |
size_t theme_index = ThemeGetNumber("custom_slot_1"); |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
95 |
if (theme_index == 0) { |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
96 |
// Theme not found |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
97 |
return; |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
98 |
} |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
99 |
Button bSwitchBackground; |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
100 |
bSwitchBackground.setLabel(_("Switch background")); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
101 |
bSwitchBackground.setAction(&themesEditSwitchBackground); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
102 |
tem.addButton(&bSwitchBackground); |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
103 |
Button bSwitchBoardBackground; |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
104 |
bSwitchBoardBackground.setLabel(_("Switch board background")); |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
105 |
bSwitchBoardBackground.setAction(&themesEditSwitchBoardBackground); |
| de41f458 |
Poul Sander |
2024-01-29 20:53 |
106 |
tem.addButton(&bSwitchBoardBackground); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
107 |
themeBackup = globalData.theme; |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
108 |
themeToEdit = ThemesGet(theme_index); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
109 |
globalData.theme = themeToEdit; |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
110 |
RunGameState(tem); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
111 |
ThemesAddOrReplace(themeToEdit); |
| 66d6174b |
Poul Sander |
2024-01-13 22:45 |
112 |
globalData.theme = themeBackup; |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
113 |
} |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
114 |
|
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
115 |
|
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
116 |
void OpenThemesMenu() { |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
117 |
ThemesMenu tm(globalData.screen, _("Themes"), true); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
118 |
Button bSwitchTheme; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
119 |
bSwitchTheme.setLabel(_("Switch theme")); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
120 |
bSwitchTheme.setAction(&switchTheme); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
121 |
tm.addButton(&bSwitchTheme); |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
122 |
Button bEditTheme1; |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
123 |
bEditTheme1.setLabel(_("Edit custom theme 1")); |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
124 |
bEditTheme1.setAction(&themesEditSlot1); |
| 7602f86d |
Poul Sander |
2024-01-10 21:39 |
125 |
tm.addButton(&bEditTheme1); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
126 |
if (!globalData.NoSound) { |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
127 |
Button bTestMusic; |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
128 |
bTestMusic.setLabel(_("Test music")); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
129 |
bTestMusic.setAction(&testMusic); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
130 |
tm.addButton(&bTestMusic); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
131 |
} |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
132 |
RunGameState(tm); |
| e35cd386 |
Poul Sander |
2023-11-29 20:33 |
133 |
} |
|
|
1970-01-01 00:00 |
134 |
|