changes in creature drawing for battle list

This commit is contained in:
Eduardo Bart 2012-02-08 03:13:52 -02:00
parent a24fe38174
commit 9bff1aa6ea
3 changed files with 43 additions and 20 deletions

View File

@ -36,6 +36,7 @@
#include <framework/graphics/paintershaderprogram.h> #include <framework/graphics/paintershaderprogram.h>
#include <framework/graphics/paintershadersources.h> #include <framework/graphics/paintershadersources.h>
#include <framework/graphics/texturemanager.h> #include <framework/graphics/texturemanager.h>
#include <framework/graphics/framebuffer.h>
#include "spritemanager.h" #include "spritemanager.h"
Creature::Creature() : Thing() Creature::Creature() : Thing()
@ -78,6 +79,12 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
g_painter.drawBoundingRect(Rect(dest + (animationOffset - getDisplacement() + 1)*scaleFactor, Size(Otc::TILE_PIXELS, Otc::TILE_PIXELS)*scaleFactor), std::max((int)(2*scaleFactor), 1)); g_painter.drawBoundingRect(Rect(dest + (animationOffset - getDisplacement() + 1)*scaleFactor, Size(Otc::TILE_PIXELS, Otc::TILE_PIXELS)*scaleFactor), std::max((int)(2*scaleFactor), 1));
} }
internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction);
}
void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction)
{
g_painter.setColor(Fw::white); g_painter.setColor(Fw::white);
if(!outfitProgram) { if(!outfitProgram) {
outfitProgram = PainterShaderProgramPtr(new PainterShaderProgram); outfitProgram = PainterShaderProgramPtr(new PainterShaderProgram);
@ -95,19 +102,20 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
// outfit is a real creature // outfit is a real creature
if(m_outfit.getCategory() == ThingsType::Creature) { if(m_outfit.getCategory() == ThingsType::Creature) {
int animationPhase = animate ? m_walkAnimationPhase : 0; int animationPhase = animateWalk ? m_walkAnimationPhase : 0;
if(isAnimateAlways()) {
if(isAnimateAlways() && animateIdle) {
int ticksPerFrame = 1000 / getAnimationPhases(); int ticksPerFrame = 1000 / getAnimationPhases();
animationPhase = (g_clock.ticks() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame; animationPhase = (g_clock.ticks() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame;
} }
// xPattern => creature direction // xPattern => creature direction
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) if(direction == Otc::NorthEast || direction == Otc::SouthEast)
xPattern = Otc::East; xPattern = Otc::East;
else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) else if(direction == Otc::NorthWest || direction == Otc::SouthWest)
xPattern = Otc::West; xPattern = Otc::West;
else else
xPattern = m_direction; xPattern = direction;
// yPattern => creature addon // yPattern => creature addon
for(yPattern = 0; yPattern < getNumPatternsY(); yPattern++) { for(yPattern = 0; yPattern < getNumPatternsY(); yPattern++) {
@ -129,12 +137,12 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
// setup texture outfit mask // setup texture outfit mask
TexturePtr maskTex; TexturePtr maskTex;
if(getLayers() > 1) { if(getLayers() > 1) {
int maskId = getSpriteId(w, h, 1, xPattern, yPattern, zPattern, m_walkAnimationPhase); int maskId = getSpriteId(w, h, 1, xPattern, yPattern, zPattern, animationPhase);
maskTex = g_sprites.getSpriteTexture(maskId); maskTex = g_sprites.getSpriteTexture(maskId);
} }
outfitProgram->setUniformTexture(MASK_TEXTURE_UNIFORM, maskTex, 1); outfitProgram->setUniformTexture(MASK_TEXTURE_UNIFORM, maskTex, 1);
internalDraw(dest + (animationOffset - Point(w,h)*Otc::TILE_PIXELS)*scaleFactor, internalDraw(dest + (-Point(w,h)*Otc::TILE_PIXELS)*scaleFactor,
scaleFactor, w, h, xPattern, yPattern, zPattern, 0, animationPhase); scaleFactor, w, h, xPattern, yPattern, zPattern, 0, animationPhase);
} }
} }
@ -155,7 +163,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
} }
if(animationPhases > 1) { if(animationPhases > 1) {
if(animate) if(animateIdle)
animationPhase = (g_clock.ticks() % (animateTicks * animationPhases)) / animateTicks; animationPhase = (g_clock.ticks() % (animateTicks * animationPhases)) / animateTicks;
else else
animationPhase = animationPhases-1; animationPhase = animationPhases-1;
@ -164,7 +172,30 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
if(m_outfit.getCategory() == ThingsType::Effect) if(m_outfit.getCategory() == ThingsType::Effect)
animationPhase = std::min(animationPhase+1, getAnimationPhases()); animationPhase = std::min(animationPhase+1, getAnimationPhases());
internalDraw(dest + animationOffset*scaleFactor, scaleFactor, 0, 0, 0, animationPhase); internalDraw(dest, scaleFactor, 0, 0, 0, animationPhase);
}
}
void Creature::drawOutfit(const Rect& destRect, bool resize)
{
static FrameBufferPtr outfitBuffer;
if(!outfitBuffer)
outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)));
outfitBuffer->bind();
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
outfitBuffer->release();
if(resize) {
Rect srcRect;
srcRect.resize(getExactSize(), getExactSize());
srcRect.moveBottomRight(Point(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS));
outfitBuffer->draw(destRect, srcRect);
} else {
Rect dest = destRect;
dest.expandTop(Otc::TILE_PIXELS);
dest.expandLeft(Otc::TILE_PIXELS);
outfitBuffer->draw(dest);
} }
} }

View File

@ -41,6 +41,8 @@ public:
virtual ~Creature() { } virtual ~Creature() { }
virtual void draw(const Point& dest, float scaleFactor, bool animate); virtual void draw(const Point& dest, float scaleFactor, bool animate);
void internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction);
void drawOutfit(const Rect& destRect, bool resize);
void drawInformation(const Point& point, bool useGray, const Rect& parentRect); void drawInformation(const Point& point, bool useGray, const Rect& parentRect);
void setId(uint32 id) { m_id = id; } void setId(uint32 id) { m_id = id; }

View File

@ -28,20 +28,10 @@ void UICreature::draw()
{ {
drawSelf(); drawSelf();
//TODO: cache with framebuffer
if(m_creature) { if(m_creature) {
g_painter.setColor(Fw::white); g_painter.setColor(Fw::white);
Rect drawRect = getChildrenRect(); Rect drawRect = getChildrenRect();
m_creature->drawOutfit(drawRect, !m_fixedCreatureSize);
float scaleFactor = drawRect.width();
if(m_fixedCreatureSize)
scaleFactor /= Otc::TILE_PIXELS;
else
scaleFactor /= m_creature->getExactSize();
Point dest = drawRect.bottomRight() - (Point(1,1)*Otc::TILE_PIXELS - m_creature->getDisplacement()) * scaleFactor;
m_creature->draw(dest, scaleFactor, false);
} }
drawChildren(); drawChildren();