File: hud.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (165 lines) | stat: -rw-r--r-- 5,023 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * This code is based on the CRAB engine
 *
 * Copyright (c) Arvind Raja Yadav
 *
 * Licensed under MIT
 *
 */

//=============================================================================
// Author:   Arvind
// Purpose:  The tray where you have inventory, map and GameObjectives icons
//=============================================================================
#include "crab/XMLDoc.h"
#include "crab/input/cursor.h"
#include "crab/ui/hud.h"

namespace Crab {

using namespace pyrodactyl::ui;
using namespace pyrodactyl::image;
using namespace pyrodactyl::input;

void HUD::load(const Common::Path &filename, pyrodactyl::level::TalkNotify &tn, pyrodactyl::level::PlayerDestMarker &pdm) {
	XMLDoc conf(filename);
	if (conf.ready()) {
		rapidxml::xml_node<char> *node = conf.doc()->first_node("hud");
		if (nodeValid(node)) {
			if (nodeValid("bg", node))
				_bg.load(node->first_node("bg"));

			if (nodeValid("tray", node))
				_menu.load(node->first_node("tray"));

			_pause.load(node->first_node("pause"));
			_gom.load(node->first_node("game_over"));
			_back.load(node->first_node("back"));
			// health.load(node->first_node("health"));

			if (nodeValid("notify", node)) {
				rapidxml::xml_node<char> *notifynode = node->first_node("notify");

				loadImgKey(g_engine->_imageManager->_notify, "img", notifynode);
				tn.load(notifynode);
				pdm.load(notifynode);

				if (nodeValid("anim", notifynode)) {
					rapidxml::xml_node<char> *animnode = notifynode->first_node("anim");
					loadImgKey(_notifyAnim, "img", animnode);
					_clip.load(animnode);

					_timer.load(animnode, "delay");
					_timer.start();
				}
			}
		}

		// Create a copy of all the tooltips
		for (const auto &i : _menu._element)
			_tooltip.push_back(i._tooltip._text);

		setTooltip();
	}
}

void HUD::draw(pyrodactyl::event::Info &info, const Common::String &id) {
	_bg.draw();
	_menu.draw();

	if (info._unread._journal) {
		g_engine->_imageManager->draw(_menu._element[HS_JOURNAL].x + _menu._element[HS_JOURNAL].w - _clip.w / 2,
									  _menu._element[HS_JOURNAL].y - _clip.h / 2, _notifyAnim, &_clip);
	}

	if (info._unread._inventory) {
		g_engine->_imageManager->draw(_menu._element[HS_INV].x + _menu._element[HS_INV].w - _clip.w / 2,
									  _menu._element[HS_INV].y - _clip.h / 2, _notifyAnim, &_clip);
	}

	if (info._unread._trait) {
		g_engine->_imageManager->draw(_menu._element[HS_CHAR].x + _menu._element[HS_CHAR].w - _clip.w / 2,
									  _menu._element[HS_CHAR].y - _clip.h / 2, _notifyAnim, &_clip);
	}

	if (info._unread._map) {
		g_engine->_imageManager->draw(_menu._element[HS_MAP].x + _menu._element[HS_MAP].w - _clip.w / 2,
									  _menu._element[HS_MAP].y - _clip.h / 2, _notifyAnim, &_clip);
	}
}

void HUD::internalEvents(bool showMap) {
	_menu._element[HS_MAP]._visible = showMap;

	if (_timer.targetReached()) {
		_clip.x += _clip.w;

		if (_clip.x >= g_engine->_imageManager->getTexture(_notifyAnim).w())
			_clip.x = 0;

		_timer.start();
	}
}

HUDSignal HUD::handleEvents(pyrodactyl::event::Info &info, const Common::Event &event) {
	g_engine->_mouse->_insideHud = _bg.contains(g_engine->_mouse->_motion.x, g_engine->_mouse->_motion.y);

	int choice = _menu.handleEvents(event);

	if (choice == HS_JOURNAL)
		info._unread._journal = false;
	else if (choice == HS_INV)
		info._unread._inventory = false;
	else if (choice == HS_CHAR)
		info._unread._trait = false;
	else if (choice == HS_MAP)
		info._unread._map = false;

	return static_cast<HUDSignal>(choice);
}

void HUD::State(const int &val) {
	int count = 0;
	for (auto i = _menu._element.begin(); i != _menu._element.end(); ++i, ++count)
		i->state(val == count);
}

void HUD::setTooltip() {
	uint count = 0;
	for (auto i = _menu._element.begin(); i != _menu._element.end() && count < _tooltip.size(); ++i, ++count)
		i->_tooltip._text = _tooltip[count] + " (" + i->_hotkey.name() + ")";

	_menu._element[HS_PAUSE]._tooltip._text = _tooltip[HS_PAUSE] + " (" + g_engine->_inputManager->getAssociatedKey(IG_PAUSE) + ")";
}

void HUD::setUI() {
	_bg.setUI();
	_menu.setUI();

	_gom.setUI();
	_pause.setUI();
	_back.setUI();
}

} // End of namespace Crab