Skip to content

Commit

Permalink
Split theme menu to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
sago007 committed Nov 29, 2023
1 parent 607bd2a commit e35cd38
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ endif()


#building/compiling/linking
add_executable(blockattack ${GUI_TYPE} ${SOURCES} ${RES_FILES})
add_executable(blockattack ${GUI_TYPE} ${SOURCES} ${RES_FILES}
source/code/menudef_themes.cpp
source/code/menudef_themes.hpp)

target_include_directories(blockattack PRIVATE "source/code/Libs/include")
target_include_directories(blockattack PRIVATE "source/code/Libs/include/cereal/external") #Contains rapidjson
Expand Down
1 change: 1 addition & 0 deletions source/code/MenuSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Source information and contacts persons can be found at
#include "global.hpp"
#include "gamecontroller.h"
#include "BlockGame.hpp"
#include "menudef_themes.hpp"

static int oldmousex = 0;
static int oldmousey = 0;
Expand Down
90 changes: 90 additions & 0 deletions source/code/menudef_themes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
===========================================================================
blockattack - Block Attack - Rise of the Blocks
Copyright (C) 2005-2013 Poul Sander
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
Source information and contacts persons can be found at
http://blockattack.net
===========================================================================
*/
#include "global.hpp"
#include "menudef_themes.hpp"
#include "MenuSystem.h"
#include "BlockGameSdl.hpp"
#include <fmt/core.h>

static void switchTheme() {
globalData.theme = ThemesGetNext();
}


static void testMusic() {
static bool highbeatNext = false;
int musicVolume = Config::getInstance()->getInt("volume_music");
std::string music_name = "bgmusic";
if (highbeatNext) {
music_name = "highbeat";
}
Mix_PlayMusic(globalData.spriteHolder->GetDataHolder().getMusicHandler(music_name.c_str()).get(), 1);
Mix_VolumeMusic(musicVolume);
highbeatNext = !highbeatNext; //Toggle between standard and highbeat
}

class ThemesMenu : public Menu {
private:
std::shared_ptr<BlockGameSdl> game;
sago::SagoTextField themeTitle;
public:
ThemesMenu(SDL_Renderer* screen, const std::string& title, bool submenu) : Menu(screen, title, submenu) {
game = std::make_shared<BlockGameSdl>(globalData.xsize-450,100,&globalData.spriteHolder->GetDataHolder());
game->putSampleBlocks();
sagoTextSetBlueFont(themeTitle);
}

void placeButtons() override {
int nextY = 100;
int X = 10;
for (Button* it : buttons) {
it->x = X;
it->y = nextY;
nextY += it->standardButton.ysize+10;
}
exit.x = X;
exit.y = nextY;
}

void Draw(SDL_Renderer* target) override {
Menu::Draw(target);
game->DoPaintJob();
themeTitle.SetText(fmt::format(_("Theme: {}"), globalData.theme.theme_name));
themeTitle.Draw(target, 10, globalData.ysize-50,sago::SagoTextField::Alignment::left);
}
};

void OpenThemesMenu() {
ThemesMenu tm(globalData.screen, _("Themes"), true);
Button bSwitchTheme;
bSwitchTheme.setLabel(_("Switch theme"));
bSwitchTheme.setAction(&switchTheme);
tm.addButton(&bSwitchTheme);
if (!globalData.NoSound) {
Button bTestMusic;
bTestMusic.setLabel(_("Test music"));
bTestMusic.setAction(&testMusic);
tm.addButton(&bTestMusic);
}
RunGameState(tm);
}
29 changes: 29 additions & 0 deletions source/code/menudef_themes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
===========================================================================
blockattack - Block Attack - Rise of the Blocks
Copyright (C) 2005-2013 Poul Sander
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
Source information and contacts persons can be found at
http://blockattack.net
===========================================================================
*/

#ifndef MENUDEF_THEMES_HPP
#define MENUDEF_THEMES_HPP

void OpenThemesMenu();

#endif // MENUDEF_THEMES_HPP

0 comments on commit e35cd38

Please sign in to comment.