Browse Source

Merge pull request #909 from diath/player_mana_bar

Add player mana bar
Eduardo Bart 3 years ago
parent
commit
fe1ca3d329
No account linked to committer's email address

+ 4
- 0
modules/client_options/game.otui View File

@@ -34,6 +34,10 @@ Panel
34 34
     id: displayHealth
35 35
     !text: tr('Display creature health bars')
36 36
 
37
+  OptionCheckBox
38
+    id: displayMana
39
+    !text: tr('Display player mana bar')
40
+
37 41
   OptionCheckBox
38 42
     id: displayText
39 43
     !text: tr('Display text messages')

+ 6
- 1
modules/client_options/options.lua View File

@@ -25,6 +25,7 @@ local defaultOptions = {
25 25
   ambientLight = 25,
26 26
   displayNames = true,
27 27
   displayHealth = true,
28
+  displayMana = true,
28 29
   displayText = true,
29 30
   dontStretchShrink = false,
30 31
   turnDelay = 50,
@@ -157,15 +158,17 @@ function hide()
157 158
 end
158 159
 
159 160
 function toggleDisplays()
160
-  if options['displayNames'] and options['displayHealth'] then
161
+  if options['displayNames'] and options['displayHealth'] and options['displayMana'] then
161 162
     setOption('displayNames', false)
162 163
   elseif options['displayHealth'] then
163 164
     setOption('displayHealth', false)
165
+    setOption('displayMana', false)
164 166
   else
165 167
     if not options['displayNames'] and not options['displayHealth'] then
166 168
       setOption('displayNames', true)
167 169
     else
168 170
       setOption('displayHealth', true)
171
+      setOption('displayMana', true)
169 172
     end
170 173
   end
171 174
 end
@@ -224,6 +227,8 @@ function setOption(key, value, force)
224 227
     gameMapPanel:setDrawNames(value)
225 228
   elseif key == 'displayHealth' then
226 229
     gameMapPanel:setDrawHealthBars(value)
230
+  elseif key == 'displayMana' then
231
+    gameMapPanel:setDrawManaBar(value)
227 232
   elseif key == 'displayText' then
228 233
     gameMapPanel:setDrawTexts(value)
229 234
   elseif key == 'dontStretchShrink' then

+ 2
- 1
src/client/const.h View File

@@ -60,11 +60,12 @@ namespace Otc
60 60
         DrawBars = 4096,
61 61
         DrawNames = 8192,
62 62
         DrawLights = 16384,
63
+        DrawManaBar = 32768,
63 64
         DrawWalls = DrawOnBottom | DrawOnTop,
64 65
         DrawEverything = DrawGround | DrawGroundBorders | DrawWalls | DrawItems |
65 66
                          DrawCreatures | DrawEffects | DrawMissiles | DrawCreaturesInformation |
66 67
                          DrawStaticTexts | DrawAnimatedTexts | DrawAnimations | DrawBars | DrawNames |
67
-                         DrawLights
68
+                         DrawLights | DrawManaBar
68 69
     };
69 70
 
70 71
     enum DatOpts {

+ 28
- 2
src/client/creature.cpp View File

@@ -241,10 +241,15 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par
241 241
     textRect.bind(parentRect);
242 242
 
243 243
     // distance them
244
+    uint32 offset = 12;
245
+    if(isLocalPlayer()) {
246
+        offset *= 2;
247
+    }
248
+
244 249
     if(textRect.top() == parentRect.top())
245
-        backgroundRect.moveTop(textRect.top() + 12);
250
+        backgroundRect.moveTop(textRect.top() + offset);
246 251
     if(backgroundRect.bottom() == parentRect.bottom())
247
-        textRect.moveTop(backgroundRect.top() - 12);
252
+        textRect.moveTop(backgroundRect.top() - offset);
248 253
 
249 254
     // health rect is based on background rect, so no worries
250 255
     Rect healthRect = backgroundRect.expanded(-1);
@@ -260,6 +265,27 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par
260 265
 
261 266
         g_painter->setColor(fillColor);
262 267
         g_painter->drawFilledRect(healthRect);
268
+
269
+        if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) {
270
+            LocalPlayerPtr player = g_game.getLocalPlayer();
271
+            if(player) {
272
+                backgroundRect.moveTop(backgroundRect.bottom());
273
+
274
+                g_painter->setColor(Color::black);
275
+                g_painter->drawFilledRect(backgroundRect);
276
+
277
+                Rect manaRect = backgroundRect.expanded(-1);
278
+                double maxMana = player->getMaxMana();
279
+                if(maxMana == 0) {
280
+                    manaRect.setWidth(25);
281
+                } else {
282
+                    manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25);
283
+                }
284
+
285
+                g_painter->setColor(Color::blue);
286
+                g_painter->drawFilledRect(manaRect);
287
+            }
288
+        }
263 289
     }
264 290
 
