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

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

View File

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

View File

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

View File

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

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;