git repos / saland

commit 4bb79b4f

Poul Sander · 2021-05-29 21:06
4bb79b4f35036e55280866e4d194b7a279b24240 patch · browse files
parent 426e8fd77d815743d4269d61d979007a5146b6be

Add "About" section

Changed files

M src/MenuSystem.cpp before
M src/MenuSystem.h before
M src/global.hpp before
A src/help/DialogBox.cpp
A src/help/DialogBox.hpp
A src/help/HelpAboutState.cpp
A src/help/HelpAboutState.hpp
A src/help/HelpCommon.cpp
A src/help/HelpCommon.hpp
A src/help/ReadKeyboard.cpp
A src/help/ReadKeyboard.h
A src/help/scopeHelpers.hpp
M src/saland.cpp before
M src/saland/globals.hpp before
diff --git a/src/MenuSystem.cpp b/src/MenuSystem.cpp index 39149a0..c7132b8 100644 --- a/src/MenuSystem.cpp +++ b/src/MenuSystem.cpp
@@ -32,6 +32,14 @@ static int oldmousey = 0;
const char* const menu_marked = "menu_marked";
const char* const menu_unmarked = "menu_unmarked";
+void sagoTextSetBlueFont(sago::SagoTextField& field) {
+ field.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ field.SetFont("freeserif");
+ field.SetFontSize(30);
+ field.SetColor({0,0,255,255});
+ field.SetOutline(1, {128,128,255,255});
+}
+
ButtonGfx standardButton;
void ButtonGfx::setSurfaces() {
diff --git a/src/MenuSystem.h b/src/MenuSystem.h index 12e7897..405f393 100644 --- a/src/MenuSystem.h +++ b/src/MenuSystem.h
@@ -34,6 +34,8 @@ https://github.com/sago007/saland
#include <memory>
#include "sago/SagoTextField.hpp"
+void sagoTextSetBlueFont(sago::SagoTextField& field);
+
//The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer
struct ButtonGfx
{
diff --git a/src/global.hpp b/src/global.hpp index b116be4..901b95f 100644 --- a/src/global.hpp +++ b/src/global.hpp
@@ -25,8 +25,10 @@ https://github.com/sago007/saland
#define GLOBAL_HPP
#include "saland/globals.hpp"
+#include "sago/GameStateInterface.hpp"
void UpdateMouseCoordinates(const SDL_Event& event, int& mousex, int& mousey);
+void RunGameState(sago::GameStateInterface& state );
#endif /* GLOBAL_HPP */
diff --git a/src/help/DialogBox.cpp b/src/help/DialogBox.cpp new file mode 100644 index 0000000..cdb7c2d --- /dev/null +++ b/src/help/DialogBox.cpp
@@ -0,0 +1,309 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#include "DialogBox.hpp"
+#include "../global.hpp"
+#include "../common.h"
+#include "ReadKeyboard.h"
+#include "utf8.h"
+#include "../MenuSystem.h"
+
+static void setButtonFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
+ field.SetHolder(holder);
+ field.SetFont("freeserif");
+ field.SetColor({255,255,255,255});
+ field.SetFontSize(24);
+ field.SetOutline(1, {0,0,0,255});
+ field.SetText(text);
+}
+
+
+bool OpenDialogbox(int x, int y, std::string& name, const std::string& header) {
+ DialogBox d(x, y, name, header);
+ RunGameState(d);
+ if (d.IsUpdated()) {
+ name = d.GetName();
+ return true;
+ }
+ return false;
+}
+
+DialogBox::DialogBox(int x, int y, const std::string& name, const std::string& header) : header(header) {
+ this->x = x;
+ this->y = y;
+ SetName(name);
+ setButtonFont(&globalData.spriteHolder->GetDataHolder(), headerLabel, header.c_str());
+ setButtonFont(&globalData.spriteHolder->GetDataHolder(), enterLabel, _("Enter to accept"));
+ setButtonFont(&globalData.spriteHolder->GetDataHolder(), cancelLabel, _("Esc to cancel"));
+ sagoTextSetBlueFont(textField);
+ sagoTextSetBlueFont(cursorLabel);
+ cursorLabel.SetText("|");
+ for (auto position = virtualKeyboard.alphabet.begin(); position != virtualKeyboard.alphabet.end() ; utf8::advance(position, 1, virtualKeyboard.alphabet.end())) {
+ auto endPosition = position;
+ utf8::advance(endPosition, 1, virtualKeyboard.alphabet.end());
+ std::string theChar(position, endPosition);
+ virtualKeyboard.gamePadChars.push_back(theChar);
+ virtualKeyboard.gamePadCharFields.emplace_back();
+ sago::SagoTextField& tf = virtualKeyboard.gamePadCharFields.back();
+ setButtonFont(&globalData.spriteHolder->GetDataHolder(), tf, theChar.c_str());
+ if (globalData.verboseLevel) {
+ std::cout << *position;
+ }
+ }
+ if (globalData.verboseLevel) {
+ std::cout << "\n";
+ }
+}
+
+
+DialogBox::~DialogBox() {
+}
+
+bool DialogBox::IsActive() {
+ return isActive;
+}
+
+static bool insideRect (int x, int y, int height, int width) {
+ if (globalData.mousex < x) {
+ return false;
+ }
+ if (globalData.mousex > x+width) {
+ return false;
+ }
+ if (globalData.mousey < y) {
+ return false;
+ }
+ if (globalData.mousey > y+height) {
+ return false;
+ }
+ return true;
+}
+
+// For use with the mouse/gamepad keyboard
+int keyboardRowLimit = 20;
+
+void DialogBox::Draw(SDL_Renderer* target) {
+ this->x = globalData.xsize/2-300;
+ this->y = globalData.ysize/2-100;
+ DrawRectYellow(target, x, y, 200, 600);
+ headerLabel.Draw(target, x+300, y+20, sago::SagoTextField::Alignment::center);
+ DrawRectYellow(target, x+25, y+128, 50, 250);
+ enterLabel.Draw(target, x+150, y+140, sago::SagoTextField::Alignment::center);
+ DrawRectYellow(target, x+325, y+128, 50, 250);
+ cancelLabel.Draw(target, x+450, y+140, sago::SagoTextField::Alignment::center);
+ DrawRectWhite(target, x+26, y+64, 54, 600-2*26);
+ textField.SetText(rk->GetString());
+ textField.Draw(target, x+40, y+76);
+ std::string strHolder = rk->GetString();
+ strHolder.erase((int)rk->CharsBeforeCursor());
+
+ if (((SDL_GetTicks()/600)%2)==1) {
+ int width = 0;
+ textField.GetRenderedSize( strHolder.c_str(), &width);
+ width -= 2;
+ cursorLabel.Draw(target, x+40+width,y+76);
+ }
+ const sago::SagoSprite& marked = globalData.spriteHolder->GetSprite("i_level_check_box_marked");
+ for (size_t i = 0; i<virtualKeyboard.gamePadCharFields.size(); ++i) {
+ if (virtualKeyboard.selectedChar == static_cast<int>(i)) {
+ marked.Draw(target, SDL_GetTicks(), globalData.xsize/2-400+(i%keyboardRowLimit)*40-5, globalData.ysize/2+150+(i/keyboardRowLimit)*40-5);
+ }
+ sago::SagoTextField& f = virtualKeyboard.gamePadCharFields.at(i);
+ f.Draw(target, globalData.xsize/2-400+(i%keyboardRowLimit)*40, globalData.ysize/2+150+(i/keyboardRowLimit)*40);
+ }
+}
+
+
+static bool isGamePadStartEvent(const SDL_Event& event) {
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_START ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool isGamePadLEvent(const SDL_Event& event) {
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool isGamePadREvent(const SDL_Event& event) {
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+void DialogBox::virtualKeyboardWriteSelectedChar(ReadKeyboard* rk, const std::string& insertChar) const {
+ if (insertChar == virtualKeyboard.backspace) {
+ rk->emulateBackspace();
+ }
+ else if (insertChar == virtualKeyboard.leftChar) {
+ rk->cursorLeft();
+ }
+ else if (insertChar == virtualKeyboard.rightChar) {
+ rk->cursorRight();
+ }
+ else {
+ rk->putchar(insertChar);
+ }
+}
+
+
+void DialogBox::ProcessInput(const SDL_Event& event, bool& processed) {
+ if (event.type == SDL_TEXTINPUT) {
+ if ((rk->ReadKey(event))&&(globalData.SoundEnabled)&&(!globalData.NoSound)) {
+ //Mix_PlayChannel(1, globalData.typingChunk.get(), 0);
+ }
+ }
+
+ if ( event.type == SDL_KEYDOWN ) {
+ if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
+ name = rk->GetString();
+ updated = true;
+ isActive = false;
+ }
+ else if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
+ isActive = false;
+ }
+ else {
+ if ((rk->ReadKey(event))&&(globalData.SoundEnabled)&&(!globalData.NoSound)) {
+ //Mix_PlayChannel(1, globalData.typingChunk.get(), 0);
+ }
+ }
+ }
+ else {
+ if (isGamePadStartEvent(event)) {
+ name = rk->GetString();
+ updated = true;
+ isActive = false;
+ }
+ if (isEscapeEvent(event)) {
+ isActive = false;
+ }
+ if (isConfirmEvent(event)) {
+ const sago::SagoTextField& f = virtualKeyboard.gamePadCharFields.at(virtualKeyboard.selectedChar);
+ const std::string& insertChar = f.GetText();
+ virtualKeyboardWriteSelectedChar(rk.get(), insertChar);
+ }
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_X ) {
+ rk->emulateBackspace();
+ }
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_Y ) {
+ rk->putchar(" ");
+ }
+ }
+ if (isGamePadLEvent(event)) {
+ rk->cursorLeft();
+ }
+ if (isGamePadREvent(event)) {
+ rk->cursorRight();
+ }
+ if (isRightEvent(event)) {
+ if ( (virtualKeyboard.selectedChar+1)/keyboardRowLimit != virtualKeyboard.selectedChar/keyboardRowLimit ) {
+ virtualKeyboard.selectedChar -= keyboardRowLimit;
+ }
+ ++virtualKeyboard.selectedChar;
+ if (virtualKeyboard.selectedChar >= static_cast<int>(virtualKeyboard.gamePadCharFields.size())) {
+ virtualKeyboard.selectedChar -= virtualKeyboard.selectedChar%keyboardRowLimit;
+ }
+ }
+ if (isLeftEvent(event)) {
+ if ( (virtualKeyboard.selectedChar-1)/keyboardRowLimit != virtualKeyboard.selectedChar/keyboardRowLimit || virtualKeyboard.selectedChar == 0 ) {
+ virtualKeyboard.selectedChar += keyboardRowLimit;
+ }
+ --virtualKeyboard.selectedChar;
+ }
+ if (isDownEvent(event)) {
+ virtualKeyboard.selectedChar+= keyboardRowLimit;
+ }
+ if (isUpEvent(event)) {
+ virtualKeyboard.selectedChar -= keyboardRowLimit;
+ }
+ if (virtualKeyboard.selectedChar < 0) {
+ virtualKeyboard.selectedChar = 0;
+ }
+ if (virtualKeyboard.selectedChar >= static_cast<int>(virtualKeyboard.gamePadCharFields.size())) {
+ virtualKeyboard.selectedChar = virtualKeyboard.gamePadCharFields.size()-1;
+ }
+ }
+ processed = true;
+ if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
+ bMouseUp=true;
+ }
+
+ if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
+ bMouseUp = false;
+ if (insideRect(x+25, y+128, 50, 250)) {
+ name = rk->GetString();
+ updated = true;
+ isActive = false;
+ }
+ if (insideRect(x+325, y+128, 50, 250)) {
+ isActive = false;
+ }
+ for (size_t i = 0; i<virtualKeyboard.gamePadCharFields.size(); ++i) {
+ sago::SagoTextField& f = virtualKeyboard.gamePadCharFields.at(i);
+ auto topx = globalData.xsize/2-400+(i%keyboardRowLimit)*40-5;
+ auto topy = globalData.ysize/2+150+(i/keyboardRowLimit)*40-5;
+ if (insideRect(topx, topy, 30, 30)) {
+ std::string insertChar = f.GetText();
+ virtualKeyboardWriteSelectedChar(rk.get(), insertChar);
+ }
+ }
+ }
+
+ if (globalData.mousex != oldmousex || globalData.mousey != oldmousey) {
+ for (size_t i = 0; i<virtualKeyboard.gamePadCharFields.size(); ++i) {
+ auto topx = globalData.xsize/2-400+(i%keyboardRowLimit)*40-5;
+ auto topy = globalData.ysize/2+150+(i/keyboardRowLimit)*40-5;
+ if (insideRect(topx, topy, 30, 30)) {
+ virtualKeyboard.selectedChar = i;
+ }
+ }
+ oldmousex = globalData.mousex;
+ oldmousey = globalData.mousey;
+ }
+}
+
+void DialogBox::SetName(const std::string& name) {
+ this->name = name;
+ rk = std::make_shared<ReadKeyboard>(name.c_str());
+}
+
+std::string DialogBox::GetName() const {
+ return name;
+}
+
+bool DialogBox::IsUpdated() const {
+ return updated;
+}
diff --git a/src/help/DialogBox.hpp b/src/help/DialogBox.hpp new file mode 100644 index 0000000..853cde3 --- /dev/null +++ b/src/help/DialogBox.hpp
@@ -0,0 +1,84 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#ifndef DIALOGBOX_HPP
+#define DIALOGBOX_HPP
+
+#include "../sago/GameStateInterface.hpp"
+#include <string>
+#include "ReadKeyboard.h"
+#include <memory>
+#include "scopeHelpers.hpp"
+#include "../global.hpp"
+#include "../sago/SagoTextField.hpp"
+#include "../saland/GameDraw.hpp"
+
+struct VirtualKeyboard {
+ const std::string leftChar = "‹";
+ const std::string rightChar = "›";
+ const std::string backspace = "«";
+ std::string alphabet = std::string(_("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ ".,:!?+_^@#%&=*")) + leftChar + rightChar + backspace;
+ std::vector<std::string> gamePadChars;
+ std::vector<sago::SagoTextField> gamePadCharFields;
+ int selectedChar = 0;
+};
+
+class DialogBox : public sago::GameStateInterface {
+public:
+ DialogBox(int x, int y, const std::string& name, const std::string& header);
+ DialogBox(const DialogBox& orig) = delete;
+ DialogBox& operator=(const DialogBox& orig) = delete;
+ virtual ~DialogBox();
+
+ bool IsActive() override;
+ void Draw(SDL_Renderer* target) override;
+ void ProcessInput(const SDL_Event& event, bool &processed) override;
+ void SetName(const std::string& name);
+ std::string GetName() const;
+ bool IsUpdated() const;
+private:
+ void virtualKeyboardWriteSelectedChar(ReadKeyboard *rk, const std::string& insertChar) const;
+ bool isActive = true;
+ bool bMouseUp = false;
+ std::shared_ptr<ReadKeyboard> rk;
+ int x;
+ int y;
+ std::string name;
+ std::string header;
+ bool updated = false;
+ SDL_TextInput textInputScope;
+ sago::SagoTextField headerLabel;
+ sago::SagoTextField enterLabel;
+ sago::SagoTextField cancelLabel;
+ sago::SagoTextField textField;
+ sago::SagoTextField cursorLabel;
+ VirtualKeyboard virtualKeyboard;
+ int oldmousex = 0;
+ int oldmousey = 0;
+};
+
+
+#endif /* DIALOGBOX_HPP */
+
diff --git a/src/help/HelpAboutState.cpp b/src/help/HelpAboutState.cpp new file mode 100644 index 0000000..7a2b308 --- /dev/null +++ b/src/help/HelpAboutState.cpp
@@ -0,0 +1,118 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#include "DialogBox.hpp"
+#include "HelpCommon.hpp"
+#include "HelpAboutState.hpp"
+#include "../global.hpp"
+#include "../common.h"
+#include "../MenuSystem.h"
+#include "sstream"
+#include "../version.h"
+#include "../sago/SagoMisc.hpp"
+
+const int buttonOffset = 160;
+
+
+
+static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
+ field.SetHolder(holder);
+ field.SetFont("freeserif");
+ field.SetColor({255,255,255,255});
+ field.SetFontSize(30);
+ field.SetOutline(1, {128,128,128,255});
+ field.SetText(text);
+}
+
+
+
+
+
+
+HelpAboutState::HelpAboutState() {
+ SDL_RendererInfo renderInfo;
+ SDL_version compiled;
+ SDL_version linked;
+ SDL_GetRendererInfo(globalData.screen, &renderInfo);
+ SDL_VERSION(&compiled);
+ SDL_GetVersion(&linked);
+ const char* audio_driver_name = SDL_GetCurrentAudioDriver();
+ if (!audio_driver_name) {
+ audio_driver_name = _("No audio driver");
+ }
+ std::stringstream infoStream;
+ infoStream << _("Name:") << " " << _("Saland Adventures") << "\n";
+ infoStream << _("Original name:") << " Saland Adventures" << "\n";
+ infoStream << _("Version:") << " " << VERSION_NUMBER << "\n";
+ infoStream << _("Homepage:") << " " << "https://salandgame.github.io\n";
+ infoStream << _("Github page:") << " " << "https://github.com/salandgame/saland\n";
+ infoStream << _("SDL render:") << " " << renderInfo.name << "\n";
+ infoStream << _("SDL audio driver:") << " " << audio_driver_name << "\n";
+ infoStream << _("SDL compiled version:") << " " << (int)compiled.major << "." << (int)compiled.minor << "." << (int)compiled.patch << "\n";
+ infoStream << _("SDL linked version:") << " " << (int)linked.major << "." << (int)linked.minor << "." << (int)linked.patch << "\n";
+ infoStream << _("Save folder:") << " " << PHYSFS_getWriteDir() << "\n";
+ infoStream << _("Locale:") << " " << setlocale( LC_CTYPE, nullptr ) << "\n";
+ setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), titleField, _("About"));
+ setHelpBoxFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str());
+ sago::WriteFileContent("about.txt", infoStream.str());
+}
+
+HelpAboutState::~HelpAboutState() {
+}
+
+bool HelpAboutState::IsActive() {
+ return isActive;
+}
+
+void HelpAboutState::ProcessInput(const SDL_Event& event, bool& processed) {
+
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
+
+ if (isConfirmEvent(event) || isEscapeEvent(event)) {
+ isActive = false;
+ processed = true;
+ }
+}
+
+void HelpAboutState::Draw(SDL_Renderer* target) {
+ //DrawBackground(target);
+ titleField.Draw(target, 50, 50);
+ DrawRectYellow(target, 40, 90, 600, 900);
+ infoBox.SetMaxWidth(850);
+ infoBox.Draw(target, 50, 100);
+#if DEBUG
+ static sago::SagoTextField mousePos;
+ mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ mousePos.SetFontSize(16);
+ mousePos.SetOutline(1, {128,128,128,255});
+ mousePos.SetText(std::string("Mouse position: ")+std::to_string(globalData.mousex)+std::string(", ")+std::to_string(globalData.mousey));
+ mousePos.Draw(target, 0,0);
+#endif
+}
+
+void HelpAboutState::Update() {
+ // If the mouse button is released, make bMouseUp equal true
+ if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
+ bMouseUp=true;
+ }
+}
diff --git a/src/help/HelpAboutState.hpp b/src/help/HelpAboutState.hpp new file mode 100644 index 0000000..8baef89 --- /dev/null +++ b/src/help/HelpAboutState.hpp
@@ -0,0 +1,50 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#ifndef HELPABOUT_HPP
+#define HELPABOUT_HPP
+
+#include "../sago/GameStateInterface.hpp"
+#include "../sago/SagoTextBox.hpp"
+#include "../sago/SagoTextField.hpp"
+
+class HelpAboutState : public sago::GameStateInterface {
+public:
+ HelpAboutState();
+ HelpAboutState(const HelpAboutState& orig) = delete;
+ virtual ~HelpAboutState();
+
+ bool IsActive() override;
+ void Draw(SDL_Renderer* target) override;
+ void ProcessInput(const SDL_Event& event, bool &processed) override;
+ void Update() override;
+
+private:
+ bool isActive = true;
+ bool bMouseUp = true;
+ sago::SagoTextField titleField;
+ sago::SagoTextBox infoBox;
+};
+
+#endif /* HELPABOUT_HPP */
+
diff --git a/src/help/HelpCommon.cpp b/src/help/HelpCommon.cpp new file mode 100644 index 0000000..7be5e13 --- /dev/null +++ b/src/help/HelpCommon.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/salandgame/saland
+===========================================================================
+*/
+
+#include "HelpCommon.hpp"
+
+
+
+template<typename T> void setHelp30FontTemplate(const sago::SagoDataHolder* holder, T& field, const char* text) {
+ field.SetHolder(holder);
+ field.SetFont("freeserif");
+ field.SetColor({255,255,255,255});
+ field.SetFontSize(30);
+ field.SetOutline(2, {0,0,0,255});
+ field.SetText(text);
+}
+
+void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
+ setHelp30FontTemplate(holder, field, text);
+}
+
+void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) {
+ setHelp30FontTemplate(holder, field, text);
+}
+
+void setHelpBoxFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) {
+ field.SetHolder(holder);
+ field.SetFont("freeserif");
+ field.SetColor({255,255,255,255});
+ field.SetColor({0,0,0,255});
+ field.SetFontSize(20);
+ field.SetOutline(0, {0,0,0,255});
+ field.SetText(text);
+}
diff --git a/src/help/HelpCommon.hpp b/src/help/HelpCommon.hpp new file mode 100644 index 0000000..6bc8c01 --- /dev/null +++ b/src/help/HelpCommon.hpp
@@ -0,0 +1,37 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+
+#ifndef _HELP_COMMON_HPP
+#define _HELP_COMMON_HPP
+
+#include "../sago/SagoTextBox.hpp"
+#include "../sago/SagoTextField.hpp"
+
+
+void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text);
+void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text);
+
+void setHelpBoxFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text);
+
+#endif //_HELP_COMMON_HPP
diff --git a/src/help/ReadKeyboard.cpp b/src/help/ReadKeyboard.cpp new file mode 100644 index 0000000..0fd4126 --- /dev/null +++ b/src/help/ReadKeyboard.cpp
@@ -0,0 +1,129 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#include "ReadKeyboard.h"
+#include "utf8.h"
+#include <iostream>
+
+ReadKeyboard::ReadKeyboard(void) {
+ maxLength = 16;
+ position = text_string.begin();
+}
+
+ReadKeyboard::~ReadKeyboard(void) {
+}
+
+int ReadKeyboard::CharsBeforeCursor() {
+ return std::distance(text_string.begin(), position);
+}
+
+ReadKeyboard::ReadKeyboard(const char* oldName) : maxLength(16), text_string(oldName) {
+ position = text_string.end();
+}
+
+
+void ReadKeyboard::putchar(const std::string& thing) {
+ if ( (int)text_string.length() < maxLength) {
+ int oldPostition = utf8::distance(text_string.begin(), position);
+ int lengthOfInsertString = utf8::distance(thing.begin(), thing.end());
+ text_string.insert(position, thing.begin(), thing.end());
+ position = text_string.begin(); //Inserting may destroy our old iterator
+ utf8::advance(position, oldPostition + lengthOfInsertString, text_string.end());
+ }
+}
+
+
+void ReadKeyboard::removeChar() {
+ if (position < text_string.end()) {
+ std::string::iterator endChar= position;
+ utf8::advance(endChar, 1, text_string.end());
+ text_string.erase(position, endChar);
+ }
+}
+
+bool ReadKeyboard::ReadKey(const SDL_Event& key) {
+ if (key.type == SDL_TEXTINPUT) {
+ putchar(key.text.text);
+ if (key.text.text[0] != 0) {
+ return true;
+ }
+ }
+ return ReadKey(key.key.keysym.sym);
+}
+
+bool ReadKeyboard::cursorLeft() {
+ if (position>text_string.begin()) {
+ utf8::prior(position, text_string.begin());
+ return true;
+ }
+ return false;
+}
+bool ReadKeyboard::cursorRight() {
+ if (position<text_string.end()) {
+ utf8::next(position, text_string.end());
+ return true;
+ }
+ return false;
+}
+
+bool ReadKeyboard::emulateBackspace() {
+ if (position>text_string.begin()) {
+ utf8::prior(position, text_string.begin());
+ ReadKeyboard::removeChar();
+ return true;
+ }
+ return false;
+}
+
+bool ReadKeyboard::ReadKey(SDL_Keycode keyPressed) {
+ if (keyPressed == SDLK_DELETE) {
+ if ((text_string.length()>0)&& (position<text_string.end())) {
+ ReadKeyboard::removeChar();
+ }
+ return true;
+ }
+ if (keyPressed == SDLK_BACKSPACE) {
+ return emulateBackspace();
+ }
+ if (keyPressed == SDLK_HOME) {
+ position = text_string.begin();
+ return true;
+ }
+ if (keyPressed == SDLK_END) {
+ position=text_string.end();
+ return true;
+ }
+ if (keyPressed == SDLK_LEFT) {
+ cursorLeft();
+ return true;
+ }
+ if ((keyPressed == SDLK_RIGHT)) {
+ cursorRight();
+ return true;
+ }
+ return true;
+}
+
+const std::string& ReadKeyboard::GetString() const {
+ return text_string;
+}
diff --git a/src/help/ReadKeyboard.h b/src/help/ReadKeyboard.h new file mode 100644 index 0000000..839a0c3 --- /dev/null +++ b/src/help/ReadKeyboard.h
@@ -0,0 +1,55 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+/*
+Added to project 5/11-2004
+*/
+
+#ifndef READKEYBOARD_HPP
+#define READKEYBOARD_HPP
+
+#include "SDL.h"
+#include <string>
+
+class ReadKeyboard
+{
+private:
+ int maxLength = 0;
+ std::string::iterator position;
+ std::string text_string;
+ void removeChar();
+public:
+ ReadKeyboard(void);
+ ~ReadKeyboard(void);
+ explicit ReadKeyboard(const char*);
+ int CharsBeforeCursor(); //Where should the cursor be placed?
+ void putchar(const std::string& );
+ bool cursorLeft();
+ bool cursorRight();
+ bool emulateBackspace();
+ bool ReadKey(const SDL_Event&);
+ bool ReadKey(SDL_Keycode); //true if key accepted
+ const std::string& GetString(void) const;
+};
+
+#endif //READKEYBOARD_HPP
\ No newline at end of file
diff --git a/src/help/scopeHelpers.hpp b/src/help/scopeHelpers.hpp new file mode 100644 index 0000000..98b502d --- /dev/null +++ b/src/help/scopeHelpers.hpp
@@ -0,0 +1,55 @@
+/*
+===========================================================================
+ * 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/salandgame/saland
+===========================================================================
+*/
+
+#ifndef SCOPEHELPERS_HPP
+#define SCOPEHELPERS_HPP
+
+#include "../common.h"
+
+
+class SDL_RendererHolder {
+ SDL_Renderer* ptr;
+public:
+ explicit SDL_RendererHolder(SDL_Renderer* input) {
+ dieOnNullptr(input, "Failed to get render");
+ ptr = input;
+ }
+
+ ~SDL_RendererHolder() {
+ SDL_DestroyRenderer(ptr);
+ }
+};
+
+class SDL_TextInput {
+public:
+ SDL_TextInput() {
+ SDL_StartTextInput();
+ }
+
+ ~SDL_TextInput() {
+ SDL_StopTextInput();
+ }
+};
+
+#endif /* SCOPEHELPERS_HPP */
+
diff --git a/src/saland.cpp b/src/saland.cpp index 18aa3f9..1bffcc5 100644 --- a/src/saland.cpp +++ b/src/saland.cpp
@@ -17,7 +17,7 @@ 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
+https://github.com/salandgame/saland
===========================================================================
*/
@@ -46,6 +46,7 @@ https://github.com/sago007/saland
#include "sago/SagoTextBox.hpp"
#include "MenuSystem.h"
+#include "help/HelpAboutState.hpp"
#include "common.h"
#include "os.hpp"
@@ -236,6 +237,11 @@ void runMenuOptions() {
RunGameState(m);
}
+static void runHelpAbout() {
+ HelpAboutState helpAbout;
+ RunGameState(helpAbout);
+}
+
void runGame() {
int posX = 100, posY = 100, width = 1280, height = 800;
SDL_Init(SDL_INIT_VIDEO);
@@ -266,6 +272,10 @@ void runGame() {
bOptions.setLabel("Options");
bOptions.setAction(runMenuOptions);
m.addButton(&bOptions);
+ Button bAbout;
+ bAbout.setLabel(_("About"));
+ bAbout.setAction(runHelpAbout);
+ m.addButton(&bAbout);
if (!globalData.isShuttingDown) {
RunGameState(m);
}
diff --git a/src/saland/globals.hpp b/src/saland/globals.hpp index 6c192a7..dabe30d 100644 --- a/src/saland/globals.hpp +++ b/src/saland/globals.hpp
@@ -42,6 +42,8 @@ struct GlobalData {
bool isShuttingDown = false;
bool fullscreen = false;
bool resetVideo = false;
+ bool SoundEnabled = true;
+ bool NoSound = false;
SDL_Renderer* screen = nullptr;
std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
sago::SagoDataHolder* dataHolder;