Version 0.95 BETA

This commit is contained in:
OTCv8
2019-10-02 03:38:52 +02:00
parent 9219c78f15
commit 5220a3bdd2
501 changed files with 38097 additions and 2 deletions

View File

@@ -0,0 +1,940 @@
gameRootPanel = nil
gameMapPanel = nil
gameRightPanels = nil
gameLeftPanels = nil
gameBottomPanel = nil
logoutButton = nil
mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
bottomSplitter = nil
limitedZoom = false
hookedMenuOptions = {}
lastDirTime = g_clock.millis()
function init()
g_ui.importStyle('styles/countwindow')
connect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
onLoginAdvice = onLoginAdvice,
}, true)
-- Call load AFTER game window has been created and
-- resized to a stable state, otherwise the saved
-- settings can get overridden by false onGeometryChange
-- events
connect(g_app, {
onRun = load,
onExit = save
})
gameRootPanel = g_ui.displayUI('gameinterface')
gameRootPanel:hide()
gameRootPanel:lower()
gameRootPanel.onGeometryChange = updateStretchShrink
mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
bottomSplitter = gameRootPanel:getChildById('bottomSplitter')
gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
gameRightPanels = gameRootPanel:getChildById('gameRightPanels')
gameLeftPanels = gameRootPanel:getChildById('gameLeftPanels')
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'),
'/images/topbuttons/logout', tryLogout, true)
gameRightPanels:addChild(g_ui.createWidget('GameSidePanel'))
refreshViewMode()
bindKeys()
connect(gameMapPanel, { onGeometryChange = updateSize, onVisibleDimensionChange = updateSize })
connect(g_game, { onMapChangeAwareRange = updateSize })
if g_game.isOnline() then
show()
end
end
function bindKeys()
gameRootPanel:setAutoRepeatDelay(20)
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+=', function() if g_game.getFeature(GameNoDebug) then return end gameMapPanel:zoomIn() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+-', function() if g_game.getFeature(GameNoDebug) then return end 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)
end
function terminate()
hide()
hookedMenuOptions = {}
markThing = nil
disconnect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
onLoginAdvice = onLoginAdvice
})
disconnect(gameMapPanel, { onGeometryChange = updateSize })
connect(gameMapPanel, { onGeometryChange = updateSize, onVisibleDimensionChange = updateSize })
logoutButton:destroy()
gameRootPanel:destroy()
end
function onGameStart()
refreshViewMode()
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()
hide()
modules.client_topmenu.getTopMenu():setImageColor('white')
end
function show()
connect(g_app, { onClose = tryExit })
modules.client_background.hide()
gameRootPanel:show()
gameRootPanel:focus()
gameMapPanel:followCreature(g_game.getLocalPlayer())
updateStretchShrink()
logoutButton:setTooltip(tr('Logout'))
addEvent(function()
if not limitedZoom or g_game.isGM() then
gameMapPanel:setMaxZoomOut(513)
gameMapPanel:setLimitVisibleRange(false)
else
gameMapPanel:setMaxZoomOut(15)
gameMapPanel:setLimitVisibleRange(true)
end
end)
end
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
if countWindow then
countWindow:destroy()
countWindow = nil
end
gameRootPanel:hide()
modules.client_background.show()
end
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
function onLoginAdvice(message)
displayInfoBox(tr("For Your Information"), message)
end
function forceExit()
g_game.cancelLogin()
scheduleEvent(exit, 10)
return true
end
function tryExit()
if exitWindow then
return true
end
local exitFunc = function() g_game.safeLogout() forceExit() end
local logoutFunc = function() g_game.safeLogout() exitWindow:destroy() exitWindow = nil end
local cancelFunc = function() exitWindow:destroy() exitWindow = nil end
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)
return true
end
function tryLogout(prompt)
if type(prompt) ~= "boolean" then
prompt = true
end
if not g_game.isOnline() then
exit()
return
end
if logoutWindow then
return
end
local msg, yesCallback
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()
g_game.forceLogout()
if logoutWindow then
logoutWindow:destroy()
logoutWindow=nil
end
end
else
msg = 'Are you sure you want to logout?'
yesCallback = function()
g_game.safeLogout()
if logoutWindow then
logoutWindow:destroy()
logoutWindow=nil
end
end
end
local noCallback = function()
logoutWindow:destroy()
logoutWindow=nil
end
if prompt then
logoutWindow = displayGeneralBox(tr('Logout'), tr(msg), {
{ text=tr('Yes'), callback=yesCallback },
{ text=tr('No'), callback=noCallback },
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
else
yesCallback()
end
end
function updateStretchShrink()
if modules.client_options.getOption('dontStretchShrink') and not alternativeView then
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
-- 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
selectedThing = nil
g_mouse.popCursor('target')
self:ungrabMouse()
gameMapPanel:blockNextMouseRelease(true)
return true
end
function onUseWith(clickedWidget, mousePosition)
if clickedWidget:getClassName() == 'UIGameMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
if selectedThing:isFluidContainer() then
g_game.useWith(selectedThing, tile:getTopMultiUseThing(), selectedSubtype)
else
g_game.useWith(selectedThing, tile:getTopUseThing(), selectedSubtype)
end
end
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(selectedThing, clickedWidget:getItem(), selectedSubtype)
elseif clickedWidget:getClassName() == 'UICreatureButton' then
local creature = clickedWidget:getCreature()
if creature then
g_game.useWith(selectedThing, creature, selectedSubtype)
end
end
end
function onTradeWith(clickedWidget, mousePosition)
if clickedWidget:getClassName() == 'UIGameMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.requestTrade(selectedThing, tile:getTopCreatureEx(clickedWidget:getPositionOffset(mousePosition)))
end
elseif clickedWidget:getClassName() == 'UICreatureButton' then
local creature = clickedWidget:getCreature()
if creature then
g_game.requestTrade(selectedThing, creature)
end
end
end
function startUseWith(thing, subType)
gameMapPanel:blockNextMouseRelease()
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
selectedSubtype = subType or 0
mouseGrabberWidget:grabMouse()
g_mouse.pushCursor('target')
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()
g_mouse.pushCursor('target')
end
function isMenuHookCategoryEmpty(category)
if category then
for _,opt in pairs(category) do
if opt then return false end
end
end
return true
end
function addMenuHook(category, name, callback, condition, shortcut)
if not hookedMenuOptions[category] then
hookedMenuOptions[category] = {}
end
hookedMenuOptions[category][name] = {
callback = callback,
condition = condition,
shortcut = shortcut
}
end
function removeMenuHook(category, name)
if not name then
hookedMenuOptions[category] = {}
else
hookedMenuOptions[category][name] = nil
end
end
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if not g_game.isOnline() then return end
local menu = g_ui.createWidget('PopupMenu')
menu:setGameMenu(true)
local classic = modules.client_options.getOption('classicControl')
local shortcut = nil
if not classic then shortcut = '(Shift)' else shortcut = nil end
if lookThing then
menu:addOption(tr('Look'), function() g_game.look(lookThing) end, shortcut)
end
if not classic then shortcut = '(Ctrl)' else shortcut = nil end
if useThing then
if useThing:isContainer() then
if useThing:getParentContainer() then
menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end, shortcut)
menu:addOption(tr('Open in new window'), function() g_game.open(useThing) end)
else
menu:addOption(tr('Open'), function() g_game.open(useThing) end, shortcut)
end
else
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
if useThing:isRotateable() then
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
end
if g_game.getFeature(GameBrowseField) and useThing:getPosition().x ~= 0xffff then
menu:addOption(tr('Browse Field'), function() g_game.browseField(useThing:getPosition()) end)
end
end
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)
end
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
if creatureThing then
local localPlayer = g_game.getLocalPlayer()
menu:addSeparator()
if creatureThing:isLocalPlayer() then
menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end)
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
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
end
if creatureThing:isPlayer() then
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
end
if not localPlayer:hasVip(creatureName) then
menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end)
end
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
local localPlayerShield = localPlayer:getShield()
local creatureShield = creatureThing:getShield()
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
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
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
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)
end
-- hooked menu options
for _,category in pairs(hookedMenuOptions) do
if not isMenuHookCategoryEmpty(category) then
menu:addSeparator()
for name,opt in pairs(category) do
if opt and opt.condition(menuPosition, lookThing, useThing, creatureThing) then
menu:addOption(name, function() opt.callback(menuPosition,
lookThing, useThing, creatureThing) end, opt.shortcut)
end
end
end
end
if g_game.getFeature(GameBot) and useThing then
menu:addSeparator()
menu:addOption(tr("ID: " .. useThing:getId()))
end
menu:display(menuPosition)
end
function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, attackCreature, marking)
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
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
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)
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
local autoWalkTile = g_map.getTile(autoWalkPos)
if autoWalkTile and not autoWalkTile:isWalkable(true) then
modules.game_textmessage.displayFailureMessage(tr('Sorry, not possible.'))
return false
end
player:autoWalk(autoWalkPos)
return true
end
return false
end
function moveStackableItem(item, toPos)
if countWindow then
return
end
if g_keyboard.isCtrlPressed() then
g_game.move(item, toPos, item:getCount())
return
elseif g_keyboard.isShiftPressed() then
g_game.move(item, toPos, 1)
return
end
local count = item:getCount()
countWindow = g_ui.createWidget('CountWindow', rootWidget)
local itembox = countWindow:getChildById('item')
local scrollbar = countWindow:getChildById('countScrollBar')
itembox:setItemId(item:getId())
itembox:setItemCount(count)
scrollbar:setMaximum(count)
scrollbar:setMinimum(1)
scrollbar:setValue(count)
local spinbox = countWindow:getChildById('spinBox')
spinbox:setMaximum(count)
spinbox:setMinimum(0)
spinbox:setValue(0)
spinbox:hideButtons()
spinbox:focus()
spinbox.firstEdit = true
local spinBoxValueChange = function(self, value)
spinbox.firstEdit = false
scrollbar:setValue(value)
end
spinbox.onValueChange = spinBoxValueChange
local check = function()
if spinbox.firstEdit then
spinbox:setValue(spinbox:getMaximum())
spinbox.firstEdit = false
end
end
local okButton = countWindow:getChildById('buttonOk')
local moveFunc = function()
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
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)
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)
g_keyboard.bindKeyPress("Enter", function() moveFunc() end, spinbox)
scrollbar.onValueChange = function(self, value)
itembox:setItemCount(value)
spinbox.onValueChange = nil
spinbox:setValue(value)
spinbox.onValueChange = spinBoxValueChange
end
countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc
okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
end
function getRootPanel()
return gameRootPanel
end
function getMapPanel()
return gameMapPanel
end
function getRightPanel()
if gameRightPanels:getChildCount() == 0 then
addRightPanel()
end
return gameRightPanels:getChildByIndex(-1)
end
function getContainerPanel()
local containerPanel = g_settings.getNumber("containerPanel")
if containerPanel >= 5 then
containerPanel = containerPanel - 4
return gameRightPanels:getChildByIndex(math.min(containerPanel, gameRightPanels:getChildCount()))
end
if gameLeftPanels:getChildCount() == 0 then
return getRightPanel()
end
return gameLeftPanels:getChildByIndex(math.min(containerPanel, gameLeftPanels:getChildCount()))
end
local function addRightPanel()
if gameRightPanels:getChildCount() >= 4 then
return
end
local panel = g_ui.createWidget('GameSidePanel')
panel:setId("rightPanel" .. (gameRightPanels:getChildCount() + 1))
gameRightPanels:insertChild(1, panel)
end
local function addLeftPanel()
if gameLeftPanels:getChildCount() >= 4 then
return
end
local panel = g_ui.createWidget('GameSidePanel')
panel:setId("leftPanel" .. (gameLeftPanels:getChildCount() + 1))
gameLeftPanels:addChild(panel)
end
local function removeRightPanel()
if gameRightPanels:getChildCount() <= 1 then
return
end
local panel = gameRightPanels:getChildByIndex(1)
panel:moveTo(gameRightPanels:getChildByIndex(2))
gameRightPanels:removeChild(panel)
end
local function removeLeftPanel()
if gameLeftPanels:getChildCount() == 0 then
return
end
local panel = gameLeftPanels:getChildByIndex(-1)
if gameLeftPanels:getChildCount() >= 2 then
panel:moveTo(gameLeftPanels:getChildByIndex(-2))
else
panel:moveTo(gameRightPanels:getChildByIndex(1))
end
gameLeftPanels:removeChild(panel)
end
function getBottomPanel()
return gameBottomPanel
end
function refreshViewMode()
local classic = g_settings.getBoolean("classicView")
local rightPanels = g_settings.getNumber("rightPanels") - gameRightPanels:getChildCount()
local leftPanels = g_settings.getNumber("leftPanels") - 1 - gameLeftPanels:getChildCount()
while rightPanels ~= 0 do
if rightPanels > 0 then
addRightPanel()
rightPanels = rightPanels - 1
else
removeRightPanel()
rightPanels = rightPanels + 1
end
end
while leftPanels ~= 0 do
if leftPanels > 0 then
addLeftPanel()
leftPanels = leftPanels - 1
else
removeLeftPanel()
leftPanels = leftPanels + 1
end
end
if not g_game.isOnline() then
return
end
local minimumWidth = (g_settings.getNumber("rightPanels") + g_settings.getNumber("leftPanels") - 1) * 200
if classic then
minimumWidth = minimumWidth + 300
end
minimumWidth = math.max(minimumWidth, 800)
g_window.setMinimumSize({ width = minimumWidth, height = 600 })
if g_window.getWidth() < minimumWidth then
local oldPos = g_window.getPosition()
local size = { width = minimumWidth, height = g_window.getHeight() }
g_window.resize(size)
g_window.move(oldPos)
end
for i=1,gameRightPanels:getChildCount()+gameLeftPanels:getChildCount() do
local panel
if i > gameRightPanels:getChildCount() then
panel = gameLeftPanels:getChildByIndex(i - gameRightPanels:getChildCount())
else
panel = gameRightPanels:getChildByIndex(i)
end
if classic then
panel:setImageColor('white')
else
panel:setImageColor('alpha')
end
end
if classic then
gameRightPanels:setMarginTop(0)
gameLeftPanels:setMarginTop(0)
gameMapPanel:setMarginLeft(0)
gameMapPanel:setMarginRight(0)
else
gameLeftPanels:setMarginTop(modules.client_topmenu.getTopMenu():getHeight() - gameLeftPanels:getPaddingTop())
gameRightPanels:setMarginTop(modules.client_topmenu.getTopMenu():getHeight() - gameRightPanels:getPaddingTop())
end
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
if classic then
gameRootPanel:addAnchor(AnchorTop, 'topMenu', AnchorBottom)
gameMapPanel:addAnchor(AnchorLeft, 'gameLeftPanels', AnchorRight)
gameMapPanel:addAnchor(AnchorRight, 'gameRightPanels', AnchorLeft)
gameMapPanel:addAnchor(AnchorBottom, 'gameBottomPanel', AnchorTop)
gameMapPanel:setKeepAspectRatio(true)
gameMapPanel:setLimitVisibleRange(false)
gameMapPanel:setZoom(11)
gameBottomPanel:addAnchor(AnchorLeft, 'gameLeftPanels', AnchorRight)
gameBottomPanel:addAnchor(AnchorRight, 'gameRightPanels', AnchorLeft)
bottomSplitter:addAnchor(AnchorLeft, 'gameLeftPanels', AnchorRight)
bottomSplitter:addAnchor(AnchorRight, 'gameRightPanels', AnchorLeft)
modules.client_topmenu.getTopMenu():setImageColor('white')
gameBottomPanel:setImageColor('white')
g_game.changeMapAwareRange(20, 16)
if modules.game_console then
modules.game_console.switchMode(false)
end
else
g_game.changeMapAwareRange(30, 20)
gameMapPanel:fill('parent')
gameRootPanel:fill('parent')
gameMapPanel:setKeepAspectRatio(false)
gameMapPanel:setLimitVisibleRange(false)
if g_game.getFeature(GameChangeMapAwareRange) then
gameMapPanel:setZoom(13)
else
gameMapPanel:setZoom(11)
end
gameBottomPanel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
gameBottomPanel:addAnchor(AnchorRight, 'parent', AnchorRight)
bottomSplitter:addAnchor(AnchorLeft, 'parent', AnchorLeft)
bottomSplitter:addAnchor(AnchorRight, 'parent', AnchorRight)
modules.client_topmenu.getTopMenu():setImageColor('#ffffff66')
if modules.game_console then
modules.game_console.switchMode(true)
end
end
end
function limitZoom()
limitedZoom = true
end
function updateSize()
local classic = g_settings.getBoolean("classicView")
local height = gameMapPanel:getHeight()
local width = gameMapPanel:getWidth()
if not classic and modules.game_console then
local newMargin = modules.game_console.consolePanel:getMarginLeft()
newMargin = math.max(0, newMargin)
newMargin = math.min(modules.game_console.consolePanel:getParent():getWidth() - modules.game_console.consolePanel:getWidth(), newMargin)
modules.game_console.consolePanel:setMarginLeft(newMargin)
end
if not classic then
local rheight = gameRootPanel:getHeight()
local rwidth = gameRootPanel:getWidth()
local dimenstion = gameMapPanel:getVisibleDimension()
local zoom = gameMapPanel:getZoom()
local awareRange = g_map.getAwareRange()
local dheight = dimenstion.height
local dwidth = dimenstion.width
local tileSize = rheight / dheight
local maxWidth = tileSize * (awareRange.width - 4)
local margin = math.max(0, math.floor((rwidth - maxWidth) / 2))
gameMapPanel:setMarginLeft(margin)
gameMapPanel:setMarginRight(margin)
end
--[[
local maxWidth = math.floor(height * 2)
local extraMargin = 0
if width >= maxWidth then
extraMargin = math.ceil((width - maxWidth) / 2)
end
local bottomMaxWidth = 1200 -- something broken, it's not pixels
local bottomMargin = 0
if width > bottomMaxWidth then
bottomMargin = math.ceil((width - bottomMaxWidth) / 2)
end
gameMapPanel:setMarginLeft(extraMargin)
gameMapPanel:setMarginRight(extraMargin) ]]
end

