From 7db6b8b5e6924e82de51e32ea7c7f4ea0fc2b35a Mon Sep 17 00:00:00 2001 From: Henrique Date: Sun, 6 Nov 2011 02:12:13 -0200 Subject: [PATCH] walk changes, nothing special --- src/framework/ui/uiwindow.cpp | 9 +-------- src/framework/util/rect.h | 14 ++++++++++++++ src/otclient/core/creature.cpp | 22 ++++------------------ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/framework/ui/uiwindow.cpp b/src/framework/ui/uiwindow.cpp index 102d6397..3cb40753 100644 --- a/src/framework/ui/uiwindow.cpp +++ b/src/framework/ui/uiwindow.cpp @@ -96,14 +96,7 @@ void UIWindow::onGeometryUpdate(const Rect& oldRect, const Rect& newRect) UIWidgetPtr parent = getParent(); if(parent) { Rect parentRect = parent->getRect(); - if(boundRect.left() < parentRect.left()) - 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()); + boundRect.bound(parentRect); } if(boundRect != newRect) diff --git a/src/framework/util/rect.h b/src/framework/util/rect.h index c4c09ea4..f5e699b8 100644 --- a/src/framework/util/rect.h +++ b/src/framework/util/rect.h @@ -251,6 +251,20 @@ public: return tmp; } + void bound(const TRect &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& operator=(const TRect& other) { x1 = other.x1; y1 = other.y1; x2 = other.x2; y2 = other.y2; return *this; } bool operator==(const TRect& other) const { return (x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2); } bool operator!=(const TRect& other) const { return (x1 != other.x1 || y1 != other.y1 || x2 != other.x2 || y2 != other.y2); } diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 5f6f5175..b55ba3c9 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -100,25 +100,11 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect) // calculate main rects Rect backgroundRect = Rect(x-(13.5), y, 27, 4); - if(backgroundRect.left() < rect.left()) - 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()); + backgroundRect.bound(rect); Size textSize = m_informationFont->calculateTextRectSize(m_name); Rect textRect = Rect(x - textSize.width() / 2.0, y-15, textSize); - if(textRect.left() < rect.left()) - 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()); + textRect.bound(rect); // distance them if(textRect.top() == rect.top()) @@ -264,7 +250,7 @@ void Creature::updateWalk() 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; g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel); @@ -285,7 +271,7 @@ void Creature::cancelWalk(Otc::Direction direction) g_dispatcher.scheduleEvent([=]() { if(!self->m_walking) self->m_animation = 0; - }, 150); + }, m_walkTimePerPixel * 2); } void Creature::setHealthPercent(uint8 healthPercent)