Skip to content

Commit

Permalink
[Config] 'isChunkMinimapEnabled' added, along with its menu option in…
Browse files Browse the repository at this point in the history
… SettingsMenuState.
  • Loading branch information
Unarelith committed Jul 28, 2020
1 parent a1366e1 commit ee1efcc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions source/client/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ u8 Config::mipmapLevels = 0;
// Input
u8 Config::mouseSensitivity = 8;

// Debug
bool Config::isChunkMinimapEnabled = false;

// Other
std::string Config::defaultUsername = "";
std::string Config::defaultServerAddress = "localhost:4242";
Expand Down Expand Up @@ -106,6 +109,8 @@ void Config::loadConfigFromFile(const char *filename) {

mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity);

isChunkMinimapEnabled = lua["isChunkMinimapEnabled"].get_or(isChunkMinimapEnabled);

defaultUsername = lua["defaultUsername"].get_or(defaultUsername);
defaultServerAddress = lua["defaultServerAddress"].get_or(defaultServerAddress);
texturePack = lua["texturePack"].get_or(texturePack);
Expand Down Expand Up @@ -144,6 +149,8 @@ void Config::saveConfigToFile(const char *filename) {
file << std::endl;
file << "mouseSensitivity = " << (u16)mouseSensitivity << std::endl;
file << std::endl;
file << "isChunkMinimapEnabled = " << (isChunkMinimapEnabled ? "true" : "false") << std::endl;
file << std::endl;
file << "defaultUsername = \"" << defaultUsername << "\"" << std::endl;
file << "defaultServerAddress = \"" << defaultServerAddress << "\"" << std::endl;
file << "texturePack = \"" << texturePack << "\"" << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions source/client/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ namespace Config {
// Input
extern u8 mouseSensitivity;

// Debug
extern bool isChunkMinimapEnabled;

// Other
extern std::string defaultUsername;
extern std::string defaultServerAddress;
Expand Down
7 changes: 4 additions & 3 deletions source/client/hud/HUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void HUD::setup() {
m_chat.setPosition(2, Config::screenHeight / Config::guiScale - 50);

m_minimap.setPosition(Config::screenWidth / Config::guiScale - Minimap::minimapSize - 15, 15);
// m_minimap.setPosition(Config::screenWidth / Config::guiScale - Minimap::minimapSize - 10 - Minimap::minimapSize / 2, 10 - Minimap::minimapSize / 2);
}

void HUD::onEvent(const SDL_Event &event) {
Expand Down Expand Up @@ -104,7 +103,8 @@ void HUD::update() {
m_blockInfoWidget.setCurrentBlock(m_blockCursor.currentBlock());
}

m_minimap.update(m_player, m_world);
if (Config::isChunkMinimapEnabled)
m_minimap.update(m_player, m_world);
}

void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
Expand All @@ -129,7 +129,8 @@ void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (Config::isFpsCounterEnabled)
target.draw(m_fpsText, states);

target.draw(m_minimap, states);
if (Config::isChunkMinimapEnabled)
target.draw(m_minimap, states);

target.draw(m_chat, states);

Expand Down
13 changes: 13 additions & 0 deletions source/client/states/SettingsMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ void SettingsMenuState::addMainButtons() {
addInputButtons();
});

m_menuWidget.addButton("Debug...", [this] (TextButton &) {
m_state = MenuState::Debug;
addDebugButtons();
});

m_menuWidget.addButton("Texture Pack...", [this] (TextButton &) {
m_stateStack->push<TexturePackSelectionState>(this);
});
Expand Down Expand Up @@ -293,6 +298,14 @@ void SettingsMenuState::addInputButtons() {
updateWidgetPosition();
}

void SettingsMenuState::addDebugButtons() {
m_menuWidget.reset(1, 8);

addToggleButton("Show chunk minimap", Config::isChunkMinimapEnabled, false);

updateWidgetPosition();
}

TextButton &SettingsMenuState::addToggleButton(const std::string &text, bool &configOption, bool worldReloadRequested) {
return m_menuWidget.addButton(text + ": " + (configOption ? "ON" : "OFF"), [=, &configOption] (TextButton &button) {
configOption = !configOption;
Expand Down
4 changes: 3 additions & 1 deletion source/client/states/SettingsMenuState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SettingsMenuState : public InterfaceState {
void addInterfaceButtons();
void addGraphicsButtons();
void addInputButtons();
void addDebugButtons();

TextButton &addToggleButton(const std::string &text, bool &configOption, bool worldReloadRequested = false);

Expand All @@ -78,7 +79,8 @@ class SettingsMenuState : public InterfaceState {
Main,
Gameplay,
Graphics,
Input
Input,
Debug
};

MenuState m_state = MenuState::Main;
Expand Down

0 comments on commit ee1efcc

Please sign in to comment.