diff --git a/data/sprites/gui_rect_yellow.sprite b/data/sprites/gui_rect_yellow.sprite new file mode 100644 index 0000000..22c33bd --- /dev/null +++ b/data/sprites/gui_rect_yellow.sprite @@ -0,0 +1,75 @@ +{ + +"ui_rect_yellow_nw" : { + "texture" : "gui_back_yellow", + "topx" : 0, + "topy" : 0, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_n" : { + "texture" : "gui_back_yellow", + "topx" : 32, + "topy" : 0, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_ne" : { + "texture" : "gui_back_yellow", + "topx" : 160, + "topy" : 0, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_e" : { + "texture" : "gui_back_yellow", + "topx" : 160, + "topy" : 32, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_se" : { + "texture" : "gui_back_yellow", + "topx" : 160, + "topy" : 160, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_s" : { + "texture" : "gui_back_yellow", + "topx" : 32, + "topy" : 160, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_sw" : { + "texture" : "gui_back_yellow", + "topx" : 0, + "topy" : 160, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_w" : { + "texture" : "gui_back_yellow", + "topx" : 0, + "topy" : 32, + "height" : 32, + "width" : 32 +}, + +"ui_rect_yellow_fill" : { + "texture" : "gui_back_yellow", + "topx" : 32, + "topy" : 32, + "height" : 32, + "width" : 32 +} + +} diff --git a/src/saland.cpp b/src/saland.cpp index 3efdd46..19956d2 100644 --- a/src/saland.cpp +++ b/src/saland.cpp @@ -252,5 +252,6 @@ int main(int argc, char* argv[]) { Config::getInstance()->setInt("fullscreen", 0); } runGame(); + Config::getInstance()->save(); return 0; } diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 6f90f7c..f548446 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -38,6 +38,7 @@ https://github.com/sago007/saland #include #include #include +#include "console/Console.hpp" int32 velocityIterations = 6; int32 positionIterations = 2; @@ -78,6 +79,7 @@ struct Game::GameImpl { Uint32 lastUpdate = 0; std::string worldName = "world1"; sago::SagoTextField bottomField; + std::shared_ptr c; }; static SpawnPoint GetSpawnpoint(const sago::tiled::TileMap& tm) { @@ -214,6 +216,9 @@ void Game::Draw(SDL_Renderer* target) { ); data->bottomField.SetText(buffer); data->bottomField.Draw(target, 2, screen_height, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::bottom); + if (data->c) { + data->c->Draw(target); + } //#if DEBUG static unsigned long int Frames; static unsigned long int Ticks; @@ -235,6 +240,12 @@ void Game::Draw(SDL_Renderer* target) { } void Game::ProcessInput(const SDL_Event& event, bool& processed) { + if (data->c) { + data->c->ProcessInput(event, processed); + if (processed) { + return; + } + } if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_SPACE) { if (data->human->castTimeRemaining == 0) { @@ -265,6 +276,9 @@ void Game::ProcessInput(const SDL_Event& event, bool& processed) { sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile); data->gameRegion.world.init_physics(data->gameRegion.physicsBox); } + if (event.key.keysym.sym == SDLK_ESCAPE && event.key.keysym.mod & KMOD_LSHIFT) { + data->c = std::make_shared(); + } } } @@ -351,4 +365,7 @@ void Game::Update() { ResetWorld(data->gameRegion.GetRegionX(), data->gameRegion.GetRegionY()+1); data->human->body->SetTransform(b2Vec2(data->gameRegion.world.tm.width/2, 1),data->human->body->GetAngle()) ; } + if (data->c && !data->c->IsActive()) { + data->c = nullptr; + } } diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index 877b904..83b5e69 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp @@ -163,3 +163,42 @@ void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const 255, 255, 0, 255); } } + +static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int width, const std::string& name) { + const int size = 32; + SDL_Rect bounds_ns = {topx, topy+size, width, height-2*size}; //bounds for south + SDL_Rect bounds_e = {topx, topy, width-size, height}; + const sago::SagoSprite& n = globalData.spriteHolder->GetSprite(name+"n"); + const sago::SagoSprite& s = globalData.spriteHolder->GetSprite(name+"s"); + const sago::SagoSprite& e = globalData.spriteHolder->GetSprite(name+"e"); + const sago::SagoSprite& w = globalData.spriteHolder->GetSprite(name+"w"); + const sago::SagoSprite& fill = globalData.spriteHolder->GetSprite(name+"fill"); + for (int i = 1; i < width/size; ++i) { + n.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy, bounds_e); + for (int j = 1; j < height/size; ++j) { + w.DrawBounded(target, SDL_GetTicks(), topx, topy+j*size, bounds_ns); + fill.Draw(target, SDL_GetTicks(),topx+i*size, topy+j*size); + e.DrawBounded(target, SDL_GetTicks(), topx+width-size, topy+j*size, bounds_ns); + } + s.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy+height-size, bounds_e); + } + //Corners + const sago::SagoSprite& nw = globalData.spriteHolder->GetSprite(name+"nw"); + const sago::SagoSprite& ne = globalData.spriteHolder->GetSprite(name+"ne"); + const sago::SagoSprite& se = globalData.spriteHolder->GetSprite(name+"se"); + const sago::SagoSprite& sw = globalData.spriteHolder->GetSprite(name+"sw"); + nw.Draw(target, SDL_GetTicks(), topx, topy); + ne.Draw(target, SDL_GetTicks(), topx+width-size, topy); + se.Draw(target, SDL_GetTicks(), topx+width-size, topy+height-size); + sw.Draw(target, SDL_GetTicks(), topx, topy+height-size); +} + +void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width) { + std::string name = "ui_rect_white_"; + DrawRect(target, topx, topy, height, width, name); +} + +void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width) { + std::string name = "ui_rect_yellow_"; + DrawRect(target, topx, topy, height, width, name); +} \ No newline at end of file diff --git a/src/saland/GameDraw.hpp b/src/saland/GameDraw.hpp index f594b24..b87e57d 100644 --- a/src/saland/GameDraw.hpp +++ b/src/saland/GameDraw.hpp @@ -38,5 +38,8 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster *entity, float time, int offsetX, int offsetY, bool drawCollision); void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile *entity, float time, int offsetX, int offsetY, bool drawCollision); +void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width); +void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width); + #endif /* GAMEDRAW_HPP */ diff --git a/src/saland/console/Console.cpp b/src/saland/console/Console.cpp new file mode 100644 index 0000000..3b04b6c --- /dev/null +++ b/src/saland/console/Console.cpp @@ -0,0 +1,53 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2018 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 +https://github.com/sago007/saland +=========================================================================== + */ + +#include "Console.hpp" +#include "../GameDraw.hpp" +#include "../globals.hpp" + +Console::Console() { +} + +Console::~Console() { +} + +bool Console::IsActive() { + return active; +}; +void Console::Draw(SDL_Renderer* target) { + int sideBoarder = 20; + DrawRectYellow(target, sideBoarder, 10, globalData.ysize/2, globalData.xsize - sideBoarder*2); +} + +void Console::ProcessInput(const SDL_Event& event, bool &processed) { + if (event.type == SDL_KEYDOWN) { + if (event.key.keysym.sym == SDLK_ESCAPE && event.key.keysym.mod & KMOD_LSHIFT) { + active = false; + processed = true; + } + } +} + +void Console::Update() { + return; +} diff --git a/src/saland/console/Console.hpp b/src/saland/console/Console.hpp new file mode 100644 index 0000000..dd07e07 --- /dev/null +++ b/src/saland/console/Console.hpp @@ -0,0 +1,44 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2018 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 +https://github.com/sago007/saland +=========================================================================== + */ + +#ifndef CONSOLE_HPP +#define CONSOLE_HPP + +#include "../../sago/GameStateInterface.hpp" + +class Console : public sago::GameStateInterface { +public: + Console(); + virtual bool IsActive() override; + virtual void Draw(SDL_Renderer* target) override; + virtual void ProcessInput(const SDL_Event& event, bool &processed) override; + virtual void Update() override; + Console(const Console& orig) = delete; + Console& operator=(const Console&) = delete; + virtual ~Console(); +private: + bool active = true; +}; + +#endif /* CONSOLE_HPP */ +