1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 17:53:47 +00:00

Minimap icon overhaul:

- Allow specifying custom minimap icons for nodes and entities
- Allow overriding minimap textures
- This removes various hacks in MiniMapRender and related
- Allow access to the MiniMapRender object via Lua
  (don't delete it or the game will crash)

Little extra: Added destructors for some entity classes
This commit is contained in:
fgenesis 2016-03-21 03:40:56 +01:00
parent 9e0d59460a
commit ce7239056b
12 changed files with 340 additions and 111 deletions

View file

@ -32,6 +32,10 @@ CollideEntity::CollideEntity() : Entity()
this->updateCull = 4000;
}
CollideEntity::~CollideEntity()
{
}
void CollideEntity::entityDied(Entity *e)
{
Entity::entityDied(e);

View file

@ -27,6 +27,7 @@ class CollideEntity : public Entity
{
public:
CollideEntity();
virtual ~CollideEntity();
float bounceAmount;
float weight;
void updateMovement(float dt);

View file

@ -286,11 +286,17 @@ Entity::Entity()
setDamageTarget(DT_AVATAR_SEED, false);
stopSoundsOnDeath = false;
minimapIcon = 0;
//debugLog("End Entity::Entity()");
}
Entity::~Entity()
{
delete minimapIcon;
}
void Entity::setDeathScene(bool v)
{
deathScene = v;
@ -1238,6 +1244,9 @@ void Entity::update(float dt)
vel = backupVel;
updateSoundPosition();
if(minimapIcon)
minimapIcon->update(dt);
}
void Entity::postUpdate(float dt)
@ -2413,6 +2422,10 @@ void Entity::onEnterState(int action)
hair->fadeAlphaWithLife = 1;
hair = 0;
}
if(minimapIcon)
{
minimapIcon->alpha.interpolateTo(0, 0.1f);
}
}
break;
@ -3149,3 +3162,10 @@ void Entity::updateSoundPosition()
{
SoundHolder::updateSoundPosition(position.x + offset.x, position.y + offset.y);
}
MinimapIcon *Entity::ensureMinimapIcon()
{
if(!minimapIcon)
minimapIcon = new MinimapIcon;
return minimapIcon;
}

View file