View File

@@ -0,0 +1,79 @@
GameSidePanel < UIMiniWindowContainer
image-source: /images/ui/panel_side
image-border: 4
padding: 4
padding-top: 0
width: 198
focusable: false
on: true
layout:
type: verticalBox
//spacing: 1
GameBottomPanel < Panel
GameMapPanel < UIGameMap
padding: 4
image-source: /images/ui/panel_map
image-border: 4
$on:
padding: 0
UIWidget
id: gameRootPanel
anchors.fill: parent
anchors.top: topMenu.bottom
GameMapPanel
id: gameMapPanel
anchors.left: gameLeftPanels.right
anchors.right: gameRightPanels.left
anchors.top: parent.top
anchors.bottom: gameBottomPanel.top
focusable: false
Panel
id: gameLeftPanels
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
focusable: false
layout:
type: horizontalBox
fit-children: true
spacing: -1
Panel
id: gameRightPanels
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
focusable: false
layout:
type: horizontalBox
fit-children: true
spacing: -1
GameBottomPanel
id: gameBottomPanel
anchors.left: gameLeftPanels.right
anchors.right: gameRightPanels.left
anchors.top: bottomSplitter.top
anchors.bottom: parent.bottom
Splitter
id: bottomSplitter
anchors.left: gameLeftPanels.right
anchors.right: gameRightPanels.left
anchors.bottom: parent.bottom
relative-margin: bottom
margin-bottom: 172
@canUpdateMargin: function(self, newMargin) if modules.client_options.getOption('dontStretchShrink') then return self:getMarginBottom() end return math.max(math.min(newMargin, self:getParent():getHeight() - 300), 100) end
@onGeometryChange: function(self) self:setMarginBottom(math.min(math.max(self:getParent():getHeight() - 300, 100), self:getMarginBottom())) end
UIWidget
id: mouseGrabber
focusable: false
visible: false

