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