git repos / blockattack-game

blame: source/code/ShowFileState.cpp

normal view · raw

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
46404443 sago007 2020-06-28 08:53 20
#include "HelpCommon.hpp"
b7550ffe sago007 2018-05-19 10:08 21
#include "ShowFileState.hpp"
b7550ffe sago007 2018-05-19 10:08 22
#include "global.hpp"
b7550ffe sago007 2018-05-19 10:08 23
#include "common.h"
b7550ffe sago007 2018-05-19 10:08 24
#include "MenuSystem.h"
b7550ffe sago007 2018-05-19 10:08 25
b7550ffe sago007 2018-05-19 10:08 26
const int buttonOffset = 160;
b7550ffe sago007 2018-05-19 10:08 27
extern sago::SagoSprite bExit;
b7550ffe sago007 2018-05-19 10:08 28
c2086a7e sago007 2018-05-19 14:16 29
static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
c2086a7e sago007 2018-05-19 14:16 30
	field.SetHolder(holder);
c2086a7e sago007 2018-05-19 14:16 31
	field.SetFont("freeserif");
c2086a7e sago007 2018-05-19 14:16 32
	field.SetColor({255,255,255,255});
c2086a7e sago007 2018-05-19 14:16 33
	field.SetFontSize(30);
c2086a7e sago007 2018-05-19 14:16 34
	field.SetOutline(1, {128,128,128,255});
c2086a7e sago007 2018-05-19 14:16 35
	field.SetText(text);
c2086a7e sago007 2018-05-19 14:16 36
}
c2086a7e sago007 2018-05-19 14:16 37
b7550ffe sago007 2018-05-19 10:08 38
ShowFileState::ShowFileState() {
c2086a7e sago007 2018-05-19 14:16 39
	setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), titleField, "");
46404443 sago007 2020-06-28 08:53 40
	setHelpBoxFont(&globalData.spriteHolder->GetDataHolder(), infoBox, "");
46404443 sago007 2020-06-28 08:53 41
	setHelpBoxFont(&globalData.spriteHolder->GetDataHolder(), filenameField, "");
b7550ffe sago007 2018-05-19 10:08 42
}
b7550ffe sago007 2018-05-19 10:08 43
b7550ffe sago007 2018-05-19 10:08 44
ShowFileState::~ShowFileState() {
b7550ffe sago007 2018-05-19 10:08 45
}
b7550ffe sago007 2018-05-19 10:08 46
b7550ffe sago007 2018-05-19 10:08 47
bool ShowFileState::IsActive() {
b7550ffe sago007 2018-05-19 10:08 48
	return isActive;
b7550ffe sago007 2018-05-19 10:08 49
}
b7550ffe sago007 2018-05-19 10:08 50
b7550ffe sago007 2018-05-19 10:08 51
void ShowFileState::ProcessInput(const SDL_Event& event, bool& processed) {
b7550ffe sago007 2018-05-19 10:08 52
b7550ffe sago007 2018-05-19 10:08 53
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
b7550ffe sago007 2018-05-19 10:08 54
b7550ffe sago007 2018-05-19 10:08 55
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
b7550ffe sago007 2018-05-19 10:08 56
		isActive = false;
b7550ffe sago007 2018-05-19 10:08 57
		processed = true;
b7550ffe sago007 2018-05-19 10:08 58
	}
b7550ffe sago007 2018-05-19 10:08 59
}
b7550ffe sago007 2018-05-19 10:08 60
c2086a7e sago007 2018-05-19 14:16 61
extern void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
c2086a7e sago007 2018-05-19 14:16 62
b7550ffe sago007 2018-05-19 10:08 63
void ShowFileState::Draw(SDL_Renderer* target) {
b7550ffe sago007 2018-05-19 10:08 64
	DrawBackground(target);
c2086a7e sago007 2018-05-19 14:16 65
	titleField.Draw(target, 50, 50);
c2086a7e sago007 2018-05-19 14:16 66
	DrawRectYellow(target, 40, 90, 600, 900);
c2086a7e sago007 2018-05-19 14:16 67
	infoBox.SetMaxWidth(850);
c2086a7e sago007 2018-05-19 14:16 68
	infoBox.Draw(target, 50, 100);
c2086a7e sago007 2018-05-19 14:16 69
	DrawRectYellow(target, 40, 700, 50, 900);
c2086a7e sago007 2018-05-19 14:16 70
	filenameField.Draw(target, 50, 715);
4b4edc1a Poul Sander 2019-04-24 17:02 71
	bExit.Draw(globalData.screen, SDL_GetTicks(), globalData.xsize-buttonOffset, globalData.ysize-buttonOffset);
b7550ffe sago007 2018-05-19 10:08 72
#if DEBUG
b7550ffe sago007 2018-05-19 10:08 73
	static sago::SagoTextField mousePos;
b7550ffe sago007 2018-05-19 10:08 74
	mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder());
b7550ffe sago007 2018-05-19 10:08 75
	mousePos.SetFontSize(16);
b7550ffe sago007 2018-05-19 10:08 76
	mousePos.SetOutline(1, {128,128,128,255});
b7550ffe sago007 2018-05-19 10:08 77
	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 78
	mousePos.Draw(target, 0,0);
b7550ffe sago007 2018-05-19 10:08 79
#endif
b7550ffe sago007 2018-05-19 10:08 80
}
b7550ffe sago007 2018-05-19 10:08 81
b7550ffe sago007 2018-05-19 10:08 82
void ShowFileState::Update() {
b7550ffe sago007 2018-05-19 10:08 83
	// If the mouse button is released, make bMouseUp equal true
b7550ffe sago007 2018-05-19 10:08 84
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
b7550ffe sago007 2018-05-19 10:08 85
		bMouseUp=true;
b7550ffe sago007 2018-05-19 10:08 86
	}
b7550ffe sago007 2018-05-19 10:08 87
b7550ffe sago007 2018-05-19 10:08 88
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
b7550ffe sago007 2018-05-19 10:08 89
		bMouseUp = false;
b7550ffe sago007 2018-05-19 10:08 90
b7550ffe sago007 2018-05-19 10:08 91
		//The Score button:
4b4edc1a Poul Sander 2019-04-24 17:02 92
		if ((globalData.mousex>globalData.xsize-buttonOffset) && (globalData.mousex<globalData.xsize-buttonOffset+bExit.GetWidth())
4b4edc1a Poul Sander 2019-04-24 17:02 93
		        && (globalData.mousey>globalData.ysize-buttonOffset) && (globalData.mousey<globalData.ysize-buttonOffset+bExit.GetHeight())) {
b7550ffe sago007 2018-05-19 10:08 94
			isActive = false;
b7550ffe sago007 2018-05-19 10:08 95
		}
b7550ffe sago007 2018-05-19 10:08 96
b7550ffe sago007 2018-05-19 10:08 97
	}
46404443 sago007 2020-06-28 08:53 98
}
1970-01-01 00:00 99