Fix scrollbar slider move, outfit exact size, charlist focus

This commit is contained in:
Henrique Santiago
2012-08-31 20:33:51 -03:00
parent 18a0d7ab94
commit 23097980a3
12 changed files with 201 additions and 113 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();

View File

@@ -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(); }

View File

@@ -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());
}

View File

@@ -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; }

View File

@@ -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;