git repos / blockattack-game

blame: source/code/HelpAboutState.cpp

normal view · raw

5147de4e Poul Sander 2018-05-06 12:59 1
/*
5147de4e Poul Sander 2018-05-06 12:59 2
===========================================================================
5147de4e Poul Sander 2018-05-06 12:59 3
blockattack - Block Attack - Rise of the Blocks
5147de4e Poul Sander 2018-05-06 12:59 4
Copyright (C) 2005-2018 Poul Sander
5147de4e Poul Sander 2018-05-06 12:59 5
5147de4e Poul Sander 2018-05-06 12:59 6
This program is free software: you can redistribute it and/or modify
5147de4e Poul Sander 2018-05-06 12:59 7
it under the terms of the GNU General Public License as published by
5147de4e Poul Sander 2018-05-06 12:59 8
the Free Software Foundation, either version 2 of the License, or
5147de4e Poul Sander 2018-05-06 12:59 9
(at your option) any later version.
5147de4e Poul Sander 2018-05-06 12:59 10
5147de4e Poul Sander 2018-05-06 12:59 11
This program is distributed in the hope that it will be useful,
5147de4e Poul Sander 2018-05-06 12:59 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
5147de4e Poul Sander 2018-05-06 12:59 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5147de4e Poul Sander 2018-05-06 12:59 14
GNU General Public License for more details.
5147de4e Poul Sander 2018-05-06 12:59 15
5147de4e Poul Sander 2018-05-06 12:59 16
You should have received a copy of the GNU General Public License
5147de4e Poul Sander 2018-05-06 12:59 17
along with this program.  If not, see http://www.gnu.org/licenses/
5147de4e Poul Sander 2018-05-06 12:59 18
5147de4e Poul Sander 2018-05-06 12:59 19
Source information and contacts persons can be found at
5147de4e Poul Sander 2018-05-06 12:59 20
https://blockattack.net
5147de4e Poul Sander 2018-05-06 12:59 21
===========================================================================
5147de4e Poul Sander 2018-05-06 12:59 22
*/
5147de4e Poul Sander 2018-05-06 12:59 23
5147de4e Poul Sander 2018-05-06 12:59 24
#include "HelpAboutState.hpp"
5147de4e Poul Sander 2018-05-06 12:59 25
#include "global.hpp"
5147de4e Poul Sander 2018-05-06 12:59 26
#include "common.h"
5147de4e Poul Sander 2018-05-06 12:59 27
#include "MenuSystem.h"
b344a21b sago007 2018-05-10 10:22 28
#include "sstream"
b344a21b sago007 2018-05-10 10:22 29
#include "version.h"
5147de4e Poul Sander 2018-05-06 12:59 30
5147de4e Poul Sander 2018-05-06 12:59 31
const int xsize = 1024;
5147de4e Poul Sander 2018-05-06 12:59 32
const int ysize = 768;
5147de4e Poul Sander 2018-05-06 12:59 33
const int buttonOffset = 160;
5147de4e Poul Sander 2018-05-06 12:59 34
extern sago::SagoSprite bExit;
5147de4e Poul Sander 2018-05-06 12:59 35
b344a21b sago007 2018-05-10 10:22 36
b344a21b sago007 2018-05-10 10:22 37
d2ba3cf5 sago007 2018-05-13 15:00 38
static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
b344a21b sago007 2018-05-10 10:22 39
	field.SetHolder(holder);
b344a21b sago007 2018-05-10 10:22 40
	field.SetFont("freeserif");
b344a21b sago007 2018-05-10 10:22 41
	field.SetColor({255,255,255,255});
b344a21b sago007 2018-05-10 10:22 42
	field.SetFontSize(30);
b344a21b sago007 2018-05-10 10:22 43
	field.SetOutline(1, {128,128,128,255});
b344a21b sago007 2018-05-10 10:22 44
	field.SetText(text);
