Skip to content

Commit

Permalink
[Config] More options added to hide interface. [TitleScreenState] Bac…
Browse files Browse the repository at this point in the history
…kground added.
  • Loading branch information
Unarelith committed Mar 4, 2020
1 parent be86e66 commit 10d5154
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions client/source/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ bool Config::isNoClipEnabled = false;

// Interface
bool Config::isBlockInfoWidgetEnabled = true;
bool Config::isFpsCounterEnabled = true;
bool Config::isHotbarVisible = true;
bool Config::isCrosshairVisible = true;

// Graphics
u16 Config::renderDistance = 8;
Expand Down Expand Up @@ -66,6 +69,9 @@ void Config::loadConfigFromFile(const char *file) {
isNoClipEnabled = lua["isNoClipEnabled"].get_or(isNoClipEnabled);

isBlockInfoWidgetEnabled = lua["isBlockInfoWidgetEnabled"].get_or(isBlockInfoWidgetEnabled);
isFpsCounterEnabled = lua["isFpsCounterEnabled"].get_or(isFpsCounterEnabled);
isHotbarVisible = lua["isHotbarVisible"].get_or(isHotbarVisible);
isCrosshairVisible = lua["isCrosshairVisible"].get_or(isCrosshairVisible);

renderDistance = lua["renderDistance"].get_or(renderDistance);
isTorchSmoothLightingEnabled = lua["isTorchSmoothLightingEnabled"].get_or(isTorchSmoothLightingEnabled);
Expand Down
3 changes: 3 additions & 0 deletions client/source/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace Config {

// Interface
extern bool isBlockInfoWidgetEnabled;
extern bool isFpsCounterEnabled;
extern bool isHotbarVisible;
extern bool isCrosshairVisible;

// Graphics
extern u16 renderDistance;
Expand Down
21 changes: 15 additions & 6 deletions client/source/hud/HUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ void HUD::onEvent(const SDL_Event &event) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F3)
m_isDebugOverlayVisible ^= 1;

m_hotbar.onEvent(event);
if (Config::isHotbarVisible)
m_hotbar.onEvent(event);

m_blockCursor.onEvent(event, m_hotbar);
}

void HUD::update() {
// FIXME: Shouldn't be called every tick
m_hotbar.update();
if (Config::isHotbarVisible)
m_hotbar.update();

m_fpsText.setText(std::to_string(gk::GameClock::getFpsAverage()) + " FPS");
if (Config::isFpsCounterEnabled)
m_fpsText.setText(std::to_string(gk::GameClock::getFpsAverage()) + " FPS");

m_blockCursor.update(m_hotbar);

Expand Down Expand Up @@ -106,12 +110,17 @@ void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (Config::isBlockInfoWidgetEnabled)
target.draw(m_blockInfoWidget, states);

target.draw(m_hotbar, states);
target.draw(m_fpsText, states);
if (Config::isHotbarVisible)
target.draw(m_hotbar, states);

if (Config::isFpsCounterEnabled)
target.draw(m_fpsText, states);

target.draw(m_chat, states);

states.transform = gk::Transform::Identity;

target.draw(m_crosshair, states);
if (Config::isCrosshairVisible)
target.draw(m_crosshair, states);
}

5 changes: 4 additions & 1 deletion client/source/states/ServerConnectState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "ServerConnectState.hpp"
#include "ServerLoadingState.hpp"

ServerConnectState::ServerConnectState() {
ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : InterfaceState(parent) {
m_textInput.setContent("localhost:4242");
m_textInput.setCharacterLimit(15 + 1 + 6);
m_textInput.setSize(400, 54);
Expand Down Expand Up @@ -86,6 +86,9 @@ void ServerConnectState::update() {
}

void ServerConnectState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (m_parent)
target.draw(*m_parent, states);

prepareDraw(target, states);

target.draw(m_textInput, states);
Expand Down
2 changes: 1 addition & 1 deletion client/source/states/ServerConnectState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class ServerConnectState : public InterfaceState {
public:
ServerConnectState();
ServerConnectState(gk::ApplicationState *parent = nullptr);

void onEvent(const SDL_Event &event) override;

Expand Down
3 changes: 3 additions & 0 deletions client/source/states/SettingsMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ void SettingsMenuState::addInterfaceButtons() {
m_menuWidget.reset(1, 8);

addToggleButton("Show block info", Config::isBlockInfoWidgetEnabled, false);
addToggleButton("Show FPS counter", Config::isFpsCounterEnabled, false);
addToggleButton("Show hotbar", Config::isHotbarVisible, false);
addToggleButton("Show crosshair", Config::isCrosshairVisible, false);
}

void SettingsMenuState::addGraphicsButtons() {
Expand Down
8 changes: 5 additions & 3 deletions client/source/states/TitleScreenState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TitleScreenState::TitleScreenState() {
m_menuWidget.setScale(Config::guiScale, Config::guiScale, 1);

m_menuWidget.addButton("Play", [this] (TextButton &) {
m_stateStack->push<ServerConnectState>();
m_stateStack->push<ServerConnectState>(this);
});

m_menuWidget.addButton("Options...", [this] (TextButton &) {
Expand All @@ -59,9 +59,11 @@ void TitleScreenState::update() {
}

void TitleScreenState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (&m_stateStack->top() == this) {
prepareDraw(target, states);
prepareDraw(target, states);

target.draw(m_background, states);

if (&m_stateStack->top() == this) {
target.draw(m_menuWidget, states);
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/source/states/TitleScreenState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TitleScreenState : public InterfaceState {
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;

MenuWidget m_menuWidget{1, 3};

gk::Image m_background{"texture-title_screen"};
};

#endif // TITLESCREENSTATE_HPP_
1 change: 1 addition & 0 deletions resources/config/textures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<texture name="furnace" path="resources/textures/furnace.png" />
<texture name="inventory" path="resources/textures/inventory.png" />
<texture name="toasts" path="resources/textures/toasts.png" />
<texture name="title_screen" path="resources/textures/title_screen.png" />
<texture name="widgets" path="resources/textures/widgets.png" />
<texture name="workbench" path="resources/textures/workbench.png" />
<texture name="player" path="resources/textures/player.png" />
Expand Down
Binary file added resources/textures/title_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 10d5154

Please sign in to comment.