git repos / saland

commit f05a15db

Poul Sander · 2019-04-21 14:41
f05a15dbc9ecee1725ca5ff5b204f0b0ceb89524 patch · browse files
parent cb147fbf9ed03c0376684038b4c7113fc9d4adab

Added a shop stub

Changed files

M src/saland/Game.cpp before
A src/saland/GameShop.cpp
A src/saland/GameShop.hpp
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 83327e5..b570692 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -27,6 +27,7 @@ https://github.com/sago007/saland
#include "GameUpdates.hpp"
#include "GameRegion.hpp"
#include "Game.hpp"
+#include "GameShop.hpp"
#include "model/World.hpp"
#include "../sagotmx/tmx_struct.h"
#include "../sago/SagoMisc.hpp"
@@ -111,11 +112,14 @@ struct ResetRegionConsoleCommand : public ConsoleCommand {
}
};
+void RunGameState(sago::GameStateInterface& state );
+
struct ShopCommand : public ConsoleCommand {
virtual std::string getCommand() const override {return "shop";}
virtual std::string run(const std::vector<std::string>&) override {
- throw std::runtime_error("Not implemented!");
- return "Region reset queued!";
+ GameShop gs;
+ RunGameState(gs);
+ return "Shop!";
}
virtual std::string helpMessage() const override {
diff --git a/src/saland/GameShop.cpp b/src/saland/GameShop.cpp new file mode 100644 index 0000000..cfffd4e --- /dev/null +++ b/src/saland/GameShop.cpp
@@ -0,0 +1,61 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2019 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 "globals.hpp"
+#include "GameShop.hpp"
+
+struct GameShop::GameShopImpl {
+ bool active = true;
+ std::string name = "Shop!!";
+ sago::SagoTextField headerField;
+};
+
+
+GameShop::GameShop() {
+ data.reset(new GameShop::GameShopImpl());
+ data->headerField.SetHolder(globalData.dataHolder);
+ data->headerField.SetFontSize(20);
+ data->headerField.SetText(data->name);
+}
+
+bool GameShop::IsActive() {
+ return data->active;
+}
+
+void GameShop::Draw(SDL_Renderer* target) {
+ data->headerField.Draw(target, globalData.xsize/2, 4, sago::SagoTextField::Alignment::center);
+}
+
+void GameShop::ProcessInput(const SDL_Event& event, bool &) {
+ if (event.type == SDL_KEYDOWN) {
+ data->active = false;
+ }
+}
+
+void GameShop::Update() {
+
+}
+
+GameShop::~GameShop() {
+
+}
\ No newline at end of file
diff --git a/src/saland/GameShop.hpp b/src/saland/GameShop.hpp new file mode 100644 index 0000000..5e19e6d --- /dev/null +++ b/src/saland/GameShop.hpp
@@ -0,0 +1,45 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2019 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 GAMESHOP_HPP
+#define GAMESHOP_HPP
+
+#include "../sago/GameStateInterface.hpp"
+#include "../sago/SagoTextField.hpp"
+#include <memory>
+
+class GameShop : public sago::GameStateInterface {
+public:
+ GameShop();
+ 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;
+ GameShop(const GameShop&) = delete;
+ virtual ~GameShop();
+private:
+ struct GameShopImpl;
+ std::unique_ptr<GameShopImpl> data;
+};
+
+#endif /* GAMEAREA_HPP */
\ No newline at end of file