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