2012-03-18 14:34:39 +01:00
GameInterface = { }
2012-01-03 21:41:00 +01:00
2012-03-18 14:34:39 +01:00
local WALK_AUTO_REPEAT_DELAY = 90
local gameRootPanel
local gameMapPanel
local gameRightPanel
local gameLeftPanel
local gameBottomPanel
local logoutButton
2012-03-29 21:25:04 +02:00
local mouseGrabberWidget
2012-03-18 14:34:39 +01:00
2012-06-21 21:31:22 +02:00
local function onLeftPanelVisibilityChange ( leftPanel , visible )
if not visible then
local children = leftPanel : getChildren ( )
for i = 1 , # children do
children [ i ] : setParent ( gameRightPanel )
end
end
end
2012-03-18 14:34:39 +01:00
function GameInterface . init ( )
2012-06-26 00:13:30 +02:00
g_ui.importStyle ( ' styles/countwindow.otui ' )
2012-03-18 14:34:39 +01:00
connect ( g_game , { onGameStart = GameInterface.show } , true )
connect ( g_game , { onGameEnd = GameInterface.hide } , true )
2012-06-26 00:13:30 +02:00
gameRootPanel = g_ui.displayUI ( ' gameinterface.otui ' )
2012-03-18 14:34:39 +01:00
gameRootPanel : hide ( )
gameRootPanel : lower ( )
2012-03-29 21:25:04 +02:00
mouseGrabberWidget = gameRootPanel : getChildById ( ' mouseGrabber ' )
2012-04-25 00:09:48 +02:00
mouseGrabberWidget.onMouseRelease = GameInterface.onMouseGrabberRelease
2012-03-29 21:25:04 +02:00
2012-03-18 14:34:39 +01:00
gameMapPanel = gameRootPanel : getChildById ( ' gameMapPanel ' )
gameRightPanel = gameRootPanel : getChildById ( ' gameRightPanel ' )
gameLeftPanel = gameRootPanel : getChildById ( ' gameLeftPanel ' )
gameBottomPanel = gameRootPanel : getChildById ( ' gameBottomPanel ' )
2012-06-21 21:31:22 +02:00
connect ( gameLeftPanel , { onVisibilityChange = onLeftPanelVisibilityChange } )
2012-03-18 14:34:39 +01:00
2012-06-20 02:15:56 +02:00
logoutButton = TopMenu.addRightButton ( ' logoutButton ' , ' Logout ' , ' /images/logout.png ' , GameInterface.tryLogout )
2012-03-18 14:34:39 +01:00
logoutButton : hide ( )
2012-06-26 00:13:30 +02:00
g_keyboard.bindKeyPress ( ' Up ' , function ( ) g_game.walk ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Right ' , function ( ) g_game.walk ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Down ' , function ( ) g_game.walk ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Left ' , function ( ) g_game.walk ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad8 ' , function ( ) g_game.walk ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad9 ' , function ( ) g_game.walk ( NorthEast ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad6 ' , function ( ) g_game.walk ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad3 ' , function ( ) g_game.walk ( SouthEast ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad2 ' , function ( ) g_game.walk ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad1 ' , function ( ) g_game.walk ( SouthWest ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad4 ' , function ( ) g_game.walk ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad7 ' , function ( ) g_game.walk ( NorthWest ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Up ' , function ( ) g_game.turn ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Right ' , function ( ) g_game.turn ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Down ' , function ( ) g_game.turn ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Left ' , function ( ) g_game.turn ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Numpad8 ' , function ( ) g_game.turn ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Numpad6 ' , function ( ) g_game.turn ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Numpad2 ' , function ( ) g_game.turn ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+Numpad4 ' , function ( ) g_game.turn ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Escape ' , function ( ) g_game.cancelAttackAndFollow ( ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Ctrl+= ' , function ( ) gameMapPanel : zoomIn ( ) end , gameRootPanel , 250 )
g_keyboard.bindKeyPress ( ' Ctrl+- ' , function ( ) gameMapPanel : zoomOut ( ) end , gameRootPanel , 250 )
g_keyboard.bindKeyDown ( ' Ctrl+Q ' , GameInterface.tryLogout , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+L ' , GameInterface.tryLogout , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+W ' , function ( ) g_map.cleanTexts ( ) TextMessage.clearMessages ( ) end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+. ' , function ( )
2012-06-22 07:26:22 +02:00
if gameMapPanel : isKeepAspectRatioEnabled ( ) then
gameMapPanel : setKeepAspectRatio ( false )
else
gameMapPanel : setKeepAspectRatio ( true )
gameMapPanel : setVisibleDimension ( { width = 15 , height = 11 } )
end
end )
2012-03-18 14:34:39 +01:00
if g_game.isOnline ( ) then
GameInterface.show ( )
end
2012-01-13 01:31:39 +01:00
end
2012-03-18 14:34:39 +01:00
function GameInterface . terminate ( )
disconnect ( g_game , { onGameStart = GameInterface.show } )
disconnect ( g_game , { onGameEnd = GameInterface.hide } )
2012-06-21 21:31:22 +02:00
disconnect ( gameLeftPanel , { onVisibilityChange = onLeftPanelVisibilityChange } )
2012-03-18 14:34:39 +01:00
logoutButton : destroy ( )
logoutButton = nil
gameRootPanel : destroy ( )
gameRootPanel = nil
gameMapPanel = nil
gameRightPanel = nil
gameLeftPanel = nil
gameBottomPanel = nil
2012-03-29 21:25:04 +02:00
mouseGrabberWidget = nil
2012-03-18 14:34:39 +01:00
GameInterface = nil
2012-01-13 01:31:39 +01:00
end
2012-03-18 14:34:39 +01:00
function GameInterface . show ( )
g_app.onClose = GameInterface.tryExit
logoutButton : show ( )
Background.hide ( )
gameRootPanel : show ( )
gameRootPanel : focus ( )
gameMapPanel : followCreature ( g_game.getLocalPlayer ( ) )
end
2012-01-12 02:21:59 +01:00
2012-03-18 14:34:39 +01:00
function GameInterface . hide ( )
gameRootPanel : hide ( )
logoutButton : hide ( )
Background.show ( )
g_app.onClose = nil
end
2012-01-12 02:21:59 +01:00
2012-03-18 14:34:39 +01:00
function GameInterface . tryExit ( )
if g_game.isOnline ( ) then
g_game.forceLogout ( )
scheduleEvent ( exit , 10 )
2012-06-20 09:10:12 +02:00
return true
2012-01-09 21:54:37 +01:00
end
end
2012-03-18 14:34:39 +01:00
function GameInterface . tryLogout ( )
if g_game.isOnline ( ) then
g_game.safeLogout ( )
return true
end
end
2012-01-09 21:54:37 +01:00
2012-04-25 00:09:48 +02:00
function GameInterface . onMouseGrabberRelease ( self , mousePosition , mouseButton )
2012-03-29 01:19:28 +02:00
if GameInterface.selectedThing == nil then return false end
if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel : recursiveGetChildByPos ( mousePosition , false )
if clickedWidget then
2012-04-25 00:09:48 +02:00
if GameInterface.selectedType == ' use ' then
GameInterface.onUseWith ( clickedWidget , mousePosition )
elseif GameInterface.selectedType == ' trade ' then
GameInterface.onTradeWith ( clickedWidget , mousePosition )
2012-03-29 01:19:28 +02:00
end
end
end
2012-04-25 00:09:48 +02:00
2012-03-29 01:19:28 +02:00
GameInterface.selectedThing = nil
2012-06-26 00:13:30 +02:00
g_mouse.restoreCursor ( )
2012-03-29 01:19:28 +02:00
self : ungrabMouse ( )
return true
end
2012-04-25 00:09:48 +02:00
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
2012-03-29 01:19:28 +02:00
function GameInterface . startUseWith ( thing )
2012-04-25 00:09:48 +02:00
GameInterface.selectedType = ' use '
GameInterface.selectedThing = thing
mouseGrabberWidget : grabMouse ( )
2012-06-26 00:13:30 +02:00
g_mouse.setTargetCursor ( )
2012-04-25 00:09:48 +02:00
end
function GameInterface . startTradeWith ( thing )
GameInterface.selectedType = ' trade '
2012-03-29 01:19:28 +02:00
GameInterface.selectedThing = thing
2012-03-29 21:25:04 +02:00
mouseGrabberWidget : grabMouse ( )
2012-06-26 00:13:30 +02:00
g_mouse.setTargetCursor ( )
2012-03-29 01:19:28 +02:00
end
2012-03-18 14:34:39 +01:00
function GameInterface . createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2012-06-26 00:13:30 +02:00
local menu = g_ui.createWidget ( ' PopupMenu ' )
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if lookThing then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Look ' ) , function ( ) g_game.look ( lookThing ) end )
2012-01-04 14:02:35 +01:00
end
2012-01-03 21:41:00 +01:00
2012-01-04 14:02:35 +01:00
if useThing then
if useThing : isContainer ( ) then
2012-03-23 14:48:05 +01:00
if useThing : getParentContainer ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Open ' ) , function ( ) g_game.open ( useThing , useThing : getParentContainer ( ) ) end )
2012-06-26 00:13:30 +02:00
menu : addOption ( tr ( ' Open in new window ' ) , function ( ) g_game.open ( useThing ) end )
2012-01-13 01:31:39 +01:00
else
2012-06-26 00:13:30 +02:00
menu : addOption ( tr ( ' Open ' ) , function ( ) g_game.open ( useThing ) end )
2012-01-13 01:31:39 +01:00
end
2012-01-03 23:27:31 +01:00
else
2012-01-04 14:02:35 +01:00
if useThing : isMultiUse ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Use with ... ' ) , function ( ) GameInterface.startUseWith ( useThing ) end )
2012-01-03 23:27:31 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Use ' ) , function ( ) g_game.use ( useThing ) end )
2012-01-03 23:27:31 +01:00
end
end
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if useThing : isRotateable ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Rotate ' ) , function ( ) g_game.rotate ( useThing ) end )
2012-01-03 23:27:31 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-09 01:43:36 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-09 01:43:36 +01:00
if lookThing and not lookThing : asCreature ( ) and not lookThing : isNotMoveable ( ) and lookThing : isPickupable ( ) then
menu : addSeparator ( )
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Trade with ... ' ) , function ( ) GameInterface.startTradeWith ( lookThing ) end )
2012-01-04 14:02:35 +01:00
end
2012-01-12 02:21:59 +01:00
2012-04-24 23:15:51 +02:00
if lookThing then
local parentContainer = lookThing : getParentContainer ( )
if parentContainer and parentContainer : hasParent ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Move up ' ) , function ( ) g_game.moveToParentContainer ( lookThing , lookThing : getCount ( ) ) end )
2012-04-24 23:15:51 +02:00
end
end
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if creatureThing then
2012-01-03 23:27:31 +01:00
menu : addSeparator ( )
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if creatureThing : asLocalPlayer ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Set Outfit ' ) , function ( ) g_game.requestOutfit ( ) end )
2012-01-12 02:21:59 +01:00
2012-03-18 14:34:39 +01:00
if creatureThing : isPartyMember ( ) --[[and not fighting]] then
if creatureThing : isPartyLeader ( ) then
if creatureThing : isPartySharedExperienceActive ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Disable Shared Experience ' ) , function ( ) g_game.partyShareExperience ( false ) end )
2012-01-11 00:38:32 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Enable Shared Experience ' ) , function ( ) g_game.partyShareExperience ( true ) end )
2012-01-11 00:38:32 +01:00
end
end
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Leave Party ' ) , function ( ) g_game.partyLeave ( ) end )
2012-01-11 00:38:32 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-03 23:27:31 +01:00
else
2012-02-08 22:23:15 +01:00
local localPlayer = g_game.getLocalPlayer ( )
2012-01-07 23:24:29 +01:00
if localPlayer then
2012-02-08 22:23:15 +01:00
if g_game.getAttackingCreature ( ) ~= creatureThing then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Attack ' ) , function ( ) g_game.attack ( creatureThing ) end )
2012-01-07 23:24:29 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Stop Attack ' ) , function ( ) g_game.cancelAttack ( ) end )
2012-01-07 23:24:29 +01:00
end
2012-01-12 02:21:59 +01:00
2012-02-08 22:23:15 +01:00
if g_game.getFollowingCreature ( ) ~= creatureThing then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Follow ' ) , function ( ) g_game.follow ( creatureThing ) end )
2012-01-07 23:24:29 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Stop Follow ' ) , function ( ) g_game.cancelFollow ( ) end )
2012-01-07 23:24:29 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-11 00:38:32 +01:00
if creatureThing : asPlayer ( ) then
menu : addSeparator ( )
2012-03-29 15:45:40 +02:00
local creatureName = creatureThing : getName ( )
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Message to %s ' , creatureName ) , function ( ) g_game.openPrivateChannel ( creatureName ) end )
2012-04-24 13:20:14 +02:00
if Console.getOwnPrivateTab ( ) then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Invite to private chat ' ) , function ( ) g_game.inviteToOwnChannel ( creatureName ) end )
menu : addOption ( tr ( ' Exclude from private chat ' ) , function ( ) g_game.excludeFromOwnChannel ( creatureName ) end ) -- [TODO] must be removed after message's popup labels been implemented
2012-04-24 13:20:14 +02:00
end
2012-07-09 08:59:16 +02:00
if ( not Player : hasVip ( creatureName ) ) then
menu : addOption ( tr ( ' Add to VIP list ' ) , function ( ) g_game.addVip ( creatureName ) end )
end
2012-01-12 02:21:59 +01:00
2012-01-11 00:38:32 +01:00
local localPlayerShield = localPlayer : asCreature ( ) : getShield ( )
local creatureShield = creatureThing : getShield ( )
2012-01-12 02:21:59 +01:00
2012-01-11 00:38:32 +01:00
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
if creatureShield == ShieldWhiteYellow then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Join %s \' s Party ' , creatureThing : getName ( ) ) , function ( ) g_game.partyJoin ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Invite to Party ' ) , function ( ) g_game.partyInvite ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
end
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Revoke %s \' s Invitation ' , creatureThing : getName ( ) ) , function ( ) g_game.partyRevokeInvitation ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
end
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
if creatureShield == ShieldWhiteBlue then
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Revoke %s \' s Invitation ' , creatureThing : getName ( ) ) , function ( ) g_game.partyRevokeInvitation ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
2012-06-10 20:52:08 +02:00
menu : addOption ( tr ( ' Pass Leadership to %s ' , creatureThing : getName ( ) ) , function ( ) g_game.partyPassLeadership ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
else
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Invite to Party ' ) , function ( ) g_game.partyInvite ( creatureThing : getId ( ) ) end )
2012-01-11 00:38:32 +01:00
end
end
end
2012-01-05 15:24:38 +01:00
end
2012-01-03 23:27:31 +01:00
end
2012-05-01 08:49:48 +02:00
if RuleViolation.hasWindowAccess ( ) then
menu : addSeparator ( )
menu : addOption ( tr ( ' Rule Violation ' ) , function ( ) RuleViolation.show ( creatureThing : getName ( ) ) end )
end
2012-06-09 15:00:08 +02:00
2012-01-03 23:27:31 +01:00
menu : addSeparator ( )
2012-04-26 21:54:16 +02:00
menu : addOption ( tr ( ' Copy Name ' ) , function ( ) g_window.setClipboardText ( creatureThing : getName ( ) ) end )
2012-01-12 02:21:59 +01:00
2012-01-03 21:41:00 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-03 21:41:00 +01:00
menu : display ( menuPosition )
end
2012-01-13 01:31:39 +01:00
2012-07-05 07:40:21 +02:00
function GameInterface . processMouseAction ( menuPosition , mouseButton , autoWalkPos , lookThing , useThing , creatureThing , multiUseThing )
2012-06-26 00:13:30 +02:00
local keyboardModifiers = g_keyboard.getModifiers ( )
2012-03-18 14:34:39 +01:00
2012-03-23 15:48:00 +01:00
if not Options.getOption ( ' classicControl ' ) then
2012-03-18 14:34:39 +01:00
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
2012-03-23 14:48:05 +01:00
if useThing : getParentContainer ( ) then
2012-04-03 01:09:47 +02:00
g_game.open ( useThing , useThing : getParentContainer ( ) )
2012-03-18 14:34:39 +01:00
return true
else
2012-06-26 00:13:30 +02:00
g_game.open ( useThing )
2012-03-18 14:34:39 +01:00
return true
end
elseif useThing : isMultiUse ( ) then
2012-03-29 01:19:28 +02:00
GameInterface.startUseWith ( useThing )
2012-03-18 14:34:39 +01:00
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
2012-07-05 07:40:21 +02:00
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed ( MouseLeftButton ) then
2012-03-18 14:34:39 +01:00
if multiUseThing : asCreature ( ) then
g_game.attack ( multiUseThing : asCreature ( ) )
return true
elseif multiUseThing : isContainer ( ) then
2012-03-23 14:48:05 +01:00
if multiUseThing : getParentContainer ( ) then
2012-04-03 01:09:47 +02:00
g_game.open ( multiUseThing , multiUseThing : getParentContainer ( ) )
2012-03-18 14:34:39 +01:00
return true
else
2012-06-26 00:13:30 +02:00
g_game.open ( multiUseThing )
2012-03-18 14:34:39 +01:00
return true
end
elseif multiUseThing : isMultiUse ( ) then
2012-03-29 01:19:28 +02:00
GameInterface.startUseWith ( useThing )
2012-03-18 14:34:39 +01:00
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
2012-07-05 07:40:21 +02:00
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
2012-03-18 14:34:39 +01:00
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
2012-07-05 07:40:21 +02:00
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
2012-07-05 14:38:48 +02:00
local dirs = g_map.findPath ( g_game.getLocalPlayer ( ) : getPosition ( ) , autoWalkPos , 127 )
2012-07-05 07:40:21 +02:00
if # dirs == 0 then
TextMessage.displayStatus ( tr ( ' There is no way. ' ) )
return true
end
g_game.autoWalk ( dirs )
return true
end
2012-03-18 14:34:39 +01:00
return false
end
2012-03-29 15:45:40 +02:00
function GameInterface . moveStackableItem ( item , toPos )
2012-06-26 00:13:30 +02:00
if g_keyboard.isCtrlPressed ( ) then
2012-06-07 14:25:41 +02:00
g_game.move ( item , toPos , item : getCount ( ) )
return
2012-06-26 00:13:30 +02:00
elseif g_keyboard.isShiftPressed ( ) then
2012-06-07 14:25:41 +02:00
g_game.move ( item , toPos , 1 )
return
end
2012-03-29 15:45:40 +02:00
2012-06-07 14:25:41 +02:00
local count = item : getCount ( )
2012-06-26 00:13:30 +02:00
local countWindow = g_ui.createWidget ( ' CountWindow ' , rootWidget )
2012-03-29 15:45:40 +02:00
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
2012-03-18 14:34:39 +01:00
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