tibia-client/modules/game_interface/gameinterface.lua

807 lines
27 KiB
Lua
Raw Normal View History

WALK_STEPS_RETRY = 10
gameRootPanel = nil
gameMapPanel = nil
gameRightPanel = nil
gameLeftPanel = nil
gameBottomPanel = nil
logoutButton = nil
mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
bottomSplitter = nil
2013-11-12 23:35:05 +01:00
limitedZoom = false
2013-01-24 20:15:07 +01:00
currentViewMode = 0
2013-01-26 21:10:30 +01:00
smartWalkDirs = {}
smartWalkDir = nil
walkFunction = nil
function init()
g_ui.importStyle('styles/countwindow')
2012-06-26 00:13:30 +02:00
connect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
onLoginAdvice = onLoginAdvice,
}, true)
gameRootPanel = g_ui.displayUI('gameinterface')
gameRootPanel:hide()
gameRootPanel:lower()
gameRootPanel.onGeometryChange = updateStretchShrink
2013-01-26 23:12:00 +01:00
gameRootPanel.onFocusChange = stopSmartWalk
mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
bottomSplitter = gameRootPanel:getChildById('bottomSplitter')
gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
2012-06-21 21:31:22 +02:00
connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'),
'/images/topbuttons/logout', tryLogout, true)
2013-01-24 20:15:07 +01:00
setupViewMode(0)
bindKeys()
load()
if g_game.isOnline() then
show()
end
end
function bindKeys()
2014-03-12 06:39:20 +01:00
gameRootPanel:setAutoRepeatDelay(200)
bindWalkKey('Up', North)
bindWalkKey('Right', East)
bindWalkKey('Down', South)
bindWalkKey('Left', West)
bindWalkKey('Numpad8', North)
bindWalkKey('Numpad9', NorthEast)
bindWalkKey('Numpad6', East)
bindWalkKey('Numpad3', SouthEast)
bindWalkKey('Numpad2', South)
bindWalkKey('Numpad1', SouthWest)
bindWalkKey('Numpad4', West)
bindWalkKey('Numpad7', NorthWest)
g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+Q', function() tryLogout(false) end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+L', function() tryLogout(false) end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
2013-01-24 20:15:07 +01:00
g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel)
2012-01-13 01:31:39 +01:00
end
function bindWalkKey(key, dir)
g_keyboard.bindKeyDown(key, function() changeWalkDir(dir) end, gameRootPanel, true)
g_keyboard.bindKeyUp(key, function() changeWalkDir(dir, true) end, gameRootPanel, true)
g_keyboard.bindKeyPress(key, function() smartWalk(dir) end, gameRootPanel)
end
function unbindWalkKey(key)
g_keyboard.unbindKeyDown(key, gameRootPanel)
g_keyboard.unbindKeyUp(key, gameRootPanel)
g_keyboard.unbindKeyPress(key, gameRootPanel)
end
function terminate()
save()
2013-01-18 19:49:41 +01:00
hide()
2013-01-26 23:12:00 +01:00
stopSmartWalk()
2013-01-26 21:10:30 +01:00
disconnect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
onLoginAdvice = onLoginAdvice
})
2012-06-21 21:31:22 +02:00
disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton:destroy()
gameRootPanel:destroy()
2012-01-13 01:31:39 +01:00
end
function onGameStart()
show()
-- open tibia has delay in auto walking
if not g_game.isOfficialTibia() then
g_game.enableFeature(GameForceFirstAutoWalkStep)
else
g_game.disableFeature(GameForceFirstAutoWalkStep)
end
end
function onGameEnd()
2013-01-26 23:40:07 +01:00
setupViewMode(0)
hide()
end
function show()
connect(g_app, { onClose = tryExit })
modules.client_background.hide()
gameRootPanel:show()
gameRootPanel:focus()
gameMapPanel:followCreature(g_game.getLocalPlayer())
2013-02-04 22:40:12 +01:00
setupViewMode(0)
updateStretchShrink()
logoutButton:setTooltip(tr('Logout'))
2013-11-12 23:35:05 +01:00
addEvent(function()
if not limitedZoom or g_game.isGM() then
gameMapPanel:setMaxZoomOut(513)
gameMapPanel:setLimitVisibleRange(false)
else
gameMapPanel:setMaxZoomOut(11)
gameMapPanel:setLimitVisibleRange(true)
end
end)
end
2012-01-12 02:21:59 +01:00
function hide()
disconnect(g_app, { onClose = tryExit })
logoutButton:setTooltip(tr('Exit'))
if logoutWindow then
logoutWindow:destroy()
logoutWindow = nil
end
if exitWindow then
exitWindow:destroy()
exitWindow = nil
end
2012-07-15 16:28:15 +02:00
if countWindow then
countWindow:destroy()
countWindow = nil
end
gameRootPanel:hide()
modules.client_background.show()
end
2012-01-12 02:21:59 +01:00
function save()
local settings = {}
settings.splitterMarginBottom = bottomSplitter:getMarginBottom()
g_settings.setNode('game_interface', settings)
end
function load()
local settings = g_settings.getNode('game_interface')
if settings then
if settings.splitterMarginBottom then
bottomSplitter:setMarginBottom(settings.splitterMarginBottom)
end
end
end
2012-09-05 21:53:48 +02:00
function onLoginAdvice(message)
2013-01-21 00:17:56 +01:00
displayInfoBox(tr("For Your Information"), message)
2012-09-05 21:53:48 +02:00
end
function forceExit()
g_game.cancelLogin()
2012-08-10 01:21:14 +02:00
scheduleEvent(exit, 10)
return true
2012-01-09 21:54:37 +01:00
end
function tryExit()
if exitWindow then
return true
end
2013-03-14 00:55:20 +01:00
local exitFunc = function() g_game.safeLogout() forceExit() end
local logoutFunc = function() g_game.safeLogout() exitWindow:destroy() exitWindow = nil end
2012-08-13 01:27:41 +02:00
local cancelFunc = function() exitWindow:destroy() exitWindow = nil end
2013-01-21 00:17:56 +01:00
exitWindow = displayGeneralBox(tr('Exit'), tr("If you shut down the program, your character might stay in the game.\nClick on 'Logout' to ensure that you character leaves the game properly.\nClick on 'Exit' if you want to exit the program without logging out your character."),
{ { text=tr('Force Exit'), callback=exitFunc },
{ text=tr('Logout'), callback=logoutFunc },
{ text=tr('Cancel'), callback=cancelFunc },
anchor=AnchorHorizontalCenter }, logoutFunc, cancelFunc)
2012-07-15 16:28:15 +02:00
2012-08-13 01:27:41 +02:00
return true
end
function tryLogout(prompt)
if type(prompt) ~= "boolean" then
prompt = true
end
if not g_game.isOnline() then
exit()
2013-03-11 18:57:59 +01:00
return
end
if logoutWindow then
return
end
local msg, yesCallback
2013-03-14 00:55:20 +01:00
if not g_game.isConnectionOk() then
msg = 'Your connection is failing, if you logout now your character will be still online, do you want to force logout?'
yesCallback = function()
2013-03-14 00:55:20 +01:00
g_game.forceLogout()
2013-03-14 01:18:17 +01:00
if logoutWindow then
logoutWindow:destroy()
logoutWindow=nil
end
2013-03-14 00:55:20 +01:00
end
else
msg = 'Are you sure you want to logout?'
yesCallback = function()
2013-03-14 00:55:20 +01:00
g_game.safeLogout()
if logoutWindow then
logoutWindow:destroy()
logoutWindow=nil
end
2013-03-14 00:55:20 +01:00
end
end
2012-07-15 16:28:15 +02:00
local noCallback = function()
logoutWindow:destroy()
logoutWindow=nil
end
if prompt then
logoutWindow = displayGeneralBox(tr('Logout'), tr(msg), {
2013-03-14 00:55:20 +01:00
{ text=tr('Yes'), callback=yesCallback },
{ text=tr('No'), callback=noCallback },
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
else
yesCallback()
2013-03-14 00:55:20 +01:00
end
end
2013-01-26 23:12:00 +01:00
function stopSmartWalk()
2013-01-26 21:10:30 +01:00
smartWalkDirs = {}
2013-01-27 00:18:07 +01:00
smartWalkDir = nil
end
2013-01-26 21:10:30 +01:00
function changeWalkDir(dir, pop)
2013-01-26 23:12:00 +01:00
while table.removevalue(smartWalkDirs, dir) do end
2013-01-26 21:10:30 +01:00
if pop then
2013-01-26 23:12:00 +01:00
if #smartWalkDirs == 0 then
stopSmartWalk()
return
end
2013-01-26 21:10:30 +01:00
else
table.insert(smartWalkDirs, 1, dir)
end
2013-01-26 21:10:30 +01:00
smartWalkDir = smartWalkDirs[1]
if modules.client_options.getOption('smartWalk') and #smartWalkDirs > 1 then
for _,d in pairs(smartWalkDirs) do
if (smartWalkDir == North and d == West) or (smartWalkDir == West and d == North) then
smartWalkDir = NorthWest
break
elseif (smartWalkDir == North and d == East) or (smartWalkDir == East and d == North) then
smartWalkDir = NorthEast
break
elseif (smartWalkDir == South and d == West) or (smartWalkDir == West and d == South) then
smartWalkDir = SouthWest
break
elseif (smartWalkDir == South and d == East) or (smartWalkDir == East and d == South) then
smartWalkDir = SouthEast
break
end
end
end
2013-01-26 21:10:30 +01:00
end
2013-01-27 00:18:07 +01:00
function smartWalk(dir)
if g_keyboard.getModifiers() == KeyboardNoModifier then
local func = walkFunction
if not func then
if modules.client_options.getOption('dashWalk') then
func = g_game.dashWalk
else
func = g_game.walk
end
2013-01-27 00:18:07 +01:00
end
local dire = smartWalkDir or dir
func(dire)
2013-01-27 00:18:07 +01:00
return true
end
2013-01-27 00:18:07 +01:00
return false
end
2013-01-26 21:10:30 +01:00
function updateStretchShrink()
2013-01-24 20:15:07 +01:00
if modules.client_options.getOption('dontStretchShrink') and not alternativeView then
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
2013-01-24 20:15:07 +01:00
-- Set gameMapPanel size to height = 11 * 32 + 2
bottomSplitter:setMarginBottom(bottomSplitter:getMarginBottom() + (gameMapPanel:getHeight() - 32 * 11) - 10)
end
end
function onMouseGrabberRelease(self, mousePosition, mouseButton)
if selectedThing == nil then return false end
if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then
if selectedType == 'use' then
onUseWith(clickedWidget, mousePosition)
elseif selectedType == 'trade' then
onTradeWith(clickedWidget, mousePosition)
end
end
end
2012-04-25 00:09:48 +02:00
selectedThing = nil
2013-01-25 14:47:51 +01:00
g_mouse.popCursor('target')
self:ungrabMouse()
return true
end
function onUseWith(clickedWidget, mousePosition)
2012-04-25 00:09:48 +02:00
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.useWith(selectedThing, tile:getTopMultiUseThing())
2012-04-25 00:09:48 +02:00
end
2012-08-17 23:36:53 +02:00
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(selectedThing, clickedWidget:getItem())
elseif clickedWidget:getClassName() == 'UICreatureButton' then
local creature = clickedWidget:getCreature()
if creature then
g_game.useWith(selectedThing, creature)
end
2012-04-25 00:09:48 +02:00
end
end
function onTradeWith(clickedWidget, mousePosition)
2012-04-25 00:09:48 +02:00
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.requestTrade(selectedThing, tile:getTopCreature())
2012-04-25 00:09:48 +02:00
end
end
end
function startUseWith(thing)
if not thing then return end
if g_ui.isMouseGrabbed() then
if selectedThing then
selectedThing = thing
selectedType = 'use'
end
return
end
selectedType = 'use'
selectedThing = thing
2012-04-25 00:09:48 +02:00
mouseGrabberWidget:grabMouse()
2013-01-25 14:47:51 +01:00
g_mouse.pushCursor('target')
2012-04-25 00:09:48 +02:00
end
function startTradeWith(thing)
if not thing then return end
if g_ui.isMouseGrabbed() then
if selectedThing then
selectedThing = thing
selectedType = 'trade'
end
return
end
selectedType = 'trade'
selectedThing = thing
mouseGrabberWidget:grabMouse()
2013-01-25 14:47:51 +01:00
g_mouse.pushCursor('target')
end
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
2012-07-26 08:10:28 +02:00
if not g_game.isOnline() then return end
2012-06-26 00:13:30 +02:00
local menu = g_ui.createWidget('PopupMenu')
local classic = modules.client_options.getOption('classicControl')
local shortcut = nil
2012-01-12 02:21:59 +01:00
if not classic then shortcut = '(Shift)' else shortcut = nil end
2012-01-04 14:02:35 +01:00
if lookThing then
menu:addOption(tr('Look'), function() g_game.look(lookThing) end, shortcut)
2012-01-04 14:02:35 +01:00
end
2012-01-03 21:41:00 +01:00
if not classic then shortcut = '(Ctrl)' else shortcut = nil end
2012-01-04 14:02:35 +01:00
if useThing then
if useThing:isContainer() then
if useThing:getParentContainer() then
menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end, shortcut)
2012-06-26 00:13:30 +02:00
menu:addOption(tr('Open in new window'), function() g_game.open(useThing) end)
2012-01-13 01:31:39 +01:00
else
menu:addOption(tr('Open'), function() g_game.open(useThing) end, shortcut)
2012-01-13 01:31:39 +01:00
end
else
2012-01-04 14:02:35 +01:00
if useThing:isMultiUse() then
menu:addOption(tr('Use with ...'), function() startUseWith(useThing) end, shortcut)
else
menu:addOption(tr('Use'), function() g_game.use(useThing) end, shortcut)
end
end
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if useThing:isRotateable() then
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
end
2012-01-12 02:21:59 +01:00
end
2012-01-12 02:21:59 +01:00
if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
menu:addSeparator()
menu:addOption(tr('Trade with ...'), function() startTradeWith(lookThing) end)
2012-01-04 14:02:35 +01:00
end
2012-01-12 02:21:59 +01:00
if lookThing then
local parentContainer = lookThing:getParentContainer()
if parentContainer and parentContainer:hasParent() then
menu:addOption(tr('Move up'), function() g_game.moveToParentContainer(lookThing, lookThing:getCount()) end)
end
end
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if creatureThing then
local localPlayer = g_game.getLocalPlayer()
menu:addSeparator()
2012-01-12 02:21:59 +01:00
if creatureThing:isLocalPlayer() then
menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end)
2012-01-12 02:21:59 +01:00
if g_game.getFeature(GamePlayerMounts) then
if not localPlayer:isMounted() then
menu:addOption(tr('Mount'), function() localPlayer:mount() end)
else
menu:addOption(tr('Dismount'), function() localPlayer:dismount() end)
end
end
if creatureThing:isPartyMember() then
if creatureThing:isPartyLeader() then
if creatureThing:isPartySharedExperienceActive() then
menu:addOption(tr('Disable Shared Experience'), function() g_game.partyShareExperience(false) end)
else
menu:addOption(tr('Enable Shared Experience'), function() g_game.partyShareExperience(true) end)
end
end
menu:addOption(tr('Leave Party'), function() g_game.partyLeave() end)
end
2012-01-12 02:21:59 +01:00
else
local localPosition = localPlayer:getPosition()
if not classic then shortcut = '(Alt)' else shortcut = nil end
if creatureThing:getPosition().z == localPosition.z then
if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end, shortcut)
else
menu:addOption(tr('Stop Attack'), function() g_game.cancelAttack() end, shortcut)
end
if g_game.getFollowingCreature() ~= creatureThing then
menu:addOption(tr('Follow'), function() g_game.follow(creatureThing) end)
else
menu:addOption(tr('Stop Follow'), function() g_game.cancelFollow() end)
end
2012-07-26 08:10:28 +02:00
end
2012-01-12 02:21:59 +01:00
if creatureThing:isPlayer() then
2012-07-26 08:10:28 +02:00
menu:addSeparator()
local creatureName = creatureThing:getName()
menu:addOption(tr('Message to %s', creatureName), function() g_game.openPrivateChannel(creatureName) end)
if modules.game_console.getOwnPrivateTab() then
menu:addOption(tr('Invite to private chat'), function() g_game.inviteToOwnChannel(creatureName) end)
menu:addOption(tr('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end) -- [TODO] must be removed after message's popup labels been implemented
2012-01-07 23:24:29 +01:00
end
if not localPlayer:hasVip(creatureName) then
2012-07-26 08:10:28 +02:00
menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end)
end
2013-01-26 21:10:30 +01:00
if modules.game_console.isIgnored(creatureName) then
menu:addOption(tr('Unignore') .. ' ' .. creatureName, function() modules.game_console.removeIgnoredPlayer(creatureName) end)
else
menu:addOption(tr('Ignore') .. ' ' .. creatureName, function() modules.game_console.addIgnoredPlayer(creatureName) end)
end
2012-07-26 08:10:28 +02:00
2012-08-02 12:12:54 +02:00
local localPlayerShield = localPlayer:getShield()
2012-07-26 08:10:28 +02:00
local creatureShield = creatureThing:getShield()
2012-01-12 02:21:59 +01:00
2012-07-26 08:10:28 +02:00
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
if creatureShield == ShieldWhiteYellow then
menu:addOption(tr('Join %s\'s Party', creatureThing:getName()), function() g_game.partyJoin(creatureThing:getId()) end)
else
menu:addOption(tr('Invite to Party'), function() g_game.partyInvite(creatureThing:getId()) end)
end
2012-07-26 08:10:28 +02:00
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
end
2012-07-26 08:10:28 +02:00
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
if creatureShield == ShieldWhiteBlue then
menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
menu:addOption(tr('Pass Leadership to %s', creatureThing:getName()), function() g_game.partyPassLeadership(creatureThing:getId()) end)
else
menu:addOption(tr('Invite to Party'), function() g_game.partyInvite(creatureThing:getId()) end)
end
end
2012-01-05 15:24:38 +01:00
end
end
if modules.game_ruleviolation.hasWindowAccess() and creatureThing:isPlayer() then
menu:addSeparator()
menu:addOption(tr('Rule Violation'), function() modules.game_ruleviolation.show(creatureThing:getName()) end)
end
menu:addSeparator()
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
2012-01-03 21:41:00 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-03 21:41:00 +01:00
menu:display(menuPosition)
end
2012-01-13 01:31:39 +01:00
function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, attackCreature)
2012-06-26 00:13:30 +02:00
local keyboardModifiers = g_keyboard.getModifiers()
if not modules.client_options.getOption('classicControl') then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
if useThing:isContainer() then
if useThing:getParentContainer() then
g_game.open(useThing, useThing:getParentContainer())
else
2012-06-26 00:13:30 +02:00
g_game.open(useThing)
end
return true
elseif useThing:isMultiUse() then
startUseWith(useThing)
return true
else
g_game.use(useThing)
return true
end
return true
elseif attackCreature and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(creatureThing)
return true
end
-- classic control
else
if useThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
local player = g_game.getLocalPlayer()
if attackCreature and attackCreature ~= player then
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing ~= player and creatureThing:getPosition().z == autoWalkPos.z then
2012-08-02 03:47:55 +02:00
g_game.attack(creatureThing)
return true
elseif useThing:isContainer() then
if useThing:getParentContainer() then
g_game.open(useThing, useThing:getParentContainer())
return true
else
g_game.open(useThing)
return true
end
elseif useThing:isMultiUse() then
startUseWith(useThing)
return true
else
g_game.use(useThing)
2013-01-25 21:51:14 +01:00
return true
end
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.look(lookThing)
return true
elseif lookThing and ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or (g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
g_game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
elseif attackCreature and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(creatureThing)
return true
end
end
local player = g_game.getLocalPlayer()
player:stopAutoWalk()
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
player:autoWalk(autoWalkPos)
2013-01-08 18:59:03 +01:00
return true
end
return false
end
function moveStackableItem(item, toPos)
if countWindow then
return
end
2012-06-26 00:13:30 +02:00
if g_keyboard.isCtrlPressed() then
g_game.move(item, toPos, item:getCount())
return
2012-06-26 00:13:30 +02:00
elseif g_keyboard.isShiftPressed() then
g_game.move(item, toPos, 1)
return
end
local count = item:getCount()
2013-01-08 18:59:03 +01:00
countWindow = g_ui.createWidget('CountWindow', rootWidget)
2013-01-08 18:59:03 +01:00
local itembox = countWindow:getChildById('item')
local scrollbar = countWindow:getChildById('countScrollBar')
2013-01-08 18:59:03 +01:00
itembox:setItemId(item:getId())
itembox:setItemCount(count)
scrollbar:setMaximum(count)
scrollbar:setMinimum(1)
scrollbar:setValue(count)
2013-01-08 18:59:03 +01:00
local spinbox = countWindow:getChildById('spinBox')
spinbox:setMaximum(count)
spinbox:setMinimum(0)
spinbox:setValue(0)
spinbox:hideButtons()
spinbox:focus()
2013-02-01 02:21:20 +01:00
spinbox.firstEdit = true
2013-01-08 18:59:03 +01:00
local spinBoxValueChange = function(self, value)
2013-02-01 02:31:09 +01:00
spinbox.firstEdit = false
scrollbar:setValue(value)
end
spinbox.onValueChange = spinBoxValueChange
2013-02-01 02:21:20 +01:00
local check = function()
if spinbox.firstEdit then
spinbox:setValue(spinbox:getMaximum())
spinbox.firstEdit = false
end
end
g_keyboard.bindKeyPress("Up", function() check() spinbox:up() end, spinbox)
g_keyboard.bindKeyPress("Down", function() check() spinbox:down() end, spinbox)
g_keyboard.bindKeyPress("Right", function() check() spinbox:up() end, spinbox)
g_keyboard.bindKeyPress("Left", function() check() spinbox:down() end, spinbox)
2013-02-01 02:21:20 +01:00
g_keyboard.bindKeyPress("PageUp", function() check() spinbox:setValue(spinbox:getValue()+10) end, spinbox)
g_keyboard.bindKeyPress("PageDown", function() check() spinbox:setValue(spinbox:getValue()-10) end, spinbox)
scrollbar.onValueChange = function(self, value)
2013-01-08 18:59:03 +01:00
itembox:setItemCount(value)
spinbox.onValueChange = nil
2012-09-02 01:16:17 +02:00
spinbox:setValue(value)
spinbox.onValueChange = spinBoxValueChange
end
local okButton = countWindow:getChildById('buttonOk')
local moveFunc = function()
2013-01-08 18:59:03 +01:00
g_game.move(item, toPos, itembox:getItemCount())
okButton:getParent():destroy()
countWindow = nil
end
local cancelButton = countWindow:getChildById('buttonCancel')
local cancelFunc = function()
cancelButton:getParent():destroy()
countWindow = nil
end
countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc
2012-07-15 16:28:15 +02:00
okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
end
function getRootPanel()
return gameRootPanel
end
function getMapPanel()
return gameMapPanel
end
function getRightPanel()
return gameRightPanel
end
function getLeftPanel()
return gameLeftPanel
end
function getBottomPanel()
return gameBottomPanel
end
2012-07-24 07:41:59 +02:00
function onLeftPanelVisibilityChange(leftPanel, visible)
2013-01-25 21:28:44 +01:00
if not visible and g_game.isOnline() then
local children = leftPanel:getChildren()
for i=1,#children do
children[i]:setParent(gameRightPanel)
end
end
end
2013-01-24 20:15:07 +01:00
function nextViewMode()
setupViewMode((currentViewMode + 1) % 3)
end
function setupViewMode(mode)
if mode == currentViewMode then return end
if currentViewMode == 2 then
gameMapPanel:addAnchor(AnchorLeft, 'gameLeftPanel', AnchorRight)
gameMapPanel:addAnchor(AnchorRight, 'gameRightPanel', AnchorLeft)
gameMapPanel:addAnchor(AnchorBottom, 'gameBottomPanel', AnchorTop)
gameRootPanel:addAnchor(AnchorTop, 'topMenu', AnchorBottom)
2013-01-25 20:26:51 +01:00
gameLeftPanel:setOn(modules.client_options.getOption('showLeftPanel'))
gameLeftPanel:setImageColor('white')
gameRightPanel:setImageColor('white')
gameLeftPanel:setMarginTop(0)
gameRightPanel:setMarginTop(0)
gameBottomPanel:setImageColor('white')
modules.client_topmenu.getTopMenu():setImageColor('white')
g_game.changeMapAwareRange(18, 14)
end
2013-01-24 20:15:07 +01:00
if mode == 0 then
gameMapPanel:setKeepAspectRatio(true)
gameMapPanel:setLimitVisibleRange(false)
gameMapPanel:setZoom(11)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
elseif mode == 1 then
gameMapPanel:setKeepAspectRatio(false)
gameMapPanel:setLimitVisibleRange(true)
gameMapPanel:setZoom(11)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
elseif mode == 2 then
2013-11-12 23:35:05 +01:00
local limit = limitedZoom and not g_game.isGM()
2013-02-04 22:40:12 +01:00
gameMapPanel:setLimitVisibleRange(limit)
2013-01-24 20:15:07 +01:00
gameMapPanel:setZoom(11)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
gameMapPanel:fill('parent')
gameRootPanel:fill('parent')
gameLeftPanel:setImageColor('alpha')
gameRightPanel:setImageColor('alpha')
gameLeftPanel:setMarginTop(modules.client_topmenu.getTopMenu()
:getHeight() - gameLeftPanel:getPaddingTop())
gameRightPanel:setMarginTop(modules.client_topmenu.getTopMenu()
:getHeight() - gameRightPanel:getPaddingTop())
2013-01-24 20:15:07 +01:00
gameLeftPanel:setOn(true)
gameLeftPanel:setVisible(true)
gameRightPanel:setOn(true)
2013-01-25 20:26:51 +01:00
gameMapPanel:setOn(true)
gameBottomPanel:setImageColor('#ffffff88')
2013-01-24 20:15:07 +01:00
modules.client_topmenu.getTopMenu():setImageColor('#ffffff66')
2013-02-04 22:40:12 +01:00
if not limit then
2013-01-24 20:15:07 +01:00
g_game.changeMapAwareRange(24, 20)
end
end
currentViewMode = mode
end
function limitZoom()
2013-11-12 23:35:05 +01:00
limitedZoom = true
2013-02-04 22:40:12 +01:00
end