git repos / blockattack-game

commit d8fe60bd

sago007 · 2018-04-02 16:15
d8fe60bddc15b220fab84ff5741c5760358d0983 patch · browse files
parent d7d1cf43756834a9d14790a8d0ef8454133a79f3

Started to add a howto screen

Changed files

A source/code/HelpHowtoState.cpp
A source/code/HelpHowtoState.hpp
M source/code/MenuSystem.cpp before
M source/code/ScoresDisplay.cpp before
M source/code/main.cpp before
M source/code/menudef.cpp before
M source/code/sago/SagoTextBox.cpp before
diff --git a/source/code/HelpHowtoState.cpp b/source/code/HelpHowtoState.cpp new file mode 100644 index 0000000..e2f13d6 --- /dev/null +++ b/source/code/HelpHowtoState.cpp
@@ -0,0 +1,64 @@
+/*
+===========================================================================
+blockattack - Block Attack - Rise of the Blocks
+Copyright (C) 2005-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://blockattack.net
+===========================================================================
+*/
+
+#include "HelpHowtoState.hpp"
+#include "global.hpp"
+#include "common.h"
+#include "MenuSystem.h"
+
+HelpHowtoState::HelpHowtoState() {
+ box.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ box.SetFontSize(30);
+ box.SetOutline(1, {128,128,128,255});
+ box.SetText(_("The basic purpose of the game is to match 3 or more blocks of identical color to make them explode.\n"
+ "You can only move blocks vertically."
+ "The blocks are constantly raising from the bottom of the screen. Once they reach the top the game will start counting down to your"
+ " imminent defeat."));
+}
+
+HelpHowtoState::~HelpHowtoState() {
+}
+
+bool HelpHowtoState::IsActive() {
+ return isActive;
+}
+
+void HelpHowtoState::ProcessInput(const SDL_Event& event, bool& processed) {
+
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
+
+ if (isConfirmEvent(event) || isEscapeEvent(event)) {
+ isActive = false;
+ processed = true;
+ }
+}
+
+void HelpHowtoState::Draw(SDL_Renderer* target) {
+ DrawBackground(target);
+ box.SetMaxWidth(1000);
+ box.Draw(target, 10,10);
+}
+
+void HelpHowtoState::Update() {
+
+}
\ No newline at end of file
diff --git a/source/code/HelpHowtoState.hpp b/source/code/HelpHowtoState.hpp new file mode 100644 index 0000000..e0954d6 --- /dev/null +++ b/source/code/HelpHowtoState.hpp
@@ -0,0 +1,48 @@
+/*
+===========================================================================
+blockattack - Block Attack - Rise of the Blocks
+Copyright (C) 2005-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://blockattack.net
+===========================================================================
+*/
+
+#ifndef HELPHOWTOSTATE_HPP
+#define HELPHOWTOSTATE_HPP
+
+#include "sago/GameStateInterface.hpp"
+#include "sago/SagoTextField.hpp"
+#include "sago/SagoTextBox.hpp"
+
+class HelpHowtoState : public sago::GameStateInterface {
+public:
+ HelpHowtoState();
+ HelpHowtoState(const HelpHowtoState& orig) = delete;
+ virtual ~HelpHowtoState();
+
+ 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;
+ sago::SagoTextBox box;
+};
+
+#endif /* HELPHOWTOSTATE_HPP */
+
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 7cc5dfc..fdac856 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -58,7 +58,7 @@ sago::SagoTextField* ButtonGfx::getLabel(const std::string& text) {
newField->SetHolder(&globalData.spriteHolder->GetDataHolder());
newField->SetFont("freeserif");
newField->SetFontSize(30);
- newField->SetOutline(1, {0,0,0,255});
+ newField->SetOutline(1, {64,64,64,255});
newField->SetText(text);
labels[text] = newField;
return labels[text].get();
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 8e49742..8c99a93 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp
@@ -36,7 +36,7 @@ static void setButtonFont(const sago::SagoDataHolder* holder, sago::SagoTextFiel
field.SetFont("freeserif");
field.SetColor({255,255,255,255});
field.SetFontSize(24);
- field.SetOutline(1, {0,0,0,255});
+ field.SetOutline(1, {128,128,128,255});
field.SetText(text);
}
diff --git a/source/code/main.cpp b/source/code/main.cpp index c7688b7..1a65b17 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -423,7 +423,7 @@ template <class T> void sagoTextSetHelpFont(T& field){
field.SetHolder(&globalData.spriteHolder->GetDataHolder());
field.SetFont("freeserif");
field.SetFontSize(30);
- field.SetOutline(1, {0,0,0,255});
+ field.SetOutline(1, {128,128,128,255});
}
void sagoTextSetHelpFont(sago::SagoTextField& gametypeNameField){
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index bedca17..33ac0ec 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -25,6 +25,7 @@ http://blockattack.net
#include <stdlib.h>
#include "MenuSystem.h"
#include "common.h"
+#include "HelpHowtoState.hpp"
using std::string;
using std::cerr;
@@ -266,6 +267,20 @@ static void MultiplayerMenu() {
RunGameState(mm);
}
+static void runHowto() {
+ HelpHowtoState howto;
+ RunGameState(howto);
+}
+
+static void HelpMenu() {
+ Menu m(globalData.screen, _("Help"), true);
+ Button bHowto;
+ bHowto.setLabel(_("How to"));
+ bHowto.setAction(runHowto);
+ m.addButton(&bHowto);
+ RunGameState(m);
+}
+
static void SinglePlayerMenu() {
Menu m(globalData.screen, _("Single player"), true);
Button bHi,bTimetrial1, bStageClear, bPuzzle, bVs1;
@@ -290,7 +305,7 @@ static void SinglePlayerMenu() {
void MainMenu() {
InitMenues();
Menu m(globalData.screen,_("Block Attack - Rise of the blocks"),false);
- Button bHi, bMulti, bConfigure,bHighscore;
+ Button bHi, bMulti, bConfigure, bHighscore, bHelp;
bHi.setLabel(_("Single player") );
bHi.setAction(SinglePlayerMenu);
bMulti.setLabel(_("Multi player") );
@@ -299,9 +314,12 @@ void MainMenu() {
bConfigure.setAction(ConfigureMenu);
bHighscore.setLabel(_("Highscores") );
bHighscore.setAction(buttonActionHighscores);
+ bHelp.setLabel(_("Help"));
+ bHelp.setAction(HelpMenu);
m.addButton(&bHi);
m.addButton(&bMulti);
m.addButton(&bConfigure);
m.addButton(&bHighscore);
+ m.addButton(&bHelp);
RunGameState(m);
}
diff --git a/source/code/sago/SagoTextBox.cpp b/source/code/sago/SagoTextBox.cpp index 730612b..c8c1271 100644 --- a/source/code/sago/SagoTextBox.cpp +++ b/source/code/sago/SagoTextBox.cpp
@@ -160,6 +160,10 @@ void SagoTextBox::SplitAndAppendLineToCache(TTF_Font* font, const std::string& t
}
void SagoTextBox::UpdateCache() {
+ if (!data->tex) {
+ std::cerr << "FATAL: SagoTextBox::UpdateCache - DataHolder not set!\n";
+ abort();
+ }
TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
const char delim = '\n';
const std::string& s = data->text;