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