@ -35,6 +35,7 @@ using namespace tinyxml2;
class ManaBall;
class Path;
struct MinimapIcon;
struct BoneLock
{
@ -202,6 +203,7 @@ class Entity : public Quad, public StateMachine, public SoundHolder
{
public:
Entity();
virtual ~Entity();
virtual void init(){}
virtual void postInit(){}
@ -502,6 +504,9 @@ public:
Vector getPushVec() const { return pushVec; }
float getPushDamage() const { return pushDamage; }
MinimapIcon *minimapIcon;
MinimapIcon *ensureMinimapIcon();
protected:
bool calledEntityDied;
Path *waterBubble;

View file

@ -135,6 +135,20 @@ enum EditTypes
};
#endif
// impl is in Minimap.cpp
struct MinimapIcon
{
MinimapIcon();
bool setTexture(std::string);
void update(float dt);
CountedPtr<Texture> tex;
InterpolatedVector color, alpha, size;
float throbMult;
bool scaleWithDistance;
static const Vector defaultSize;
};
class ManaBall : public Quad
{
public:

View file

@ -63,8 +63,17 @@ protected:
float lightLevel;
void onUpdate(float dt);
void onRender();
void renderIcon(MinimapIcon *ico, const Vector& pos);
InterpolatedVector lerp;
public:
static bool setWaterBitTex(const std::string& name);
static bool setTopTex(const std::string& name);
static bool setBottomTex(const std::string& name);
static bool setAvatarTex(const std::string& name);
static bool setHealthBarTex(const std::string& name);
static bool setMaxHealthMarkerTex(const std::string& name);
};
class WorldMapRender : public RenderObject, public ActionMapper

View file

@ -47,8 +47,6 @@ namespace MiniMapRenderSpace
const float iconBaseSize = 14;
// Additional radius added (or subtracted) by "throb" effect
const float iconThrobSize = 6;
// Size of cooking icon (fixed)
const float iconCookSize = 16;
// Maximum offset of warp/save/cooking icons from center of minimap
const float iconMaxOffset = miniMapRadius * miniMapScale * (7.0f/8.0f);
// Distance at which the icon decreases to minimum size
@ -66,11 +64,9 @@ namespace MiniMapRenderSpace
const int healthMarkerSize = 20;
CountedPtr<Texture> texCook = 0;
CountedPtr<Texture> texWaterBit = 0;
CountedPtr<Texture> texMinimapBtm = 0;
CountedPtr<Texture> texMinimapTop = 0;
CountedPtr<Texture> texRipple = 0;
CountedPtr<Texture> texNaija = 0;
CountedPtr<Texture> texHealthBar = 0;
CountedPtr<Texture> texMarker = 0;
@ -91,6 +87,69 @@ namespace MiniMapRenderSpace
using namespace MiniMapRenderSpace;
const Vector MinimapIcon::defaultSize(iconBaseSize, iconBaseSize);
MinimapIcon::MinimapIcon()
: color(1,1,1), alpha(1), size(defaultSize), throbMult(iconThrobSize), scaleWithDistance(true)
{
}
void MinimapIcon::update(float dt)
{
color.update(dt);
alpha.update(dt);
size.update(dt);
}
// pretty much copied from RenderObject::setTexture()
static bool _setTex(CountedPtr<Texture> &tex, std::string name)
{
stringToLowerUserData(name);
if (name.empty())
{
tex = NULL;
return false;
}
if(tex && tex->getLoadResult() == TEX_SUCCESS && name == tex->name)
return true; // no texture change
tex = core->addTexture(name);
return tex && tex->getLoadResult() == TEX_SUCCESS;
}
bool MinimapIcon::setTexture(std::string name)
{
return _setTex(tex, name);
}
bool MiniMapRender::setWaterBitTex(const std::string& name)
{
return _setTex(texWaterBit, name);
}
bool MiniMapRender::setTopTex(const std::string& name)
{
return _setTex(texMinimapTop, name);
}
bool MiniMapRender::setBottomTex(const std::string& name)
{
return _setTex(texMinimapBtm, name);
}
bool MiniMapRender::setAvatarTex(const std::string& name)
{
return _setTex(texNaija, name);
}
bool MiniMapRender::setHealthBarTex(const std::string& name)
{
return _setTex(texHealthBar, name);
}
bool MiniMapRender::setMaxHealthMarkerTex(const std::string& name)
{
return _setTex(texMarker, name);
}
MiniMapRender::MiniMapRender() : RenderObject()
{
toggleOn = 1;
@ -108,13 +167,11 @@ MiniMapRender::MiniMapRender() : RenderObject()
cull = false;
lightLevel = 1.0;
texCook = core->addTexture("GUI/ICON-FOOD");
texWaterBit = core->addTexture("GUI/MINIMAP/WATERBIT");
texMinimapBtm = core->addTexture("GUI/MINIMAP/BTM");
texMinimapTop = core->addTexture("GUI/MINIMAP/TOP");
texRipple = core->addTexture("GUI/MINIMAP/RIPPLE");
texNaija = core->addTexture("GEMS/NAIJA-TOKEN");
texHealthBar = core->addTexture("PARTICLES/glow-masked");
texWaterBit = core->addTexture("gui/minimap/waterbit");
texMinimapBtm = core->addTexture("gui/minimap/btm");
texMinimapTop = core->addTexture("gui/minimap/top");
texNaija = core->addTexture("gems/naija-token");
texHealthBar = core->addTexture("particles/glow-masked");
texMarker = core->addTexture("gui/minimap/marker");
buttons.clear();
@ -164,11 +221,9 @@ void MiniMapRender::destroy()
{
RenderObject::destroy();
UNREFTEX(texCook);
UNREFTEX(texWaterBit);
UNREFTEX(texMinimapBtm);
UNREFTEX(texMinimapTop);
UNREFTEX(texRipple);
UNREFTEX(texNaija);
UNREFTEX(texHealthBar);
UNREFTEX(texMarker);
@ -541,14 +596,10 @@ void MiniMapRender::onRender()
if (!radarHide)
{
const float factor = sinf(game->getTimer()*PI);
const float iconSize = iconBaseSize + factor*iconThrobSize;
texRipple->apply();
// FIXME: use getFirstPathOfType?
for (int i = 0; i < dsq->game->getNumPaths(); i++)
{
Path *p = dsq->game->getPath(i);
if (!p->nodes.empty() && (p->pathType==PATH_COOK || p->pathType==PATH_SAVEPOINT || p->pathType==PATH_WARP))
if (!p->nodes.empty() && p->minimapIcon)
{
bool render = true;
Path *p2 = dsq->game->getNearestPath(p->nodes[0].position, PATH_RADARHIDE);
@ -562,95 +613,18 @@ void MiniMapRender::onRender()
if (render)
{
Vector pt(p->nodes[0].position);
Vector d = pt - dsq->game->avatar->position;
const float len = d.getLength2D();
float iconScale;
if (len < iconMaxOffset)
{
iconScale = 1;
}
else
{
d *= iconMaxOffset / len;
float k;
if (len < iconMaxDistance)
k = ((iconMaxDistance - len) / (iconMaxDistance - iconMaxOffset));
else
k = 0;
iconScale = iconMinScale + k*(1-iconMinScale);
}
const Vector miniMapPos = Vector(d)*Vector(1.0f/miniMapScale, 1.0f/miniMapScale);
switch(p->pathType)
{
case PATH_COOK:
{
glColor4f(1, 1, 1, 1);
glTranslatef(miniMapPos.x, miniMapPos.y, 0);
const float sz = iconCookSize * iconScale;
texCook->apply();
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(-sz, sz);
glTexCoord2f(1, 1);
glVertex2f(sz, sz);
glTexCoord2f(1, 0);
glVertex2f(sz, -sz);
glTexCoord2f(0, 0);
glVertex2f(-sz, -sz);
glEnd();
glTranslatef(-miniMapPos.x, -miniMapPos.y, 0);
texRipple->apply();
render = false; // Skip common rendering code
}
break;
case PATH_SAVEPOINT:
{
glColor4f(1.0, 0, 0, alphaValue*0.75f);
}
break;
case PATH_WARP:
{
if (p->naijaHome)
{
glColor4f(1.0, 0.9, 0.2, alphaValue*0.75f);
}
else
{
glColor4f(1.0, 1.0, 1.0, alphaValue*0.75f);
renderIcon(p->minimapIcon, p->nodes[0].position);
}
}
break;
}
if (render)
FOR_ENTITIES(i)
{
glTranslatef(miniMapPos.x, miniMapPos.y, 0);
const float sz = iconSize * iconScale;
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(-sz, sz);
glTexCoord2f(1, 1);
glVertex2f(sz, sz);
glTexCoord2f(1, 0);
glVertex2f(sz, -sz);
glTexCoord2f(0, 0);
glVertex2f(-sz, -sz);
glEnd();
glTranslatef(-miniMapPos.x, -miniMapPos.y, 0);
Entity *e = *i;
if(e->minimapIcon)
renderIcon(e->minimapIcon, e->position);
}
}
}
}
texRipple->unbind();
}
glColor4f(1,1,1, alphaValue);
@ -789,3 +763,48 @@ void MiniMapRender::onRender()
#endif
}
void MiniMapRender::renderIcon(MinimapIcon *ico, const Vector& pos)
{
if(!ico->tex)
return;
Vector d = pos - dsq->game->avatar->position;
const float len = d.getLength2D();
float iconScale;
if (len < iconMaxOffset || !ico->scaleWithDistance)
{
iconScale = 1;
}
else
{
d *= iconMaxOffset / len;
float k;
if (len < iconMaxDistance)
k = ((iconMaxDistance - len) / (iconMaxDistance - iconMaxOffset));
else
k = 0;
iconScale = iconMinScale + k*(1-iconMinScale);
}
ico->tex->apply();
const Vector c = ico->color;
const float a = ico->alpha.x * this->alpha.x;
glColor4f(c.x, c.y, c.z, a);
const Vector miniMapPos = Vector(d)*Vector(1.0f/miniMapScale, 1.0f/miniMapScale);
const float factor = sinf(game->getTimer()*PI);
const float addSize = factor * ico->throbMult;
const Vector sz = (ico->size + Vector(addSize, addSize)) * iconScale;
glPushMatrix();
glTranslatef(miniMapPos.x, miniMapPos.y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(-sz.x, sz.y);
glTexCoord2f(1, 1);
glVertex2f(sz.x, sz.y);
glTexCoord2f(1, 0);
glVertex2f(sz.x, -sz.y);
glTexCoord2f(0, 0);
glVertex2f(-sz.x, -sz.y);
glEnd();
glPopMatrix();
}

View file

@ -32,7 +32,6 @@ Path::Path()
pathShape = PATHSHAPE_RECT;
toFlip = -1;
replayVox = 0;
naijaHome = false;
addEmitter = false;
emitter = 0;
active = true;
@ -55,6 +54,7 @@ Path::Path()
spiritFreeze = true;
pauseFreeze = true;
activationRange = 800;
minimapIcon = 0;
}
void Path::clampPosition(Vector *pos, float radius)
@ -207,6 +207,9 @@ int Path::getDown()
void Path::destroy()
{
delete minimapIcon;
minimapIcon = NULL;
if (emitter)
{
emitter->safeKill();
@ -346,6 +349,11 @@ void Path::refreshScript()
else if (label == "cook")
{
pathType = PATH_COOK;
ensureMinimapIcon();
minimapIcon->setTexture("gui/icon-food");
minimapIcon->size = Vector(16, 16);
minimapIcon->scaleWithDistance = false;
minimapIcon->throbMult = 0.0f;
}
else if (label == "zoom")
{
@ -371,6 +379,10 @@ void Path::refreshScript()
else if (label == "savepoint")
{
pathType = PATH_SAVEPOINT;
ensureMinimapIcon();
minimapIcon->setTexture("gui/minimap/ripple");
minimapIcon->color = Vector(1, 0, 0);
minimapIcon->alpha = 0.75f;
}
else if (label == "steam")
{
@ -405,6 +417,10 @@ void Path::refreshScript()
else if (type == "out")
localWarpType = LOCALWARP_OUT;
pathType = PATH_WARP;
ensureMinimapIcon();
minimapIcon->setTexture("gui/minimap/ripple");
minimapIcon->alpha = 0.75f;
}
else if (label == "vox" || label == "voice")
{
@ -422,10 +438,12 @@ void Path::refreshScript()
// warpType is just char, which does not automatically skip spaces like strings would
warpType = warpTypeStr.length() ? warpTypeStr[0] : 0;
ensureMinimapIcon();
minimapIcon->setTexture("gui/minimap/ripple");
minimapIcon->alpha = 0.75f;
if (warpMap.find("vedha")!=std::string::npos)
{
naijaHome = true;
}
minimapIcon->color = Vector(1.0f, 0.9f, 0.2f);
pathType = PATH_WARP;
}
else if (label == "se")
@ -489,6 +507,9 @@ void Path::init()
void Path::update(float dt)
{
if(minimapIcon)
minimapIcon->update(dt);
if (!(pauseFreeze && dsq->game->isPaused()) && !(spiritFreeze && dsq->game->isWorldPaused()))
{
if (addEmitter && emitter)
@ -731,3 +752,10 @@ void Path::luaDebugMsg(const std::string &func, const std::string &msg)
{
debugLog("luaScriptError: Path [" + name + "]: " + func + " : " + msg);
}
MinimapIcon *Path::ensureMinimapIcon()
{
if(!minimapIcon)
minimapIcon = new MinimapIcon;
return minimapIcon;
}

View file

@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#undef PATH_MAX // May be set by a system header.
struct MinimapIcon;
class PathNode
{
public:
@ -107,11 +109,14 @@ public:
void activate(Entity *e=0);
void refreshScript();
MinimapIcon *ensureMinimapIcon();
Script *script;
bool updateFunction;
bool activateFunction;
bool cursorActivation;
int replayVox;
MinimapIcon *minimapIcon;
std::string warpMap, warpNode, vox, spawnEnemyName, content;
float amount, time;
@ -130,7 +135,6 @@ public:
LocalWarpType localWarpType;
bool naijaHome;
bool catchActions;
bool songFunc, songNoteFunc, songNoteDoneFunc;
bool neverSpawned;

View file

@ -9403,6 +9403,108 @@ luaFunc(getPerformanceFreq)
#endif
}
// ---------- Minimap related ------------------
luaFunc(getMinimapRender)
{
luaReturnPtr(dsq->game->miniMapRender);
}
luaFunc(minimap_setWaterBitTex)
{
luaReturnBool(MiniMapRender::setWaterBitTex(getString(L)));
}
luaFunc(minimap_setTopTex)
{
luaReturnBool(MiniMapRender::setTopTex(getString(L)));
}
luaFunc(minimap_setBottomTex)
{
luaReturnBool(MiniMapRender::setBottomTex(getString(L)));
}
luaFunc(minimap_setAvatarIconTex)
{
luaReturnBool(MiniMapRender::setAvatarTex(getString(L)));
}
luaFunc(minimap_setHealthBarTex)
{
luaReturnBool(MiniMapRender::setAvatarTex(getString(L)));
}
luaFunc(minimap_setMaxHealthMarkerTex)
{
luaReturnBool(MiniMapRender::setMaxHealthMarkerTex(getString(L)));
}
template<typename T>
int mmicon_delete(lua_State *L, T *obj)
{
delete obj->minimapIcon;
obj->minimapIcon = NULL;
luaReturnNil();
}
template<typename T>
int mmicon_tex(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
MinimapIcon *ico = obj->ensureMinimapIcon();
bool good = ico->setTexture(getString(L, 2));
luaReturnBool(good);
}
template<typename T>
int mmicon_size(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
luaReturnNum(interpolateVec2(L, obj->ensureMinimapIcon()->size, 2));
}
template<typename T>
int mmicon_color(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
luaReturnNum(interpolateVec3(L, obj->ensureMinimapIcon()->color, 2));
}
template<typename T>
int mmicon_alpha(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
luaReturnNum(interpolateVec1(L, obj->ensureMinimapIcon()->alpha, 2));
}
template<typename T>
int mmicon_scaleWithDistance(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
obj->ensureMinimapIcon()->scaleWithDistance = getBool(L, 2);
luaReturnNil();
}
template<typename T>
int mmicon_throb(lua_State *L, T *obj)
{
if(!obj)
luaReturnNil();
obj->ensureMinimapIcon()->throbMult = lua_tonumber(L, 2);
luaReturnNil();
}
luaFunc(entity_mmicon_delete) { return mmicon_delete(L, entity(L)); }
luaFunc(entity_mmicon_tex) { return mmicon_tex(L, entity(L)); }
luaFunc(entity_mmicon_size) { return mmicon_size(L, entity(L)); }
luaFunc(entity_mmicon_color) { return mmicon_color(L, entity(L)); }
luaFunc(entity_mmicon_alpha) { return mmicon_alpha(L, entity(L)); }
luaFunc(entity_mmicon_scaleWithDistance) { return mmicon_scaleWithDistance(L, entity(L)); }
luaFunc(entity_mmicon_throb) { return mmicon_throb(L, entity(L)); }
luaFunc(node_mmicon_delete) { return mmicon_delete(L, path(L)); }
luaFunc(node_mmicon_tex) { return mmicon_tex(L, path(L)); }
luaFunc(node_mmicon_size) { return mmicon_size(L, path(L)); }
luaFunc(node_mmicon_color) { return mmicon_color(L, path(L)); }
luaFunc(node_mmicon_alpha) { return mmicon_alpha(L, path(L)); }
luaFunc(node_mmicon_scaleWithDistance) { return mmicon_scaleWithDistance(L, path(L)); }
luaFunc(node_mmicon_throb) { return mmicon_throb(L, path(L)); }
//--------------------------------------------------------------------------------------------
#define luaRegister(func) {#func, l_##func}
@ -10432,7 +10534,26 @@ static const struct {
luaRegister(getPerformanceCounter),
luaRegister(getPerformanceFreq),
luaRegister(getMinimapRender),
luaRegister(minimap_setWaterBitTex),
luaRegister(minimap_setTopTex),
luaRegister(minimap_setBottomTex),
luaRegister(minimap_setAvatarIconTex),
luaRegister(minimap_setHealthBarTex),
luaRegister(entity_mmicon_delete),
luaRegister(entity_mmicon_tex),
luaRegister(entity_mmicon_size),
luaRegister(entity_mmicon_color),
luaRegister(entity_mmicon_alpha),
luaRegister(entity_mmicon_scaleWithDistance),
luaRegister(entity_mmicon_throb),
luaRegister(node_mmicon_delete),
luaRegister(node_mmicon_tex),
luaRegister(node_mmicon_size),
luaRegister(node_mmicon_color),
luaRegister(node_mmicon_alpha),
luaRegister(node_mmicon_scaleWithDistance),
luaRegister(node_mmicon_throb),
#undef MK_FUNC
#undef MK_ALIAS

View file

@ -80,6 +80,10 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
}
}
ScriptedEntity::~ScriptedEntity()
{
}
void ScriptedEntity::setAutoSkeletalUpdate(bool v)
{
skeletalSprite.ignoreUpdate = !v;
@ -814,4 +818,3 @@ void ScriptedEntity::deathNotify(RenderObject *r)
}
CollideEntity::deathNotify(r);
}

View file

@ -30,6 +30,7 @@ class ScriptedEntity : public CollideEntity, public Segmented
{
public:
ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY);
virtual ~ScriptedEntity();
void init();
void postInit();
void destroy();