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"
8cb016a5 sago007 2019-03-09 15:41 30
#include "sago/SagoMisc.hpp"
5147de4e Poul Sander 2018-05-06 12:59 31
5147de4e Poul Sander 2018-05-06 12:59 32
const int xsize = 1024;
5147de4e Poul Sander 2018-05-06 12:59 33
const int ysize = 768;
5147de4e Poul Sander 2018-05-06 12:59 34
const int buttonOffset = 160;
5147de4e Poul Sander 2018-05-06 12:59 35
extern sago::SagoSprite bExit;
5147de4e Poul Sander 2018-05-06 12:59 36
b344a21b sago007 2018-05-10 10:22 37
b344a21b sago007 2018-05-10 10:22 38
d2ba3cf5 sago007 2018-05-13 15:00 39
static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
b344a21b sago007 2018-05-10 10:22 40
	field.SetHolder(holder);
b344a21b sago007 2018-05-10 10:22 41
	field.SetFont("freeserif");
b344a21b sago007 2018-05-10 10:22 42
	field.SetColor({255,255,255,255});
b344a21b sago007 2018-05-10 10:22 43
	field.SetFontSize(30);
b344a21b sago007 2018-05-10 10:22 44
	field.SetOutline(1, {128,128,128,255});
b344a21b sago007 2018-05-10 10:22 45
	field.SetText(text);
b344a21b sago007 2018-05-10 10:22 46
}
b344a21b sago007 2018-05-10 10:22 47
d2ba3cf5 sago007 2018-05-13 15:00 48
static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) {
b344a21b sago007 2018-05-10 10:22 49
	field.SetHolder(holder);
b344a21b sago007 2018-05-10 10:22 50
	field.SetFont("freeserif");
b344a21b sago007 2018-05-10 10:22 51
	field.SetColor({255,255,255,255});
a2197600 sago007 2018-05-11 15:45 52
	field.SetColor({0,0,0,255});
db2f559e sago007 2018-05-10 10:36 53
	field.SetFontSize(20);
a2197600 sago007 2018-05-11 15:45 54
	field.SetOutline(0, {0,0,0,255});
b344a21b sago007 2018-05-10 10:22 55
	field.SetText(text);
b344a21b sago007 2018-05-10 10:22 56
}
b344a21b sago007 2018-05-10 10:22 57
0e662388 sago007 2019-03-09 12:21 58
0e662388 sago007 2019-03-09 12:21 59
b344a21b sago007 2018-05-10 10:22 60
5147de4e Poul Sander 2018-05-06 12:59 61
HelpAboutState::HelpAboutState() {
0e662388 sago007 2019-03-09 12:21 62
	SDL_RendererInfo renderInfo;
0e662388 sago007 2019-03-09 12:21 63
	SDL_version compiled;
0e662388 sago007 2019-03-09 12:21 64
	SDL_version linked;
b344a21b sago007 2018-05-10 10:22 65
	SDL_GetRendererInfo(globalData.screen, &renderInfo);
0e662388 sago007 2019-03-09 12:21 66
	SDL_VERSION(&compiled);
0e662388 sago007 2019-03-09 12:21 67
	SDL_GetVersion(&linked);
0e662388 sago007 2019-03-09 12:21 68
	const char* audio_driver_name = SDL_GetCurrentAudioDriver();
0e662388 sago007 2019-03-09 12:21 69
	if (!audio_driver_name) {
0e662388 sago007 2019-03-09 12:21 70
		audio_driver_name = _("No audio driver");
0e662388 sago007 2019-03-09 12:21 71
	}
b344a21b sago007 2018-05-10 10:22 72
	std::stringstream infoStream;
0082cd9a sago007 2018-05-13 14:31 73
	infoStream << _("Name:") << " " << _("Block Attack - Rise of the Blocks") << "\n";
0082cd9a sago007 2018-05-13 14:31 74
	infoStream << _("Original name:") << " Block Attack - Rise of the Blocks" << "\n";
0082cd9a sago007 2018-05-13 14:31 75
	infoStream << _("Version:") << " " << VERSION_NUMBER << "\n";
0082cd9a sago007 2018-05-13 14:31 76
	infoStream << _("Homepage:") << " " << "https://blockattack.net\n";
0082cd9a sago007 2018-05-13 14:31 77
	infoStream << _("Github page:") << " " << "https://github.com/blockattack/blockattack-game\n";
0082cd9a sago007 2018-05-13 14:31 78
	infoStream << _("SDL render:") << " " << renderInfo.name << "\n";
0e662388 sago007 2019-03-09 12:21 79
	infoStream << _("SDL audio driver:") << " " << audio_driver_name << "\n";
0e662388 sago007 2019-03-09 12:21 80
	infoStream << _("SDL compiled version:") << " " << (int)compiled.major << "." << (int)compiled.minor << "." << (int)compiled.patch << "\n";
0e662388 sago007 2019-03-09 12:21 81
	infoStream << _("SDL linked version:") << " " << (int)linked.major << "." << (int)linked.minor << "." << (int)linked.patch << "\n";
0082cd9a sago007 2018-05-13 14:31 82
	infoStream << _("Save folder:") << " " << PHYSFS_getWriteDir() << "\n";
0082cd9a sago007 2018-05-13 14:31 83
	infoStream << _("Locale:") << " " << setlocale( LC_CTYPE, nullptr ) << "\n";
b344a21b sago007 2018-05-10 10:22 84
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), titleField, _("About"));
b344a21b sago007 2018-05-10 10:22 85
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str());
8cb016a5 sago007 2019-03-09 15:41 86
	sago::WriteFileContent("about.txt", infoStream.str());