265 291
     if(drawFlags & Otc::DrawNames) {

+ 2
- 0
src/client/luafunctions.cpp View File

@@ -749,6 +749,7 @@ void Client::registerLuaFunctions()
749 749
     g_lua.bindClassMemberFunction<UIMap>("setDrawNames", &UIMap::setDrawNames);
750 750
     g_lua.bindClassMemberFunction<UIMap>("setDrawHealthBars", &UIMap::setDrawHealthBars);
751 751
     g_lua.bindClassMemberFunction<UIMap>("setDrawLights", &UIMap::setDrawLights);
752
+    g_lua.bindClassMemberFunction<UIMap>("setDrawManaBar", &UIMap::setDrawManaBar);
752 753
     g_lua.bindClassMemberFunction<UIMap>("setAnimated", &UIMap::setAnimated);
753 754
     g_lua.bindClassMemberFunction<UIMap>("setKeepAspectRatio", &UIMap::setKeepAspectRatio);
754 755
     g_lua.bindClassMemberFunction<UIMap>("setMapShader", &UIMap::setMapShader);
@@ -761,6 +762,7 @@ void Client::registerLuaFunctions()
761 762
     g_lua.bindClassMemberFunction<UIMap>("isDrawingNames", &UIMap::isDrawingNames);
762 763
     g_lua.bindClassMemberFunction<UIMap>("isDrawingHealthBars", &UIMap::isDrawingHealthBars);
763 764
     g_lua.bindClassMemberFunction<UIMap>("isDrawingLights", &UIMap::isDrawingLights);
765
+    g_lua.bindClassMemberFunction<UIMap>("isDrawingManaBar", &UIMap::isDrawingManaBar);
764 766
     g_lua.bindClassMemberFunction<UIMap>("isLimitVisibleRangeEnabled", &UIMap::isLimitVisibleRangeEnabled);
765 767
     g_lua.bindClassMemberFunction<UIMap>("isAnimating", &UIMap::isAnimating);
766 768
     g_lua.bindClassMemberFunction<UIMap>("isKeepAspectRatioEnabled", &UIMap::isKeepAspectRatioEnabled);

+ 1
- 0
src/client/mapview.cpp View File

@@ -234,6 +234,7 @@ void MapView::draw(const Rect& rect)
234 234
             int flags = 0;
235 235
             if(m_drawNames){ flags = Otc::DrawNames; }
236 236
             if(m_drawHealthBars) { flags |= Otc::DrawBars; }
237
+            if(m_drawManaBar) { flags |= Otc::DrawManaBar; }
237 238
             creature->drawInformation(p, g_map.isCovered(pos, m_cachedFirstVisibleFloor), rect, flags);
238 239
         }
239 240
     }

+ 4
- 0
src/client/mapview.h View File

@@ -108,6 +108,9 @@ public:
108 108
     void setDrawLights(bool enable);
109 109
     bool isDrawingLights() { return m_drawLights; }
110 110
 
111
+    void setDrawManaBar(bool enable) { m_drawManaBar = enable; }
112
+    bool isDrawingManaBar() { return m_drawManaBar; }
113
+
111 114
     void move(int x, int y);
112 115
 
113 116
     void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); }
@@ -153,6 +156,7 @@ private:
153 156
     stdext::boolean<true> m_drawNames;
154 157
     stdext::boolean<true> m_drawHealthBars;
155 158
     stdext::boolean<false> m_drawLights;
159
+    stdext::boolean<true> m_drawManaBar;
156 160
     stdext::boolean<true> m_smooth;
157 161
 
158 162
     stdext::boolean<true> m_follow;

+ 2
- 0
src/client/uimap.h View File

@@ -57,6 +57,7 @@ public:
57 57
     void setDrawNames(bool enable) { m_mapView->setDrawNames(enable); }
58 58
     void setDrawHealthBars(bool enable) { m_mapView->setDrawHealthBars(enable); }
59 59
     void setDrawLights(bool enable) { m_mapView->setDrawLights(enable); }
60
+    void setDrawManaBar(bool enable) { m_mapView->setDrawManaBar(enable); }
60 61
     void setAnimated(bool enable) { m_mapView->setAnimated(enable); }
61 62
     void setKeepAspectRatio(bool enable);
62 63
     void setMapShader(const PainterShaderProgramPtr& shader, float fadeout, float fadein) { m_mapView->setShader(shader, fadein, fadeout); }
@@ -70,6 +71,7 @@ public:
70 71
     bool isDrawingNames() { return m_mapView->isDrawingNames(); }
71 72
     bool isDrawingHealthBars() { return m_mapView->isDrawingHealthBars(); }
72 73
     bool isDrawingLights() { return m_mapView->isDrawingLights(); }
74
+    bool isDrawingManaBar() { return m_mapView->isDrawingManaBar(); }
73 75
     bool isAnimating() { return m_mapView->isAnimating(); }
74 76
     bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }
75 77
     bool isLimitVisibleRangeEnabled() { return m_limitVisibleRange; }

Loading…
Cancel
Save