b344a21b sago007 2018-05-10 10:22 45
}
b344a21b sago007 2018-05-10 10:22 46
d2ba3cf5 sago007 2018-05-13 15:00 47
static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) {
b344a21b sago007 2018-05-10 10:22 48
	field.SetHolder(holder);
b344a21b sago007 2018-05-10 10:22 49
	field.SetFont("freeserif");
b344a21b sago007 2018-05-10 10:22 50
	field.SetColor({255,255,255,255});
a2197600 sago007 2018-05-11 15:45 51
	field.SetColor({0,0,0,255});
db2f559e sago007 2018-05-10 10:36 52
	field.SetFontSize(20);
a2197600 sago007 2018-05-11 15:45 53
	field.SetOutline(0, {0,0,0,255});
b344a21b sago007 2018-05-10 10:22 54
	field.SetText(text);
b344a21b sago007 2018-05-10 10:22 55
}
b344a21b sago007 2018-05-10 10:22 56
b344a21b sago007 2018-05-10 10:22 57
static SDL_RendererInfo renderInfo;
b344a21b sago007 2018-05-10 10:22 58
5147de4e Poul Sander 2018-05-06 12:59 59
HelpAboutState::HelpAboutState() {
b344a21b sago007 2018-05-10 10:22 60
	SDL_GetRendererInfo(globalData.screen, &renderInfo);
b344a21b sago007 2018-05-10 10:22 61
	std::stringstream infoStream;
0082cd9a sago007 2018-05-13 14:31 62
	infoStream << _("Name:") << " " << _("Block Attack - Rise of the Blocks") << "\n";
0082cd9a sago007 2018-05-13 14:31 63
	infoStream << _("Original name:") << " Block Attack - Rise of the Blocks" << "\n";
0082cd9a sago007 2018-05-13 14:31 64
	infoStream << _("Version:") << " " << VERSION_NUMBER << "\n";
0082cd9a sago007 2018-05-13 14:31 65
	infoStream << _("Homepage:") << " " << "https://blockattack.net\n";
0082cd9a sago007 2018-05-13 14:31 66
	infoStream << _("Github page:") << " " << "https://github.com/blockattack/blockattack-game\n";
0082cd9a sago007 2018-05-13 14:31 67
	infoStream << _("SDL render:") << " " << renderInfo.name << "\n";
0082cd9a sago007 2018-05-13 14:31 68
	infoStream << _("Save folder:") << " " << PHYSFS_getWriteDir() << "\n";
0082cd9a sago007 2018-05-13 14:31 69
	infoStream << _("Locale:") << " " << setlocale( LC_CTYPE, nullptr ) << "\n";
b344a21b sago007 2018-05-10 10:22 70
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), titleField, _("About"));
b344a21b sago007 2018-05-10 10:22 71
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str());
5147de4e Poul Sander 2018-05-06 12:59 72
}
5147de4e Poul Sander 2018-05-06 12:59 73
5147de4e Poul Sander 2018-05-06 12:59 74
HelpAboutState::~HelpAboutState() {
5147de4e Poul Sander 2018-05-06 12:59 75
}
5147de4e Poul Sander 2018-05-06 12:59 76
5147de4e Poul Sander 2018-05-06 12:59 77
bool HelpAboutState::IsActive() {
5147de4e Poul Sander 2018-05-06 12:59 78
	return isActive;
5147de4e Poul Sander 2018-05-06 12:59 79
}
5147de4e Poul Sander 2018-05-06 12:59 80
5147de4e Poul Sander 2018-05-06 12:59 81
void HelpAboutState::ProcessInput(const SDL_Event& event, bool& processed) {
5147de4e Poul Sander 2018-05-06 12:59 82
5147de4e Poul Sander 2018-05-06 12:59 83
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
5147de4e Poul Sander 2018-05-06 12:59 84
5147de4e Poul Sander 2018-05-06 12:59 85
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
5147de4e Poul Sander 2018-05-06 12:59 86
		isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 87
		processed = true;
5147de4e Poul Sander 2018-05-06 12:59 88
	}
5147de4e Poul Sander 2018-05-06 12:59 89
}
5147de4e Poul Sander 2018-05-06 12:59 90
db2f559e sago007 2018-05-10 10:36 91
extern void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
db2f559e sago007 2018-05-10 10:36 92
5147de4e Poul Sander 2018-05-06 12:59 93
void HelpAboutState::Draw(SDL_Renderer* target) {
5147de4e Poul Sander 2018-05-06 12:59 94
	DrawBackground(target);
b344a21b sago007 2018-05-10 10:22 95
	titleField.Draw(target, 50, 50);
db2f559e sago007 2018-05-10 10:36 96
	DrawRectYellow(target, 40, 90, 600, 900);
a2197600 sago007 2018-05-11 15:45 97
	infoBox.SetMaxWidth(850);
b344a21b sago007 2018-05-10 10:22 98
	infoBox.Draw(target, 50, 100);
5147de4e Poul Sander 2018-05-06 12:59 99
	bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset);
5147de4e Poul Sander 2018-05-06 12:59 100
#if DEBUG
5147de4e Poul Sander 2018-05-06 12:59 101
	static sago::SagoTextField mousePos;
5147de4e Poul Sander 2018-05-06 12:59 102
	mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder());
5147de4e Poul Sander 2018-05-06 12:59 103
	mousePos.SetFontSize(16);
5147de4e Poul Sander 2018-05-06 12:59 104
	mousePos.SetOutline(1, {128,128,128,255});
5147de4e Poul Sander 2018-05-06 12:59 105
	mousePos.SetText(std::string("Mouse position: ")+std::to_string(globalData.mousex)+std::string(", ")+std::to_string(globalData.mousey));
5147de4e Poul Sander 2018-05-06 12:59 106
	mousePos.Draw(target, 0,0);
5147de4e Poul Sander 2018-05-06 12:59 107
#endif
5147de4e Poul Sander 2018-05-06 12:59 108
}
5147de4e Poul Sander 2018-05-06 12:59 109
5147de4e Poul Sander 2018-05-06 12:59 110
void HelpAboutState::Update() {
5147de4e Poul Sander 2018-05-06 12:59 111
	// If the mouse button is released, make bMouseUp equal true
5147de4e Poul Sander 2018-05-06 12:59 112
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
5147de4e Poul Sander 2018-05-06 12:59 113
		bMouseUp=true;
5147de4e Poul Sander 2018-05-06 12:59 114
	}
5147de4e Poul Sander 2018-05-06 12:59 115
5147de4e Poul Sander 2018-05-06 12:59 116
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
5147de4e Poul Sander 2018-05-06 12:59 117
		bMouseUp = false;
5147de4e Poul Sander 2018-05-06 12:59 118
5147de4e Poul Sander 2018-05-06 12:59 119
		//The Score button:
d2ba3cf5 sago007 2018-05-13 15:00 120
		if ((globalData.mousex>xsize-buttonOffset) && (globalData.mousex<xsize-buttonOffset+bExit.GetWidth())
d2ba3cf5 sago007 2018-05-13 15:00 121
		        && (globalData.mousey>ysize-buttonOffset) && (globalData.mousey<ysize-buttonOffset+bExit.GetHeight())) {
5147de4e Poul Sander 2018-05-06 12:59 122
			isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 123
		}
5147de4e Poul Sander 2018-05-06 12:59 124
5147de4e Poul Sander 2018-05-06 12:59 125
	}
5147de4e Poul Sander 2018-05-06 12:59 126
}