View File

@@ -0,0 +1,36 @@
Module
name: game_interface
description: Create the game interface, where the ingame stuff starts
author: OTClient team
website: https://github.com/edubart/otclient
sandboxed: true
scripts: [ widgets/uigamemap, widgets/uiitem, gameinterface ]
load-later:
- game_hotkeys
- game_questlog
- game_textmessage
- game_console
- game_outfit
- game_healthinfo
- game_skills
- game_inventory
- game_containers
- game_viplist
- game_battle
- game_minimap
- game_npctrade
- game_textwindow
- game_playertrade
- game_bugreport
- game_playerdeath
- game_playermount
- game_ruleviolation
- game_market
- game_spelllist
- game_cooldown
- game_modaldialog
- game_unjustifiedpoints
- game_walking
- game_shop
@onLoad: init()
@onUnload: terminate()

View File

@@ -0,0 +1,53 @@
CountWindow < MainWindow
id: countWindow
!text: tr('Move Stackable Item')
size: 196 90
SpinBox
id: spinBox
anchors.left: parent.left
anchors.top: parent.top
width: 1
height: 1
phantom: true
margin-top: 2
focusable: true
Item
id: item
anchors.left: parent.left
anchors.top: parent.top
margin-top: 2
margin-left: -4
focusable: false
virtual: true
HorizontalScrollBar
id: countScrollBar
anchors.left: prev.right
anchors.right: parent.right
anchors.top: prev.top
margin-left: 10
margin-top: -2
focusable: false
Button
id: buttonCancel
!text: tr('Cancel')
height: 20
anchors.left: countScrollBar.horizontalCenter
anchors.right: countScrollBar.right
anchors.top: countScrollBar.bottom
margin-top: 7
focusable: false
Button
id: buttonOk
!text: tr('Ok')
height: 20
anchors.right: countScrollBar.horizontalCenter
anchors.left: countScrollBar.left
anchors.top: countScrollBar.bottom
margin-top: 7
margin-right: 6
focusable: false

