Fixed #165, Fine tune fixes!

* Fixed an issue with the cooldown timing.
* Fixed issue with 'right click' using items under players.
* Some changes to the minimap control (ctrl + mouse wheel to
  change floors and tweaked the zoom/move speeds).
* Fixed some bugs in the trade module.
* Added new Spells table for spell related functions
  (Also added getSpellByName and getSpellByWords).
* Fixed an issue with follow/attack cancelling (wasn't calling
  onFollowChanged for updates in battle, etc).
This commit is contained in:
BeniS 2013-01-07 04:04:49 +13:00
parent 3fa5993177
commit fddbafebd3
8 changed files with 124 additions and 66 deletions

View File

@ -34,6 +34,7 @@ function init()
mouseWidget = g_ui.createWidget('UIButton') mouseWidget = g_ui.createWidget('UIButton')
mouseWidget:setVisible(false) mouseWidget:setVisible(false)
mouseWidget:setFocusable(false) mouseWidget:setFocusable(false)
mouseWidget.cancelNextRelease = false
battleWindow:setContentMinimumHeight(80) battleWindow:setContentMinimumHeight(80)
--battleWindow:setContentMaximumHeight(384) --battleWindow:setContentMaximumHeight(384)
@ -220,21 +221,27 @@ function addCreature(creature)
end end
function onMouseRelease(self, mousePosition, mouseButton) function onMouseRelease(self, mousePosition, mouseButton)
if mouseButton == MouseRightButton then if mouseWidget.cancelNextRelease then
mouseWidget.cancelNextRelease = false
return false
end
if ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton)
or (g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
mouseWidget.cancelNextRelease = true
g_game.look(self.creature)
return true
elseif mouseButton == MouseRightButton and g_keyboard.isCtrlPressed() and not g_mouse.isPressed(MouseLeftButton) then
modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature) modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature)
return true return true
elseif mouseButton == MouseLeftButton then elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
if g_keyboard.isShiftPressed() then
g_game.look(self.creature)
else
if self.isTarget then if self.isTarget then
g_game.cancelAttack() g_game.cancelAttack()
else else
g_game.attack(self.creature) g_game.attack(self.creature)
end end
end
return true return true
end end
return false
end end
function removeAllCreatures() function removeAllCreatures()

View File

@ -65,7 +65,7 @@ function updateProgressRect(progressRect, interval, init)
if init then if init then
progressRect:setPercent(0) progressRect:setPercent(0)
else else
progressRect:setPercent(progressRect:getPercent() + 4) progressRect:setPercent(progressRect:getPercent() + 5)
end end
if progressRect:getPercent() < 100 then if progressRect:getPercent() < 100 then
@ -78,6 +78,7 @@ function onSpellCooldown(iconId, duration)
local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId] local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId]
if not spellName then return end if not spellName then return end
local duration = duration - (g_game.getPing()/2)
local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon) local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon)
if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then
otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1] otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1]
@ -102,6 +103,7 @@ end
function onSpellGroupCooldown(groupId, duration) function onSpellGroupCooldown(groupId, duration)
if not SpellGroups[groupId] then return end if not SpellGroups[groupId] then return end
local duration = duration - (g_game.getPing()/2)
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId]) local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId]) local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
if icon then if icon then

View File

@ -95,9 +95,12 @@ function bindKeys()
end end
function terminate() function terminate()
disconnect(g_game, { onGameStart = show, disconnect(g_game, {
onGameStart = show,
onGameEnd = hide, onGameEnd = hide,
onLoginAdvice = onLoginAdvice }) onLoginAdvice = onLoginAdvice
})
disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange }) disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton:destroy() logoutButton:destroy()
@ -475,6 +478,8 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
g_game.attack(creatureThing) g_game.attack(creatureThing)
return true return true
end end
-- classic control
else else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
@ -493,7 +498,7 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
startUseWith(useThing) startUseWith(useThing)
return true return true
else else
g_game.use(multiUseThing) g_game.use(useThing)
end end
return true return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then

View File