5147de4e Poul Sander 2018-05-06 12:59 87
}
5147de4e Poul Sander 2018-05-06 12:59 88
5147de4e Poul Sander 2018-05-06 12:59 89
HelpAboutState::~HelpAboutState() {
5147de4e Poul Sander 2018-05-06 12:59 90
}
5147de4e Poul Sander 2018-05-06 12:59 91
5147de4e Poul Sander 2018-05-06 12:59 92
bool HelpAboutState::IsActive() {
5147de4e Poul Sander 2018-05-06 12:59 93
	return isActive;
5147de4e Poul Sander 2018-05-06 12:59 94
}
5147de4e Poul Sander 2018-05-06 12:59 95
5147de4e Poul Sander 2018-05-06 12:59 96
void HelpAboutState::ProcessInput(const SDL_Event& event, bool& processed) {
5147de4e Poul Sander 2018-05-06 12:59 97
5147de4e Poul Sander 2018-05-06 12:59 98
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
5147de4e Poul Sander 2018-05-06 12:59 99
5147de4e Poul Sander 2018-05-06 12:59 100
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
5147de4e Poul Sander 2018-05-06 12:59 101
		isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 102
		processed = true;
5147de4e Poul Sander 2018-05-06 12:59 103
	}
5147de4e Poul Sander 2018-05-06 12:59 104
}
5147de4e Poul Sander 2018-05-06 12:59 105
db2f559e sago007 2018-05-10 10:36 106
extern void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
db2f559e sago007 2018-05-10 10:36 107
5147de4e Poul Sander 2018-05-06 12:59 108
void HelpAboutState::Draw(SDL_Renderer* target) {
5147de4e Poul Sander 2018-05-06 12:59 109
	DrawBackground(target);
b344a21b sago007 2018-05-10 10:22 110
	titleField.Draw(target, 50, 50);
db2f559e sago007 2018-05-10 10:36 111
	DrawRectYellow(target, 40, 90, 600, 900);
a2197600 sago007 2018-05-11 15:45 112
	infoBox.SetMaxWidth(850);
b344a21b sago007 2018-05-10 10:22 113
	infoBox.Draw(target, 50, 100);
5147de4e Poul Sander 2018-05-06 12:59 114
	bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset);
5147de4e Poul Sander 2018-05-06 12:59 115
#if DEBUG
5147de4e Poul Sander 2018-05-06 12:59 116
	static sago::SagoTextField mousePos;
5147de4e Poul Sander 2018-05-06 12:59 117
	mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder());
5147de4e Poul Sander 2018-05-06 12:59 118
	mousePos.SetFontSize(16);
5147de4e Poul Sander 2018-05-06 12:59 119
	mousePos.SetOutline(1, {128,128,128,255});
5147de4e Poul Sander 2018-05-06 12:59 120
	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 121
	mousePos.Draw(target, 0,0);
5147de4e Poul Sander 2018-05-06 12:59 122
#endif
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
void HelpAboutState::Update() {
5147de4e Poul Sander 2018-05-06 12:59 126
	// If the mouse button is released, make bMouseUp equal true
5147de4e Poul Sander 2018-05-06 12:59 127
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
5147de4e Poul Sander 2018-05-06 12:59 128
		bMouseUp=true;
5147de4e Poul Sander 2018-05-06 12:59 129
	}
5147de4e Poul Sander 2018-05-06 12:59 130
5147de4e Poul Sander 2018-05-06 12:59 131
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
5147de4e Poul Sander 2018-05-06 12:59 132
		bMouseUp = false;
5147de4e Poul Sander 2018-05-06 12:59 133
5147de4e Poul Sander 2018-05-06 12:59 134
		//The Score button:
d2ba3cf5 sago007 2018-05-13 15:00 135
		if ((globalData.mousex>xsize-buttonOffset) && (globalData.mousex<xsize-buttonOffset+bExit.GetWidth())
d2ba3cf5 sago007 2018-05-13 15:00 136
		        && (globalData.mousey>ysize-buttonOffset) && (globalData.mousey<ysize-buttonOffset+bExit.GetHeight())) {
5147de4e Poul Sander 2018-05-06 12:59 137
			isActive = false;
5147de4e Poul Sander 2018-05-06 12:59 138
		}
5147de4e Poul Sander 2018-05-06 12:59 139
5147de4e Poul Sander 2018-05-06 12:59 140
	}
5147de4e Poul Sander 2018-05-06 12:59 141
}