From 1b83126ed5bcdd2a78e393eaf5e094e776d8da2e Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 5 Jan 2012 16:34:37 -0200 Subject: [PATCH] separator fix, fix draw outside map --- modules/game/thing.lua | 3 +-- src/framework/math/rect.h | 6 ++++++ src/otclient/core/animatedtext.cpp | 9 ++++++--- src/otclient/core/animatedtext.h | 2 +- src/otclient/core/creature.cpp | 12 ++++++------ src/otclient/core/creature.h | 4 ++-- src/otclient/core/effect.cpp | 2 +- src/otclient/core/effect.h | 2 +- src/otclient/core/item.cpp | 2 +- src/otclient/core/item.h | 2 +- src/otclient/core/map.cpp | 8 ++++---- src/otclient/core/missile.cpp | 2 +- src/otclient/core/missile.h | 2 +- src/otclient/core/statictext.cpp | 9 ++++++--- src/otclient/core/statictext.h | 2 +- src/otclient/core/thing.h | 2 +- src/otclient/core/tile.cpp | 12 ++++++------ src/otclient/core/tile.h | 2 +- src/otclient/ui/uicreature.cpp | 2 +- src/otclient/ui/uiitem.cpp | 2 +- 20 files changed, 49 insertions(+), 38 deletions(-) diff --git a/modules/game/thing.lua b/modules/game/thing.lua index e39bff16..c4e26026 100644 --- a/modules/game/thing.lua +++ b/modules/game/thing.lua @@ -22,10 +22,9 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) if useThing:isRotateable() then menu:addOption('Rotate', function() Game.rotate(useThing) end) end - - menu:addSeparator() if not useThing:isNotMoveable() and useThing:isPickupable() then + menu:addSeparator() menu:addOption('Trade with ...', function() print('trade with') end) end end diff --git a/src/framework/math/rect.h b/src/framework/math/rect.h index 38c91626..f62b8e95 100644 --- a/src/framework/math/rect.h +++ b/src/framework/math/rect.h @@ -159,6 +159,12 @@ public: return true; } + bool contains(const TRect &r, bool insideOnly = false) const { + if(contains(r.topLeft(), insideOnly) && contains(r.bottomRight(), insideOnly)) + return true; + return false; + } + bool intersects(const TRect &r) const { if(isNull() || r.isNull()) return false; diff --git a/src/otclient/core/animatedtext.cpp b/src/otclient/core/animatedtext.cpp index aed685eb..0eac7c0f 100644 --- a/src/otclient/core/animatedtext.cpp +++ b/src/otclient/core/animatedtext.cpp @@ -43,10 +43,13 @@ void AnimatedText::start() }, DURATION); } -void AnimatedText::draw(const Point& p) +void AnimatedText::draw(const Point& p, const Rect& visibleRect) { - if(m_font) - m_font->renderText(m_text, Rect(p + Point(20 - m_textSize.width() / 2, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize), Fw::AlignLeft, m_color); + if(m_font) { + Rect rect = Rect(p + Point(20 - m_textSize.width() / 2, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize); + if(visibleRect.contains(rect)) + m_font->renderText(m_text, rect, Fw::AlignLeft, m_color); + } } void AnimatedText::setColor(int color) diff --git a/src/otclient/core/animatedtext.h b/src/otclient/core/animatedtext.h index cab8afd3..8e019d74 100644 --- a/src/otclient/core/animatedtext.h +++ b/src/otclient/core/animatedtext.h @@ -36,7 +36,7 @@ public: AnimatedText(); void start(); - void draw(const Point& p); + void draw(const Point& p, const Rect& visibleRect); void setColor(int color); void setText(const std::string& text); diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index e0d324b5..65c794f6 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -57,7 +57,7 @@ int LEGS_COLOR_UNIFORM = 12; int FEET_COLOR_UNIFORM = 13; int MASK_TEXTURE_UNIFORM = 14; -void Creature::draw(const Point& p) +void Creature::draw(const Point& p, const Rect&) { if(m_showVolatileSquare) { g_painter.setColor(m_volatileSquareColor); @@ -125,7 +125,7 @@ void Creature::draw(const Point& p) } } -void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect) +void Creature::drawInformation(int x, int y, bool useGray, const Rect& visibleRect) { Color fillColor = Color(96, 96, 96); @@ -134,15 +134,15 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect) // calculate main rects Rect backgroundRect = Rect(x-(13.5), y, 27, 4); - backgroundRect.bound(rect); + backgroundRect.bound(visibleRect); Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-12, m_nameSize); - textRect.bound(rect); + textRect.bound(visibleRect); // distance them - if(textRect.top() == rect.top()) + if(textRect.top() == visibleRect.top()) backgroundRect.moveTop(textRect.top() + 12); - if(backgroundRect.bottom() == rect.bottom()) + if(backgroundRect.bottom() == visibleRect.bottom()) textRect.moveTop(backgroundRect.top() - 12); // health rect is based on background rect, so no worries diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 9f0752ba..00ad7c6b 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -37,8 +37,8 @@ public: Creature(); virtual ~Creature() { } - virtual void draw(const Point& p); - void drawInformation(int x, int y, bool useGray, const Rect& rect); + virtual void draw(const Point& p, const Rect&); + void drawInformation(int x, int y, bool useGray, const Rect& visibleRect); void setName(const std::string& name); void setHealthPercent(uint8 healthPercent); diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 10aa0cfb..3f6eff8e 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -51,7 +51,7 @@ void Effect::start() }, TICKS_PER_FRAME * getAnimationPhases()); } -void Effect::draw(const Point& p) +void Effect::draw(const Point& p, const Rect&) { internalDraw(p, 0); } diff --git a/src/otclient/core/effect.h b/src/otclient/core/effect.h index d47ec072..8564c1ba 100644 --- a/src/otclient/core/effect.h +++ b/src/otclient/core/effect.h @@ -35,7 +35,7 @@ class Effect : public Thing public: Effect(); - void draw(const Point& p); + void draw(const Point& p, const Rect&); void start(); void updateAnimation(); diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index a66d6b19..108647da 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -32,7 +32,7 @@ Item::Item() : Thing() m_data = 0; } -void Item::draw(const Point& p) +void Item::draw(const Point& p, const Rect&) { if(m_type->dimensions[ThingType::AnimationPhases] > 1) m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * m_type->dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME; diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index 92fa6552..201e8bf7 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -35,7 +35,7 @@ public: TICKS_PER_FRAME = 500 }; - void draw(const Point& p); + void draw(const Point& p, const Rect&); void setPos(const Position &position); void setData(int data); diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index daa2233f..6b66afab 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -81,7 +81,7 @@ void Map::draw(const Rect& rect) // skip tiles that are behind another tile //if(isCompletlyCovered(tilePos, firstFloor)) // continue; - tile->draw(positionTo2D(tilePos) - m_drawOffset); + tile->draw(positionTo2D(tilePos) - m_drawOffset, rect); } } } @@ -89,7 +89,7 @@ void Map::draw(const Rect& rect) // after drawing all tiles, draw shots for(const MissilePtr& shot : m_missilesAtFloor[iz]) { Position missilePos = shot->getPos(); - shot->draw(positionTo2D(missilePos) - m_drawOffset); + shot->draw(positionTo2D(missilePos) - m_drawOffset, rect); } } @@ -135,7 +135,7 @@ void Map::draw(const Rect& rect) Point pos = positionTo2D((*it)->getPos()) - m_drawOffset; pos.x *= horizontalStretchFactor; pos.y *= verticalStretchFactor; - (*it)->draw(rect.topLeft() + pos); + (*it)->draw(rect.topLeft() + pos, rect); } // draw static text @@ -143,7 +143,7 @@ void Map::draw(const Rect& rect) Point pos = positionTo2D((*it)->getPos()) - m_drawOffset; pos.x *= horizontalStretchFactor; pos.y *= verticalStretchFactor; - (*it)->draw(rect.topLeft() + pos); + (*it)->draw(rect.topLeft() + pos, rect); } } diff --git a/src/otclient/core/missile.cpp b/src/otclient/core/missile.cpp index a8cb6461..70788f27 100644 --- a/src/otclient/core/missile.cpp +++ b/src/otclient/core/missile.cpp @@ -32,7 +32,7 @@ Missile::Missile() : Thing() m_startTicks = 0; } -void Missile::draw(const Point& p) +void Missile::draw(const Point& p, const Rect&) { float time = (g_clock.ticks() - m_startTicks) / m_duration; internalDraw(p + Point(m_positionDelta.x * time, m_positionDelta.y * time), 0); diff --git a/src/otclient/core/missile.h b/src/otclient/core/missile.h index b2130329..1cd67e40 100644 --- a/src/otclient/core/missile.h +++ b/src/otclient/core/missile.h @@ -35,7 +35,7 @@ class Missile : public Thing public: Missile(); - void draw(const Point& p); + void draw(const Point& p, const Rect&); void updateAnimation(); diff --git a/src/otclient/core/statictext.cpp b/src/otclient/core/statictext.cpp index dd3c344b..1fe940fe 100644 --- a/src/otclient/core/statictext.cpp +++ b/src/otclient/core/statictext.cpp @@ -31,10 +31,13 @@ StaticText::StaticText() m_font = g_fonts.getFont("verdana-11px-rounded"); } -void StaticText::draw(const Point& p) +void StaticText::draw(const Point& p, const Rect& visibleRect) { - if(m_font) - m_font->renderText(m_text, Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize), Fw::AlignCenter, m_color); + if(m_font) { + Rect rect = Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize); + if(visibleRect.contains(rect)) + m_font->renderText(m_text, rect, Fw::AlignCenter, m_color); + } } bool StaticText::addMessage(const std::string& name, int type, const std::string& message) diff --git a/src/otclient/core/statictext.h b/src/otclient/core/statictext.h index 7e7e948c..1cde07ae 100644 --- a/src/otclient/core/statictext.h +++ b/src/otclient/core/statictext.h @@ -35,7 +35,7 @@ public: StaticText(); - void draw(const Point& p); + void draw(const Point& p, const Rect& visibleRect); std::string getName() { return m_name; } int getMessageType() { return m_type; } diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index 55bf3c68..3a694e05 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -41,7 +41,7 @@ public: virtual void start() {} - virtual void draw(const Point& p) = 0; + virtual void draw(const Point& p, const Rect&) = 0; void setId(int id); virtual void setPos(const Position& position) { m_position = position; } diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index c13a2470..93095dc7 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -36,7 +36,7 @@ Tile::Tile(const Position& position) m_position = position; } -void Tile::draw(const Point& p) +void Tile::draw(const Point& p, const Rect& visibleRect) { m_drawElevation = 0; @@ -45,7 +45,7 @@ void Tile::draw(const Point& p) ThingType *type = thing->getType(); if(!type->properties[ThingType::IsGround] && !type->properties[ThingType::IsGroundBorder] && !type->properties[ThingType::IsOnBottom]) break; - thing->draw(p - m_drawElevation); + thing->draw(p - m_drawElevation, visibleRect); m_drawElevation += type->parameters[ThingType::Elevation]; if(m_drawElevation > MAX_DRAW_ELEVATION) m_drawElevation = MAX_DRAW_ELEVATION; @@ -57,7 +57,7 @@ void Tile::draw(const Point& p) ThingType *type = thing->getType(); if(thing->asCreature() || type->properties[ThingType::IsOnTop] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsGround]) break; - thing->draw(p - m_drawElevation); + thing->draw(p - m_drawElevation, visibleRect); m_drawElevation += type->parameters[ThingType::Elevation]; if(m_drawElevation > MAX_DRAW_ELEVATION) m_drawElevation = MAX_DRAW_ELEVATION; @@ -74,7 +74,7 @@ void Tile::draw(const Point& p) // only render creatures where bottom right is inside our rect if(thisTileRect.contains(creatureRect.bottomRight())) { - creature->draw(Point(p.x + xi*32 - m_drawElevation, p.y + yi*32 - m_drawElevation)); + creature->draw(Point(p.x + xi*32 - m_drawElevation, p.y + yi*32 - m_drawElevation), visibleRect); } } } @@ -82,13 +82,13 @@ void Tile::draw(const Point& p) // effects for(const EffectPtr& effect : m_effects) - effect->draw(p - m_drawElevation); + effect->draw(p - m_drawElevation, visibleRect); // top items for(const ThingPtr& thing : m_things) { ThingType *type = thing->getType(); if(type->properties[ThingType::IsOnTop]) - thing->draw(p); + thing->draw(p, visibleRect); } } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index af482130..51aa1123 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -34,7 +34,7 @@ class Tile : public LuaObject public: Tile(const Position& position); - void draw(const Point& p); + void draw(const Point& p, const Rect& visibleRect); void clean(); ThingPtr addThing(const ThingPtr& thing, int stackPos = -1); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index f6eb0fb5..e74fb5ed 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -35,7 +35,7 @@ void UICreature::render() if(m_creature) { g_painter.setColor(Fw::white); - m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin); + m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin, m_rect); } renderChildren(); diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index 4167f52a..7a5dd020 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -35,7 +35,7 @@ void UIItem::render() if(m_item) { g_painter.setColor(Fw::white); - m_item->draw(m_rect.bottomRight() - Point(32, 32) + m_itemMargin); + m_item->draw(m_rect.bottomRight() - Point(32, 32) + m_itemMargin, m_rect); } renderChildren();