View File

@@ -0,0 +1,191 @@
UIGameMap = extends(UIMap, "UIGameMap")
function UIGameMap.create()
local gameMap = UIGameMap.internalCreate()
gameMap:setKeepAspectRatio(true)
gameMap:setVisibleDimension({width = 15, height = 11})
gameMap:setDrawLights(true)
gameMap.markedThing = nil
gameMap.blockNextRelease = 0
gameMap:updateMarkedCreature()
return gameMap
end
function UIGameMap:onDestroy()
if self.updateMarkedCreatureEvent then
removeEvent(self.updateMarkedCreatureEvent)
end
end
function UIGameMap:markThing(thing, color)
if self.markedThing == thing then
return
end
if self.markedThing then
self.markedThing:setMarked('')
end
self.markedThing = thing
if self.markedThing and g_settings.getBoolean('highlightThingsUnderCursor') then
self.markedThing:setMarked(color)
end
end
function UIGameMap: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.currentDragThing = thing
g_mouse.pushCursor('target')
self.allowNextRelease = false
return true
end
function UIGameMap:onDragLeave(droppedWidget, mousePos)
self.currentDragThing = nil
self.hoveredWho = nil
g_mouse.popCursor('target')
return true
end
function UIGameMap:onDrop(widget, mousePos)
if not self:canAcceptDrop(widget, mousePos) then return false end
local tile = self:getTile(mousePos)
if not tile then return false end
local thing = widget.currentDragThing
local toPos = tile:getPosition()
local thingPos = thing:getPosition()
if thingPos.x == toPos.x and thingPos.y == toPos.y and thingPos.z == toPos.z then return false end
if thing:isItem() and thing:getCount() > 1 then
modules.game_interface.moveStackableItem(thing, toPos)
else
g_game.move(thing, toPos, 1)
end
return true
end
function UIGameMap:onMouseMove(mousePos, mouseMoved)
self.mousePos = mousePos
return false
end
function UIGameMap:onDragMove(mousePos, mouseMoved)
self.mousePos = mousePos
return false
end
function UIGameMap:updateMarkedCreature()
self.updateMarkedCreatureEvent = scheduleEvent(function() self:updateMarkedCreature() end, 100)
if self.mousePos and g_game.isOnline() then
self.markingMouseRelease = true
self:onMouseRelease(self.mousePos, MouseRightButton)
self.markingMouseRelease = false
end
end
function UIGameMap:onMousePress()
if not self:isDragging() and self.blockNextRelease < g_clock.millis() then
self.allowNextRelease = true
self.markingMouseRelease = false
end
end
function UIGameMap:blockNextMouseRelease(postAction)
self.allowNextRelease = false
if postAction then
self.blockNextRelease = g_clock.millis() + 150
else
self.blockNextRelease = g_clock.millis() + 250
end
end
function UIGameMap:onMouseRelease(mousePosition, mouseButton)
if not self.allowNextRelease and not self.markingMouseRelease then
return true
end
local autoWalkPos = self:getPosition(mousePosition)
local positionOffset = self:getPositionOffset(mousePosition)
-- happens when clicking outside of map boundaries
if not autoWalkPos then
if self.markingMouseRelease then
self:markThing(nil)
end
return false
end
local localPlayerPos = g_game.getLocalPlayer():getPosition()
if autoWalkPos.z ~= localPlayerPos.z then
local dz = autoWalkPos.z - localPlayerPos.z
autoWalkPos.x = autoWalkPos.x + dz
autoWalkPos.y = autoWalkPos.y + dz
autoWalkPos.z = localPlayerPos.z
end
local lookThing
local useThing
local creatureThing
local multiUseThing
local attackCreature
local tile = self:getTile(mousePosition)
if tile then
lookThing = tile:getTopLookThingEx(positionOffset)
useThing = tile:getTopUseThing()
creatureThing = tile:getTopCreatureEx(positionOffset)
end
local autoWalkTile = g_map.getTile(autoWalkPos)
if autoWalkTile then
attackCreature = autoWalkTile:getTopCreatureEx(positionOffset)
end
if self.markingMouseRelease then
if attackCreature then
self:markThing(attackCreature, 'yellow')
elseif creatureThing then
self:markThing(creatureThing, 'yellow')
elseif useThing and not useThing:isGround() then
self:markThing(useThing, 'yellow')
elseif lookThing and not lookThing:isGround() then
self:markThing(lookThing, 'yellow')
else
self:markThing(nil, '')
end
return
end
local ret = modules.game_interface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, attackCreature, self.markingMouseRelease)
if ret then
self.allowNextRelease = false
end
return ret
end
function UIGameMap:canAcceptDrop(widget, mousePos)
if not widget or not widget.currentDragThing then return false end
local children = rootWidget:recursiveGetChildrenByPos(mousePos)
for i=1,#children do
local child = children[i]
if child == self then
return true
elseif not child:isPhantom() then
return false
end
end
error('Widget ' .. self:getId() .. ' not in drop list.')
return false
end

