healthbars.cpp

main 147 lines · 3.6 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#include "healthbars.h"
24
25#include <framework/graphics/texturemanager.h>
26
27HealthBars g_healthBars;
28
29void HealthBars::init()
30{
31 m_healthBars.reserve(21);
32 m_healthBars.push_back(nullptr); // 0 = default bar
33 m_manaBars.reserve(21);
34 m_manaBars.push_back(nullptr); // 0 = default bar
35}
36
37void HealthBars::terminate()
38{
39 m_healthBars.clear();
40 m_manaBars.clear();
41}
42
43void HealthBars::addHealthBackground(const std::string& path, int offsetX, int offsetY, int barOffsetX, int barOffsetY, int height) {
44 HealthBarPtr bar(new HealthBar);
45 bar->setPath(path);
46 bar->setTexture(path);
47 bar->setOffset(offsetX, offsetY);
48 bar->setBarOffset(barOffsetX, barOffsetY);
49 bar->setHeight(height);
50 m_healthBars.push_back(bar);
51}
52
53void HealthBars::addManaBackground(const std::string& path, int offsetX, int offsetY, int barOffsetX, int barOffsetY, int height) {
54 HealthBarPtr bar(new HealthBar);
55 bar->setPath(path);
56 bar->setTexture(path);
57 bar->setOffset(offsetX, offsetY);
58 bar->setBarOffset(barOffsetX, barOffsetY);
59 bar->setHeight(height);
60 m_manaBars.push_back(bar);
61}
62
63std::string HealthBars::getHealthBarPath(int id)
64{
65 HealthBarPtr bar = getHealthBar(id);
66 if (bar) {
67 return bar->getPath();
68 }
69
70 return std::string();
71}
72
73std::string HealthBars::getManaBarPath(int id)
74{
75 HealthBarPtr bar = getManaBar(id);
76 if (bar) {
77 return bar->getPath();
78 }
79
80 return std::string();
81}
82
83Point HealthBars::getHealthBarOffset(int id)
84{
85 HealthBarPtr bar = getHealthBar(id);
86 if (bar) {
87 return bar->getOffset();
88 }
89
90 return Point();
91}
92
93Point HealthBars::getManaBarOffset(int id)
94{
95 HealthBarPtr bar = getManaBar(id);
96 if (bar) {
97 return bar->getOffset();
98 }
99
100 return Point();
101}
102
103Point HealthBars::getHealthBarOffsetBar(int id)
104{
105 HealthBarPtr bar = getHealthBar(id);
106 if (bar) {
107 return bar->getBarOffset();
108 }
109
110 return Point();
111}
112
113Point HealthBars::getManaBarOffsetBar(int id)
114{
115 HealthBarPtr bar = getManaBar(id);
116 if (bar) {
117 return bar->getBarOffset();
118 }
119
120 return Point();
121}
122
123int HealthBars::getHealthBarHeight(int id)
124{
125 HealthBarPtr bar = getHealthBar(id);
126 if (bar) {
127 return bar->getHeight();
128 }
129
130 return 0;
131}
132
133int HealthBars::getManaBarHeight(int id)
134{
135 HealthBarPtr bar = getManaBar(id);
136 if (bar) {
137 return bar->getHeight();
138 }
139
140 return 0;
141}
142
143void HealthBar::setTexture(const std::string& path)
144{
145 m_texture = g_textures.getTexture(path);
146}
147
Top