Skip to content

Commit

Permalink
Add minimal gui code
Browse files Browse the repository at this point in the history
  • Loading branch information
abarichello committed Jan 13, 2019
1 parent 9a2e8b3 commit 98eacbd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -18,6 +18,8 @@ Release/

# Dependencies
SFML**
include/
lib/

# Scons
.sconsign.dblite
Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Expand Up @@ -15,7 +15,7 @@ print("--- Using compiler: {}".format(env["CXX"]))

# Link libraries
LINUX_LIBS = ["stdc++", "sfml-graphics", "sfml-window", "sfml-system", "tgui"]
WIN_LIBS = ["sfml-graphics", "sfml-window", "sfml-system"]
WIN_LIBS = ["tgui", "sfml-graphics", "sfml-window", "sfml-system"]
MINGW_LIBS = ["-static-libgcc", "-static-libstdc++", "sfml-graphics", "sfml-window", "sfml-system"]

# Compiler/Linker flags
Expand Down
6 changes: 4 additions & 2 deletions src/game/Map.cpp
Expand Up @@ -37,7 +37,9 @@ void Map::loadMinimap() {
}
}

texture.loadFromImage(image);
sf::Texture tex;
tex.loadFromImage(image);
texture = tex;
minimap.setTexture(texture);
minimap.setPosition(minimapPos);
minimap.setScale(minimapScale);
Expand All @@ -46,7 +48,7 @@ void Map::loadMinimap() {
}

void Map::drawMinimap(sf::RenderWindow& window) {
window.draw(minimap);
minimap.draw(window, sf::RenderStates::Default);
}

// Save minimap as a image to disk
Expand Down
7 changes: 4 additions & 3 deletions src/game/Map.h
@@ -1,6 +1,7 @@
#pragma once

#include <SFML/Graphics.hpp>
#include <TGUI/Widgets/Canvas.hpp>
#include <string>
#include <unordered_map>

Expand All @@ -23,14 +24,14 @@ class Map {

private:
sf::Image image;
sf::Texture texture;
sf::Sprite minimap;
tgui::Texture texture;
tgui::Sprite minimap;

sf::Color background = sf::Color(170, 170, 170, transparency);
sf::Color border = sf::Color(100, 100, 100, transparency);
sf::Color unknown = sf::Color(12, 247, 12, transparency);

const std::string minimapPath = "minimap.png";
const std::string minimapPath = "./minimap.png";

// TODO: Load map from elsewhere
int map[24][24] = {
Expand Down
5 changes: 4 additions & 1 deletion src/states/GameState.cpp
Expand Up @@ -8,6 +8,7 @@ bool GameState::input(const sf::Event& event) {
if (event.key.code == sf::Keyboard::Escape) {
context.window->close();
}
gui.handleEvent(event);
return true;
}

Expand All @@ -17,5 +18,7 @@ bool GameState::update(float delta) {
}

void GameState::draw() {
player1.draw(*context.window);
sf::RenderWindow& window = *context.window;
player1.draw(window);
gui.draw();
}
2 changes: 1 addition & 1 deletion src/states/State.cpp
Expand Up @@ -6,7 +6,7 @@ State::SharedContext::SharedContext(sf::RenderWindow& window, TextureHolder& tex
}

State::State(StateManager& stateManager, SharedContext context)
: stateManager(&stateManager), context(context) {
: stateManager(&stateManager), context(context), gui(*context.window) {
}

State::~State() {
Expand Down
2 changes: 2 additions & 0 deletions src/states/State.h
@@ -1,5 +1,6 @@
#pragma once

#include <TGUI/Gui.hpp>
#include <memory>

#include "StateType.h"
Expand Down Expand Up @@ -29,6 +30,7 @@ class State {
void requestPop();
void requestClear();
SharedContext context;
tgui::Gui gui;

private:
StateManager* stateManager;
Expand Down

0 comments on commit 98eacbd

Please sign in to comment.