View File

@@ -0,0 +1,111 @@
function UIItem:onDragEnter(mousePos)
if self:isVirtual() then return false end
local item = self:getItem()
if not item then return false end
self:setBorderWidth(1)
self.currentDragThing = item
g_mouse.pushCursor('target')
return true
end
function UIItem:onDragLeave(droppedWidget, mousePos)
if self:isVirtual() then return false end
self.currentDragThing = nil
g_mouse.popCursor('target')
self:setBorderWidth(0)
self.hoveredWho = nil
return true
end
function UIItem:onDrop(widget, mousePos, forced)
if not self:canAcceptDrop(widget, mousePos) and not forced then return false end
local item = widget.currentDragThing
if not item or not item:isItem() then return false end
local toPos = self.position
local itemPos = item:getPosition()
if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end
if item:getCount() > 1 then
modules.game_interface.moveStackableItem(item, toPos)
else
g_game.move(item, toPos, 1)
end
self:setBorderWidth(0)
return true
end
function UIItem:onDestroy()
if self == g_ui.getDraggingWidget() and self.hoveredWho then
self.hoveredWho:setBorderWidth(0)
end
if self.hoveredWho then
self.hoveredWho = nil
end
end
function UIItem:onHoverChange(hovered)
UIWidget.onHoverChange(self, hovered)
if self:isVirtual() or not self:isDraggable() then return end
local draggingWidget = g_ui.getDraggingWidget()
if draggingWidget and self ~= draggingWidget then
local gotMap = draggingWidget:getClassName() == 'UIGameMap'
local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
if hovered and (gotItem or gotMap) then
self:setBorderWidth(1)
draggingWidget.hoveredWho = self
else
self:setBorderWidth(0)
draggingWidget.hoveredWho = nil
end
end
end
function UIItem:onMouseRelease(mousePosition, mouseButton)
if self.cancelNextRelease then
self.cancelNextRelease = false
return true
end
if self:isVirtual() then return false end
local item = self:getItem()
if not item or not self:containsPoint(mousePosition) then return false end
if modules.client_options.getOption('classicControl') and
((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
(g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
g_game.look(item)
self.cancelNextRelease = true
return true
elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, nil) then
return true
end
return false
end
function UIItem:canAcceptDrop(widget, mousePos)
if self:isVirtual() or not self:isDraggable() then return false end
if not widget or not widget.currentDragThing then return false end
local children = rootWidget:recursiveGetChildrenByPos(mousePos)
for i=1,#children do
local child = children[i]
if child == self then
return true
elseif not child:isPhantom() then
return false
end
end
error('Widget ' .. self:getId() .. ' not in drop list.')
return false
end