@ -35,7 +35,6 @@ function init()
minimapWindow:setContentMaximumHeight(256) minimapWindow:setContentMaximumHeight(256)
minimapWidget = minimapWindow:recursiveGetChildById('minimap') minimapWidget = minimapWindow:recursiveGetChildById('minimap')
--g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseRightButton)
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton) g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton)
minimapWidget:setAutoViewMode(false) minimapWidget:setAutoViewMode(false)
@ -293,15 +292,18 @@ function isClickInRange(position, fromPosition, toPosition)
return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y) return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y)
end end
function reset() function reset(zoom)
if zoom == nil then zoom = true end
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if not player then return end if not player then return end
minimapWidget:followCreature(player) minimapWidget:followCreature(player)
if zoom then
minimapWidget:setZoom(DEFAULT_ZOOM) minimapWidget:setZoom(DEFAULT_ZOOM)
end
end end
function center() function center()
reset() reset(false)
updateMapFlags() updateMapFlags()
end end
@ -319,10 +321,11 @@ function compassClick(self, mousePos, mouseButton, elapsed)
dx = dx/radius dx = dx/radius
dy = dy/radius dy = dy/radius
if dx > 0.5 then movex = 1 end local speed = math.ceil(minimapWidget:getZoom()/22)
if dx < -0.5 then movex = -1 end if dx > 0.5 then movex = speed end
if dy > 0.5 then movey = -1 end if dx < -0.5 then movex = -speed end
if dy < -0.5 then movey = 1 end if dy > 0.5 then movey = -speed end
if dy < -0.5 then movey = speed end
local cameraPos = minimapWidget:getCameraPosition() local cameraPos = minimapWidget:getCameraPosition()
local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z} local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z}
@ -331,23 +334,39 @@ function compassClick(self, mousePos, mouseButton, elapsed)
updateMapFlags() updateMapFlags()
end end
function onButtonClick(id) function miniMapZoomIn(zoom)
if id == "zoomIn" then minimapWidget:setZoom(math.max(minimapWidget:getMaxZoomIn(), minimapWidget:getZoom()-zoom))
minimapWidget:setZoom(math.max(minimapWidget:getMaxZoomIn(), minimapWidget:getZoom()-15)) end
elseif id == "zoomOut" then
minimapWidget:setZoom(math.min(minimapWidget:getMaxZoomOut(), minimapWidget:getZoom()+15)) function miniMapZoomOut(zoom)
elseif id == "floorUp" then minimapWidget:setZoom(math.min(minimapWidget:getMaxZoomOut(), minimapWidget:getZoom()+zoom))
end
function minimapFloorUp(floors)
local pos = minimapWidget:getCameraPosition() local pos = minimapWidget:getCameraPosition()
pos.z = pos.z - 1 pos.z = pos.z - floors
if pos.z > MAX_FLOOR_UP then if pos.z > MAX_FLOOR_UP then
minimapWidget:setCameraPosition(pos) minimapWidget:setCameraPosition(pos)
end end
elseif id == "floorDown" then end
function minimapFloorDown(floors)
local pos = minimapWidget:getCameraPosition() local pos = minimapWidget:getCameraPosition()
pos.z = pos.z + 1 pos.z = pos.z + floors
if pos.z < MAX_FLOOR_DOWN then if pos.z < MAX_FLOOR_DOWN then
minimapWidget:setCameraPosition(pos) minimapWidget:setCameraPosition(pos)
end end
end
function onButtonClick(id)
if id == "zoomIn" then
miniMapZoomIn(20)
elseif id == "zoomOut" then
miniMapZoomOut(20)
elseif id == "floorUp" then
minimapFloorUp(1)
elseif id == "floorDown" then
minimapFloorDown(1)
end end
updateMapFlags() updateMapFlags()
@ -375,10 +394,16 @@ function onMinimapMouseRelease(self, mousePosition, mouseButton)
end end
function onMinimapMouseWheel(self, mousePos, direction) function onMinimapMouseWheel(self, mousePos, direction)
if direction == MouseWheelUp then local keyboardModifiers = g_keyboard.getModifiers()
self:zoomIn()
else if direction == MouseWheelUp and keyboardModifiers == KeyboardNoModifier then
self:zoomOut() miniMapZoomIn(10)
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardNoModifier then
miniMapZoomOut(10)
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardCtrlModifier then
minimapFloorUp(1)
elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then
minimapFloorDown(1)
end end
updateMapFlags() updateMapFlags()
end end

View File

