mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
Refactoring and flexibility changes
* Split game module into game and game_interface * Move core_lib to corelib * Move miniwindow to corelib * Introduce init.lua script for initializing the client, giving much more flexibility * OTClient is no longer Application derived and is much simpler
This commit is contained in:
405
modules/game_interface/gameinterface.lua
Normal file
405
modules/game_interface/gameinterface.lua
Normal file
@@ -0,0 +1,405 @@
|
||||
GameInterface = {}
|
||||
|
||||
local WALK_AUTO_REPEAT_DELAY = 90
|
||||
local gameRootPanel
|
||||
local gameMapPanel
|
||||
local gameRightPanel
|
||||
local gameLeftPanel
|
||||
local gameBottomPanel
|
||||
local logoutButton
|
||||
local mouseGrabberWidget
|
||||
|
||||
function GameInterface.init()
|
||||
connect(g_game, { onGameStart = GameInterface.show }, true)
|
||||
connect(g_game, { onGameEnd = GameInterface.hide }, true)
|
||||
|
||||
gameRootPanel = displayUI('gameinterface.otui')
|
||||
gameRootPanel:hide()
|
||||
gameRootPanel:lower()
|
||||
|
||||
mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
|
||||
mouseGrabberWidget.onMouseRelease = GameInterface.onMouseGrabberRelease
|
||||
|
||||
gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
|
||||
gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
|
||||
gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
|
||||
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
|
||||
|
||||
logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', '/images/logout.png', GameInterface.tryLogout)
|
||||
logoutButton:hide()
|
||||
|
||||
Keyboard.bindKeyPress('Up', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Right', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Down', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Left', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad8', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad9', function() g_game.walk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad6', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad3', function() g_game.walk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad2', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad1', function() g_game.walk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad4', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Numpad7', function() g_game.walk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
Keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel, 250)
|
||||
Keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel, 250)
|
||||
Keyboard.bindKeyDown('Ctrl+Q', GameInterface.tryLogout, gameRootPanel)
|
||||
Keyboard.bindKeyDown('Ctrl+L', GameInterface.tryLogout, gameRootPanel)
|
||||
Keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() TextMessage.clearMessages() end, gameRootPanel)
|
||||
|
||||
if g_game.isOnline() then
|
||||
GameInterface.show()
|
||||
end
|
||||
end
|
||||
|
||||
function GameInterface.terminate()
|
||||
disconnect(g_game, { onGameStart = GameInterface.show })
|
||||
disconnect(g_game, { onGameEnd = GameInterface.hide })
|
||||
|
||||
logoutButton:destroy()
|
||||
logoutButton = nil
|
||||
gameRootPanel:destroy()
|
||||
gameRootPanel = nil
|
||||
gameMapPanel = nil
|
||||
gameRightPanel = nil
|
||||
gameLeftPanel = nil
|
||||
gameBottomPanel = nil
|
||||
mouseGrabberWidget = nil
|
||||
GameInterface = nil
|
||||
end
|
||||
|
||||
function GameInterface.show()
|
||||
g_app.onClose = GameInterface.tryExit
|
||||
logoutButton:show()
|
||||
Background.hide()
|
||||
gameRootPanel:show()
|
||||
gameRootPanel:focus()
|
||||
gameMapPanel:followCreature(g_game.getLocalPlayer())
|
||||
end
|
||||
|
||||
function GameInterface.hide()
|
||||
gameRootPanel:hide()
|
||||
logoutButton:hide()
|
||||
Background.show()
|
||||
g_app.onClose = nil
|
||||
end
|
||||
|
||||
function GameInterface.tryExit()
|
||||
if g_game.isOnline() then
|
||||
g_game.forceLogout()
|
||||
scheduleEvent(exit, 10)
|
||||
end
|
||||
end
|
||||
|
||||
function GameInterface.tryLogout()
|
||||
if g_game.isOnline() then
|
||||
g_game.safeLogout()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function GameInterface.onMouseGrabberRelease(self, mousePosition, mouseButton)
|
||||
if GameInterface.selectedThing == nil then return false end
|
||||
if mouseButton == MouseLeftButton then
|
||||
local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
|
||||
if clickedWidget then
|
||||
if GameInterface.selectedType == 'use' then
|
||||
GameInterface.onUseWith(clickedWidget, mousePosition)
|
||||
elseif GameInterface.selectedType == 'trade' then
|
||||
GameInterface.onTradeWith(clickedWidget, mousePosition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
GameInterface.selectedThing = nil
|
||||
Mouse.restoreCursor()
|
||||
self:ungrabMouse()
|
||||
return true
|
||||
end
|
||||
|
||||
function GameInterface.onUseWith(clickedWidget, mousePosition)
|
||||
if clickedWidget:getClassName() == 'UIMap' then
|
||||
local tile = clickedWidget:getTile(mousePosition)
|
||||
if tile then
|
||||
g_game.useWith(GameInterface.selectedThing, tile:getTopMultiUseThing())
|
||||
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
||||
g_game.useWith(GameInterface.selectedThing, clickedWidget:getItem())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GameInterface.onTradeWith(clickedWidget, mousePosition)
|
||||
if clickedWidget:getClassName() == 'UIMap' then
|
||||
local tile = clickedWidget:getTile(mousePosition)
|
||||
if tile then
|
||||
g_game.requestTrade(GameInterface.selectedThing, tile:getTopCreature())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GameInterface.startUseWith(thing)
|
||||
GameInterface.selectedType = 'use'
|
||||
GameInterface.selectedThing = thing
|
||||
mouseGrabberWidget:grabMouse()
|
||||
Mouse.setTargetCursor()
|
||||
end
|
||||
|
||||
function GameInterface.startTradeWith(thing)
|
||||
GameInterface.selectedType = 'trade'
|
||||
GameInterface.selectedThing = thing
|
||||
mouseGrabberWidget:grabMouse()
|
||||
Mouse.setTargetCursor()
|
||||
end
|
||||
|
||||
function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
local menu = createWidget('PopupMenu')
|
||||
|
||||
if lookThing then
|
||||
menu:addOption(tr('Look'), function() g_game.look(lookThing) end)
|
||||
end
|
||||
|
||||
if useThing then
|
||||
if useThing:isContainer() then
|
||||
if useThing:getParentContainer() then
|
||||
menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end)
|
||||
menu:addOption(tr('Open in new window'), function() g_game.open(useThing, nil) end)
|
||||
else
|
||||
menu:addOption(tr('Open'), function() g_game.open(useThing, nil) end)
|
||||
end
|
||||
else
|
||||
if useThing:isMultiUse() then
|
||||
menu:addOption(tr('Use with ...'), function() GameInterface.startUseWith(useThing) end)
|
||||
else
|
||||
menu:addOption(tr('Use'), function() g_game.use(useThing) end)
|
||||
end
|
||||
end
|
||||
|
||||
if useThing:isRotateable() then
|
||||
menu:addOption(tr('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(tr('Trade with ...'), function() GameInterface.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
|
||||
menu:addSeparator()
|
||||
|
||||
if creatureThing:asLocalPlayer() then
|
||||
menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end)
|
||||
|
||||
if creatureThing:isPartyMember() --[[and not fighting]] 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 localPlayer = g_game.getLocalPlayer()
|
||||
if localPlayer then
|
||||
if g_game.getAttackingCreature() ~= creatureThing then
|
||||
menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end)
|
||||
else
|
||||
menu:addOption(tr('Stop Attack'), function() g_game.cancelAttack() end)
|
||||
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
|
||||
|
||||
if creatureThing:asPlayer() then
|
||||
menu:addSeparator()
|
||||
local creatureName = creatureThing:getName()
|
||||
menu:addOption(tr('Message to %s', creatureName), function() g_game.openPrivateChannel(creatureName) end)
|
||||
if 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
|
||||
menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end)
|
||||
|
||||
local localPlayerShield = localPlayer:asCreature():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
|
||||
end
|
||||
|
||||
if RuleViolation.hasWindowAccess() then
|
||||
menu:addSeparator()
|
||||
menu:addOption(tr('Rule Violation'), function() RuleViolation.show(creatureThing:getName()) end)
|
||||
end
|
||||
|
||||
menu:addSeparator()
|
||||
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
|
||||
|
||||
end
|
||||
|
||||
menu:display(menuPosition)
|
||||
end
|
||||
|
||||
function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
|
||||
local keyboardModifiers = Keyboard.getModifiers()
|
||||
|
||||
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
||||
-- todo auto walk
|
||||
return true
|
||||
end
|
||||
|
||||
if not Options.getOption('classicControl') then
|
||||
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||
GameInterface.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())
|
||||
return true
|
||||
else
|
||||
g_game.open(useThing, nil)
|
||||
return true
|
||||
end
|
||||
elseif useThing:isMultiUse() then
|
||||
GameInterface.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:getParentContainer() then
|
||||
g_game.open(multiUseThing, multiUseThing:getParentContainer())
|
||||
return true
|
||||
else
|
||||
g_game.open(multiUseThing, nil)
|
||||
return true
|
||||
end
|
||||
elseif multiUseThing:isMultiUse() then
|
||||
GameInterface.startUseWith(useThing)
|
||||
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
|
||||
GameInterface.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 GameInterface.moveStackableItem(item, toPos)
|
||||
if Keyboard.isCtrlPressed() then
|
||||
g_game.move(item, toPos, item:getCount())
|
||||
return
|
||||
elseif Keyboard.isShiftPressed() then
|
||||
g_game.move(item, toPos, 1)
|
||||
return
|
||||
end
|
||||
|
||||
local count = item:getCount()
|
||||
local countWindow = createWidget('CountWindow', rootWidget)
|
||||
local spinbox = countWindow:getChildById('countSpinBox')
|
||||
local scrollbar = countWindow:getChildById('countScrollBar')
|
||||
spinbox:setMaximum(count)
|
||||
spinbox:setMinimum(1)
|
||||
spinbox:setValue(count)
|
||||
scrollbar:setMaximum(count)
|
||||
scrollbar:setMinimum(1)
|
||||
scrollbar:setValue(count)
|
||||
scrollbar.onValueChange = function(self, value) spinbox:setValue(value) end
|
||||
spinbox.onValueChange = function(self, value) scrollbar:setValue(value) end
|
||||
|
||||
local okButton = countWindow:getChildById('buttonOk')
|
||||
local moveFunc = function()
|
||||
g_game.move(item, toPos, spinbox:getValue())
|
||||
okButton:getParent():destroy()
|
||||
end
|
||||
|
||||
countWindow.onEnter = moveFunc
|
||||
okButton.onClick = moveFunc
|
||||
end
|
||||
|
||||
function GameInterface.getRootPanel()
|
||||
return gameRootPanel
|
||||
end
|
||||
|
||||
function GameInterface.getMapPanel()
|
||||
return gameMapPanel
|
||||
end
|
||||
|
||||
function GameInterface.getRightPanel()
|
||||
return gameRightPanel
|
||||
end
|
||||
|
||||
function GameInterface.getLeftPanel()
|
||||
return gameLeftPanel
|
||||
end
|
||||
|
||||
function GameInterface.getBottomPanel()
|
||||
return gameBottomPanel
|
||||
end
|
66
modules/game_interface/gameinterface.otui
Normal file
66
modules/game_interface/gameinterface.otui
Normal file
@@ -0,0 +1,66 @@
|
||||
GameSidePanel < UIMiniWindowContainer
|
||||
image-source: /images/sidepanel.png
|
||||
image-border: 4
|
||||
padding: 4
|
||||
|
||||
GameBottomPanel < Panel
|
||||
image-source: /images/bottompanel.png
|
||||
image-border: 4
|
||||
|
||||
GameMapPanel < UIGameMap
|
||||
padding: 4
|
||||
image-source: /images/mappanel.png
|
||||
image-border: 4
|
||||
|
||||
UIWidget
|
||||
id: gameRootPanel
|
||||
anchors.fill: parent
|
||||
anchors.top: topMenu.bottom
|
||||
|
||||
GameMapPanel
|
||||
id: gameMapPanel
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: gameBottomPanel.top
|
||||
focusable: false
|
||||
|
||||
GameBottomPanel
|
||||
id: gameBottomPanel
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.top: bottomSplitter.top
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
GameSidePanel
|
||||
id: gameLeftPanel
|
||||
width: 190
|
||||
layout: verticalBox
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
focusable: false
|
||||
|
||||
GameSidePanel
|
||||
id: gameRightPanel
|
||||
layout: verticalBox
|
||||
width: 190
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
focusable: false
|
||||
|
||||
Splitter
|
||||
id: bottomSplitter
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.bottom: parent.bottom
|
||||
relative-margin: bottom
|
||||
margin-bottom: 172
|
||||
@canUpdateMargin: function(self, newMargin) 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
|
21
modules/game_interface/interface.otmod
Normal file
21
modules/game_interface/interface.otmod
Normal file
@@ -0,0 +1,21 @@
|
||||
Module
|
||||
name: game_interface
|
||||
description: Create the game interface, where the ingame stuff starts
|
||||
author: OTClient team
|
||||
website: www.otclient.info
|
||||
|
||||
@onLoad: |
|
||||
importStyle 'styles/items.otui'
|
||||
importStyle 'styles/creatures.otui'
|
||||
importStyle 'styles/miniwindow.otui'
|
||||
importStyle 'styles/countwindow.otui'
|
||||
|
||||
dofile 'widgets/uigamemap'
|
||||
dofile 'widgets/uiitem'
|
||||
|
||||
dofile 'gameinterface'
|
||||
|
||||
GameInterface.init()
|
||||
|
||||
@onUnload: |
|
||||
GameInterface.terminate()
|
41
modules/game_interface/styles/countwindow.otui
Normal file
41
modules/game_interface/styles/countwindow.otui
Normal file
@@ -0,0 +1,41 @@
|
||||
CountWindow < MainWindow
|
||||
id: countWindow
|
||||
!text: tr('Move Stackable Item')
|
||||
size: 196 112
|
||||
@onEscape: self:destroy()
|
||||
|
||||
Label
|
||||
!text: tr('Amount:')
|
||||
width: 64
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin-top: 2
|
||||
|
||||
SpinBox
|
||||
id: countSpinBox
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
|
||||
HorizontalScrollBar
|
||||
id: countScrollBar
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 8
|
||||
|
||||
Button
|
||||
id: buttonOk
|
||||
!text: tr('Ok')
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 5
|
||||
|
||||
Button
|
||||
id: buttonCancel
|
||||
!text: tr('Cancel')
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
@onClick: self:getParent():destroy()
|
5
modules/game_interface/styles/creatures.otui
Normal file
5
modules/game_interface/styles/creatures.otui
Normal file
@@ -0,0 +1,5 @@
|
||||
Creature < UICreature
|
||||
size: 80 80
|
||||
padding: 1
|
||||
image-source: /images/panel_flat.png
|
||||
image-border: 1
|
6
modules/game_interface/styles/items.otui
Normal file
6
modules/game_interface/styles/items.otui
Normal file
@@ -0,0 +1,6 @@
|
||||
Item < UIItem
|
||||
size: 34 34
|
||||
padding: 1
|
||||
image-source: /images/item.png
|
||||
font: verdana-11px-rounded
|
||||
border-color: white
|
91
modules/game_interface/styles/miniwindow.otui
Normal file
91
modules/game_interface/styles/miniwindow.otui
Normal file
@@ -0,0 +1,91 @@
|
||||
MiniWindow < UIMiniWindow
|
||||
font: verdana-11px-antialised
|
||||
icon-rect: 4 4 16 16
|
||||
width: 192
|
||||
height: 200
|
||||
text-offset: 24 5
|
||||
text-align: topLeft
|
||||
image-source: /images/miniwindow.png
|
||||
image-border: 4
|
||||
image-border-top: 23
|
||||
image-border-bottom: 4
|
||||
focusable: false
|
||||
&minimizedHeight: 24
|
||||
|
||||
$on:
|
||||
image-border-bottom: 2
|
||||
|
||||
UIButton
|
||||
id: closeButton
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin-top: 5
|
||||
margin-right: 5
|
||||
size: 14 14
|
||||
image-source: /images/miniwindowbuttons.png
|
||||
image-clip: 28 0 14 14
|
||||
|
||||
$hover:
|
||||
image-clip: 28 14 14 14
|
||||
|
||||
$pressed:
|
||||
image-clip: 28 28 14 14
|
||||
|
||||
UIButton
|
||||
id: minimizeButton
|
||||
anchors.top: closeButton.top
|
||||
anchors.right: closeButton.left
|
||||
margin-right: 3
|
||||
size: 14 14
|
||||
image-source: /images/miniwindowbuttons.png
|
||||
image-clip: 0 0 14 14
|
||||
|
||||
$hover:
|
||||
image-clip: 0 14 14 14
|
||||
|
||||
$pressed:
|
||||
image-clip: 0 28 14 14
|
||||
|
||||
$on:
|
||||
image-clip: 14 0 14 14
|
||||
|
||||
$on hover:
|
||||
image-clip: 14 14 14 14
|
||||
|
||||
$on pressed:
|
||||
image-clip: 14 28 14 14
|
||||
|
||||
VerticalScrollBar
|
||||
id: miniwindowScrollBar
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
step: 14
|
||||
margin-top: 22
|
||||
margin-right: 2
|
||||
margin-bottom: 3
|
||||
pixels-scroll: true
|
||||
|
||||
$!on:
|
||||
width: 0
|
||||
|
||||
ResizeBorder
|
||||
id: bottomResizeBorder
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: 3
|
||||
minimum: 64
|
||||
background: #ffffff88
|
||||
|
||||
MiniWindowContents < ScrollablePanel
|
||||
id: contentsPanel
|
||||
anchors.fill: parent
|
||||
anchors.right: miniwindowScrollBar.left
|
||||
margin-top: 19
|
||||
padding: 3 5 3 5
|
||||
vertical-scrollbar: miniwindowScrollBar
|
||||
|
||||
BorderlessGameWindow < UIWindow
|
||||
focusable: false
|
||||
margin: 2
|
78
modules/game_interface/widgets/uigamemap.lua
Normal file
78
modules/game_interface/widgets/uigamemap.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
UIGameMap = extends(UIMap)
|
||||
|
||||
function UIGameMap.create()
|
||||
local gameMap = UIGameMap.internalCreate()
|
||||
gameMap:setKeepAspectRatio(true)
|
||||
gameMap:setVisibleDimension({width = 15, height = 11})
|
||||
return gameMap
|
||||
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
|
||||
Mouse.setTargetCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIGameMap:onDragLeave(droppedWidget, mousePos)
|
||||
self.currentDragThing = nil
|
||||
Mouse.restoreCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIGameMap: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 thing = widget.currentDragThing
|
||||
local toPos = tile:getPosition()
|
||||
|
||||
local itemPos = thing:getPosition()
|
||||
if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end
|
||||
|
||||
if thing:asItem() and thing:getCount() > 1 then
|
||||
GameInterface.moveStackableItem(thing, toPos)
|
||||
else
|
||||
g_game.move(thing, toPos, 1)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
||||
if self.cancelNextRelease then
|
||||
self.cancelNextRelease = false
|
||||
return true
|
||||
end
|
||||
|
||||
local tile = self:getTile(mousePosition)
|
||||
if tile == nil then return false end
|
||||
|
||||
if Options.getOption('classicControl') and
|
||||
((Mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
|
||||
(Mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
|
||||
local tile = self:getTile(mousePosition)
|
||||
g_game.look(tile:getTopLookThing())
|
||||
self.cancelNextRelease = true
|
||||
return true
|
||||
elseif GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then
|
||||
return true
|
||||
elseif mouseButton == MouseLeftButton and self:isPressed() then
|
||||
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), tile:getPosition(), 255)
|
||||
if #dirs == 0 then
|
||||
TextMessage.displayStatus(tr('There is no way.'))
|
||||
return true
|
||||
end
|
||||
g_game.autoWalk(dirs)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
81
modules/game_interface/widgets/uiitem.lua
Normal file
81
modules/game_interface/widgets/uiitem.lua
Normal file
@@ -0,0 +1,81 @@
|
||||
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
|
||||
Mouse.setTargetCursor()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIItem:onDragLeave(droppedWidget, mousePos)
|
||||
if self:isVirtual() then return false end
|
||||
self.currentDragThing = nil
|
||||
Mouse.restoreCursor()
|
||||
self:setBorderWidth(0)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIItem:onDrop(widget, mousePos)
|
||||
if self:isVirtual() then return false end
|
||||
|
||||
if not widget or not widget.currentDragThing then return false end
|
||||
|
||||
local item = widget.currentDragThing
|
||||
local toPos = self.position
|
||||
|
||||
local itemPos = item:getPosition()
|
||||
if itemPos.x == self.position.x and itemPos.y == self.position.y and itemPos.z == self.position.z then return false end
|
||||
|
||||
if item:getCount() > 1 then
|
||||
GameInterface.moveStackableItem(item, toPos)
|
||||
else
|
||||
g_game.move(item, toPos, 1)
|
||||
end
|
||||
|
||||
self:setBorderWidth(0)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIItem:onHoverChange(hovered)
|
||||
UIWidget.onHoverChange(self, hovered)
|
||||
|
||||
if self:isVirtual() then return end
|
||||
|
||||
local draggingWidget = g_ui.getDraggingWidget()
|
||||
if draggingWidget and self ~= draggingWidget then
|
||||
local gotMap = draggingWidget:getClassName() == 'UIMap'
|
||||
local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
|
||||
if hovered and (gotItem or gotMap) then
|
||||
self:setBorderWidth(1)
|
||||
else
|
||||
self:setBorderWidth(0)
|
||||
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 Options.getOption('classicControl') and
|
||||
((Mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
|
||||
(Mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
|
||||
g_game.look(item)
|
||||
self.cancelNextRelease = true
|
||||
return true
|
||||
elseif GameInterface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
Reference in New Issue
Block a user