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