@ -41,7 +41,6 @@ function init()
searchText = npcWindow:recursiveGetChildById('searchText') searchText = npcWindow:recursiveGetChildById('searchText')
setupPanel = npcWindow:recursiveGetChildById('setupPanel') setupPanel = npcWindow:recursiveGetChildById('setupPanel')
quantityLabel = setupPanel:getChildById('quantity')
quantityScroll = setupPanel:getChildById('quantityScroll') quantityScroll = setupPanel:getChildById('quantityScroll')
nameLabel = setupPanel:getChildById('name') nameLabel = setupPanel:getChildById('name')
priceLabel = setupPanel:getChildById('price') priceLabel = setupPanel:getChildById('price')
@ -117,8 +116,7 @@ function onItemBoxChecked(widget)
end end
function onQuantityValueChange(quantity) function onQuantityValueChange(quantity)
if quantityLabel and selectedItem then if selectedItem then
quantityLabel:setText(quantity)
weightLabel:setText(string.format('%.2f', selectedItem.weight*quantity) .. ' ' .. WEIGHT_UNIT) weightLabel:setText(string.format('%.2f', selectedItem.weight*quantity) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(getItemPrice(selectedItem) .. ' ' .. CURRENCY) priceLabel:setText(getItemPrice(selectedItem) .. ' ' .. CURRENCY)
end end
@ -191,7 +189,6 @@ function clearSelectedItem()
nameLabel:clearText() nameLabel:clearText()
weightLabel:clearText() weightLabel:clearText()
priceLabel:clearText() priceLabel:clearText()
quantityLabel:clearText()
tradeButton:disable() tradeButton:disable()
quantityScroll:setMaximum(1) quantityScroll:setMaximum(1)
if selectedItem then if selectedItem then
@ -208,17 +205,22 @@ function getCurrentTradeType()
end end
end end
function getItemPrice(item) function getItemPrice(item, single)
local amount = 1
local single = single or false
if not single then
amount = quantityScroll:getValue()
end
if getCurrentTradeType() == BUY then if getCurrentTradeType() == BUY then
if buyWithBackpack:isChecked() then if buyWithBackpack:isChecked() then
if item.ptr:isStackable() then if item.ptr:isStackable() then
return item.price*quantityScroll:getValue() + 20; return item.price*amount + 20
else else
return item.price*quantityScroll:getValue() + math.ceil(quantityScroll:getValue()/20)*20 return item.price*amount + math.ceil(amount/20)*20
end end
end end
end end
return item.price*quantityScroll:getValue() return item.price*amount
end end
function getSellQuantity(item) function getSellQuantity(item)
@ -241,7 +243,7 @@ end
function canTradeItem(item) function canTradeItem(item)
if getCurrentTradeType() == BUY then if getCurrentTradeType() == BUY then
return (ignoreCapacity:isChecked() or (not ignoreCapacity:isChecked() and playerFreeCapacity >= item.weight)) and playerMoney >= getItemPrice(item) return (ignoreCapacity:isChecked() or (not ignoreCapacity:isChecked() and playerFreeCapacity >= item.weight)) and playerMoney >= getItemPrice(item, true)
else else
return getSellQuantity(item) > 0 return getSellQuantity(item) > 0
end end
@ -252,16 +254,18 @@ function refreshItem(item)
weightLabel:setText(string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT) weightLabel:setText(string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(getItemPrice(item) .. ' ' .. CURRENCY) priceLabel:setText(getItemPrice(item) .. ' ' .. CURRENCY)
quantityLabel:setText(1)
quantityScroll:setValue(1)
if getCurrentTradeType() == BUY then if getCurrentTradeType() == BUY then
local capacityMaxCount = math.floor(playerFreeCapacity / item.weight) local capacityMaxCount = math.floor(playerFreeCapacity / item.weight)
if ignoreCapacity:isChecked() then if ignoreCapacity:isChecked() then
capacityMaxCount = 100 capacityMaxCount = 100
end end
local priceMaxCount = math.floor(playerMoney / getItemPrice(item)) local priceMaxCount = math.floor(playerMoney / getItemPrice(item, true))
quantityScroll:setMaximum(math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount)))) local finalCount = math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount)))
quantityScroll:setMaximum(finalCount)
if quantityScroll:getValue() > finalCount then
quantityScroll:setValue(finalCount)
end
else else
local removeAmount = 0 local removeAmount = 0
if ignoreEquipped:isChecked() then if ignoreEquipped:isChecked() then
@ -413,7 +417,7 @@ function onFreeCapacityChange(localPlayer, freeCapacity, oldFreeCapacity)
end end
end end
function onInventoryChange(inventory, item, oldeItem) function onInventoryChange(inventory, item, oldItem)
if selectedItem then if selectedItem then
refreshItem(selectedItem) refreshItem(selectedItem)
end end

View File

@ -69,7 +69,7 @@ MainWindow
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
step: 16 step: 24
pixels-scroll: true pixels-scroll: true
ScrollablePanel ScrollablePanel
@ -154,17 +154,6 @@ MainWindow
NPCOfferLabel NPCOfferLabel
id: capacity id: capacity
Label
!text: tr('Quantity:')
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 5
margin-left: 5
width: 85
NPCOfferLabel
id: quantity
HorizontalScrollBar HorizontalScrollBar
id: quantityScroll id: quantityScroll
anchors.left: parent.left anchors.left: parent.left
@ -173,6 +162,7 @@ MainWindow
margin-top: 5 margin-top: 5
margin-left: 5 margin-left: 5
margin-right: 5 margin-right: 5
show-value: true
minimum: 1 minimum: 1
maximum: 100 maximum: 100
step: 1 step: 1

View File

@ -314,3 +314,21 @@ SpellGroups = {
[3] = 'Support', [3] = 'Support',
[4] = 'Special' [4] = 'Special'
} }
Spells = {}
function Spells.getSpellByName(name)
return SpellInfo[name:lower():trim()]
end
function Spells.getSpellByWords(words)
local words = words:lower():trim()
for i,category in pairs(SpellInfo) do
for k,spell in pairs(category) do
if spell.words == words then
return spell
end
end
end
return nil
end

View File

@ -862,7 +862,14 @@ void Game::cancelAttackAndFollow()
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
if(isFollowing())
setFollowingCreature(nullptr);
if(isAttacking())
setAttackingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow(); m_protocolGame->sendCancelAttackAndFollow();
g_lua.callGlobalField("g_game", "onCancelAttackAndFollow");
} }
void Game::talk(const std::string& message) void Game::talk(const std::string& message)