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
b344a21b sago007 2018-05-10 10:22 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
b344a21b sago007 2018-05-10 10:22 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 << _("Author:") << " " << "Poul Sander (sago007)\n";
5dfe56da sago007 2018-05-13 14:58 68
	infoStream << _("Contributers:") << " " << "Gonéri Le Bouder, Jordà Polo, mstraube, Paul Wise, Iwan Gabovitch (qubodup), scootergrisen\n";
5dfe56da sago007 2018-05-13 14:58 69
	infoStream << _("Other credits:") << " " << "Blender Foundation, Dietrich Radel, Dustin Norlander, Free Software Foundation, Kenney Vleugels, nicefrog, OpenArena\n";
0082cd9a sago007 2018-05-13 14:31 70
	infoStream << _("SDL render:") << " " << renderInfo.name << "\n";
0082cd9a sago007 2018-05-13 14:31 71
	infoStream << _("Save folder:") << " " << PHYSFS_getWriteDir() << "\n";
0082cd9a sago007 2018-05-13 14:31 72
	infoStream << _("Locale:") << " " << setlocale( LC_CTYPE, nullptr ) << "\n";
b344a21b sago007 2018-05-10 10:22 73
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), titleField, _("About"));
b344a21b sago007 2018-05-10 10:22 74
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str());
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
HelpAboutState::~HelpAboutState() {
5147de4e Poul Sander 2018-05-06 12:59 78
}
5147de4e Poul Sander 2018-05-06 12:59 79
5147de4e Poul Sander 2018-05-06 12:59 80
bool HelpAboutState::IsActive() {
5147de4e Poul Sander 2018-05-06 12:59 81
	return isActive;
5147de4e Poul Sander 2018-05-06 12:59 82
}
5147de4e Poul Sander 2018-05-06 12:59 83
5147de4e Poul Sander 2018-05-06 12:59 84
void HelpAboutState::ProcessInput(const SDL_Event& event, bool& processed) {
5147de4e Poul Sander 2018-05-06 12:59 85
5147de4e Poul Sander 2018-05-06 12:59 86
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
5147de4e Poul Sander 2018-05-06 12:59 87
5147de4e Poul Sander 2018-05-06 12:59 88
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
5147de4e Poul Sander 2018-05-06 12:59 89
		isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 90
		processed = true;
5147de4e Poul Sander 2018-05-06 12:59 91
	}
5147de4e Poul Sander 2018-05-06 12:59 92
}
5147de4e Poul Sander 2018-05-06 12:59 93
db2f559e sago007 2018-05-10 10:36 94
extern void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
db2f559e sago007 2018-05-10 10:36 95
5147de4e Poul Sander 2018-05-06 12:59 96
void HelpAboutState::Draw(SDL_Renderer* target) {
5147de4e Poul Sander 2018-05-06 12:59 97
	DrawBackground(target);
b344a21b sago007 2018-05-10 10:22 98
	titleField.Draw(target, 50, 50);
db2f559e sago007 2018-05-10 10:36 99
	DrawRectYellow(target, 40, 90, 600, 900);
a2197600 sago007 2018-05-11 15:45 100
	infoBox.SetMaxWidth(850);
b344a21b sago007 2018-05-10 10:22 101
	infoBox.Draw(target, 50, 100);
5147de4e Poul Sander 2018-05-06 12:59 102
	bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset);
5147de4e Poul Sander 2018-05-06 12:59 103
#if DEBUG
5147de4e Poul Sander 2018-05-06 12:59 104
	static sago::SagoTextField mousePos;
5147de4e Poul Sander 2018-05-06 12:59 105
	mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder());
5147de4e Poul Sander 2018-05-06 12:59 106
	mousePos.SetFontSize(16);
5147de4e Poul Sander 2018-05-06 12:59 107
	mousePos.SetOutline(1, {128,128,128,255});
5147de4e Poul Sander 2018-05-06 12:59 108
	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 109
	mousePos.Draw(target, 0,0);
5147de4e Poul Sander 2018-05-06 12:59 110
#endif
5147de4e Poul Sander 2018-05-06 12:59 111
}
5147de4e Poul Sander 2018-05-06 12:59 112
5147de4e Poul Sander 2018-05-06 12:59 113
void HelpAboutState::Update() {
5147de4e Poul Sander 2018-05-06 12:59 114
	// If the mouse button is released, make bMouseUp equal true
5147de4e Poul Sander 2018-05-06 12:59 115
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
5147de4e Poul Sander 2018-05-06 12:59 116
		bMouseUp=true;
5147de4e Poul Sander 2018-05-06 12:59 117
	}
5147de4e Poul Sander 2018-05-06 12:59 118
5147de4e Poul Sander 2018-05-06 12:59 119
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
5147de4e Poul Sander 2018-05-06 12:59 120
		bMouseUp = false;
5147de4e Poul Sander 2018-05-06 12:59 121
5147de4e Poul Sander 2018-05-06 12:59 122
		//The Score button:
5147de4e Poul Sander 2018-05-06 12:59 123
		if ((globalData.mousex>xsize-buttonOffset) && (globalData.mousex<xsize-buttonOffset+bExit.GetWidth()) 
5147de4e Poul Sander 2018-05-06 12:59 124
				&& (globalData.mousey>ysize-buttonOffset) && (globalData.mousey<ysize-buttonOffset+bExit.GetHeight())) {
5147de4e Poul Sander 2018-05-06 12:59 125
			isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 126
		}
5147de4e Poul Sander 2018-05-06 12:59 127
5147de4e Poul Sander 2018-05-06 12:59 128
	}
5147de4e Poul Sander 2018-05-06 12:59 129
}