From 9d5abb0243d65f7fcd05c48b7788df98e1d2222b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 8 Jan 2013 17:40:25 -0200 Subject: [PATCH] Fix minor issues in item drawing * Add some utilities functions --- src/client/item.cpp | 11 +++++++- src/client/luavaluecasts.h | 4 +-- src/client/uicreature.cpp | 27 ++++++++++++++++++- src/client/uiitem.cpp | 4 ++- src/client/uiitem.h | 3 +++ src/framework/cmake/FindZLIB.cmake | 2 +- src/framework/core/resourcemanager.cpp.rej | 30 ---------------------- src/framework/stdext/packed_vector.h | 6 ++--- src/framework/util/color.h | 6 +++++ src/framework/util/rect.h | 5 ++++ 10 files changed, 59 insertions(+), 39 deletions(-) delete mode 100644 src/framework/core/resourcemanager.cpp.rej diff --git a/src/client/item.cpp b/src/client/item.cpp index 5237efca..f0dc174f 100644 --- a/src/client/item.cpp +++ b/src/client/item.cpp @@ -65,6 +65,12 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *l // determine animation phase int animationPhase = calculateAnimationPhase(animate); + if(getAnimationPhases() > 1) { + if(animate) + animationPhase = (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; + else + animationPhase = getAnimationPhases()-1; + } // determine x,y,z patterns int xPattern = 0, yPattern = 0, zPattern = 0; @@ -353,9 +359,12 @@ int Item::calculateAnimationPhase(bool animate) int Item::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) { + int exactSize = 0; calculatePatterns(xPattern, yPattern, zPattern); animationPhase = calculateAnimationPhase(true); - return Thing::getExactSize(0, xPattern, yPattern, zPattern, animationPhase); + for(layer = 0; layer < getLayers(); ++layer) + exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase)); + return exactSize; } const ThingTypePtr& Item::getThingType() diff --git a/src/client/luavaluecasts.h b/src/client/luavaluecasts.h index 0478d35b..3851a54c 100644 --- a/src/client/luavaluecasts.h +++ b/src/client/luavaluecasts.h @@ -20,8 +20,8 @@ * THE SOFTWARE. */ -#ifndef OTCLIENT_LUAVALUECASTS_H -#define OTCLIENT_LUAVALUECASTS_H +#ifndef CLIENT_LUAVALUECASTS_H +#define CLIENT_LUAVALUECASTS_H #include "global.h" #include diff --git a/src/client/uicreature.cpp b/src/client/uicreature.cpp index 86c1f1b0..b4a5e9b7 100644 --- a/src/client/uicreature.cpp +++ b/src/client/uicreature.cpp @@ -33,7 +33,7 @@ void UICreature::drawSelf(Fw::DrawPane drawPane) if(m_creature) { Rect drawRect = getPaddingRect(); - g_painter->setColor(Color::white); + g_painter->setColor(m_imageColor); m_creature->drawOutfit(drawRect, !m_fixedCreatureSize); } } @@ -53,5 +53,30 @@ void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& s for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "fixed-creature-size") setFixedCreatureSize(node->value()); + else if(node->tag() == "outfit-id") { + Outfit outfit = (m_creature ? m_creature->getOutfit() : Outfit()); + outfit.setId(node->value()); + setOutfit(outfit); + } + else if(node->tag() == "outfit-head") { + Outfit outfit = (m_creature ? m_creature->getOutfit() : Outfit()); + outfit.setHead(node->value()); + setOutfit(outfit); + } + else if(node->tag() == "outfit-body") { + Outfit outfit = (m_creature ? m_creature->getOutfit() : Outfit()); + outfit.setBody(node->value()); + setOutfit(outfit); + } + else if(node->tag() == "outfit-legs") { + Outfit outfit = (m_creature ? m_creature->getOutfit() : Outfit()); + outfit.setLegs(node->value()); + setOutfit(outfit); + } + else if(node->tag() == "outfit-feet") { + Outfit outfit = (m_creature ? m_creature->getOutfit() : Outfit()); + outfit.setFeet(node->value()); + setOutfit(outfit); + } } } diff --git a/src/client/uiitem.cpp b/src/client/uiitem.cpp index 9491017d..eb062013 100644 --- a/src/client/uiitem.cpp +++ b/src/client/uiitem.cpp @@ -44,7 +44,7 @@ void UIItem::drawSelf(Fw::DrawPane drawPane) drawImage(m_rect); - if(m_item) { + if(m_itemVisible && m_item) { Rect drawRect = getPaddingRect(); Point dest = drawRect.bottomRight() + Point(1,1); @@ -97,6 +97,8 @@ void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& style setItemId(node->value()); else if(node->tag() == "item-count") setItemCount(node->value()); + else if(node->tag() == "item-visible") + setItemVisible(node->value()); else if(node->tag() == "virtual") setVirtual(node->value()); } diff --git a/src/client/uiitem.h b/src/client/uiitem.h index 8bcbf952..7b454fd2 100644 --- a/src/client/uiitem.h +++ b/src/client/uiitem.h @@ -36,6 +36,7 @@ public: void setItemId(int id); void setItemCount(int count) { if(m_item) m_item->setCount(count); } void setItemSubType(int subType) { if(m_item) m_item->setSubType(subType); } + void setItemVisible(bool visible) { m_itemVisible = visible; } void setItem(const ItemPtr& item) { m_item = item; } void setVirtual(bool virt) { m_virtual = virt; } void clearItem() { setItemId(0); } @@ -45,12 +46,14 @@ public: int getItemSubType() { return m_item ? m_item->getSubType() : 0; } ItemPtr getItem() { return m_item; } bool isVirtual() { return m_virtual; } + bool isItemVisible() { return m_itemVisible; } protected: void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); ItemPtr m_item; stdext::boolean m_virtual; + stdext::boolean m_itemVisible; }; #endif diff --git a/src/framework/cmake/FindZLIB.cmake b/src/framework/cmake/FindZLIB.cmake index da12d9e0..b12f75ef 100644 --- a/src/framework/cmake/FindZLIB.cmake +++ b/src/framework/cmake/FindZLIB.cmake @@ -5,7 +5,7 @@ FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h) SET(_ZLIB_STATIC_LIBS libz.a libzlib.a zlib1.a) -SET(_ZLIB_SHARED_LIBS z zlib zdll zlib1) +SET(_ZLIB_SHARED_LIBS libz.dll.a zdll zlib zlib1 z) IF(USE_STATIC_LIBS) FIND_LIBRARY(ZLIB_LIBRARY NAMES ${_ZLIB_STATIC_LIBS} ${_ZLIB_SHARED_LIBS}) ELSE() diff --git a/src/framework/core/resourcemanager.cpp.rej b/src/framework/core/resourcemanager.cpp.rej deleted file mode 100644 index ec8fa930..00000000 --- a/src/framework/core/resourcemanager.cpp.rej +++ /dev/null @@ -1,30 +0,0 @@ ---- src/framework/core/resourcemanager.cpp -+++ src/framework/core/resourcemanager.cpp -@@ -34,19 +35,21 @@ - void ResourceManager::discoverWorkDir(const std::string& existentFile) - { - // search for modules directory -- std::string sep = PHYSFS_getDirSeparator(); -- std::string possiblePaths[] = { boost::filesystem::current_path().generic_string() + sep, -- g_resources.getBaseDir() + ".." + sep}; -+ std::string possiblePaths[] = { g_resources.getCurrentDir(), -+ g_resources.getBaseDir(), -+ g_resources.getBaseDir() + "../" }; - bool found = false; - for(const std::string& dir : possiblePaths) { -- // try to directory to modules path to see if it exists -- std::ifstream fin(dir + existentFile); -- if(fin) { -+ if(!PHYSFS_addToSearchPath(dir.c_str(), 0)) -+ continue; -+ -+ if(PHYSFS_exists(existentFile.c_str())) { - g_logger.debug(stdext::format("Found work dir at '%s'", dir.c_str())); - m_workDir = dir; - found = true; - break; - } -+ PHYSFS_removeFromSearchPath(dir.c_str()); - } - - if(!found) diff --git a/src/framework/stdext/packed_vector.h b/src/framework/stdext/packed_vector.h index c9a66c8c..e87f5a8e 100644 --- a/src/framework/stdext/packed_vector.h +++ b/src/framework/stdext/packed_vector.h @@ -58,10 +58,10 @@ public: const_iterator cend() const { return m_data + m_size; } reverse_iterator rbegin() { return reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return reverse_iterator(end()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rend() const { return reverse_iterator(begin()); } + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } size_type size() const { return m_size; } @@ -140,7 +140,7 @@ public: return tmp + i; } - void swap(packed_vector& other) { std::swap(m_size, other.m_size); std::swap(m_data, other.m_data); return *this; } + void swap(packed_vector& other) { std::swap(m_size, other.m_size); std::swap(m_data, other.m_data); } operator std::vector() const { return std::vector(begin(), end()); } diff --git a/src/framework/util/color.h b/src/framework/util/color.h index c21477d2..3ba38732 100644 --- a/src/framework/util/color.h +++ b/src/framework/util/color.h @@ -63,6 +63,12 @@ public: void setRGBA(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) { m_r = r/255.0f; m_g = g/255.0f; m_b = b/255.0f; m_a = a/255.0f; } void setRGBA(uint32 rgba) { setRGBA((rgba >> 0) & 0xff, (rgba >> 8) & 0xff, (rgba >> 16) & 0xff, (rgba >> 24) & 0xff); } + Color operator+(const Color& other) const { return Color(m_r + other.m_r, m_g + other.m_g, m_b + other.m_b, m_a + other.m_a); } + Color operator-(const Color& other) const { return Color(m_r - other.m_r, m_g - other.m_g, m_b - other.m_b, m_a - other.m_a); } + + Color operator*(float v) const { return Color(m_r*v, m_g*v, m_b*v, m_a*v); } + Color operator/(float v) const { return Color(m_r/v, m_g/v, m_b/v, m_a/v); } + Color& operator=(uint32_t rgba) { setRGBA(rgba); return *this; } bool operator==(uint32_t rgba) const { return this->rgba() == rgba; } diff --git a/src/framework/util/rect.h b/src/framework/util/rect.h index 01616222..9cf3d9ce 100644 --- a/src/framework/util/rect.h +++ b/src/framework/util/rect.h @@ -24,6 +24,7 @@ #define RECT_H #include "../stdext/types.h" +#include "../const.h" #include template @@ -108,6 +109,10 @@ public: void moveBottomRight(const TPoint &p) { moveRight(p.x); moveBottom(p.y); } void moveTopRight(const TPoint &p) { moveRight(p.x); moveTop(p.y); } void moveBottomLeft(const TPoint &p) { moveLeft(p.x); moveBottom(p.y); } + void moveTopCenter(const TPoint &p) { moveHorizontalCenter(p.x); moveTop(p.y); } + void moveBottomCenter(const TPoint &p) { moveHorizontalCenter(p.x); moveBottom(p.y); } + void moveCenterLeft(const TPoint &p) { moveLeft(p.x); moveVerticalCenter(p.y); } + void moveCenterRight(const TPoint &p) { moveRight(p.x); moveVerticalCenter(p.y); } TRect translated(int x, int y) const { return TRect(TPoint(x1 + x, y1 + y), TPoint(x2 + x, y2 + y)); } TRect translated(const TPoint &p) const { return TRect(TPoint(x1 + p.x, y1 + p.y), TPoint(x2 + p.x, y2 + p.y)); }