mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
restore some game functionallity
* i'm gradually restoring game functionality with the new modules design, though still a lot to do * you can reload all scripts and modules using Ctrl+R shortcut while playing (finally! this is the reason of all this rework) * a bunch of fixes, but new regression too :P * fix performance issue that could lead freezes in the client in older machines * completely new game module with new design * fix crashs in map render * remove uigame.cpp (now every game input is via lua) * enable DEBUG macro by default, with it you are able to view any possible lua leak while running
This commit is contained in:
90
modules/old/game/game.lua
Normal file
90
modules/old/game/game.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
-- private variables
|
||||
local m_mouseGrabberWidget
|
||||
|
||||
-- private functions
|
||||
local function onGameKeyPress(self, keyCode, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardCtrlModifier then
|
||||
if keyCode == KeyG then
|
||||
CharacterList.show()
|
||||
return true
|
||||
elseif keyCode == KeyQ then
|
||||
g_game.safeLogout()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function onUseWithMouseRelease(self, mousePosition, mouseButton)
|
||||
if g_game.selectedThing == nil then return false end
|
||||
if mouseButton == MouseLeftButton then
|
||||
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
|
||||
if clickedWidget then
|
||||
if clickedWidget:getClassName() == 'UIMap' then
|
||||
local tile = clickedWidget:getTile(mousePosition)
|
||||
if tile then
|
||||
g_game.useWith(g_game.selectedThing, tile:getTopMultiUseThing())
|
||||
end
|
||||
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
||||
g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
|
||||
elseif clickedWidget.isBattleButton then
|
||||
g_game.useWith(g_game.selectedThing, clickedWidget.creature)
|
||||
end
|
||||
end
|
||||
end
|
||||
g_game.selectedThing = nil
|
||||
Mouse.restoreCursor()
|
||||
self:ungrabMouse()
|
||||
return true
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function g_game.startUseWith(thing)
|
||||
g_game.selectedThing = thing
|
||||
m_mouseGrabberWidget:grabMouse()
|
||||
Mouse.setTargetCursor()
|
||||
end
|
||||
|
||||
function g_game.createInterface()
|
||||
|
||||
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 g_game.destroyInterface()
|
||||
if g_game.gameUi then
|
||||
g_game.gameUi:destroy()
|
||||
g_game.gameUi = nil
|
||||
end
|
||||
Background.show()
|
||||
CharacterList.show()
|
||||
end
|
||||
|
||||
function g_game.show()
|
||||
g_game.gameUi:show()
|
||||
g_game.gameUi:focus()
|
||||
g_game.gameMapPanel:focus()
|
||||
end
|
||||
|
||||
function g_game.hide()
|
||||
g_game.gameUi:hide()
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
|
||||
local function onApplicationClose()
|
||||
if g_game.isOnline() then
|
||||
g_game.forceLogout()
|
||||
else
|
||||
exit()
|
||||
end
|
||||
end
|
||||
|
||||
setonclose(onApplicationClose)
|
||||
connect(g_game, { onGameStart = g_game.createInterface }, true)
|
||||
connect(g_game, { onGameEnd = g_game.destroyInterface })
|
17
modules/old/game/game.otmod
Normal file
17
modules/old/game/game.otmod
Normal file
@@ -0,0 +1,17 @@
|
||||
Module
|
||||
name: game
|
||||
description: Create the game interface, where the ingame stuff starts
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
reloadable: true
|
||||
|
||||
dependencies:
|
||||
- game_tibiafiles
|
||||
//- game_shaders
|
||||
|
||||
onLoad: |
|
||||
dofile 'game'
|
||||
dofile 'thing'
|
||||
dofile 'creature'
|
||||
dofile 'player'
|
||||
dofile 'map'
|
33
modules/old/game/game.otui
Normal file
33
modules/old/game/game.otui
Normal file
@@ -0,0 +1,33 @@
|
||||
UIGame
|
||||
id: gameRootInterface
|
||||
anchors.fill: parent
|
||||
anchors.top: topMenu.bottom
|
||||
|
||||
InterfacePanel
|
||||
id: gameRightPanel
|
||||
width: 178
|
||||
layout: verticalBox
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
InterfacePanel2
|
||||
id: gameBottomPanel
|
||||
height: 170
|
||||
anchors.left: parent.left
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
Map
|
||||
id: gameMapPanel
|
||||
anchors.left: parent.left
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: gameBottomPanel.top
|
||||
focusable: false
|
||||
|
||||
UIWidget
|
||||
id: mouseGrabber
|
||||
focusable: false
|
||||
visible: false
|
||||
|
57
modules/old/game/map.lua
Normal file
57
modules/old/game/map.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
function UIMap:onDragEnter(mousePos)
|
||||
local tile = self:getTile(mousePos)
|
||||
if not tile then return false end
|
||||
|
||||
local thing = tile:getTopMoveThing()
|
||||
if not thing then return false end
|
||||
|
||||
self.parsed = false
|
||||
self.currentDragThing = thing
|
||||
Mouse.setTargetCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onDragLeave(droppedWidget, mousePos)
|
||||
if not self.parsed then
|
||||
self.currentDragThing = nil
|
||||
end
|
||||
|
||||
Mouse.restoreCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onDrop(widget, mousePos)
|
||||
if not widget or not widget.currentDragThing then return false end
|
||||
|
||||
local tile = self:getTile(mousePos)
|
||||
if not tile then return false end
|
||||
|
||||
local count = widget.currentDragThing:getCount()
|
||||
if widget.currentDragThing:isStackable() and count > 1 then
|
||||
widget.parsed = true
|
||||
local moveWindow = displayUI('/game/movewindow.otui')
|
||||
local spinbox = moveWindow:getChildById('spinbox')
|
||||
spinbox:setMaximum(count)
|
||||
spinbox:setMinimum(1)
|
||||
spinbox:setCurrentIndex(count)
|
||||
|
||||
local okButton = moveWindow:getChildById('buttonOk')
|
||||
okButton.onClick = function()
|
||||
g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex())
|
||||
okButton:getParent():destroy()
|
||||
widget.currentDragThing = nil
|
||||
end
|
||||
moveWindow.onEnter = okButton.onClick
|
||||
else
|
||||
g_game.move(widget.currentDragThing, tile:getPosition(), 1)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMap:onMouseRelease(mousePosition, mouseButton)
|
||||
local tile = self:getTile(mousePosition)
|
||||
if tile and g_game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
|
||||
return false
|
||||
end
|
||||
|
40
modules/old/game/movewindow.otui
Normal file
40
modules/old/game/movewindow.otui
Normal file
@@ -0,0 +1,40 @@
|
||||
CountWindow < MainWindow
|
||||
text: Move Item
|
||||
size: 196 112
|
||||
@onEscape: self:destroy()
|
||||
|
||||
Label
|
||||
text: Amount:
|
||||
width: 64
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin-top: 2
|
||||
|
||||
SpinBox
|
||||
id: spinbox
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
|
||||
HorizontalSeparator
|
||||
id: separator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.top
|
||||
margin-bottom: 10
|
||||
|
||||
Button
|
||||
id: buttonOk
|
||||
text: Ok
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 10
|
||||
|
||||
Button
|
||||
id: buttonCancel
|
||||
text: Cancel
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
@onClick: self:getParent():destroy()
|
31
modules/old/game/player.lua
Normal file
31
modules/old/game/player.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
function Player:isPartyLeader()
|
||||
local shield = self:getShield()
|
||||
return (shield == ShieldWhiteYellow or
|
||||
shield == ShieldYellow or
|
||||
shield == ShieldYellowSharedExp or
|
||||
shield == ShieldYellowNoSharedExpBlink or
|
||||
shield == ShieldYellowNoSharedExp)
|
||||
end
|
||||
|
||||
function Player:isPartyMember()
|
||||
local shield = self:getShield()
|
||||
return (shield == ShieldWhiteYellow or
|
||||
shield == ShieldYellow or
|
||||
shield == ShieldYellowSharedExp or
|
||||
shield == ShieldYellowNoSharedExpBlink or
|
||||
shield == ShieldYellowNoSharedExp or
|
||||
shield == ShieldBlueSharedExp or
|
||||
shield == ShieldBlueNoSharedExpBlink or
|
||||
shield == ShieldBlueNoSharedExp or
|
||||
shield == ShieldBlue)
|
||||
end
|
||||
|
||||
function Player:isPartySharedExperienceActive()
|
||||
local shield = self:getShield()
|
||||
return (shield == ShieldYellowSharedExp or
|
||||
shield == ShieldYellowNoSharedExpBlink or
|
||||
shield == ShieldYellowNoSharedExp or
|
||||
shield == ShieldBlueSharedExp or
|
||||
shield == ShieldBlueNoSharedExpBlink or
|
||||
shield == ShieldBlueNoSharedExp)
|
||||
end
|
193
modules/old/game/thing.lua
Normal file
193
modules/old/game/thing.lua
Normal file
@@ -0,0 +1,193 @@
|
||||
|
||||
function Thing:isInsideContainer()
|
||||
local pos = self:getPosition()
|
||||
return (pos and pos.x == 65535 and pos.y >= 64)
|
||||
end
|
||||
|
||||
function Thing:getContainerId()
|
||||
local pos = self:getPosition()
|
||||
if not pos then return 0 end
|
||||
return pos.y - 64
|
||||
end
|
||||
|
||||
-- public functions
|
||||
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
|
||||
-- todo auto walk
|
||||
return true
|
||||
end
|
||||
|
||||
if not Options.classicControl then
|
||||
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||
g_game.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:isInsideContainer() then
|
||||
g_game.open(useThing, useThing:getContainerId())
|
||||
return true
|
||||
else
|
||||
g_game.open(useThing, Containers.getFreeContainerId())
|
||||
return true
|
||||
end
|
||||
elseif useThing:isMultiUse() then
|
||||
g_game.startUseWith(useThing)
|
||||
return true
|
||||
else
|
||||
g_game.use(useThing)
|
||||
return true
|
||||
end
|
||||
return true
|
||||
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
g_game.attack(creatureThing)
|
||||
return true
|
||||
end
|
||||
else
|
||||
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||
if multiUseThing:asCreature() then
|
||||
g_game.attack(multiUseThing:asCreature())
|
||||
return true
|
||||
elseif multiUseThing:isContainer() then
|
||||
if multiUseThing:isInsideContainer() then
|
||||
g_game.open(multiUseThing, multiUseThing:getContainerId())
|
||||
return true
|
||||
else
|
||||
g_game.open(multiUseThing, Containers.getFreeContainerId())
|
||||
return true
|
||||
end
|
||||
elseif multiUseThing:isMultiUse() then
|
||||
g_game.startUseWith(multiUseThing)
|
||||
return true
|
||||
else
|
||||
g_game.use(multiUseThing)
|
||||
end
|
||||
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
|
||||
g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
return true
|
||||
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
g_game.attack(creatureThing)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
local menu = createWidget('PopupMenu')
|
||||
|
||||
if lookThing then
|
||||
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() 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() g_game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
end
|
||||
else
|
||||
if useThing:isMultiUse() then
|
||||
menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
|
||||
else
|
||||
menu:addOption('Use', function() g_game.use(useThing) end)
|
||||
end
|
||||
end
|
||||
|
||||
if useThing:isRotateable() then
|
||||
menu:addOption('Rotate', function() g_game.rotate(useThing) end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
|
||||
menu:addSeparator()
|
||||
menu:addOption('Trade with ...', function() print('trade with') end)
|
||||
end
|
||||
|
||||
-- check for move up
|
||||
|
||||
if creatureThing then
|
||||
menu:addSeparator()
|
||||
|
||||
if creatureThing:asLocalPlayer() then
|
||||
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() g_game.partyShareExperience(false) end)
|
||||
else
|
||||
menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
|
||||
end
|
||||
end
|
||||
menu:addOption('Leave Party', function() g_game.partyLeave() end)
|
||||
end
|
||||
|
||||
else
|
||||
local localPlayer = g_game.getLocalPlayer()
|
||||
if localPlayer then
|
||||
if g_game.getAttackingCreature() ~= creatureThing then
|
||||
menu:addOption('Attack', function() g_game.attack(creatureThing) end)
|
||||
else
|
||||
menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
|
||||
end
|
||||
|
||||
if g_game.getFollowingCreature() ~= creatureThing then
|
||||
menu:addOption('Follow', function() g_game.follow(creatureThing) end)
|
||||
else
|
||||
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() g_game.addVip(creatureThing:getName()) end)
|
||||
menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
|
||||
|
||||
local localPlayerShield = localPlayer:asCreature():getShield()
|
||||
local creatureShield = creatureThing:getShield()
|
||||
|
||||
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
|
||||
if creatureShield == ShieldWhiteYellow then
|
||||
menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end)
|
||||
else
|
||||
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() 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() 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() g_game.partyPassLeadership(creatureThing:getId()) end)
|
||||
else
|
||||
menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
menu:addSeparator()
|
||||
menu:addOption('Copy Name', function() g_window.setClipboardText(creatureThing:getName()) end)
|
||||
|
||||
end
|
||||
|
||||
menu:display(menuPosition)
|
||||
end
|
||||
|
Reference in New Issue
Block a user