mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 07:26:49 +01:00
reaname and cleanup many stuff
This commit is contained in:
@@ -8,7 +8,7 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
|
||||
CharacterList.show()
|
||||
return true
|
||||
elseif keyCode == KeyQ then
|
||||
Game.safeLogout()
|
||||
g_game.safeLogout()
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -16,97 +16,97 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
|
||||
end
|
||||
|
||||
local function onUseWithMouseRelease(self, mousePosition, mouseButton)
|
||||
if Game.selectedThing == nil then return false end
|
||||
if g_game.selectedThing == nil then return false end
|
||||
if mouseButton == MouseLeftButton then
|
||||
local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition)
|
||||
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
|
||||
if clickedWidget then
|
||||
if clickedWidget:getClassName() == 'UIMap' then
|
||||
local tile = clickedWidget:getTile(mousePosition)
|
||||
if tile then
|
||||
Game.useWith(Game.selectedThing, tile:getTopMultiUseThing())
|
||||
g_game.useWith(g_game.selectedThing, tile:getTopMultiUseThing())
|
||||
end
|
||||
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
||||
Game.useWith(Game.selectedThing, clickedWidget:getItem())
|
||||
g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
|
||||
end
|
||||
end
|
||||
end
|
||||
Game.selectedThing = nil
|
||||
g_game.selectedThing = nil
|
||||
Mouse.restoreCursor()
|
||||
self:ungrabMouse()
|
||||
return true
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Game.startUseWith(thing)
|
||||
Game.selectedThing = thing
|
||||
function g_game.startUseWith(thing)
|
||||
g_game.selectedThing = thing
|
||||
m_mouseGrabberWidget:grabMouse()
|
||||
Mouse.setTargetCursor()
|
||||
end
|
||||
|
||||
function Game.createInterface()
|
||||
function g_game.createInterface()
|
||||
Background.hide()
|
||||
CharacterList.destroyLoadBox()
|
||||
Game.gameUi = displayUI('game.otui')
|
||||
g_game.gameUi = displayUI('game.otui')
|
||||
|
||||
--Keyboard.bindKeyPress('Up', function() Game.walk(North) end)
|
||||
--Keyboard.bindKeyPress('Down', function() Game.walk(South) end)
|
||||
--Keyboard.bindKeyPress('Left', function() Game.walk(West) end)
|
||||
--Keyboard.bindKeyPress('Right', function() Game.walk(East) end)
|
||||
--Keyboard.bindKeyPress('Up', function() g_game.walk(North) end)
|
||||
--Keyboard.bindKeyPress('Down', function() g_game.walk(South) end)
|
||||
--Keyboard.bindKeyPress('Left', function() g_game.walk(West) end)
|
||||
--Keyboard.bindKeyPress('Right', function() g_game.walk(East) end)
|
||||
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end)
|
||||
Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end)
|
||||
|
||||
rootWidget:moveChildToIndex(Game.gameUi, 1)
|
||||
Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')
|
||||
Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel')
|
||||
Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel')
|
||||
m_mouseGrabberWidget = Game.gameUi:getChildById('mouseGrabber')
|
||||
connect(Game.gameUi, { onKeyPress = onGameKeyPress })
|
||||
rootWidget:moveChildToIndex(g_game.gameUi, 1)
|
||||
g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
|
||||
g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel')
|
||||
g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel')
|
||||
m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
|
||||
connect(g_game.gameUi, { onKeyPress = onGameKeyPress })
|
||||
connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
|
||||
end
|
||||
|
||||
function Game.destroyInterface()
|
||||
if Game.gameUi then
|
||||
Game.gameUi:destroy()
|
||||
Game.gameUi = nil
|
||||
function g_game.destroyInterface()
|
||||
if g_game.gameUi then
|
||||
g_game.gameUi:destroy()
|
||||
g_game.gameUi = nil
|
||||
end
|
||||
Background.show()
|
||||
CharacterList.show()
|
||||
end
|
||||
|
||||
function Game.show()
|
||||
Game.gameUi:show()
|
||||
Game.gameUi:focus()
|
||||
Game.gameMapPanel:focus()
|
||||
function g_game.show()
|
||||
g_game.gameUi:show()
|
||||
g_game.gameUi:focus()
|
||||
g_game.gameMapPanel:focus()
|
||||
end
|
||||
|
||||
function Game.hide()
|
||||
Game.gameUi:hide()
|
||||
function g_game.hide()
|
||||
g_game.gameUi:hide()
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Game.onLoginError(message)
|
||||
function g_game.onLoginError(message)
|
||||
CharacterList.destroyLoadBox()
|
||||
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
|
||||
connect(errorBox, { onOk = CharacterList.show })
|
||||
end
|
||||
|
||||
function Game.onConnectionError(message)
|
||||
function g_game.onConnectionError(message)
|
||||
CharacterList.destroyLoadBox()
|
||||
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
|
||||
connect(errorBox, { onOk = CharacterList.show })
|
||||
end
|
||||
|
||||
local function onApplicationClose()
|
||||
if Game.isOnline() then
|
||||
Game.forceLogout()
|
||||
if g_game.isOnline() then
|
||||
g_game.forceLogout()
|
||||
else
|
||||
exit()
|
||||
end
|
||||
end
|
||||
|
||||
setonclose(onApplicationClose)
|
||||
connect(Game, { onGameStart = Game.createInterface }, true)
|
||||
connect(Game, { onGameEnd = Game.destroyInterface })
|
||||
connect(g_game, { onGameStart = g_game.createInterface }, true)
|
||||
connect(g_game, { onGameEnd = g_game.destroyInterface })
|
||||
|
||||
@@ -36,10 +36,10 @@ function UIMap:onDrop(widget, mousePos)
|
||||
spinbox:setCurrentIndex(count)
|
||||
|
||||
local okButton = moveWindow:getChildById('buttonOk')
|
||||
okButton.onClick = function() Game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
|
||||
okButton.onClick = function() g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
|
||||
moveWindow.onEnter = okButton.onClick
|
||||
else
|
||||
Game.move(widget.currentDragThing, tile:getPosition(), 1)
|
||||
g_game.move(widget.currentDragThing, tile:getPosition(), 1)
|
||||
end
|
||||
|
||||
return true
|
||||
@@ -47,7 +47,7 @@ end
|
||||
|
||||
function UIMap:onMouseRelease(mousePosition, mouseButton)
|
||||
local tile = self:getTile(mousePosition)
|
||||
if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
|
||||
if tile and g_game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ function Thing:getContainerId()
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
|
||||
function g_game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
|
||||
local keyboardModifiers = g_window.getKeyboardModifiers()
|
||||
|
||||
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
||||
@@ -21,60 +21,60 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
|
||||
|
||||
if not Options.classicControl then
|
||||
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
return true
|
||||
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
Game.look(lookThing)
|
||||
g_game.look(lookThing)
|
||||
return true
|
||||
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
if useThing:isContainer() then
|
||||
if useThing:isInsideContainer() then
|
||||
Game.open(useThing, useThing:getContainerId())
|
||||
g_game.open(useThing, useThing:getContainerId())
|
||||
return true
|
||||
else
|
||||
Game.open(useThing, Containers.getFreeContainerId())
|
||||
g_game.open(useThing, Containers.getFreeContainerId())
|
||||
return true
|
||||
end
|
||||
elseif useThing:isMultiUse() then
|
||||
Game.startUseWith(useThing)
|
||||
g_game.startUseWith(useThing)
|
||||
return true
|
||||
else
|
||||
Game.use(useThing)
|
||||
g_game.use(useThing)
|
||||
return true
|
||||
end
|
||||
return true
|
||||
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
Game.attack(creatureThing)
|
||||
g_game.attack(creatureThing)
|
||||
return true
|
||||
end
|
||||
else
|
||||
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||
if multiUseThing:asCreature() then
|
||||
Game.attack(multiUseThing:asCreature())
|
||||
g_game.attack(multiUseThing:asCreature())
|
||||
return true
|
||||
elseif multiUseThing:isContainer() then
|
||||
if multiUseThing:isInsideContainer() then
|
||||
Game.open(multiUseThing, multiUseThing:getContainerId())
|
||||
g_game.open(multiUseThing, multiUseThing:getContainerId())
|
||||
return true
|
||||
else
|
||||
Game.open(multiUseThing, Containers.getFreeContainerId())
|
||||
g_game.open(multiUseThing, Containers.getFreeContainerId())
|
||||
return true
|
||||
end
|
||||
elseif multiUseThing:isMultiUse() then
|
||||
Game.startUseWith(multiUseThing)
|
||||
g_game.startUseWith(multiUseThing)
|
||||
return true
|
||||
else
|
||||
Game.use(multiUseThing)
|
||||
g_game.use(multiUseThing)
|
||||
end
|
||||
return true
|
||||
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
Game.look(lookThing)
|
||||
g_game.look(lookThing)
|
||||
return true
|
||||
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
return true
|
||||
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
Game.attack(creatureThing)
|
||||
g_game.attack(creatureThing)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -83,31 +83,31 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
|
||||
end
|
||||
|
||||
|
||||
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
function g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
local menu = createWidget('PopupMenu')
|
||||
|
||||
if lookThing then
|
||||
menu:addOption('Look', function() Game.look(lookThing) end)
|
||||
menu:addOption('Look', function() g_game.look(lookThing) end)
|
||||
end
|
||||
|
||||
if useThing then
|
||||
if useThing:isContainer() then
|
||||
if useThing:isInsideContainer() then
|
||||
menu:addOption('Open', function() Game.open(useThing, useThing:getContainerId()) end)
|
||||
menu:addOption('Open in new window', function() Game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
|
||||
menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
else
|
||||
menu:addOption('Open', function() Game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
end
|
||||
else
|
||||
if useThing:isMultiUse() then
|
||||
menu:addOption('Use with ...', function() Game.startUseWith(useThing) end)
|
||||
menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
|
||||
else
|
||||
menu:addOption('Use', function() Game.use(useThing) end)
|
||||
menu:addOption('Use', function() g_game.use(useThing) end)
|
||||
end
|
||||
end
|
||||
|
||||
if useThing:isRotateable() then
|
||||
menu:addOption('Rotate', function() Game.rotate(useThing) end)
|
||||
menu:addOption('Rotate', function() g_game.rotate(useThing) end)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -123,38 +123,38 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
menu:addSeparator()
|
||||
|
||||
if creatureThing:asLocalPlayer() then
|
||||
menu:addOption('Set Outfit', function() Game.requestOutfit() end)
|
||||
menu:addOption('Set Outfit', function() g_game.requestOutfit() end)
|
||||
|
||||
if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
|
||||
if creatureThing:asPlayer():isPartyLeader() then
|
||||
if creatureThing:asPlayer():isPartySharedExperienceActive() then
|
||||
menu:addOption('Disable Shared Experience', function() Game.partyShareExperience(false) end)
|
||||
menu:addOption('Disable Shared Experience', function() g_game.partyShareExperience(false) end)
|
||||
else
|
||||
menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end)
|
||||
menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
|
||||
end
|
||||
end
|
||||
menu:addOption('Leave Party', function() Game.partyLeave() end)
|
||||
menu:addOption('Leave Party', function() g_game.partyLeave() end)
|
||||
end
|
||||
|
||||
else
|
||||
local localPlayer = Game.getLocalPlayer()
|
||||
local localPlayer = g_game.getLocalPlayer()
|
||||
if localPlayer then
|
||||
if localPlayer:getAttackingCreature() ~= creatureThing then
|
||||
menu:addOption('Attack', function() Game.attack(creatureThing) end)
|
||||
if g_game.getAttackingCreature() ~= creatureThing then
|
||||
menu:addOption('Attack', function() g_game.attack(creatureThing) end)
|
||||
else
|
||||
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
|
||||
menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
|
||||
end
|
||||
|
||||
if localPlayer:getFollowingCreature() ~= creatureThing then
|
||||
menu:addOption('Follow', function() Game.follow(creatureThing) end)
|
||||
if g_game.getFollowingCreature() ~= creatureThing then
|
||||
menu:addOption('Follow', function() g_game.follow(creatureThing) end)
|
||||
else
|
||||
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
|
||||
menu:addOption('Stop Follow', function() g_game.cancelFollow() end)
|
||||
end
|
||||
|
||||
if creatureThing:asPlayer() then
|
||||
menu:addSeparator()
|
||||
menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
|
||||
menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end)
|
||||
menu:addOption('Add to VIP list', function() g_game.addVip(creatureThing:getName()) end)
|
||||
menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
|
||||
|
||||
local localPlayerShield = localPlayer:asCreature():getShield()
|
||||
@@ -162,21 +162,21 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
|
||||
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
|
||||
if creatureShield == ShieldWhiteYellow then
|
||||
menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() Game.partyJoin(creatureThing:getId()) end)
|
||||
menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end)
|
||||
else
|
||||
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
|
||||
menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
|
||||
end
|
||||
elseif localPlayerShield == ShieldWhiteYellow then
|
||||
if creatureShield == ShieldWhiteBlue then
|
||||
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
|
||||
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
|
||||
end
|
||||
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
|
||||
if creatureShield == ShieldWhiteBlue then
|
||||
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
|
||||
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
|
||||
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
|
||||
menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() Game.partyPassLeadership(creatureThing:getId()) end)
|
||||
menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() g_game.partyPassLeadership(creatureThing:getId()) end)
|
||||
else
|
||||
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
|
||||
menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user