From 23097980a34b3789b1d3312632ef419d5a97dee3 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Fri, 31 Aug 2012 20:33:51 -0300 Subject: [PATCH] Fix scrollbar slider move, outfit exact size, charlist focus --- init.lua | 4 +- modules/client_entergame/characterlist.otui | 13 ++ modules/corelib/ui/uiscrollbar.lua | 13 +- modules/game_interface/gameinterface.lua | 15 +- src/otclient/creature.cpp | 28 +++ src/otclient/creature.h | 1 + src/otclient/item.cpp | 222 +++++++++++--------- src/otclient/item.h | 4 + src/otclient/thing.h | 2 +- src/otclient/thingtype.cpp | 8 + src/otclient/thingtype.h | 2 +- src/otclient/uiitem.cpp | 2 +- 12 files changed, 201 insertions(+), 113 deletions(-) diff --git a/init.lua b/init.lua index 1cf988e2..63c9626a 100644 --- a/init.lua +++ b/init.lua @@ -30,7 +30,7 @@ g_configs.load("/config.otml") g_modules.discoverModules() -- libraries modules 0-99 -g_modules.autoLoadModules(99); +g_modules.autoLoadModules(99) g_modules.ensureModuleLoaded("corelib") g_modules.ensureModuleLoaded("gamelib") @@ -39,7 +39,7 @@ g_modules.autoLoadModules(499) g_modules.ensureModuleLoaded("client") -- game modules 500-999 -g_modules.autoLoadModules(999); +g_modules.autoLoadModules(999) g_modules.ensureModuleLoaded("game_interface") -- mods 1000-9999 diff --git a/modules/client_entergame/characterlist.otui b/modules/client_entergame/characterlist.otui index 4f3a4d35..07b6c187 100644 --- a/modules/client_entergame/characterlist.otui +++ b/modules/client_entergame/characterlist.otui @@ -2,6 +2,11 @@ CharacterWidget < UIWidget height: 14 focusable: true background-color: alpha + @onFocusChange: | + local children = self:getChildren() + for i=1,#children do + children[i]:setOn(self:isFocused()) + end $focus: background-color: #ffffff22 @@ -15,6 +20,10 @@ CharacterWidget < UIWidget text-auto-resize: true background-color: alpha text-offset: 2 0 + on: true + + $!on: + color: #aaaaaa Label id: worldName @@ -26,6 +35,10 @@ CharacterWidget < UIWidget text-auto-resize: true background-color: alpha &baseText: '(%s)' + on: true + + $!on: + color: #aaaaaa MainWindow id: charactersWindow diff --git a/modules/corelib/ui/uiscrollbar.lua b/modules/corelib/ui/uiscrollbar.lua index 8f732593..88ca6457 100644 --- a/modules/corelib/ui/uiscrollbar.lua +++ b/modules/corelib/ui/uiscrollbar.lua @@ -72,21 +72,20 @@ local function updateSlider(self) end end -local function parseSliderPos(self, pos) - local point +local function parseSliderPos(self, pos, move) + local point, delta if self.orientation == 'vertical' then point = pos.y + delta = move.y else point = pos.x + delta = move.x end local range, pxrange, px, offset, center = calcValues(self) - offset = math.min(math.max(point - center, -pxrange/2), pxrange/2) - local newvalue = math.floor(((offset / (pxrange - px)) + 0.5) * (range - 1)) + self.minimum + local newvalue = self.value + delta * (range / (pxrange - px)) self:setValue(newvalue) - -- this function must be reworked, scroll is not that good based on center end - -- public functions function UIScrollBar.create() local scrollbar = UIScrollBar.internalCreate() @@ -105,7 +104,7 @@ function UIScrollBar:onSetup() --signalcall(self.onValueChange, self, self.value) g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end, 300) g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end, 300) - g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end) + g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos, mouseMoved) end) updateSlider(self) end diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 5d73c278..15fdb375 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -458,7 +458,7 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u end function moveStackableItem(item, toPos) - if(countWindow) then + if countWindow then return end if g_keyboard.isCtrlPressed() then @@ -479,8 +479,17 @@ function moveStackableItem(item, toPos) scrollbar:setMaximum(count) scrollbar:setMinimum(1) scrollbar:setValue(count) - scrollbar.onValueChange = function(self, value) spinbox:setValue(value) end - spinbox.onValueChange = function(self, value) scrollbar:setValue(value) end + + local spinBoxValueChange = function(self, value) + scrollbar:setValue(value) + end + spinbox.onValueChange = spinBoxValueChange + + scrollbar.onValueChange = function(self, value) + spinbox.onValueChange = nil + spinbox:setValue(math.round(value)) + spinbox.onValueChange = spinBoxValueChange + end local okButton = countWindow:getChildById('buttonOk') local moveFunc = function() diff --git a/src/otclient/creature.cpp b/src/otclient/creature.cpp index cc43874b..ed81b547 100644 --- a/src/otclient/creature.cpp +++ b/src/otclient/creature.cpp @@ -681,6 +681,34 @@ int Creature::getDisplacementY() return Thing::getDisplacementY(); } +int Creature::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) +{ + int exactSize = 0; + + animationPhase = m_walkAnimationPhase; + + if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) + xPattern = Otc::East; + else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) + xPattern = Otc::West; + else + xPattern = m_direction; + + zPattern = 0; + if(m_outfit.getMount() != 0) + zPattern = 1; + + for(yPattern = 0; yPattern < getNumPatternY(); yPattern++) { + if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1)))) + continue; + + for(layer = 0; layer < getLayers(); ++layer) + exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase)); + } + + return exactSize; +} + const ThingTypePtr& Creature::getThingType() { return g_things.getThingType(m_outfit.getId(), ThingCategoryCreature); diff --git a/src/otclient/creature.h b/src/otclient/creature.h index ec7bd652..713c4db8 100644 --- a/src/otclient/creature.h +++ b/src/otclient/creature.h @@ -91,6 +91,7 @@ public: virtual Point getDisplacement(); virtual int getDisplacementX(); virtual int getDisplacementY(); + virtual int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0); void updateShield(); diff --git a/src/otclient/item.cpp b/src/otclient/item.cpp index 89b7b9f9..4998b37c 100644 --- a/src/otclient/item.cpp +++ b/src/otclient/item.cpp @@ -64,7 +64,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) return; // determine animation phase - int animationPhase = 0; + int animationPhase = calculateAnimationPhase(animate); if(getAnimationPhases() > 1) { if(animate) animationPhase = (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; @@ -74,103 +74,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) // determine x,y,z patterns int xPattern = 0, yPattern = 0, zPattern = 0; - if(isStackable() && getNumPatternX() == 4 && getNumPatternY() == 2) { - if(m_countOrSubType <= 0) { - xPattern = 0; - yPattern = 0; - } else if(m_countOrSubType < 5) { - xPattern = m_countOrSubType-1; - yPattern = 0; - } else if(m_countOrSubType < 10) { - xPattern = 0; - yPattern = 1; - } else if(m_countOrSubType < 25) { - xPattern = 1; - yPattern = 1; - } else if(m_countOrSubType < 50) { - xPattern = 2; - yPattern = 1; - } else { - xPattern = 3; - yPattern = 1; - } - } else if(isHangable()) { - const TilePtr& tile = getTile(); - if(tile) { - if(tile->mustHookSouth()) - xPattern = getNumPatternX() >= 2 ? 1 : 0; - else if(tile->mustHookEast()) - xPattern = getNumPatternX() >= 3 ? 2 : 0; - } - } else if(isSplash() || isFluidContainer()) { - int color = Otc::FluidTransparent; - switch(m_countOrSubType) { - case Otc::FluidNone: - color = Otc::FluidTransparent; - break; - case Otc::FluidWater: - color = Otc::FluidBlue; - break; - case Otc::FluidMana: - color = Otc::FluidPurple; - break; - case Otc::FluidBeer: - color = Otc::FluidBrown; - break; - case Otc::FluidOil: - color = Otc::FluidBrown; - break; - case Otc::FluidBlood: - color = Otc::FluidRed; - break; - case Otc::FluidSlime: - color = Otc::FluidGreen; - break; - case Otc::FluidMud: - color = Otc::FluidBrown; - break; - case Otc::FluidLemonade: - color = Otc::FluidYellow; - break; - case Otc::FluidMilk: - color = Otc::FluidWhite; - break; - case Otc::FluidWine: - color = Otc::FluidPurple; - break; - case Otc::FluidHealth: - color = Otc::FluidRed; - break; - case Otc::FluidUrine: - color = Otc::FluidYellow; - break; - case Otc::FluidRum: - color = Otc::FluidBrown; - break; - case Otc::FluidFruidJuice: - color = Otc::FluidYellow; - break; - case Otc::FluidCoconutMilk: - color = Otc::FluidWhite; - break; - case Otc::FluidTea: - color = Otc::FluidBrown; - break; - case Otc::FluidMead: - color = Otc::FluidBrown; - break; - default: - color = Otc::FluidTransparent; - break; - } - - xPattern = (color % 4) % getNumPatternX(); - yPattern = (color / 4) % getNumPatternY(); - } else if(isGround() || isOnBottom()) { - xPattern = m_position.x % getNumPatternX(); - yPattern = m_position.y % getNumPatternY(); - zPattern = m_position.z % getNumPatternZ(); - } + calculatePatterns(xPattern, yPattern, zPattern); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase); } @@ -341,6 +245,128 @@ ItemPtr Item::clone() return item; } +void Item::calculatePatterns(int& xPattern, int& yPattern, int& zPattern) +{ + if(isStackable() && getNumPatternX() == 4 && getNumPatternY() == 2) { + if(m_countOrSubType <= 0) { + xPattern = 0; + yPattern = 0; + } else if(m_countOrSubType < 5) { + xPattern = m_countOrSubType-1; + yPattern = 0; + } else if(m_countOrSubType < 10) { + xPattern = 0; + yPattern = 1; + } else if(m_countOrSubType < 25) { + xPattern = 1; + yPattern = 1; + } else if(m_countOrSubType < 50) { + xPattern = 2; + yPattern = 1; + } else { + xPattern = 3; + yPattern = 1; + } + } else if(isHangable()) { + const TilePtr& tile = getTile(); + if(tile) { + if(tile->mustHookSouth()) + xPattern = getNumPatternX() >= 2 ? 1 : 0; + else if(tile->mustHookEast()) + xPattern = getNumPatternX() >= 3 ? 2 : 0; + } + } else if(isSplash() || isFluidContainer()) { + int color = Otc::FluidTransparent; + switch(m_countOrSubType) { + case Otc::FluidNone: + color = Otc::FluidTransparent; + break; + case Otc::FluidWater: + color = Otc::FluidBlue; + break; + case Otc::FluidMana: + color = Otc::FluidPurple; + break; + case Otc::FluidBeer: + color = Otc::FluidBrown; + break; + case Otc::FluidOil: + color = Otc::FluidBrown; + break; + case Otc::FluidBlood: + color = Otc::FluidRed; + break; + case Otc::FluidSlime: + color = Otc::FluidGreen; + break; + case Otc::FluidMud: + color = Otc::FluidBrown; + break; + case Otc::FluidLemonade: + color = Otc::FluidYellow; + break; + case Otc::FluidMilk: + color = Otc::FluidWhite; + break; + case Otc::FluidWine: + color = Otc::FluidPurple; + break; + case Otc::FluidHealth: + color = Otc::FluidRed; + break; + case Otc::FluidUrine: + color = Otc::FluidYellow; + break; + case Otc::FluidRum: + color = Otc::FluidBrown; + break; + case Otc::FluidFruidJuice: + color = Otc::FluidYellow; + break; + case Otc::FluidCoconutMilk: + color = Otc::FluidWhite; + break; + case Otc::FluidTea: + color = Otc::FluidBrown; + break; + case Otc::FluidMead: + color = Otc::FluidBrown; + break; + default: + color = Otc::FluidTransparent; + break; + } + + xPattern = (color % 4) % getNumPatternX(); + yPattern = (color / 4) % getNumPatternY(); + } else if(isGround() || isOnBottom()) { + xPattern = m_position.x % getNumPatternX(); + yPattern = m_position.y % getNumPatternY(); + zPattern = m_position.z % getNumPatternZ(); + } +} + +int Item::calculateAnimationPhase(bool animate) +{ + if(getAnimationPhases() > 1) { + if(animate) + return (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; + else + return getAnimationPhases()-1; + } + return 0; +} + +int Item::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) +{ + int exactSize = 0; + calculatePatterns(xPattern, yPattern, zPattern); + animationPhase = calculateAnimationPhase(true); + for(layer = 0; layer < getLayers(); ++layer) + exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase)); + return exactSize; +} + const ThingTypePtr& Item::getThingType() { return g_things.getThingType(m_clientId, ThingCategoryItem); diff --git a/src/otclient/item.h b/src/otclient/item.h index 8cadd880..18de0531 100644 --- a/src/otclient/item.h +++ b/src/otclient/item.h @@ -124,6 +124,10 @@ public: void addContainerItem(const ItemPtr& i) { m_containerItems.push_back(i); } void clearContainerItems() { m_containerItems.clear(); } + void calculatePatterns(int& xPattern, int& yPattern, int& zPattern); + int calculateAnimationPhase(bool animate); + int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0); + const ThingTypePtr& getThingType(); ThingType *rawGetThingType(); diff --git a/src/otclient/thing.h b/src/otclient/thing.h index fbbd56d6..fb7bc52f 100644 --- a/src/otclient/thing.h +++ b/src/otclient/thing.h @@ -68,7 +68,7 @@ public: virtual Point getDisplacement() { return rawGetThingType()->getDisplacement(); } virtual int getDisplacementX() { return rawGetThingType()->getDisplacementX(); } virtual int getDisplacementY() { return rawGetThingType()->getDisplacementY(); } - int getExactSize() { return rawGetThingType()->getExactSize(); } + virtual int getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) { return rawGetThingType()->getExactSize(layer, xPattern, yPattern, zPattern, animationPhase); } int getLayers() { return rawGetThingType()->getLayers(); } int getNumPatternX() { return rawGetThingType()->getNumPatternX(); } int getNumPatternY() { return rawGetThingType()->getNumPatternY(); } diff --git a/src/otclient/thingtype.cpp b/src/otclient/thingtype.cpp index 5fe00ec8..c75c6068 100644 --- a/src/otclient/thingtype.cpp +++ b/src/otclient/thingtype.cpp @@ -287,3 +287,11 @@ uint ThingType::getTextureIndex(int l, int x, int y, int z) { * m_numPatternY + y) * m_numPatternX + x; } + +int ThingType::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) +{ + getTexture(animationPhase); // we must calculate it anyway. + int frameIndex = getTextureIndex(layer, xPattern, yPattern, zPattern); + Size size = m_texturesFramesOriginRects[animationPhase][frameIndex].size() - m_texturesFramesOffsets[animationPhase][frameIndex].toSize(); + return std::max(size.width(), size.height()); +} diff --git a/src/otclient/thingtype.h b/src/otclient/thingtype.h index 74be2afa..e53b45a4 100644 --- a/src/otclient/thingtype.h +++ b/src/otclient/thingtype.h @@ -117,7 +117,7 @@ public: Size getSize() { return m_size; } int getWidth() { return m_size.width(); } int getHeight() { return m_size.height(); } - int getExactSize() { return m_exactSize; } + int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0); int getLayers() { return m_layers; } int getNumPatternX() { return m_numPatternX; } int getNumPatternY() { return m_numPatternY; } diff --git a/src/otclient/uiitem.cpp b/src/otclient/uiitem.cpp index a9f8a492..c27e0cde 100644 --- a/src/otclient/uiitem.cpp +++ b/src/otclient/uiitem.cpp @@ -48,7 +48,7 @@ void UIItem::drawSelf(Fw::DrawPane drawPane) Rect drawRect = getPaddingRect(); Point dest = drawRect.bottomRight() + Point(1,1); - int exactSize = m_item->getExactSize(); + int exactSize = std::max(32, m_item->getExactSize()); if(exactSize == 0) return;