Client Upload Part 2

RD Core / Commit #5

Commit Client Upload Part 2

Alex Alex committed 19/10/2026 00:06 main Patch
1,244 files +271,215 -0
A RD_Client/src/client/tile.h +197-0 View file
@@ -0,0 +1,197 @@
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+#ifndef TILE_H
24+#define TILE_H
25+
26+#include "declarations.h"
27+#include "mapview.h"
28+#include "effect.h"
29+#include "creature.h"
30+#include "item.h"
31+#include <framework/luaengine/luaobject.h>
32+#include <framework/stdext/time.h>
33+
34+enum tileflags_t
35+{
36+ TILESTATE_NONE = 0,
37+ TILESTATE_PROTECTIONZONE = 1 << 0,
38+ TILESTATE_TRASHED = 1 << 1,
39+ TILESTATE_OPTIONALZONE = 1 << 2,
40+ TILESTATE_NOLOGOUT = 1 << 3,
41+ TILESTATE_HARDCOREZONE = 1 << 4,
42+ TILESTATE_REFRESH = 1 << 5,
43+
44+ // internal usage
45+ TILESTATE_HOUSE = 1 << 6,
46+ TILESTATE_TELEPORT = 1 << 17,
47+ TILESTATE_MAGICFIELD = 1 << 18,
48+ TILESTATE_MAILBOX = 1 << 19,
49+ TILESTATE_TRASHHOLDER = 1 << 20,
50+ TILESTATE_BED = 1 << 21,
51+ TILESTATE_DEPOT = 1 << 22,
52+ TILESTATE_TRANSLUECENT_LIGHT = 1 << 23,
53+
54+ TILESTATE_LAST = 1 << 24
55+};
56+
57+class Tile : public LuaObject
58+{
59+public:
60+ enum {
61+ MAX_THINGS = 10
62+ };
63+
64+ Tile(const Position& position);
65+
66+ void calculateCorpseCorrection();
67+
68+ void drawGround(const Point& dest, LightView* lightView = nullptr);
69+ void drawBottom(const Point& dest, LightView* lightView = nullptr);
70+ void drawCreatures(const Point& dest, LightView* lightView = nullptr);
71+ void drawTop(const Point& dest, LightView* lightView = nullptr);
72+ void drawTexts(Point dest);
73+ void drawWidget(Point dest);
74+
75+public:
76+ void clean();
77+
78+ void addWalkingCreature(const CreaturePtr& creature);
79+ void removeWalkingCreature(const CreaturePtr& creature);
80+
81+ void addThing(const ThingPtr& thing, int stackPos);
82+ bool removeThing(ThingPtr thing);
83+ ThingPtr getThing(int stackPos);
84+ EffectPtr getEffect(uint16 id);
85+ bool hasThing(const ThingPtr& thing);
86+ int getThingStackPos(const ThingPtr& thing);
87+ ThingPtr getTopThing();
88+
89+ ThingPtr getTopLookThing();
90+ ThingPtr getTopLookThingEx(Point offset);
91+ ThingPtr getTopUseThing();
92+ CreaturePtr getTopCreature();
93+ CreaturePtr getTopCreatureEx(Point offset);
94+ ThingPtr getTopMoveThing();
95+ ThingPtr getTopMultiUseThing();
96+ ThingPtr getTopMultiUseThingEx(Point offset);
97+
98+ const Position& getPosition() { return m_position; }
99+ int getDrawElevation() { return m_drawElevation; }
100+ std::vector<ItemPtr> getItems();
101+ std::vector<CreaturePtr> getCreatures();
102+ std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
103+ std::vector<ThingPtr> getThings() { return m_things; }
104+ std::vector<EffectPtr> getEffects() { return m_effects; }
105+ ItemPtr getGround();
106+ int getGroundSpeed();
107+ bool isBlocking() { return m_blocking != 0; }
108+ uint8 getMinimapColorByte();
109+ int getThingCount() { return m_things.size() + m_effects.size(); }
110+ bool isPathable();
111+ bool isWalkable(bool ignoreCreatures = false);
112+ bool isFullGround();
113+ bool isFullyOpaque();
114+ bool isSingleDimension();
115+ bool isLookPossible();
116+ bool isBlockingProjectile();
117+ bool isClickable();
118+ bool isEmpty();
119+ bool isDrawable();
120+ bool hasTranslucentLight() { return m_flags & TILESTATE_TRANSLUECENT_LIGHT; }
121+ bool mustHookSouth();
122+ bool mustHookEast();
123+ bool hasCreature();
124+ bool hasBlockingCreature();
125+ bool limitsFloorsView(bool isFreeView = false);
126+ bool canErase();
127+ int getElevation();
128+ bool hasElevation(int elevation = 1);
129+ void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
130+
131+ void remFlag(uint32 flag) { m_flags &= ~flag; }
132+ void setFlag(uint32 flag) { m_flags |= flag; }
133+ void setFlags(uint32 flags) { m_flags = flags; }
134+ bool hasFlag(uint32 flag) { return (m_flags & flag) == flag; }
135+ uint32 getFlags() { return m_flags; }
136+
137+ void setHouseId(uint32 hid) { m_houseId = hid; }
138+ uint32 getHouseId() { return m_houseId; }
139+ bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
140+
141+ void select() { m_selected = true; }
142+ void unselect() { m_selected = false; }
143+ bool isSelected() { return m_selected; }
144+
145+ TilePtr asTile() { return static_self_cast<Tile>(); }
146+
147+ void setSpeed(uint16_t speed, uint8_t blocking) {
148+ m_speed = speed;
149+ m_blocking = blocking;
150+ }
151+
152+ void setText(const std::string& text, Color color);
153+ std::string getText();
154+ void setTimer(int time, Color color);
155+ int getTimer();
156+ void setFill(Color color);
157+ void resetFill() { m_fill = Color::alpha; }
158+
159+ bool canShoot(int distance);
160+
161+ void setWidget(UIWidgetPtr widget) { m_widget = widget; }
162+ UIWidgetPtr getWidget() { return m_widget; }
163+ void removeWidget() {
164+ if (m_widget) {
165+ m_widget->destroy();
166+ m_widget = nullptr;
167+ }
168+ }
169+
170+private:
171+ void checkTranslucentLight();
172+
173+ std::vector<CreaturePtr> m_walkingCreatures;
174+ std::vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
175+ std::vector<ThingPtr> m_things;
176+ Position m_position;
177+ uint8 m_drawElevation;
178+ uint8 m_minimapColor;
179+ uint32 m_flags, m_houseId;
180+ uint16 m_speed = 0;
181+ uint8 m_blocking = 0;
182+
183+ uint32_t m_lastCreature = 0;
184+ int m_topCorrection = 0;
185+ int m_topDraws = 0;
186+
187+ stdext::boolean<false> m_selected;
188+
189+ ticks_t m_timer = 0;
190+ StaticTextPtr m_timerText;
191+ StaticTextPtr m_text;
192+ Color m_fill = Color::alpha;
193+
194+ UIWidgetPtr m_widget;
195+};
196+
197+#endif
A RD_Client/src/client/towns.cpp +80-0 View file
@@ -0,0 +1,80 @@
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 "towns.h"
24+
25+TownManager g_towns;
26+
27+Town::Town(uint32 tid, const std::string& name, const Position& pos)
28+ : m_id(tid), m_name(name)
29+{
30+ if(pos.isValid())
31+ m_pos = pos;
32+}
33+
34+TownManager::TownManager()
35+{
36+ m_nullTown = TownPtr(new Town);
37+}
38+
39+void TownManager::addTown(const TownPtr &town)
40+{
41+ if(findTown(town->getId()) == m_towns.end())
42+ m_towns.push_back(town);
43+}
44+
45+void TownManager::removeTown(uint32 townId)
46+{
47+ auto it = findTown(townId);
48+ if(it != m_towns.end())
49+ m_towns.erase(it);
50+}
51+
52+const TownPtr& TownManager::getTown(uint32 townId)
53+{
54+ auto it = std::find_if(m_towns.begin(), m_towns.end(),
55+ [=] (const TownPtr& town) -> bool { return town->getId() == townId; });
56+ if(it != m_towns.end())
57+ return *it;
58+ return m_nullTown;
59+}
60+
61+const TownPtr& TownManager::getTownByName(std::string name)
62+{
63+ auto it = std::find_if(m_towns.begin(), m_towns.end(),
64+ [=] (const TownPtr& town) -> bool { return town->getName() == name; } );
65+ if(it != m_towns.end())
66+ return *it;
67+ return m_nullTown;
68+}
69+
70+TownList::iterator TownManager::findTown(uint32 townId)
71+{
72+ return std::find_if(m_towns.begin(), m_towns.end(),
73+ [=] (const TownPtr& town) -> bool { return town->getId() == townId; });
74+}
75+
76+void TownManager::sort()
77+{
78+ m_towns.sort([] (const TownPtr& lhs, const TownPtr& rhs) { return lhs->getName() < rhs->getName(); });
79+}
80+
A RD_Client/src/client/towns.h +73-0 View file
@@ -0,0 +1,73 @@
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+#ifndef TOWNS_H
24+#define TOWNS_H
25+
26+#include "declarations.h"
27+#include <framework/luaengine/luaobject.h>
28+
29+class Town : public LuaObject
30+{
31+public:
32+ Town() { }
33+ Town(uint32 tid, const std::string& name, const Position& pos=Position());
34+
35+ void setId(uint32 tid) { m_id = tid; }
36+ void setName(const std::string& name) { m_name = name; }
37+ void setPos(const Position& pos) { m_pos = pos; }
38+
39+ uint32 getId() { return m_id; }
40+ std::string getName() { return m_name; }
41+ Position getPos() { return m_pos; }
42+
43+private:
44+ uint32 m_id;
45+ std::string m_name;
46+ Position m_pos; // temple pos
47+};
48+
49+class TownManager
50+{
51+public:
52+ TownManager();
53+
54+ void addTown(const TownPtr& town);
55+ void removeTown(uint32 townId);
56+ const TownPtr& getTown(uint32 townId);
57+ const TownPtr& getTownByName(std::string name);
58+
59+ void sort();
60+ TownList getTowns() { return m_towns; }
61+ void clear() { m_towns.clear(); m_nullTown = nullptr; }
62+
63+private:
64+ TownList m_towns;
65+ TownPtr m_nullTown;
66+
67+protected:
68+ TownList::iterator findTown(uint32 townId);
69+};
70+
71+extern TownManager g_towns;
72+
73+#endif
A RD_Client/src/client/uicreature.cpp +134-0 View file
@@ -0,0 +1,134 @@
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 "uicreature.h"
24+#include "spritemanager.h"
25+#include <framework/otml/otml.h>
26+#include <framework/graphics/drawqueue.h>
27+
28+void UICreature::drawSelf(Fw::DrawPane drawPane)
29+{
30+ if (drawPane != Fw::ForegroundPane)
31+ return;
32+
33+ UIWidget::drawSelf(drawPane);
34+
35+ if (m_creature) {
36+ if (m_autoRotating) {
37+ auto ticks = (g_clock.millis() % 4000) / 4;
38+ Otc::Direction new_dir;
39+ if (ticks < 250) {
40+ new_dir = Otc::South;
41+ } else if (ticks < 500) {
42+ new_dir = Otc::East;
43+ } else if (ticks < 750) {
44+ new_dir = Otc::North;
45+ } else {
46+ new_dir = Otc::West;
47+ }
48+ if (new_dir != m_direction) {
49+ m_direction = new_dir;
50+ }
51+ }
52+
53+ m_creature->drawOutfit(Rect(getPaddingRect().topLeft(), getSize() * m_scale), m_direction, m_imageColor, m_animate, true, m_oldScaling);
54+ }
55+}
56+
57+void UICreature::setOutfit(const Outfit& outfit)
58+{
59+ if (!m_creature)
60+ m_creature = CreaturePtr(new Creature);
61+ m_direction = Otc::South;
62+ m_creature->setOutfit(outfit);
63+}
64+
65+void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
66+{
67+ UIWidget::onStyleApply(styleName, styleNode);
68+
69+ for (const OTMLNodePtr& node : styleNode->children()) {
70+ if (node->tag() == "fixed-creature-size")
71+ setFixedCreatureSize(node->value<bool>());
72+ else if (node->tag() == "outfit-id") {
73+ Outfit outfit = getOutfit();
74+ outfit.setId(node->value<int>());
75+ setOutfit(outfit);
76+ } else if (node->tag() == "outfit-head") {
77+ Outfit outfit = getOutfit();
78+ outfit.setHead(node->value<int>());
79+ setOutfit(outfit);
80+ } else if (node->tag() == "outfit-body") {
81+ Outfit outfit = getOutfit();
82+ outfit.setBody(node->value<int>());
83+ setOutfit(outfit);
84+ } else if (node->tag() == "outfit-legs") {
85+ Outfit outfit = getOutfit();
86+ outfit.setLegs(node->value<int>());
87+ setOutfit(outfit);
88+ } else if (node->tag() == "outfit-feet") {
89+ Outfit outfit = getOutfit();
90+ outfit.setFeet(node->value<int>());
91+ setOutfit(outfit);
92+ } else if (node->tag() == "outfit-addons") {
93+ Outfit outfit = getOutfit();
94+ outfit.setAddons(node->value<int>());
95+ setOutfit(outfit);
96+ } else if (node->tag() == "outfit-mount") {
97+ Outfit outfit = getOutfit();
98+ outfit.setMount(node->value<int>());
99+ setOutfit(outfit);
100+ } else if (node->tag() == "outfit-wings") {
101+ Outfit outfit = getOutfit();
102+ outfit.setWings(node->value<int>());
103+ setOutfit(outfit);
104+ } else if (node->tag() == "outfit-aura") {
105+ Outfit outfit = getOutfit();
106+ outfit.setAura(node->value<int>());
107+ setOutfit(outfit);
108+ } else if (node->tag() == "outfit-shader") {
109+ Outfit outfit = getOutfit();
110+ outfit.setShader(node->value<std::string>());
111+ setOutfit(outfit);
112+ } else if (node->tag() == "outfit-center") {
113+ setCenter(node->value<bool>());
114+ } else if (node->tag() == "scale") {
115+ setScale(node->value<float>());
116+ } else if (node->tag() == "animate") {
117+ setAnimate(node->value<bool>());
118+ } else if (node->tag() == "old-scaling") {
119+ setOldScaling(node->value<bool>());
120+ }
121+ }
122+}
123+
124+void UICreature::onGeometryChange(const Rect& oldRect, const Rect& newRect)
125+{
126+ UIWidget::onGeometryChange(oldRect, newRect);
127+}
128+
129+void UICreature::setCenter(bool value)
130+{
131+ Outfit outfit = getOutfit();
132+ outfit.setCenter(value);
133+ setOutfit(outfit);
134+}
A RD_Client/src/client/uicreature.h +69-0 View file
@@ -0,0 +1,69 @@
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+#ifndef UICREATURE_H
24+#define UICREATURE_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+#include "creature.h"
29+
30+class UICreature : public UIWidget
31+{
32+public:
33+ void drawSelf(Fw::DrawPane drawPane);
34+
35+ void setCreature(const CreaturePtr& creature) { m_creature = creature; }
36+ void setFixedCreatureSize(bool fixed) { m_scale = fixed ? 1.0 : 0; }
37+ void setOutfit(const Outfit& outfit);
38+
39+ CreaturePtr getCreature() { return m_creature; }
40+ Outfit getOutfit() { return m_creature ? m_creature->getOutfit() : Outfit(); }
41+ bool isFixedCreatureSize() { return m_scale > 0; }
42+
43+ void setAutoRotating(bool value) { m_autoRotating = value; }
44+ void setDirection(Otc::Direction direction) { m_direction = direction; }
45+ Otc::Direction getDirection() { return m_direction; }
46+
47+ void setScale(float scale) { m_scale = scale; }
48+ float getScale() { return m_scale; }
49+
50+ void setAnimate(bool value) { m_animate = value; }
51+ bool isAnimating() { return m_animate; }
52+
53+ void setCenter(bool value);
54+
55+ void setOldScaling(bool value) { m_oldScaling = value; }
56+
57+protected:
58+ void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
59+ void onGeometryChange(const Rect& oldRect, const Rect& newRect) override;
60+
61+ CreaturePtr m_creature;
62+ stdext::boolean<false> m_autoRotating;
63+ stdext::boolean<false> m_animate;
64+ stdext::boolean<false> m_oldScaling;
65+ Otc::Direction m_direction = Otc::South;
66+ float m_scale = 1.0;
67+};
68+
69+#endif
A RD_Client/src/client/uigraph.cpp +85-0 View file
@@ -0,0 +1,85 @@
1+
2+#include "uigraph.h"
3+#include <framework/graphics/drawqueue.h>
4+#include <framework/graphics/textrender.h>
5+#include <framework/graphics/fontmanager.h>
6+#include <framework/core/eventdispatcher.h>
7+
8+UIGraph::UIGraph()
9+{
10+}
11+
12+void UIGraph::drawSelf(Fw::DrawPane drawPane)
13+{
14+ if (drawPane != Fw::ForegroundPane)
15+ return;
16+
17+ UIWidget::drawSelf(drawPane);
18+
19+ Rect dest = getPaddingRect();
20+
21+ float offsetX = dest.left();
22+ float offsetY = dest.top();
23+ size_t elements = std::min<size_t>(m_values.size(), dest.width() / (m_width * 2) - 1);
24+ size_t start = m_values.size() - elements;
25+ int minVal = 0xFFFFFF, maxVal = -0xFFFFFF;
26+ for (size_t i = start; i < m_values.size(); ++i) {
27+ if (minVal > m_values[i])
28+ minVal = m_values[i];
29+ if (maxVal < m_values[i])
30+ maxVal = m_values[i];
31+ }
32+ // round
33+ maxVal = (1 + maxVal / 10) * 10;
34+ minVal = (minVal / 10) * 10;
35+ float step = (float)(dest.height()) / std::max<float>(1, (maxVal - minVal));
36+ std::vector<Point> points;
37+ for (size_t i = start, j = 0; i < m_values.size(); ++i) {
38+ points.push_back(Point(offsetX + j * m_width, offsetY + 1 + (maxVal - m_values[i]) * step));
39+ j += 2;
40+ }
41+
42+ if (elements > 0) {
43+ g_drawQueue->addLine(points, m_width, m_color);
44+ if(!m_title.empty())
45+ g_drawQueue->addText(m_font, m_title, dest, Fw::AlignTopCenter);
46+ if (m_showLabes) {
47+ g_drawQueue->addText(m_font, std::to_string(m_values.back()), dest, Fw::AlignTopRight);
48+ g_drawQueue->addText(m_font, std::to_string(maxVal), dest, Fw::AlignTopLeft);
49+ g_drawQueue->addText(m_font, std::to_string(minVal), dest, Fw::AlignBottomLeft);
50+ }
51+ }
52+}
53+
54+void UIGraph::clear()
55+{
56+ m_values.clear();
57+}
58+
59+void UIGraph::addValue(int value, bool ignoreSmallValues)
60+{
61+ if (ignoreSmallValues) {
62+ if (!m_values.empty() && m_values.back() <= 2 && value <= 2 && ++m_ignores <= 10)
63+ return;
64+ m_ignores = 0;
65+ }
66+ m_values.push_back(value);
67+ while (m_values.size() > m_capacity)
68+ m_values.pop_front();
69+}
70+
71+void UIGraph::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
72+{
73+ UIWidget::onStyleApply(styleName, styleNode);
74+
75+ for (const OTMLNodePtr& node : styleNode->children()) {
76+ if (node->tag() == "line-width")
77+ setLineWidth(node->value<int>());
78+ else if (node->tag() == "capacity")
79+ setCapacity(node->value<int>());
80+ else if (node->tag() == "title")
81+ setTitle(node->value<std::string>());
82+ else if (node->tag() == "show-labels")
83+ setShowLabels(node->value<bool>());
84+ }
85+}
A RD_Client/src/client/uigraph.h +44-0 View file
@@ -0,0 +1,44 @@
1+#ifndef UIGRAPH_H
2+#define UIGRAPH_H
3+
4+#include "declarations.h"
5+#include <framework/ui/uiwidget.h>
6+
7+class UIGraph : public UIWidget {
8+public:
9+ UIGraph();
10+
11+ void drawSelf(Fw::DrawPane drawPane);
12+
13+ void clear();
14+ void addValue(int value, bool ignoreSmallValues = false);
15+ void setLineWidth(int width)
16+ {
17+ m_width = width;
18+ }
19+ void setCapacity(int capacity)
20+ {
21+ m_capacity = capacity;
22+ }
23+ void setTitle(const std::string& title)
24+ {
25+ m_title = title;
26+ }
27+ void setShowLabels(bool value)
28+ {
29+ m_showLabes = value;
30+ }
31+
32+protected:
33+ void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
34+
35+private:
36+ std::string m_title;
37+ size_t m_capacity = 100;
38+ size_t m_ignores = 0;
39+ int m_width = 1;
40+ bool m_showLabes = true;
41+ std::deque<int> m_values;
42+};
43+
44+#endif
A RD_Client/src/client/uiitem.cpp +155-0 View file
@@ -0,0 +1,155 @@
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 "uiitem.h"
24+#include "spritemanager.h"
25+#include "game.h"
26+#include <framework/otml/otml.h>
27+#include <framework/graphics/graphics.h>
28+#include <framework/graphics/fontmanager.h>
29+
30+UIItem::UIItem()
31+{
32+ m_draggable = true;
33+}
34+
35+void UIItem::drawSelf(Fw::DrawPane drawPane)
36+{
37+ if(drawPane != Fw::ForegroundPane)
38+ return;
39+ // draw style components in order
40+ if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
41+ Rect backgroundDestRect = m_rect;
42+ backgroundDestRect.expand(-m_borderWidth.top, -m_borderWidth.right, -m_borderWidth.bottom, -m_borderWidth.left);
43+ drawBackground(m_rect);
44+ }
45+
46+ drawImage(m_rect);
47+
48+ if(m_itemVisible && m_item) {
49+ Rect drawRect = getPaddingRect();
50+
51+ int exactSize = std::max<int>(g_sprites.spriteSize(), m_item->getExactSize());
52+ if(exactSize == 0)
53+ return;
54+
55+ m_item->setColor(m_color);
56+ m_item->draw(drawRect);
57+
58+ if(m_font && m_showCount && (m_item->isStackable() || m_item->isChargeable()) && m_item->getCountOrSubType() > 1) {
59+ g_drawQueue->addText(m_font, m_countText, Rect(m_rect.topLeft(), m_rect.bottomRight() - Point(3, 0)), Fw::AlignBottomRight, Color(231, 231, 231));
60+ }
61+
62+ if (m_showId) {
63+ g_drawQueue->addText(m_font, std::to_string(m_item->getServerId()), m_rect, Fw::AlignBottomRight, Color(231, 231, 231));
64+ }
65+ }
66+
67+ drawBorder(m_rect);
68+ drawIcon(m_rect);
69+ drawText(m_rect);
70+}
71+
72+void UIItem::setItemId(int id)
73+{
74+ if (!m_item && id != 0)
75+ m_item = Item::create(id);
76+ else {
77+ // remove item
78+ if (id == 0)
79+ m_item = nullptr;
80+ else
81+ m_item->setId(id);
82+ }
83+
84+ if (m_item)
85+ m_item->setShader(m_shader);
86+
87+ callLuaField("onItemChange");
88+}
89+
90+void UIItem::setItemCount(int count)
91+{
92+ if (m_item) {
93+ m_item->setCount(count);
94+ callLuaField("onItemChange");
95+ cacheCountText();
96+ }
97+}
98+void UIItem::setItemSubType(int subType)
99+{
100+ if (m_item) {
101+ m_item->setSubType(subType);
102+ callLuaField("onItemChange");
103+ }
104+}
105+
106+void UIItem::setItem(const ItemPtr& item)
107+{
108+ m_item = item;
109+ if (m_item) {
110+ m_item->setShader(m_shader);
111+ cacheCountText();
112+ callLuaField("onItemChange");
113+ }
114+}
115+
116+void UIItem::setItemShader(const std::string& str)
117+{
118+ m_shader = str;
119+
120+ if (m_item) {
121+ m_item->setShader(m_shader);
122+ callLuaField("onItemChange");
123+ }
124+}
125+
126+void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
127+{
128+ UIWidget::onStyleApply(styleName, styleNode);
129+
130+ for(const OTMLNodePtr& node : styleNode->children()) {
131+ if(node->tag() == "item-id")
132+ setItemId(node->value<int>());
133+ else if(node->tag() == "item-count")
134+ setItemCount(node->value<int>());
135+ else if(node->tag() == "item-visible")
136+ setItemVisible(node->value<bool>());
137+ else if(node->tag() == "virtual")
138+ setVirtual(node->value<bool>());
139+ else if(node->tag() == "show-id")
140+ m_showId = node->value<bool>();
141+ else if(node->tag() == "shader")
142+ setItemShader(node->value());
143+ }
144+}
145+
146+void UIItem::cacheCountText()
147+{
148+ int count = m_item->getCountOrSubType();
149+ if (!g_game.getFeature(Otc::GameCountU16) || count < 1000) {
150+ m_countText = std::to_string(count);
151+ return;
152+ }
153+
154+ m_countText = stdext::format("%.0fk", count / 1000.0);
155+}
A RD_Client/src/client/uiitem.h +67-0 View file
@@ -0,0 +1,67 @@
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+#ifndef UIITEM_H
24+#define UIITEM_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+#include "item.h"
29+
30+class UIItem : public UIWidget
31+{
32+public:
33+ UIItem();
34+ void drawSelf(Fw::DrawPane drawPane);
35+
36+ void setItemId(int id);
37+ void setItemCount(int count);
38+ void setItemSubType(int subType);
39+ void setItemVisible(bool visible) { m_itemVisible = visible; }
40+ void setItem(const ItemPtr& item);
41+ void setVirtual(bool virt) { m_virtual = virt; }
42+ void clearItem() { setItemId(0); }
43+ void setShowCount(bool value) { m_showCount = value; }
44+ void setItemShader(const std::string& str);
45+
46+ int getItemId() { return m_item ? m_item->getId() : 0; }
47+ int getItemCount() { return m_item ? m_item->getCount() : 0; }
48+ int getItemSubType() { return m_item ? m_item->getSubType() : 0; }
49+ int getItemCountOrSubType() { return m_item ? m_item->getCountOrSubType() : 0; }
50+ ItemPtr getItem() { return m_item; }
51+ bool isVirtual() { return m_virtual; }
52+ bool isItemVisible() { return m_itemVisible; }
53+
54+protected:
55+ void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
56+ void cacheCountText();
57+
58+ ItemPtr m_item;
59+ stdext::boolean<false> m_virtual;
60+ stdext::boolean<true> m_itemVisible;
61+ stdext::boolean<false> m_showId;
62+ stdext::boolean<true> m_showCount;
63+ std::string m_shader;
64+ std::string m_countText;
65+};
66+
67+#endif
A RD_Client/src/client/uimap.cpp +236-0 View file
@@ -0,0 +1,236 @@
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 "uimap.h"
24+#include "game.h"
25+#include "map.h"
26+#include "mapview.h"
27+#include <framework/otml/otml.h>
28+#include <framework/graphics/graphics.h>
29+#include <framework/util/extras.h>
30+#include <framework/graphics/shadermanager.h>
31+#include "localplayer.h"
32+
33+UIMap::UIMap()
34+{
35+ m_draggable = true;
36+ m_mapView = MapViewPtr(new MapView);
37+ m_zoom = m_mapView->getVisibleDimension().height();
38+ m_keepAspectRatio = true;
39+ m_limitVisibleRange = false;
40+ m_aspectRatio = m_mapView->getVisibleDimension().ratio();
41+ m_maxZoomIn = 3;
42+ m_maxZoomOut = 513;
43+ m_mapRect.resize(1,1);
44+ g_map.addMapView(m_mapView);
45+}
46+
47+UIMap::~UIMap()
48+{
49+ g_map.removeMapView(m_mapView);
50+}
51+
52+bool UIMap::onMouseMove(const Point& mousePos, const Point& mouseMoved)
53+{
54+ m_mousePosition = mousePos;
55+ return UIWidget::onMouseMove(mousePos, mouseMoved);
56+}
57+
58+void UIMap::drawSelf(Fw::DrawPane drawPane)
59+{
60+ VALIDATE_DISPATCHER_THREAD();
61+ UIWidget::drawSelf(drawPane);
62+
63+ if(drawPane == Fw::ForegroundPane) {
64+ g_drawQueue->addBoundingRect(m_mapRect.expanded(1), 1, Color::black);
65+ g_drawQueue->markMapPosition();
66+ } else if(drawPane == Fw::MapBackgroundPane) {
67+ m_mapView->drawMapBackground(m_mapRect, getTile(m_mousePosition));
68+ if (!m_shader.empty()) {
69+ g_drawQueue->setShader(m_shader);
70+ }
71+ } else if (drawPane == Fw::MapForegroundPane) {
72+ m_mapView->drawMapForeground(m_mapRect);
73+ }
74+}
75+
76+void UIMap::movePixels(int x, int y)
77+{
78+ m_mapView->move(x, y);
79+}
80+
81+bool UIMap::setZoom(int zoom)
82+{
83+ m_zoom = stdext::clamp<int>(zoom, m_maxZoomIn, m_maxZoomOut);
84+ updateVisibleDimension();
85+ return false;
86+}
87+
88+bool UIMap::zoomIn()
89+{
90+ int delta = 2;
91+ if(m_zoom - delta < m_maxZoomIn)
92+ delta--;
93+
94+ if(m_zoom - delta < m_maxZoomIn)
95+ return false;
96+
97+ m_zoom -= delta;
98+ updateVisibleDimension();
99+ return true;
100+}
101+
102+bool UIMap::zoomOut()
103+{
104+ int delta = 2;
105+ if(m_zoom + delta > m_maxZoomOut)
106+ delta--;
107+
108+ if(m_zoom + delta > m_maxZoomOut)
109+ return false;
110+
111+ m_zoom += 2;
112+ updateVisibleDimension();
113+ return true;
114+}
115+
116+void UIMap::setVisibleDimension(const Size& visibleDimension)
117+{
118+ m_mapView->setVisibleDimension(visibleDimension);
119+ m_aspectRatio = visibleDimension.ratio();
120+
121+ if(m_keepAspectRatio)
122+ updateMapSize();
123+}
124+
125+void UIMap::setKeepAspectRatio(bool enable)
126+{
127+ m_keepAspectRatio = enable;
128+ if(enable)
129+ m_aspectRatio = getVisibleDimension().ratio();
130+ updateMapSize();
131+}
132+
133+Position UIMap::getPosition(const Point& mousePos)
134+{
135+ if (!m_mapRect.contains(mousePos))
136+ return Position();
137+
138+ Point relativeMousePos = mousePos - m_mapRect.topLeft();
139+ return m_mapView->getPosition(relativeMousePos, m_mapRect.size());
140+}
141+
142+Point UIMap::getPositionOffset(const Point& mousePos)
143+{
144+ if (!m_mapRect.contains(mousePos))
145+ return Point(0, 0);
146+
147+ Point relativeMousePos = mousePos - m_mapRect.topLeft();
148+ return m_mapView->getPositionOffset(relativeMousePos, m_mapRect.size());
149+}
150+
151+TilePtr UIMap::getTile(const Point& mousePos)
152+{
153+ Position tilePos = getPosition(mousePos);
154+ if(!tilePos.isValid())
155+ return nullptr;
156+
157+ // we must check every floor, from top to bottom to check for a clickable tile
158+ TilePtr tile;
159+ tilePos.coveredUp(tilePos.z - m_mapView->getCachedFirstVisibleFloor());
160+ for(int i = m_mapView->getCachedFirstVisibleFloor(); i <= m_mapView->getCachedLastVisibleFloor(); i++) {
161+ tile = g_map.getTile(tilePos);
162+ if(tile && tile->isClickable())
163+ break;
164+ tilePos.coveredDown();
165+ }
166+
167+ if(!tile || !tile->isClickable())
168+ return nullptr;
169+
170+ return tile;
171+}
172+
173+void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
174+{
175+ UIWidget::onStyleApply(styleName, styleNode);
176+ for(const OTMLNodePtr& node : styleNode->children()) {
177+ if(node->tag() == "multifloor")
178+ setMultifloor(node->value<bool>());
179+ else if(node->tag() == "draw-texts")
180+ setDrawTexts(node->value<bool>());
181+ else if(node->tag() == "draw-lights")
182+ setDrawLights(node->value<bool>());
183+ else if(node->tag() == "animated")
184+ setAnimated(node->value<bool>());
185+ }
186+}
187+
188+void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
189+{
190+ UIWidget::onGeometryChange(oldRect, newRect);
191+ updateMapSize();
192+}
193+
194+void UIMap::updateVisibleDimension()
195+{
196+ int dimensionHeight = m_zoom;
197+
198+ float ratio = m_aspectRatio;
199+ if(!m_limitVisibleRange && !m_mapRect.isEmpty() && !m_keepAspectRatio)
200+ ratio = m_mapRect.size().ratio();
201+
202+ if(dimensionHeight % 2 == 0)
203+ dimensionHeight += 1;
204+ int dimensionWidth = m_zoom * ratio;
205+ if(dimensionWidth % 2 == 0)
206+ dimensionWidth += 1;
207+
208+ m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
209+
210+ if(m_keepAspectRatio)
211+ updateMapSize();
212+
213+ callLuaField("onVisibleDimensionChange", dimensionWidth, dimensionHeight);
214+}
215+
216+void UIMap::updateMapSize()
217+{
218+ Rect clippingRect = getPaddingRect();
219+ Size mapSize;
220+ if(m_keepAspectRatio) {
221+ Rect mapRect = clippingRect.expanded(-1);
222+ mapSize = Size(m_aspectRatio*m_zoom, m_zoom);
223+ mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
224+ } else {
225+ mapSize = clippingRect.expanded(-1).size();
226+ }
227+
228+ m_mapRect.resize(mapSize);
229+ m_mapRect.moveCenter(clippingRect.center());
230+ m_mapView->optimizeForSize(mapSize);
231+
232+ if(!m_keepAspectRatio)
233+ updateVisibleDimension();
234+}
235+
236+/* vim: set ts=4 sw=4 et: */
A RD_Client/src/client/uimap.h +121-0 View file
@@ -0,0 +1,121 @@
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+#ifndef UIMAP_H
24+#define UIMAP_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+#include "tile.h"
29+
30+#include "mapview.h"
31+
32+class UIMap : public UIWidget
33+{
34+public:
35+ UIMap();
36+ ~UIMap();
37+
38+ bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
39+
40+ void drawSelf(Fw::DrawPane drawPane);
41+
42+ void movePixels(int x, int y);
43+ bool setZoom(int zoom);
44+ bool zoomIn();
45+ bool zoomOut();
46+ void followCreature(const CreaturePtr& creature) { m_mapView->followCreature(creature); }
47+
48+ void setCameraPosition(const Position& pos) { m_mapView->setCameraPosition(pos); }
49+ void setMaxZoomIn(int maxZoomIn) { m_maxZoomIn = maxZoomIn; }
50+ void setMaxZoomOut(int maxZoomOut) { m_maxZoomOut = maxZoomOut; }
51+ void setMultifloor(bool enable) { m_mapView->setMultifloor(enable); }
52+ void lockVisibleFloor(int floor) { m_mapView->lockFirstVisibleFloor(floor); }
53+ void unlockVisibleFloor() { m_mapView->unlockFirstVisibleFloor(); }
54+ void setVisibleDimension(const Size& visibleDimension);
55+ void setDrawFlags(Otc::DrawFlags drawFlags) { m_mapView->setDrawFlags(drawFlags); }
56+ void setDrawTexts(bool enable) { m_mapView->setDrawTexts(enable); }
57+ void setDrawNames(bool enable) { m_mapView->setDrawNames(enable); }
58+ void setDrawHealthBars(bool enable) { m_mapView->setDrawHealthBars(enable); }
59+ void setDrawHealthBarsOnTop(bool enable) { m_mapView->setDrawHealthBarsOnTop(enable); }
60+ void setDrawLights(bool enable) { m_mapView->setDrawLights(enable); }
61+ void setDrawManaBar(bool enable) { m_mapView->setDrawManaBar(enable); }
62+ void setDrawPlayerBars(bool enable) { m_mapView->setDrawPlayerBars(enable); }
63+ void setAnimated(bool enable) { m_mapView->setAnimated(enable); }
64+ void setKeepAspectRatio(bool enable);
65+ void setMinimumAmbientLight(float intensity) { m_mapView->setMinimumAmbientLight(intensity); }
66+ void setLimitVisibleRange(bool limitVisibleRange) { m_limitVisibleRange = limitVisibleRange; updateVisibleDimension(); }
67+ void setFloorFading(int value) { m_mapView->setFloorFading(value); }
68+ void setCrosshair(const std::string& type) { m_mapView->setCrosshair(type); }
69+ bool isMultifloor() { return m_mapView->isMultifloor(); }
70+ bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
71+ bool isDrawingNames() { return m_mapView->isDrawingNames(); }
72+ bool isDrawingHealthBars() { return m_mapView->isDrawingHealthBars(); }
73+ bool isDrawingHealthBarsOnTop() { return m_mapView->isDrawingHealthBarsOnTop(); }
74+ bool isDrawingLights() { return m_mapView->isDrawingLights(); }
75+ bool isDrawingManaBar() { return m_mapView->isDrawingManaBar(); }
76+ bool isAnimating() { return m_mapView->isAnimating(); }
77+ bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }
78+ bool isLimitVisibleRangeEnabled() { return m_limitVisibleRange; }
79+
80+ Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
81+ CreaturePtr getFollowingCreature() { return m_mapView->getFollowingCreature(); }
82+ Otc::DrawFlags getDrawFlags() { return m_mapView->getDrawFlags(); }
83+ Position getCameraPosition() { return m_mapView->getCameraPosition(); }
84+ Position getPosition(const Point& mousePos);
85+ Point getPositionOffset(const Point& mousePos);
86+ TilePtr getTile(const Point& mousePos);
87+ int getMaxZoomIn() { return m_maxZoomIn; }
88+ int getMaxZoomOut() { return m_maxZoomOut; }
89+ int getZoom() { return m_zoom; }
90+ float getMinimumAmbientLight() { return m_mapView->getMinimumAmbientLight(); }
91+
92+ void setShader(const std::string& shader)
93+ {
94+ m_shader = shader;
95+ }
96+ std::string getShader()
97+ {
98+ return m_shader;
99+ }
100+
101+protected:
102+ virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
103+ virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
104+
105+private:
106+ void updateVisibleDimension();
107+ void updateMapSize();
108+
109+ int m_zoom;
110+ MapViewPtr m_mapView;
111+ Rect m_mapRect;
112+ Point m_mousePosition;
113+ float m_aspectRatio;
114+ bool m_keepAspectRatio;
115+ bool m_limitVisibleRange;
116+ int m_maxZoomIn;
117+ int m_maxZoomOut;
118+ std::string m_shader;
119+};
120+
121+#endif
A RD_Client/src/client/uimapanchorlayout.cpp +92-0 View file
@@ -0,0 +1,92 @@
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 "declarations.h"
24+#include "uimapanchorlayout.h"
25+#include "uiminimap.h"
26+#include <framework/ui/uiwidget.h>
27+
28+int UIPositionAnchor::getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWidgetPtr& parentWidget)
29+{
30+ UIMinimapPtr minimap = hookedWidget->static_self_cast<UIMinimap>();
31+ Rect hookedRect = minimap->getTileRect(m_hookedPosition);
32+ int point = 0;
33+ if(hookedRect.isValid()) {
34+ switch(m_hookedEdge) {
35+ case Fw::AnchorLeft:
36+ point = hookedRect.left();
37+ break;
38+ case Fw::AnchorRight:
39+ point = hookedRect.right();
40+ break;
41+ case Fw::AnchorTop:
42+ point = hookedRect.top();
43+ break;
44+ case Fw::AnchorBottom:
45+ point = hookedRect.bottom();
46+ break;
47+ case Fw::AnchorHorizontalCenter:
48+ point = hookedRect.horizontalCenter();
49+ break;
50+ case Fw::AnchorVerticalCenter:
51+ point = hookedRect.verticalCenter();
52+ break;
53+ default:
54+ // must never happens
55+ VALIDATE(false);
56+ break;
57+ }
58+ }
59+ return point;
60+}
61+
62+void UIMapAnchorLayout::addPositionAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, const Position& hookedPosition, Fw::AnchorEdge hookedEdge)
63+{
64+ if(!anchoredWidget)
65+ return;
66+
67+ VALIDATE(anchoredWidget != getParentWidget());
68+
69+ UIPositionAnchorPtr anchor(new UIPositionAnchor(anchoredEdge, hookedPosition, hookedEdge));
70+ UIAnchorGroupPtr& anchorGroup = m_anchorsGroups[anchoredWidget];
71+ if(!anchorGroup)
72+ anchorGroup = UIAnchorGroupPtr(new UIAnchorGroup);
73+
74+ anchorGroup->addAnchor(anchor);
75+
76+ // layout must be updated because a new anchor got in
77+ update();
78+}
79+
80+void UIMapAnchorLayout::centerInPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
81+{
82+ addPositionAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedPosition, Fw::AnchorHorizontalCenter);
83+ addPositionAnchor(anchoredWidget, Fw::AnchorVerticalCenter, hookedPosition, Fw::AnchorVerticalCenter);
84+}
85+
86+void UIMapAnchorLayout::fillPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
87+{
88+ addPositionAnchor(anchoredWidget, Fw::AnchorLeft, hookedPosition, Fw::AnchorLeft);
89+ addPositionAnchor(anchoredWidget, Fw::AnchorRight, hookedPosition, Fw::AnchorRight);
90+ addPositionAnchor(anchoredWidget, Fw::AnchorTop, hookedPosition, Fw::AnchorTop);
91+ addPositionAnchor(anchoredWidget, Fw::AnchorBottom, hookedPosition, Fw::AnchorBottom);
92+}
A RD_Client/src/client/uimapanchorlayout.h +55-0 View file
@@ -0,0 +1,55 @@
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+#ifndef UIMAPANCHORLAYOUT_H
24+#define UIMAPANCHORLAYOUT_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uianchorlayout.h>
28+
29+class UIPositionAnchor : public UIAnchor
30+{
31+public:
32+ UIPositionAnchor(Fw::AnchorEdge anchoredEdge, const Position& hookedPosition, Fw::AnchorEdge hookedEdge) :
33+ UIAnchor(anchoredEdge, std::string(), hookedEdge), m_hookedPosition(hookedPosition) { }
34+
35+ UIWidgetPtr getHookedWidget(const UIWidgetPtr& widget, const UIWidgetPtr& parentWidget) { return parentWidget; }
36+ int getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWidgetPtr& parentWidget);
37+
38+private:
39+ Position m_hookedPosition;
40+};
41+
42+class UIMapAnchorLayout : public UIAnchorLayout
43+{
44+public:
45+ UIMapAnchorLayout(UIWidgetPtr parentWidget) : UIAnchorLayout(parentWidget) { }
46+
47+ void addPositionAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
48+ const Position& hookedPosition, Fw::AnchorEdge hookedEdge);
49+ void centerInPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition);
50+ void fillPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition);
51+
52+protected:
53+};
54+
55+#endif
A RD_Client/src/client/uiminimap.cpp +154-0 View file
@@ -0,0 +1,154 @@
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 "uiminimap.h"
24+#include "game.h"
25+#include "luavaluecasts_client.h"
26+#include "minimap.h"
27+#include "uimapanchorlayout.h"
28+
29+#include "uimapanchorlayout.h"
30+#include <framework/graphics/painter.h>
31+
32+UIMinimap::UIMinimap() {
33+ m_zoom = 0;
34+ m_scale = 1.0f;
35+ m_minZoom = -5;
36+ m_maxZoom = 5;
37+ m_layout =
38+ UIMapAnchorLayoutPtr(new UIMapAnchorLayout(static_self_cast<UIWidget>()));
39+}
40+
41+void UIMinimap::drawSelf(Fw::DrawPane drawPane) {
42+ UIWidget::drawSelf(drawPane);
43+
44+ if (drawPane != Fw::ForegroundPane)
45+ return;
46+
47+ g_minimap.draw(getPaddingRect(), getCameraPosition(), m_scale, m_color);
48+}
49+
50+bool UIMinimap::setZoom(int zoom) {
51+ if (zoom == m_zoom)
52+ return true;
53+
54+ if (zoom < m_minZoom || zoom > m_maxZoom)
55+ return false;
56+
57+ int oldZoom = m_zoom;
58+ m_zoom = zoom;
59+ if (m_zoom < 0)
60+ m_scale = 1.0f / (1 << std::abs(zoom));
61+ else if (m_zoom > 0)
62+ m_scale = 1.0f * (1 << std::abs(zoom));
63+ else
64+ m_scale = 1;
65+ m_layout->update();
66+
67+ onZoomChange(zoom, oldZoom);
68+ return true;
69+}
70+
71+void UIMinimap::setCameraPosition(const Position &pos) {
72+ Position oldPos = m_cameraPosition;
73+ m_cameraPosition = pos;
74+ m_layout->update();
75+
76+ onCameraPositionChange(pos, oldPos);
77+}
78+
79+bool UIMinimap::floorUp() {
80+ Position pos = getCameraPosition();
81+ if (!pos.up())
82+ return false;
83+ setCameraPosition(pos);
84+ return true;
85+}
86+
87+bool UIMinimap::floorDown() {
88+ Position pos = getCameraPosition();
89+ if (!pos.down())
90+ return false;
91+ setCameraPosition(pos);
92+ return true;
93+}
94+
95+Point UIMinimap::getTilePoint(const Position &pos) {
96+ return g_minimap.getTilePoint(pos, getPaddingRect(), getCameraPosition(),
97+ m_scale);
98+}
99+
100+Rect UIMinimap::getTileRect(const Position &pos) {
101+ return g_minimap.getTileRect(pos, getPaddingRect(), getCameraPosition(),
102+ m_scale);
103+}
104+
105+Position UIMinimap::getTilePosition(const Point &mousePos) {
106+ return g_minimap.getTilePosition(mousePos, getPaddingRect(),
107+ getCameraPosition(), m_scale);
108+}
109+
110+void UIMinimap::anchorPosition(const UIWidgetPtr &anchoredWidget,
111+ Fw::AnchorEdge anchoredEdge,
112+ const Position &hookedPosition,
113+ Fw::AnchorEdge hookedEdge) {
114+ UIMapAnchorLayoutPtr layout = m_layout->static_self_cast<UIMapAnchorLayout>();
115+ VALIDATE(layout);
116+ layout->addPositionAnchor(anchoredWidget, anchoredEdge, hookedPosition,
117+ hookedEdge);
118+}
119+
120+void UIMinimap::fillPosition(const UIWidgetPtr &anchoredWidget,
121+ const Position &hookedPosition) {
122+ UIMapAnchorLayoutPtr layout = m_layout->static_self_cast<UIMapAnchorLayout>();
123+ VALIDATE(layout);
124+ layout->fillPosition(anchoredWidget, hookedPosition);
125+}
126+
127+void UIMinimap::centerInPosition(const UIWidgetPtr &anchoredWidget,
128+ const Position &hookedPosition) {
129+ UIMapAnchorLayoutPtr layout = m_layout->static_self_cast<UIMapAnchorLayout>();
130+ VALIDATE(layout);
131+ layout->centerInPosition(anchoredWidget, hookedPosition);
132+}
133+
134+void UIMinimap::onZoomChange(int zoom, int oldZoom) {
135+ callLuaField("onZoomChange", zoom, oldZoom);
136+}
137+
138+void UIMinimap::onCameraPositionChange(const Position &position,
139+ const Position &oldPosition) {
140+ callLuaField("onCameraPositionChange", position, oldPosition);
141+}
142+
143+void UIMinimap::onStyleApply(const std::string &styleName,
144+ const OTMLNodePtr &styleNode) {
145+ UIWidget::onStyleApply(styleName, styleNode);
146+ for (const OTMLNodePtr &node : styleNode->children()) {
147+ if (node->tag() == "zoom")
148+ setZoom(node->value<int>());
149+ else if (node->tag() == "max-zoom")
150+ setMaxZoom(node->value<int>());
151+ else if (node->tag() == "min-zoom")
152+ setMinZoom(node->value<int>());
153+ }
154+}
A RD_Client/src/client/uiminimap.h +82-0 View file
@@ -0,0 +1,82 @@
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+#ifndef UIMINIMAP_H
24+#define UIMINIMAP_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+
29+class UIMinimap : public UIWidget {
30+public:
31+ UIMinimap();
32+
33+ void drawSelf(Fw::DrawPane drawPane);
34+
35+ bool zoomIn() { return setZoom(m_zoom + 1); }
36+ bool zoomOut() { return setZoom(m_zoom - 1); }
37+
38+ bool setZoom(int zoom);
39+ void setMinZoom(int minZoom) { m_minZoom = minZoom; }
40+ void setMaxZoom(int maxZoom) { m_maxZoom = maxZoom; }
41+ void setCameraPosition(const Position &pos);
42+ bool floorUp();
43+ bool floorDown();
44+
45+ Point getTilePoint(const Position &pos);
46+ Rect getTileRect(const Position &pos);
47+ Position getTilePosition(const Point &mousePos);
48+
49+ Position getCameraPosition() { return m_cameraPosition; }
50+ int getMinZoom() { return m_minZoom; }
51+ int getMaxZoom() { return m_maxZoom; }
52+ int getZoom() { return m_zoom; }
53+ float getScale() { return m_scale; }
54+
55+ void anchorPosition(const UIWidgetPtr &anchoredWidget,
56+ Fw::AnchorEdge anchoredEdge,
57+ const Position &hookedPosition,
58+ Fw::AnchorEdge hookedEdge);
59+ void fillPosition(const UIWidgetPtr &anchoredWidget,
60+ const Position &hookedPosition);
61+ void centerInPosition(const UIWidgetPtr &anchoredWidget,
62+ const Position &hookedPosition);
63+
64+protected:
65+ virtual void onZoomChange(int zoom, int oldZoom);
66+ virtual void onCameraPositionChange(const Position &position,
67+ const Position &oldPosition);
68+ virtual void onStyleApply(const std::string &styleName,
69+ const OTMLNodePtr &styleNode);
70+
71+private:
72+ void update();
73+
74+ Rect m_mapArea;
75+ Position m_cameraPosition;
76+ float m_scale;
77+ int m_zoom;
78+ int m_minZoom;
79+ int m_maxZoom;
80+};
81+
82+#endif
A RD_Client/src/client/uiprogressrect.cpp +96-0 View file
@@ -0,0 +1,96 @@
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 "uiprogressrect.h"
24+#include <framework/otml/otml.h>
25+#include <framework/graphics/graphics.h>
26+#include <framework/graphics/fontmanager.h>
27+
28+UIProgressRect::UIProgressRect()
29+{
30+ m_percent = 0;
31+}
32+
33+void UIProgressRect::drawSelf(Fw::DrawPane drawPane)
34+{
35+ if(drawPane != Fw::ForegroundPane)
36+ return;
37+
38+ // todo: check +1 to right/bottom
39+ // todo: add smooth
40+ Rect drawRect = getPaddingRect();
41+
42+ // 0% - 12.5% (12.5)
43+ // triangle from top center, to top right (var x)
44+ if(m_percent < 12.5) {
45+ Point var = Point(std::max<int>(m_percent - 0.0, 0.0) * (drawRect.right() - drawRect.horizontalCenter()) / 12.5, 0);
46+ g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topRight() + Point(1,0), drawRect.topCenter() + var, m_backgroundColor);
47+ }
48+
49+ // 12.5% - 37.5% (25)
50+ // triangle from top right to bottom right (var y)
51+ if(m_percent < 37.5) {
52+ Point var = Point(0, std::max<int>(m_percent - 12.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
53+ g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.bottomRight() + Point(1,1), drawRect.topRight() + var + Point(1,0), m_backgroundColor);
54+ }
55+
56+ // 37.5% - 62.5% (25)
57+ // triangle from bottom right to bottom left (var x)
58+ if(m_percent < 62.5) {
59+ Point var = Point(std::max<int>(m_percent - 37.5, 0.0) * (drawRect.right() - drawRect.left()) / 25.0, 0);
60+ g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.bottomLeft() + Point(0,1), drawRect.bottomRight() - var + Point(1,1), m_backgroundColor);
61+ }
62+
63+ // 62.5% - 87.5% (25)
64+ // triangle from bottom left to top left
65+ if(m_percent < 87.5) {
66+ Point var = Point(0, std::max<int>(m_percent - 62.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
67+ g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topLeft(), drawRect.bottomLeft() - var + Point(0,1), m_backgroundColor);
68+ }
69+
70+ // 87.5% - 100% (12.5)
71+ // triangle from top left to top center
72+ if(m_percent < 100) {
73+ Point var = Point(std::max<int>(m_percent - 87.5, 0.0) * (drawRect.horizontalCenter() - drawRect.left()) / 12.5, 0);
74+ g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topCenter(), drawRect.topLeft() + var, m_backgroundColor);
75+ }
76+
77+ drawImage(m_rect);
78+ drawBorder(m_rect);
79+ drawIcon(m_rect);
80+ drawText(m_rect);
81+}
82+
83+void UIProgressRect::setPercent(float percent)
84+{
85+ m_percent = stdext::clamp<float>((double)percent, 0.0, 100.0);
86+}
87+
88+void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
89+{
90+ UIWidget::onStyleApply(styleName, styleNode);
91+
92+ for(const OTMLNodePtr& node : styleNode->children()) {
93+ if(node->tag() == "percent")
94+ setPercent(node->value<float>());
95+ }
96+}
A RD_Client/src/client/uiprogressrect.h +45-0 View file
@@ -0,0 +1,45 @@
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+#ifndef UIPROGRESSRECT_H
24+#define UIPROGRESSRECT_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+#include "item.h"
29+
30+class UIProgressRect : public UIWidget
31+{
32+public:
33+ UIProgressRect();
34+ void drawSelf(Fw::DrawPane drawPane);
35+
36+ void setPercent(float percent);
37+ float getPercent() { return m_percent; }
38+
39+protected:
40+ void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
41+
42+ float m_percent;
43+};
44+
45+#endif
A RD_Client/src/client/uisprite.cpp +86-0 View file
@@ -0,0 +1,86 @@
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 "uisprite.h"
24+#include <framework/otml/otml.h>
25+#include <framework/graphics/graphics.h>
26+#include <framework/graphics/texturemanager.h>
27+#include <client/spritemanager.h>
28+
29+UISprite::UISprite() :
30+ m_spriteId(0),
31+ m_spriteColor(Color::white)
32+{ }
33+
34+void UISprite::drawSelf(Fw::DrawPane drawPane)
35+{
36+ if(drawPane != Fw::ForegroundPane)
37+ return;
38+
39+ // draw style components in order
40+ if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
41+ Rect backgroundDestRect = m_rect;
42+ backgroundDestRect.expand(-m_borderWidth.top, -m_borderWidth.right, -m_borderWidth.bottom, -m_borderWidth.left);
43+ drawBackground(m_rect);
44+ }
45+
46+ drawImage(m_rect);
47+
48+ if(m_spriteVisible && m_sprite) {
49+ g_drawQueue->addTexturedRect(getPaddingRect(), m_sprite, Rect(Point(0, 0), m_sprite->getSize()), m_spriteColor);
50+ }
51+
52+ drawBorder(m_rect);
53+ drawIcon(m_rect);
54+ drawText(m_rect);
55+}
56+
57+void UISprite::setSpriteId(uint32 id)
58+{
59+ if(!g_sprites.isLoaded())
60+ return;
61+
62+ m_spriteId = id;
63+ if(id == 0)
64+ m_sprite = nullptr;
65+ else {
66+ ImagePtr image = g_sprites.getSpriteImage(id);
67+ if(image)
68+ m_sprite = new Texture(image);
69+ else
70+ m_sprite = nullptr;
71+ }
72+}
73+
74+void UISprite::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
75+{
76+ UIWidget::onStyleApply(styleName, styleNode);
77+
78+ for(const OTMLNodePtr& node : styleNode->children()) {
79+ if(node->tag() == "sprite-id")
80+ setSpriteId(node->value<uint32>());
81+ else if(node->tag() == "sprite-visible")
82+ setSpriteVisible(node->value<bool>());
83+ else if(node->tag() == "sprite-color")
84+ setSpriteColor(node->value<Color>());
85+ }
86+}
A RD_Client/src/client/uisprite.h +56-0 View file
@@ -0,0 +1,56 @@
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+#ifndef UISPRITE_H
24+#define UISPRITE_H
25+
26+#include "declarations.h"
27+#include <framework/ui/uiwidget.h>
28+
29+class UISprite : public UIWidget
30+{
31+public:
32+ UISprite();
33+ void drawSelf(Fw::DrawPane drawPane);
34+
35+ void setSpriteId(uint32 id);
36+ uint32 getSpriteId() { return m_spriteId; }
37+ void clearSprite() { setSpriteId(0); }
38+
39+ void setSpriteColor(Color color) { m_spriteColor = color; }
40+
41+ bool isSpriteVisible() { return m_spriteVisible; }
42+ void setSpriteVisible(bool visible) { m_spriteVisible = visible; }
43+
44+ bool hasSprite() { return m_sprite != nullptr; }
45+
46+protected:
47+ void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
48+
49+ TexturePtr m_sprite;
50+ uint32 m_spriteId;
51+ Color m_spriteColor;
52+
53+ stdext::boolean<true> m_spriteVisible;
54+};
55+
56+#endif
A RD_Client/src/client/walkmatrix.h +140-0 View file
@@ -0,0 +1,140 @@
1+#pragma once
2+
3+#include <cstdint>
4+#include <string>
5+#include <sstream>
6+
7+#include "position.h"
8+
9+class WalkMatrix {
10+public:
11+
12+ void updatePosition(const Position& newPos)
13+ {
14+ int32_t xdiff = pos.x - newPos.x;
15+ int32_t ydiff = pos.y - newPos.y;
16+ if (pos.z != newPos.z || std::abs(xdiff) > 6 || std::abs(ydiff) > 6) {
17+ pos = newPos;
18+ return clear();
19+ }
20+ pos = newPos;
21+
22+ if (xdiff < 0) {
23+ for (int x = 0; x < 7; ++x) {
24+ for (int y = 0; y < 7; ++y) {
25+ if (x - xdiff > 6) {
26+ matrix[x][y] = 0;
27+ } else {
28+ matrix[x][y] = matrix[x - xdiff][y];
29+ }
30+ }
31+ }
32+ }
33+ if (xdiff > 0) {
34+ for (int x = 6; x >= 0; --x) {
35+ for (int y = 6; y >= 0; --y) {
36+ if (x - xdiff < 0) {
37+ matrix[x][y] = 0;
38+ } else {
39+ matrix[x][y] = matrix[x - xdiff][y];
40+ }
41+ }
42+ }
43+ }
44+ if (ydiff < 0) {
45+ for (int x = 0; x < 7; ++x) {
46+ for (int y = 0; y < 7; ++y) {
47+ if (y - ydiff > 6) {
48+ matrix[x][y] = 0;
49+ } else {
50+ matrix[x][y] = matrix[x][y - ydiff];
51+ }
52+ }
53+ }
54+ }
55+ if (ydiff > 0) {
56+ for (int x = 6; x >= 0; --x) {
57+ for (int y = 6; y >= 0; --y) {
58+ if (y - ydiff < 0) {
59+ matrix[x][y] = 0;
60+ } else {
61+ matrix[x][y] = matrix[x][y - ydiff];
62+ }
63+ }
64+ }
65+ }
66+ }
67+
68+ bool inRange(const Position& pos2)
69+ {
70+ if (pos.z != pos2.z) return false;
71+ int32_t xdiff = pos.x - pos2.x;
72+ int32_t ydiff = pos.y - pos2.y;
73+ if (std::abs(xdiff) > 3 || std::abs(ydiff) > 3) return false;
74+ return true;
75+ }
76+
77+ int32_t update(const Position& pos2, int32_t value = 0)
78+ {
79+ if (pos.z != pos2.z) return 0;
80+ int32_t xdiff = pos.x - pos2.x;
81+ int32_t ydiff = pos.y - pos2.y;
82+ if (std::abs(xdiff) > 3 || std::abs(ydiff) > 3) return 0;
83+ if (value != 0) {
84+ matrix[3 - xdiff][3 - ydiff] = value;
85+ return value;
86+ }
87+ counter += 1;
88+ matrix[3 - xdiff][3 - ydiff] = counter;
89+ return counter;
90+ }
91+
92+ int32_t get(const Position& pos2)
93+ {
94+ if (pos.z != pos2.z) return 0;
95+ int32_t xdiff = pos.x - pos2.x;
96+ int32_t ydiff = pos.y - pos2.y;
97+ if (std::abs(xdiff) > 3 || std::abs(ydiff) > 3) return 0;
98+ return matrix[3 - xdiff][3 - ydiff];
99+ }
100+
101+ void clear()
102+ {
103+ for (auto& x : matrix) {
104+ for (auto& y : x) {
105+ y = 0;
106+ }
107+ }
108+ }
109+
110+ uint32_t reset(uint32_t value = 0)
111+ {
112+ if (value == 0) {
113+ counter += 1;
114+ value = counter;
115+ }
116+ for (auto& x : matrix) {
117+ for (auto& y : x) {
118+ y = value;
119+ }
120+ }
121+ return value;
122+ }
123+
124+ std::string dump()
125+ {
126+ std::stringstream ss;
127+ for (int y = 0; y < 7; ++y) {
128+ for (int x = 0; x < 7; ++x) {
129+ ss << matrix[x][y] << "\t";
130+ }
131+ ss << "\n";
132+ }
133+ return ss.str();
134+ }
135+
136+private:
137+ Position pos;
138+ int32_t matrix[7][7] = { { 0 } };
139+ int32_t counter = 0;
140+};
Top