Index: binaries/data/mods/mod/gui/gui.rng
===================================================================
--- binaries/data/mods/mod/gui/gui.rng
+++ binaries/data/mods/mod/gui/gui.rng
@@ -242,7 +242,7 @@
-
+
@@ -252,7 +252,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
Index: binaries/data/mods/public/gui/session/minimap/MiniMap.xml
===================================================================
--- binaries/data/mods/public/gui/session/minimap/MiniMap.xml
+++ binaries/data/mods/public/gui/session/minimap/MiniMap.xml
@@ -63,8 +63,10 @@
mask="true"
flare_texture_count="16"
flare_render_size="32"
- flare_animation_speed="11"
+ flare_animation_speed="10.67"
flare_interleave="true"
flare_lifetime_seconds="6"
+ flare_start_fade_seconds="0.25"
+ flare_stop_fade_seconds="0.5"
/>
Index: source/gui/ObjectTypes/CMiniMap.h
===================================================================
--- source/gui/ObjectTypes/CMiniMap.h
+++ source/gui/ObjectTypes/CMiniMap.h
@@ -80,6 +80,8 @@
CGUISimpleSetting m_FlareInterleave;
CGUISimpleSetting m_FlareAnimationSpeed;
CGUISimpleSetting m_FlareLifetimeSeconds;
+ CGUISimpleSetting m_FlareStartFadeSeconds;
+ CGUISimpleSetting m_FlareStopFadeSeconds;
// Whether to draw a black square around and under the minimap.
CGUISimpleSetting m_Mask;
@@ -94,7 +96,8 @@
void DrawViewRect(CCanvas2D& canvas) const;
- void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double curentTime) const;
+ void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double currentTime) const;
+ void DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex, const CRect& destination, const CColor& color, float alpha) const;
void GetMouseWorldCoordinates(float& x, float& z) const;
Index: source/gui/ObjectTypes/CMiniMap.cpp
===================================================================
--- source/gui/ObjectTypes/CMiniMap.cpp
+++ source/gui/ObjectTypes/CMiniMap.cpp
@@ -36,6 +36,7 @@
#include "lib/external_libraries/libsdl.h"
#include "lib/ogl.h"
#include "lib/timer.h"
+#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/CStrInternStatic.h"
@@ -136,7 +137,9 @@
m_MapSize(0), m_MapScale(1.f), m_Mask(this, "mask", false),
m_FlareTextureCount(this, "flare_texture_count", 0), m_FlareRenderSize(this, "flare_render_size", 0),
m_FlareInterleave(this, "flare_interleave", false), m_FlareAnimationSpeed(this, "flare_animation_speed", 0.0f),
- m_FlareLifetimeSeconds(this, "flare_lifetime_seconds", 0.0f)
+ m_FlareLifetimeSeconds(this, "flare_lifetime_seconds", 0.0f),
+ m_FlareStartFadeSeconds(this, "flare_start_fade_seconds", 0.0f),
+ m_FlareStopFadeSeconds(this, "flare_stop_fade_seconds", 0.0f)
{
m_Clicking = false;
m_MouseHovering = false;
@@ -341,19 +344,36 @@
flareCenter.X - m_FlareRenderSize, flareCenter.Y - m_FlareRenderSize,
flareCenter.X + m_FlareRenderSize, flareCenter.Y + m_FlareRenderSize);
- const u32 flooredStep = floor((currentTime - flare.time) * m_FlareAnimationSpeed);
+ const double deltaTime = currentTime - flare.time;
+ const double remainingTime = m_FlareLifetimeSeconds - deltaTime;
+ const u32 flooredStep = floor(deltaTime * m_FlareAnimationSpeed);
+
+ const float startFadeAlpha = m_FlareStartFadeSeconds > 0.0f ? deltaTime / m_FlareStartFadeSeconds : 1.0f;
+ const float stopFadeAlpha = m_FlareStopFadeSeconds > 0.0f ? remainingTime / m_FlareStopFadeSeconds : 1.0f;
+ const float alpha = Clamp(std::min(
+ SmoothStep(0.0f, 1.0f, startFadeAlpha), SmoothStep(0.0f, 1.0f, stopFadeAlpha)),
+ 0.0f, 1.0f);
- CTexturePtr texture = m_FlareTextures[flooredStep % m_FlareTextures.size()];
- // TODO: Only draw inside the minimap circle.
- canvas.DrawTexture(texture, destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), flare.color, CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
+ DrawFlareFrame(canvas, flooredStep % m_FlareTextures.size(), destination, flare.color, alpha);
- // Draw a second circle if the first has reached half of the animation
+ // Draw a second circle if the first has reached half of the animation.
if (m_FlareInterleave && flooredStep >= m_FlareTextures.size() / 2)
{
- texture = m_FlareTextures[(flooredStep - m_FlareTextures.size() / 2) % m_FlareTextures.size()];
- // TODO: Only draw inside the minimap circle.
- canvas.DrawTexture(texture, destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), flare.color, CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
+ DrawFlareFrame(canvas, (flooredStep - m_FlareTextures.size() / 2) % m_FlareTextures.size(),
+ destination, flare.color, alpha);
}
+}
+
+void CMiniMap::DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex,
+ const CRect& destination, const CColor& color, float alpha) const
+{
+ // TODO: Only draw inside the minimap circle.
+ CTexturePtr texture = m_FlareTextures[frameIndex % m_FlareTextures.size()];
+ CColor finalColor = color;
+ finalColor.a *= alpha;
+ canvas.DrawTexture(texture, destination,
+ CRect(0, 0, texture->GetWidth(), texture->GetHeight()), finalColor,
+ CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
}
void CMiniMap::Draw(CCanvas2D& canvas)
Index: source/maths/MathUtil.h
===================================================================
--- source/maths/MathUtil.h
+++ source/maths/MathUtil.h
@@ -22,13 +22,13 @@
#define RADTODEG(a) ((a) * (180.0f/(float)M_PI))
#define SQR(x) ((x) * (x))
-template
+template
inline T Interpolate(const T& a, const T& b, float t)
{
return a + (b - a) * t;
}
-template
+template
inline T Clamp(T value, T min, T max)
{
if (value <= min)
@@ -36,6 +36,13 @@
else if (value >= max)
return max;
return value;
+}
+
+template
+inline T SmoothStep(T edge0, T edge1, T value)
+{
+ value = Clamp((value - edge0) / (edge1 - edge0), 0, 1);
+ return value * value * (3 - 2 * value);
}
inline float sgn(float a)