walk changes, nothing special

This commit is contained in:
Henrique 2011-11-06 02:12:13 -02:00
parent 4208e40c76
commit 7db6b8b5e6
3 changed files with 19 additions and 26 deletions

View File

@ -96,14 +96,7 @@ void UIWindow::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
UIWidgetPtr parent = getParent(); UIWidgetPtr parent = getParent();
if(parent) { if(parent) {
Rect parentRect = parent->getRect(); Rect parentRect = parent->getRect();
if(boundRect.left() < parentRect.left()) boundRect.bound(parentRect);
boundRect.moveLeft(parentRect.left());
if(boundRect.top() < parentRect.top())
boundRect.moveTop(parentRect.top());
if(boundRect.bottom() > parentRect.bottom())
boundRect.moveBottom(parentRect.bottom());
if(boundRect.right() > parentRect.right())
boundRect.moveRight(parentRect.right());
} }
if(boundRect != newRect) if(boundRect != newRect)

View File

@ -251,6 +251,20 @@ public:
return tmp; return tmp;
} }
void bound(const TRect<T> &r) {
if(isNull() || r.isNull())
return;
if(left() < r.left())
moveLeft(r.left());
if(top() < r.top())
moveTop(r.top());
if(bottom() > r.bottom())
moveBottom(r.bottom());
if(right() > r.right())
moveRight(r.right());
}
TRect<T>& operator=(const TRect<T>& other) { x1 = other.x1; y1 = other.y1; x2 = other.x2; y2 = other.y2; return *this; } TRect<T>& operator=(const TRect<T>& other) { x1 = other.x1; y1 = other.y1; x2 = other.x2; y2 = other.y2; return *this; }
bool operator==(const TRect<T>& other) const { return (x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2); } bool operator==(const TRect<T>& other) const { return (x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2); }
bool operator!=(const TRect<T>& other) const { return (x1 != other.x1 || y1 != other.y1 || x2 != other.x2 || y2 != other.y2); } bool operator!=(const TRect<T>& other) const { return (x1 != other.x1 || y1 != other.y1 || x2 != other.x2 || y2 != other.y2); }

View File

@ -100,25 +100,11 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect)
// calculate main rects // calculate main rects
Rect backgroundRect = Rect(x-(13.5), y, 27, 4); Rect backgroundRect = Rect(x-(13.5), y, 27, 4);
if(backgroundRect.left() < rect.left()) backgroundRect.bound(rect);
backgroundRect.moveLeft(rect.left());
if(backgroundRect.top() < rect.top())
backgroundRect.moveTop(rect.top());
if(backgroundRect.bottom() > rect.bottom())
backgroundRect.moveBottom(rect.bottom());
if(backgroundRect.right() > rect.right())
backgroundRect.moveRight(rect.right());
Size textSize = m_informationFont->calculateTextRectSize(m_name); Size textSize = m_informationFont->calculateTextRectSize(m_name);
Rect textRect = Rect(x - textSize.width() / 2.0, y-15, textSize); Rect textRect = Rect(x - textSize.width() / 2.0, y-15, textSize);
if(textRect.left() < rect.left()) textRect.bound(rect);
textRect.moveLeft(rect.left());
if(textRect.top() < rect.top())
textRect.moveTop(rect.top());
if(textRect.bottom() > rect.bottom())
textRect.moveBottom(rect.bottom());
if(textRect.right() > rect.right())
textRect.moveRight(rect.right());
// distance them // distance them
if(textRect.top() == rect.top()) if(textRect.top() == rect.top())
@ -264,7 +250,7 @@ void Creature::updateWalk()
m_walkOffsetX = -totalPixelsWalked; m_walkOffsetX = -totalPixelsWalked;
} }
int totalWalkTileTicks = (int)m_walkTimePerPixel*32; int totalWalkTileTicks = (int)m_walkTimePerPixel*32 * 0.5;
m_animation = (g_platform.getTicks() % totalWalkTileTicks) / (totalWalkTileTicks / (type.animationPhases - 1)) + 1; m_animation = (g_platform.getTicks() % totalWalkTileTicks) / (totalWalkTileTicks / (type.animationPhases - 1)) + 1;
g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel); g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel);
@ -285,7 +271,7 @@ void Creature::cancelWalk(Otc::Direction direction)
g_dispatcher.scheduleEvent([=]() { g_dispatcher.scheduleEvent([=]() {
if(!self->m_walking) if(!self->m_walking)
self->m_animation = 0; self->m_animation = 0;
}, 150); }, m_walkTimePerPixel * 2);
} }
void Creature::setHealthPercent(uint8 healthPercent) void Creature::setHealthPercent(uint8 healthPercent)