health bar improvement, drawOffset bug fix
This commit is contained in:
parent
377a249f52
commit
80211b9985
|
@ -13,6 +13,11 @@ Module
|
||||||
importFont('helvetica-14px-bold')
|
importFont('helvetica-14px-bold')
|
||||||
importFont('terminus-14px-bold')
|
importFont('terminus-14px-bold')
|
||||||
|
|
||||||
|
importFont('tibia-8px-antialised')
|
||||||
|
importFont('tibia-10px-antialised')
|
||||||
|
importFont('tibia-10px-monochrome')
|
||||||
|
importFont('tibia-12px-rounded')
|
||||||
|
|
||||||
setDefaultFont('helvetica-12px')
|
setDefaultFont('helvetica-12px')
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
@ -44,38 +44,44 @@ void Creature::draw(int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::drawName(int x, int y)
|
void Creature::drawInformation(int x, int y, bool useGray)
|
||||||
{
|
{
|
||||||
|
Color fillColor = Color(96, 96, 96);
|
||||||
|
|
||||||
|
if(!useGray) {
|
||||||
// health bar
|
// health bar
|
||||||
Color healthColor = Color::black;
|
fillColor = Color::black;
|
||||||
if(m_healthPercent > 60 && m_healthPercent <= 100) {
|
if(m_healthPercent > 60 && m_healthPercent <= 100) {
|
||||||
healthColor.setRed(0.0f);
|
fillColor.setRed(0.0f);
|
||||||
healthColor.setGreen(0.75f);
|
fillColor.setGreen(0.75f);
|
||||||
} else if(m_healthPercent > 30 && m_healthPercent <= 60) {
|
} else if(m_healthPercent > 30 && m_healthPercent <= 60) {
|
||||||
healthColor.setRed(0.75f);
|
fillColor.setRed(0.75f);
|
||||||
healthColor.setGreen(0.75f);
|
fillColor.setGreen(0.75f);
|
||||||
} else if(m_healthPercent > 10 && m_healthPercent <= 30) {
|
} else if(m_healthPercent > 10 && m_healthPercent <= 30) {
|
||||||
healthColor.setRed(0.75f);
|
fillColor.setRed(0.75f);
|
||||||
healthColor.setGreen(0.00f);
|
fillColor.setGreen(0.00f);
|
||||||
} else if(m_healthPercent > 0 && m_healthPercent <= 10) {
|
} else if(m_healthPercent > 0 && m_healthPercent <= 10) {
|
||||||
healthColor.setRed(0.25f);
|
fillColor.setRed(0.25f);
|
||||||
healthColor.setGreen(0.00f);
|
fillColor.setGreen(0.00f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect healthRect = Rect(x-(14.5), y-2, 27, 4);
|
Rect backgroundRect = Rect(x-(14.5), y-2, 27, 4);
|
||||||
|
Rect healthRect = backgroundRect.expanded(-1);
|
||||||
|
healthRect.setWidth((m_healthPercent/100.0)*25);
|
||||||
|
|
||||||
g_graphics.bindColor(Color::black);
|
g_graphics.bindColor(Color::black);
|
||||||
g_graphics.drawBoundingRect(healthRect);
|
g_graphics.drawFilledRect(backgroundRect);
|
||||||
|
|
||||||
g_graphics.bindColor(healthColor);
|
g_graphics.bindColor(fillColor);
|
||||||
g_graphics.drawFilledRect(healthRect.expanded(-1));
|
g_graphics.drawFilledRect(healthRect);
|
||||||
|
|
||||||
// restore white color
|
// restore white color
|
||||||
g_graphics.bindColor(Color::white);
|
g_graphics.bindColor(Color::white);
|
||||||
|
|
||||||
// name
|
// name
|
||||||
FontPtr font = g_fonts.getDefaultFont();
|
FontPtr font = g_fonts.getFont("tibia-12px-rounded");
|
||||||
font->renderText(m_name, Rect(x-50, y-16, 100, 16), AlignTopCenter);
|
font->renderText(m_name, Rect(x-50, y-16, 100, 16), AlignTopCenter, fillColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ThingAttributes& Creature::getAttributes()
|
const ThingAttributes& Creature::getAttributes()
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
virtual ~Creature() { }
|
virtual ~Creature() { }
|
||||||
|
|
||||||
virtual void draw(int x, int y);
|
virtual void draw(int x, int y);
|
||||||
void drawName(int x, int y);
|
void drawInformation(int x, int y, bool useGray);
|
||||||
|
|
||||||
void setName(const std::string& name) { m_name = name; }
|
void setName(const std::string& name) { m_name = name; }
|
||||||
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; }
|
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; }
|
||||||
|
|
|
@ -18,10 +18,11 @@ void Map::draw(const Rect& rect)
|
||||||
|
|
||||||
// player is above 7
|
// player is above 7
|
||||||
|
|
||||||
|
int drawFloorStop = 0;
|
||||||
if(playerPos.z <= 7) {
|
if(playerPos.z <= 7) {
|
||||||
|
|
||||||
// player pos it 8-6. check if we can draw upper floors.
|
// player pos it 8-6. check if we can draw upper floors.
|
||||||
int drawFloorStop = 0;
|
|
||||||
|
|
||||||
// if there is a window on north, east, south or west
|
// if there is a window on north, east, south or west
|
||||||
//Position direction[4] = {Position(0, -1, 0), Position(1, 0, 0), Position(0, 1, 0), Position(-1, 0, 0)};
|
//Position direction[4] = {Position(0, -1, 0), Position(1, 0, 0), Position(0, 1, 0), Position(-1, 0, 0)};
|
||||||
|
@ -56,7 +57,7 @@ void Map::draw(const Rect& rect)
|
||||||
for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) {
|
for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) {
|
||||||
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz);
|
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz);
|
||||||
if(const TilePtr& tile = m_tiles[itemPos])
|
if(const TilePtr& tile = m_tiles[itemPos])
|
||||||
tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32, 0);
|
tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,8 +80,21 @@ void Map::draw(const Rect& rect)
|
||||||
for(int ix = -7; ix <= 7; ++ix) {
|
for(int ix = -7; ix <= 7; ++ix) {
|
||||||
for(int iy = -5; iy <= 5; ++iy) {
|
for(int iy = -5; iy <= 5; ++iy) {
|
||||||
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, playerPos.z);
|
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, playerPos.z);
|
||||||
if(const TilePtr& tile = m_tiles[itemPos])
|
if(const TilePtr& tile = m_tiles[itemPos]) {
|
||||||
tile->draw(((ix + 7)*32+5)*horizontalStretchFactor, ((iy + 5)*32 - 8)*verticalStretchFactor, 1);
|
std::deque<ThingPtr> creatures = tile->getCreatures();
|
||||||
|
for(auto it = creatures.rbegin(), end = creatures.rend(); it != end; ++it) {
|
||||||
|
const ThingPtr& thing = *it;
|
||||||
|
const CreaturePtr& creature = thing->asCreature();
|
||||||
|
|
||||||
|
int x = (ix + 7)*32 + 5 - tile->getDrawNextOffset();
|
||||||
|
int y = (iy + 5)*32 - 8 - tile->getDrawNextOffset();
|
||||||
|
|
||||||
|
// TODO: create isCovered function.
|
||||||
|
bool useGray = (drawFloorStop != playerPos.z-1);
|
||||||
|
|
||||||
|
creature->drawInformation(x*horizontalStretchFactor, y*verticalStretchFactor, useGray);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,10 @@ Tile::Tile()
|
||||||
m_drawNextOffset = 0;
|
m_drawNextOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tile::draw(int x, int y, int step)
|
void Tile::draw(int x, int y)
|
||||||
{
|
{
|
||||||
// STEP 0 = draw map
|
|
||||||
// STEP 1 = draw creature names
|
|
||||||
// STEP 2 = draw speak
|
|
||||||
|
|
||||||
FontPtr font = g_fonts.getDefaultFont();
|
FontPtr font = g_fonts.getDefaultFont();
|
||||||
|
|
||||||
if(step == 0) {
|
|
||||||
m_drawNextOffset = 0;
|
m_drawNextOffset = 0;
|
||||||
|
|
||||||
if(m_ground)
|
if(m_ground)
|
||||||
|
@ -66,9 +61,8 @@ void Tile::draw(int x, int y, int step)
|
||||||
const ThingAttributes& thingAttributes = thing->getAttributes();
|
const ThingAttributes& thingAttributes = thing->getAttributes();
|
||||||
|
|
||||||
if(thingAttributes.alwaysOnTopOrder == 3) {
|
if(thingAttributes.alwaysOnTopOrder == 3) {
|
||||||
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
|
thing->draw(x, y);
|
||||||
//font->renderText("T3", Rect(x + 5, y+5, 100, 100));
|
//font->renderText("T3", Rect(x + 5, y+5, 100, 100));
|
||||||
m_drawNextOffset += thingAttributes.drawNextOffset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,16 +71,6 @@ void Tile::draw(int x, int y, int step)
|
||||||
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
|
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(step == 1) {
|
|
||||||
for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) {
|
|
||||||
const ThingPtr& thing = *it;
|
|
||||||
const CreaturePtr& creature = thing->asCreature();
|
|
||||||
creature->drawName(x - m_drawNextOffset, y - m_drawNextOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tile::addThing(ThingPtr thing, uint8 stackpos)
|
void Tile::addThing(ThingPtr thing, uint8 stackpos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,17 +4,12 @@
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
#include <framework/luascript/luaobject.h>
|
#include <framework/luascript/luaobject.h>
|
||||||
|
|
||||||
enum RenderStep
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Tile : public LuaObject
|
class Tile : public LuaObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tile();
|
Tile();
|
||||||
|
|
||||||
void draw(int x, int y, int step);
|
void draw(int x, int y);
|
||||||
|
|
||||||
void addThing(ThingPtr thing, uint8 stackpos);
|
void addThing(ThingPtr thing, uint8 stackpos);
|
||||||
ThingPtr getThing(uint8 stackpos);
|
ThingPtr getThing(uint8 stackpos);
|
||||||
|
@ -27,6 +22,9 @@ public:
|
||||||
|
|
||||||
int getStackSize();
|
int getStackSize();
|
||||||
|
|
||||||
|
std::deque<ThingPtr> getCreatures() { return m_creatures; }
|
||||||
|
int getDrawNextOffset() { return m_drawNextOffset; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ThingPtr m_ground;
|
ThingPtr m_ground;
|
||||||
std::deque<ThingPtr> m_itemsBottom;
|
std::deque<ThingPtr> m_itemsBottom;
|
||||||
|
|
Loading…
Reference in New Issue