2013-01-23 08:31:28 +01:00
WALK_AUTO_REPEAT_DELAY = 180
2013-01-07 18:17:01 +01:00
WALK_STEPS_RETRY = 10
2012-07-24 07:30:08 +02:00
gameRootPanel = nil
gameMapPanel = nil
gameRightPanel = nil
gameLeftPanel = nil
gameBottomPanel = nil
logoutButton = nil
mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
2012-10-10 01:25:50 +02:00
bottomSplitter = nil
2013-01-24 20:15:07 +01:00
limitZoom = false
currentViewMode = 0
2012-07-24 07:30:08 +02:00
2013-01-23 08:31:28 +01:00
lastDir = nil
walkEvent = nil
2012-12-29 18:41:14 +01:00
arrowKeys = {
2012-12-30 07:14:49 +01:00
[ North ] = ' Up ' ,
2012-12-29 18:41:14 +01:00
[ South ] = ' Down ' ,
[ East ] = ' Right ' ,
[ West ] = ' Left ' ,
[ NorthEast ] = ' Numpad9 ' ,
[ SouthEast ] = ' Numpad3 ' ,
[ NorthWest ] = ' Numpad7 ' ,
[ SouthWest ] = ' Numpad1 '
}
2012-07-24 07:30:08 +02:00
function init ( )
2013-01-18 23:39:11 +01:00
g_ui.importStyle ( ' styles/countwindow ' )
2012-06-26 00:13:30 +02:00
2013-01-07 18:17:01 +01:00
connect ( g_game , {
2013-01-18 06:27:29 +01:00
onGameStart = onGameStart ,
onGameEnd = onGameEnd ,
2013-01-08 16:32:37 +01:00
onLoginAdvice = onLoginAdvice
2013-01-07 18:17:01 +01:00
} , true )
2013-01-18 23:39:11 +01:00
gameRootPanel = g_ui.displayUI ( ' gameinterface ' )
2012-03-18 14:34:39 +01:00
gameRootPanel : hide ( )
gameRootPanel : lower ( )
2012-10-10 22:20:32 +02:00
gameRootPanel.onGeometryChange = updateStretchShrink
2012-03-18 14:34:39 +01:00
2012-03-29 21:25:04 +02:00
mouseGrabberWidget = gameRootPanel : getChildById ( ' mouseGrabber ' )
2012-07-24 07:30:08 +02:00
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
2012-03-29 21:25:04 +02:00
2012-10-10 01:25:50 +02:00
bottomSplitter = gameRootPanel : getChildById ( ' bottomSplitter ' )
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
2013-01-24 17:01:28 +01:00
logoutButton = modules.client_topmenu . addLeftButton ( ' logoutButton ' , tr ( ' Exit ' ) , ' /images/topbuttons/logout ' , tryLogout , true )
2012-03-18 14:34:39 +01:00
2013-01-24 20:15:07 +01:00
setupViewMode ( 0 )
2012-08-25 21:11:54 +02:00
bindKeys ( )
if g_game.isOnline ( ) then
show ( )
end
end
function bindKeys ( )
2012-08-29 17:41:04 +02:00
g_keyboard.bindKeyPress ( ' Up ' , function ( ) smartWalk ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Right ' , function ( ) smartWalk ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Down ' , function ( ) smartWalk ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Left ' , function ( ) smartWalk ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
2012-12-29 18:41:14 +01:00
2013-01-23 08:31:28 +01:00
g_keyboard.bindKeyDown ( ' Up ' , function ( ) changeWalkDir ( North ) end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Right ' , function ( ) changeWalkDir ( East ) end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Down ' , function ( ) changeWalkDir ( South ) end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Left ' , function ( ) changeWalkDir ( West ) end , gameRootPanel )
2012-08-29 17:41:04 +02:00
g_keyboard.bindKeyPress ( ' Numpad8 ' , function ( ) smartWalk ( North ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad9 ' , function ( ) smartWalk ( NorthEast ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad6 ' , function ( ) smartWalk ( East ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad3 ' , function ( ) smartWalk ( SouthEast ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad2 ' , function ( ) smartWalk ( South ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad1 ' , function ( ) smartWalk ( SouthWest ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad4 ' , function ( ) smartWalk ( West ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
g_keyboard.bindKeyPress ( ' Numpad7 ' , function ( ) smartWalk ( NorthWest ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
2012-06-26 00:13:30 +02:00
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 )
2013-01-08 16:32:37 +01:00
g_keyboard.bindKeyPress ( ' Escape ' , function ( ) g_game.cancelAttackAndFollow ( ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
2012-06-26 00:13:30 +02:00
g_keyboard.bindKeyPress ( ' Ctrl+= ' , function ( ) gameMapPanel : zoomIn ( ) end , gameRootPanel , 250 )
g_keyboard.bindKeyPress ( ' Ctrl+- ' , function ( ) gameMapPanel : zoomOut ( ) end , gameRootPanel , 250 )
2012-07-24 07:30:08 +02:00
g_keyboard.bindKeyDown ( ' Ctrl+Q ' , logout , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+L ' , logout , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+W ' , function ( ) g_map.cleanTexts ( ) modules.game_textmessage . clearMessages ( ) end , gameRootPanel )
2012-10-05 20:17:10 +02:00
g_keyboard.bindKeyDown ( ' Ctrl+N ' , function ( ) gameMapPanel : setDrawTexts ( not gameMapPanel : isDrawingTexts ( ) ) end , gameRootPanel )
2013-01-24 20:15:07 +01:00
g_keyboard.bindKeyDown ( ' Ctrl+. ' , nextViewMode , gameRootPanel )
2012-01-13 01:31:39 +01:00
end
2012-07-24 07:30:08 +02:00
function terminate ( )
2013-01-18 19:49:41 +01:00
hide ( )
2013-01-06 16:04:49 +01:00
disconnect ( g_game , {
2013-01-18 06:27:29 +01:00
onGameStart = onGameStart ,
onGameEnd = onGameEnd ,
2013-01-06 16:04:49 +01:00
onLoginAdvice = onLoginAdvice
} )
2012-06-21 21:31:22 +02:00
disconnect ( gameLeftPanel , { onVisibilityChange = onLeftPanelVisibilityChange } )
2012-03-18 14:34:39 +01:00
logoutButton : destroy ( )
gameRootPanel : destroy ( )
2012-01-13 01:31:39 +01:00
end
2013-01-18 06:27:29 +01:00
function onGameStart ( )
2013-01-21 00:17:56 +01:00
logoutButton : setTooltip ( tr ( ' Logout ' ) )
2013-01-18 06:27:29 +01:00
show ( )
-- open tibia has delay in auto walking
if not g_game.isOfficialTibia ( ) then
g_game.enableFeature ( GameForceFirstAutoWalkStep )
end
end
function onGameEnd ( )
2013-01-21 00:17:56 +01:00
logoutButton : setTooltip ( tr ( ' Exit ' ) )
2013-01-18 06:27:29 +01:00
hide ( )
end
2012-07-24 07:30:08 +02:00
function show ( )
connect ( g_app , { onClose = tryExit } )
2013-01-18 23:39:11 +01:00
modules.client_background . hide ( )
2012-03-18 14:34:39 +01:00
gameRootPanel : show ( )
gameRootPanel : focus ( )
gameMapPanel : followCreature ( g_game.getLocalPlayer ( ) )
2012-12-28 17:15:57 +01:00
updateStretchShrink ( )
2012-03-18 14:34:39 +01:00
end
2012-01-12 02:21:59 +01:00
2012-07-24 07:30:08 +02:00
function hide ( )
disconnect ( g_app , { onClose = tryExit } )
2012-07-15 13:49:28 +02:00
if logoutWindow then
2012-07-14 12:59:32 +02:00
logoutWindow : destroy ( )
logoutWindow = nil
end
2012-07-15 13:49:28 +02:00
if exitWindow then
2012-07-14 12:59:32 +02:00
exitWindow : destroy ( )
exitWindow = nil
end
2012-07-15 16:28:15 +02:00
if countWindow then
2012-07-14 12:59:32 +02:00
countWindow : destroy ( )
countWindow = nil
end
2012-03-18 14:34:39 +01:00
gameRootPanel : hide ( )
2013-01-18 23:39:11 +01:00
modules.client_background . show ( )
2012-03-18 14:34:39 +01:00
end
2012-01-12 02:21:59 +01:00
2012-09-05 21:53:48 +02:00
function onLoginAdvice ( message )
2013-01-21 00:17:56 +01:00
displayInfoBox ( tr ( " For Your Information " ) , message )
2012-09-05 21:53:48 +02:00
end
2012-07-26 12:19:34 +02:00
function forceExit ( )
2012-08-10 01:21:14 +02:00
scheduleEvent ( exit , 10 )
return true
2012-01-09 21:54:37 +01:00
end
2012-07-24 07:30:08 +02:00
function tryExit ( )
2012-07-15 13:49:28 +02:00
if exitWindow then
2012-07-13 08:31:05 +02:00
return true
end
2012-07-12 18:45:22 +02:00
2012-08-13 01:27:41 +02:00
local exitFunc = function ( ) logout ( ) forceExit ( ) end
local logoutFunc = function ( ) logout ( ) exitWindow : destroy ( ) exitWindow = nil end
local cancelFunc = function ( ) exitWindow : destroy ( ) exitWindow = nil end
2013-01-21 00:17:56 +01:00
exitWindow = displayGeneralBox ( tr ( ' Exit ' ) , tr ( " If you shut down the program, your character might stay in the game. \n Click on 'Logout' to ensure that you character leaves the game properly. \n Click 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 } ,
2012-08-19 16:30:57 +02:00
anchor = AnchorHorizontalCenter } , logoutFunc , cancelFunc )
2012-07-15 16:28:15 +02:00
2012-08-13 01:27:41 +02:00
return true
2012-07-12 18:45:22 +02:00
end
2012-07-24 07:30:08 +02:00
function logout ( )
2012-03-18 14:34:39 +01:00
if g_game.isOnline ( ) then
g_game.safeLogout ( )
return true
end
end
2012-01-09 21:54:37 +01:00
2012-07-24 07:30:08 +02:00
function tryLogout ( )
2013-01-18 06:53:41 +01:00
if not g_game.isOnline ( ) then
exit ( )
end
2012-07-15 13:49:28 +02:00
if logoutWindow then
2012-07-13 08:31:05 +02:00
return
end
2012-07-12 18:45:22 +02:00
2012-08-13 01:27:41 +02:00
local yesCallback = function ( ) logout ( ) logoutWindow : destroy ( ) logoutWindow = nil end
local noCallback = function ( ) logoutWindow : destroy ( ) logoutWindow = nil end
2012-07-15 16:28:15 +02:00
2013-01-21 00:17:56 +01:00
logoutWindow = displayGeneralBox ( tr ( ' Logout ' ) , tr ( ' Are you sure you want to logout? ' ) , {
{ text = tr ( ' Yes ' ) , callback = yesCallback } ,
{ text = tr ( ' No ' ) , callback = noCallback } ,
2012-08-13 01:27:41 +02:00
anchor = AnchorHorizontalCenter } , yesCallback , noCallback )
2012-07-12 18:45:22 +02:00
end
2013-01-23 08:31:28 +01:00
function changeWalkDir ( dir )
local player = g_game.getLocalPlayer ( )
local lastWalkDir = g_game.getLastWalkDir ( )
if lastWalkDir ~= dir and player : isWalking ( ) then
smartWalk ( dir )
end
end
2012-08-29 17:41:04 +02:00
function smartWalk ( defaultDir )
2012-12-29 18:41:14 +01:00
local rebindKey = false
2013-01-23 08:31:28 +01:00
local lastKey = arrowKeys [ lastDir ]
2012-12-29 18:41:14 +01:00
2012-12-31 17:34:15 +01:00
-- choose the new direction
2012-12-29 18:41:14 +01:00
if not g_keyboard.isKeyPressed ( arrowKeys [ defaultDir ] ) then
local changeDir = false
for k , v in pairs ( arrowKeys ) do
if g_keyboard.isKeyPressed ( v ) then
defaultDir = k
changeDir = true
break
end
end
if not changeDir then
return
end
end
-- key is still pressed from previous walk event
2013-01-23 08:31:28 +01:00
if lastDir and lastDir ~= defaultDir and g_keyboard.isKeyPressed ( lastKey ) then
2012-12-29 18:41:14 +01:00
if g_keyboard.isKeySetPressed ( arrowKeys ) then
g_keyboard.unbindKeyPress ( lastKey , gameRootPanel )
rebindKey = true
end
end
local dir = defaultDir
2013-01-18 23:39:11 +01:00
if modules.client_options . getOption ( ' smartWalk ' ) then
2012-08-26 06:27:30 +02:00
if g_keyboard.isKeyPressed ( ' Up ' ) and g_keyboard.isKeyPressed ( ' Left ' ) then
dir = NorthWest
elseif g_keyboard.isKeyPressed ( ' Up ' ) and g_keyboard.isKeyPressed ( ' Right ' ) then
dir = NorthEast
elseif g_keyboard.isKeyPressed ( ' Down ' ) and g_keyboard.isKeyPressed ( ' Left ' ) then
dir = SouthWest
elseif g_keyboard.isKeyPressed ( ' Down ' ) and g_keyboard.isKeyPressed ( ' Right ' ) then
dir = SouthEast
end
end
2012-08-25 21:11:54 +02:00
2013-01-18 23:39:11 +01:00
if modules.client_options . getOption ( ' walkBooster ' ) then
2012-08-25 21:11:54 +02:00
if g_game.getLocalPlayer ( ) : canWalk ( dir ) then
g_game.walk ( dir )
else
g_game.forceWalk ( dir )
end
else
2012-12-30 07:14:49 +01:00
g_game.walk ( dir )
2012-12-29 18:41:14 +01:00
end
if rebindKey then
2013-01-23 08:31:28 +01:00
g_keyboard.bindKeyPress ( lastKey , function ( ) smartWalk ( lastDir ) end , gameRootPanel , WALK_AUTO_REPEAT_DELAY )
2012-08-25 21:11:54 +02:00
end
2013-01-23 08:31:28 +01:00
lastDir = dir
2012-08-25 21:11:54 +02:00
end
2012-10-10 01:25:50 +02:00
function updateStretchShrink ( )
2013-01-24 20:15:07 +01:00
if modules.client_options . getOption ( ' dontStretchShrink ' ) and not alternativeView then
2012-10-10 01:25:50 +02:00
gameMapPanel : setVisibleDimension ( { width = 15 , height = 11 } )
2013-01-24 20:15:07 +01:00
-- Set gameMapPanel size to height = 11 * 32 + 2
bottomSplitter : setMarginBottom ( bottomSplitter : getMarginBottom ( ) + ( gameMapPanel : getHeight ( ) - 32 * 11 ) - 10 )
2012-08-25 21:11:54 +02:00
end
end
2012-07-24 07:30:08 +02:00
function onMouseGrabberRelease ( self , mousePosition , mouseButton )
if selectedThing == nil then return false end
2012-03-29 01:19:28 +02:00
if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel : recursiveGetChildByPos ( mousePosition , false )
if clickedWidget then
2012-07-24 07:30:08 +02:00
if selectedType == ' use ' then
onUseWith ( clickedWidget , mousePosition )
elseif selectedType == ' trade ' then
onTradeWith ( clickedWidget , mousePosition )
2012-03-29 01:19:28 +02:00
end
end
end
2012-04-25 00:09:48 +02:00
2012-07-24 07:30:08 +02:00
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-07-24 07:30:08 +02:00
function onUseWith ( clickedWidget , mousePosition )
2012-04-25 00:09:48 +02:00
if clickedWidget : getClassName ( ) == ' UIMap ' then
local tile = clickedWidget : getTile ( mousePosition )
if tile then
2013-01-09 20:29:58 +01:00
g_game.useWith ( selectedThing , tile : getTopMultiUseThing ( ) )
2012-04-25 00:09:48 +02:00
end
2012-08-17 23:36:53 +02:00
elseif clickedWidget : getClassName ( ) == ' UIItem ' and not clickedWidget : isVirtual ( ) then
g_game.useWith ( selectedThing , clickedWidget : getItem ( ) )
2012-08-25 18:05:33 +02:00
elseif clickedWidget : getClassName ( ) == ' UICreatureButton ' then
local creature = clickedWidget : getCreature ( )
if creature then
g_game.useWith ( selectedThing , creature )
end
2012-04-25 00:09:48 +02:00
end
end
2012-07-24 07:30:08 +02:00
function onTradeWith ( clickedWidget , mousePosition )
2012-04-25 00:09:48 +02:00
if clickedWidget : getClassName ( ) == ' UIMap ' then
local tile = clickedWidget : getTile ( mousePosition )
if tile then
2012-07-24 07:30:08 +02:00
g_game.requestTrade ( selectedThing , tile : getTopCreature ( ) )
2012-04-25 00:09:48 +02:00
end
end
end
2012-07-24 07:30:08 +02:00
function startUseWith ( thing )
2013-01-21 22:36:53 +01:00
if not thing then return end
2012-07-24 07:30:08 +02:00
selectedType = ' use '
selectedThing = thing
2012-04-25 00:09:48 +02:00
mouseGrabberWidget : grabMouse ( )
2012-06-26 00:13:30 +02:00
g_mouse.setTargetCursor ( )
2012-04-25 00:09:48 +02:00
end
2012-07-24 07:30:08 +02:00
function startTradeWith ( thing )
selectedType = ' trade '
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-07-24 07:30:08 +02:00
function createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2012-07-26 08:10:28 +02:00
if not g_game.isOnline ( ) then return end
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-07-24 07:30:08 +02:00
menu : addOption ( tr ( ' Use with ... ' ) , function ( ) 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-07-29 05:34:40 +02:00
if lookThing and not lookThing : isCreature ( ) and not lookThing : isNotMoveable ( ) and lookThing : isPickupable ( ) then
2012-01-09 01:43:36 +01:00
menu : addSeparator ( )
2012-07-24 07:30:08 +02:00
menu : addOption ( tr ( ' Trade with ... ' ) , function ( ) 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-08-20 14:28:19 +02:00
local localPlayer = g_game.getLocalPlayer ( )
2012-01-03 23:27:31 +01:00
menu : addSeparator ( )
2012-01-12 02:21:59 +01:00
2012-07-29 05:34:40 +02:00
if creatureThing : isLocalPlayer ( ) 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-08-25 07:02:07 +02:00
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
2012-08-20 14:28:19 +02:00
end
if creatureThing : isPartyMember ( ) then
2012-03-18 14:34:39 +01:00
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-07-26 08:10:28 +02:00
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
2012-01-12 02:21:59 +01:00
2012-07-29 05:34:40 +02:00
if creatureThing : isPlayer ( ) then
2012-07-26 08:10:28 +02:00
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
2012-01-07 23:24:29 +01:00
end
2012-07-26 08:10:28 +02:00
if ( not Player : hasVip ( creatureName ) ) then
menu : addOption ( tr ( ' Add to VIP list ' ) , function ( ) g_game.addVip ( creatureName ) end )
end
2013-01-10 04:20:26 +01:00
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
2012-07-26 08:10:28 +02:00
2012-08-02 12:12:54 +02:00
local localPlayerShield = localPlayer : getShield ( )
2012-07-26 08:10:28 +02:00
local creatureShield = creatureThing : getShield ( )
2012-01-12 02:21:59 +01:00
2012-07-26 08:10:28 +02:00
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 )
2012-04-24 13:20:14 +02:00
end
2012-07-26 08:10:28 +02:00
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
menu : addOption ( tr ( ' Revoke %s \' s Invitation ' , creatureThing : getName ( ) ) , function ( ) g_game.partyRevokeInvitation ( creatureThing : getId ( ) ) end )
2012-07-09 08:59:16 +02:00
end
2012-07-26 08:10:28 +02:00
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 )
2012-01-11 00:38:32 +01:00
end
end
2012-01-05 15:24:38 +01:00
end
2012-01-03 23:27:31 +01:00
end
2012-07-26 11:12:20 +02:00
if modules.game_ruleviolation . hasWindowAccess ( ) then
2012-05-01 08:49:48 +02:00
menu : addSeparator ( )
2012-07-26 11:12:20 +02:00
menu : addOption ( tr ( ' Rule Violation ' ) , function ( ) modules.game_ruleviolation . show ( creatureThing : getName ( ) ) end )
2012-05-01 08:49:48 +02:00
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
2013-01-09 20:29:58 +01:00
function processMouseAction ( menuPosition , mouseButton , autoWalkPos , lookThing , useThing , creatureThing )
2012-06-26 00:13:30 +02:00
local keyboardModifiers = g_keyboard.getModifiers ( )
2012-03-18 14:34:39 +01:00
2013-01-18 23:39:11 +01:00
if not modules.client_options . getOption ( ' classicControl ' ) then
2012-03-18 14:34:39 +01:00
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
2012-07-24 07:30:08 +02:00
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2012-03-18 14:34:39 +01:00
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
else
2012-06-26 00:13:30 +02:00
g_game.open ( useThing )
2012-03-18 14:34:39 +01:00
end
2012-08-25 00:59:33 +02:00
return true
2012-03-18 14:34:39 +01:00
elseif useThing : isMultiUse ( ) then
2012-07-24 07:30:08 +02:00
startUseWith ( useThing )
2012-03-18 14:34:39 +01:00
return true
else
g_game.use ( useThing )
2013-01-21 22:36:53 +01:00
return true
2012-03-18 14:34:39 +01:00
end
return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and ( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.attack ( creatureThing )
return true
end
2013-01-06 16:04:49 +01:00
-- classic control
2012-03-18 14:34:39 +01:00
else
2013-01-09 20:29:58 +01:00
if useThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed ( MouseLeftButton ) then
2012-07-13 08:31:05 +02:00
local player = g_game.getLocalPlayer ( )
2012-08-02 04:05:02 +02:00
if creatureThing and creatureThing ~= player then
2012-08-02 03:47:55 +02:00
g_game.attack ( creatureThing )
2012-03-18 14:34:39 +01:00
return true
2013-01-09 20:29:58 +01:00
elseif useThing : isContainer ( ) then
if useThing : getParentContainer ( ) then
g_game.open ( useThing , useThing : getParentContainer ( ) )
2012-03-18 14:34:39 +01:00
return true
else
2013-01-09 20:29:58 +01:00
g_game.open ( useThing )
2012-03-18 14:34:39 +01:00
return true
end
2013-01-09 20:29:58 +01:00
elseif useThing : isMultiUse ( ) then
2012-07-24 07:30:08 +02:00
startUseWith ( useThing )
2012-03-18 14:34:39 +01:00
return true
else
2013-01-06 16:04:49 +01:00
g_game.use ( useThing )
2012-03-18 14:34:39 +01:00
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
2013-01-06 16:04:49 +01:00
g_game.look ( lookThing )
2012-07-05 07:40:21 +02:00
return true
2012-03-18 14:34:39 +01:00
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and ( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
2012-07-24 07:30:08 +02:00
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2012-03-18 14:34:39 +01:00
return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and ( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.attack ( creatureThing )
return true
end
end
2013-01-08 16:32:37 +01:00
local player = g_game.getLocalPlayer ( )
2013-01-22 13:01:30 +01:00
player : stopAutoWalk ( )
2013-01-08 16:32:37 +01:00
2012-07-05 07:40:21 +02:00
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
2013-01-07 18:17:01 +01:00
if not player : autoWalk ( autoWalkPos ) then
2013-01-08 16:32:37 +01:00
modules.game_textmessage . displayStatusMessage ( tr ( ' There is no way. ' ) )
2012-07-05 07:40:21 +02:00
end
2013-01-08 18:59:03 +01:00
return true
2012-07-05 07:40:21 +02:00
end
2012-03-18 14:34:39 +01:00
return false
end
2012-07-24 07:30:08 +02:00
function moveStackableItem ( item , toPos )
2012-09-01 01:33:51 +02:00
if countWindow then
2012-07-13 08:31:05 +02:00
return
end
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
local count = item : getCount ( )
2013-01-08 18:59:03 +01:00
2012-07-13 08:31:05 +02:00
countWindow = g_ui.createWidget ( ' CountWindow ' , rootWidget )
2013-01-08 18:59:03 +01:00
local itembox = countWindow : getChildById ( ' item ' )
2012-03-29 15:45:40 +02:00
local scrollbar = countWindow : getChildById ( ' countScrollBar ' )
2013-01-08 18:59:03 +01:00
itembox : setItemId ( item : getId ( ) )
itembox : setItemCount ( count )
2012-03-29 15:45:40 +02:00
scrollbar : setMaximum ( count )
scrollbar : setMinimum ( 1 )
scrollbar : setValue ( count )
2012-09-01 01:33:51 +02:00
2013-01-08 18:59:03 +01:00
local spinbox = countWindow : getChildById ( ' spinBox ' )
spinbox : setMaximum ( count )
spinbox : setMinimum ( 0 )
spinbox : setValue ( 0 )
spinbox : hideButtons ( )
spinbox : focus ( )
2012-09-01 01:33:51 +02:00
local spinBoxValueChange = function ( self , value )
scrollbar : setValue ( value )
end
spinbox.onValueChange = spinBoxValueChange
scrollbar.onValueChange = function ( self , value )
2013-01-08 18:59:03 +01:00
itembox : setItemCount ( value )
2012-09-01 01:33:51 +02:00
spinbox.onValueChange = nil
2012-09-02 01:16:17 +02:00
spinbox : setValue ( value )
2012-09-01 01:33:51 +02:00
spinbox.onValueChange = spinBoxValueChange
end
2012-03-29 15:45:40 +02:00
local okButton = countWindow : getChildById ( ' buttonOk ' )
local moveFunc = function ( )
2013-01-08 18:59:03 +01:00
g_game.move ( item , toPos , itembox : getItemCount ( ) )
2012-03-29 15:45:40 +02:00
okButton : getParent ( ) : destroy ( )
2012-07-13 08:31:05 +02:00
countWindow = nil
end
local cancelButton = countWindow : getChildById ( ' buttonCancel ' )
local cancelFunc = function ( )
cancelButton : getParent ( ) : destroy ( )
countWindow = nil
2012-03-29 15:45:40 +02:00
end
countWindow.onEnter = moveFunc
2012-07-13 08:31:05 +02:00
countWindow.onEscape = cancelFunc
2012-07-15 16:28:15 +02:00
2012-03-29 15:45:40 +02:00
okButton.onClick = moveFunc
2012-07-13 08:31:05 +02:00
cancelButton.onClick = cancelFunc
2012-03-29 15:45:40 +02:00
end
2012-07-24 07:30:08 +02:00
function getRootPanel ( )
2012-03-18 14:34:39 +01:00
return gameRootPanel
end
2012-07-24 07:30:08 +02:00
function getMapPanel ( )
2012-03-18 14:34:39 +01:00
return gameMapPanel
end
2012-07-24 07:30:08 +02:00
function getRightPanel ( )
2012-03-18 14:34:39 +01:00
return gameRightPanel
end
2012-07-24 07:30:08 +02:00
function getLeftPanel ( )
2012-03-18 14:34:39 +01:00
return gameLeftPanel
end
2012-07-24 07:30:08 +02:00
function getBottomPanel ( )
2012-03-18 14:34:39 +01:00
return gameBottomPanel
end
2012-07-24 07:30:08 +02:00
2012-07-24 07:41:59 +02:00
function onLeftPanelVisibilityChange ( leftPanel , visible )
2012-07-24 07:30:08 +02:00
if not visible then
local children = leftPanel : getChildren ( )
for i = 1 , # children do
children [ i ] : setParent ( gameRightPanel )
end
end
2012-12-28 17:15:57 +01:00
end
2013-01-21 22:36:53 +01:00
2013-01-24 20:15:07 +01:00
function nextViewMode ( )
setupViewMode ( ( currentViewMode + 1 ) % 3 )
end
function setupViewMode ( mode )
if mode == currentViewMode then return end
if currentViewMode == 2 then
2013-01-21 22:36:53 +01:00
gameMapPanel : addAnchor ( AnchorLeft , ' gameLeftPanel ' , AnchorRight )
gameMapPanel : addAnchor ( AnchorRight , ' gameRightPanel ' , AnchorLeft )
gameMapPanel : addAnchor ( AnchorBottom , ' gameBottomPanel ' , AnchorTop )
gameRootPanel : addAnchor ( AnchorTop , ' topMenu ' , AnchorBottom )
gameLeftPanel : setOn ( false )
gameLeftPanel : setVisible ( false )
gameLeftPanel : setImageColor ( ' white ' )
gameRightPanel : setImageColor ( ' white ' )
gameLeftPanel : setMarginTop ( 0 )
gameRightPanel : setMarginTop ( 0 )
gameBottomPanel : setImageColor ( ' white ' )
modules.client_topmenu . getTopMenu ( ) : setImageColor ( ' white ' )
g_game.changeMapAwareRange ( 18 , 14 )
end
2013-01-24 20:15:07 +01:00
if mode == 0 then
gameMapPanel : setKeepAspectRatio ( true )
gameMapPanel : setLimitVisibleRange ( false )
gameMapPanel : setZoom ( 11 )
gameMapPanel : setVisibleDimension ( { width = 15 , height = 11 } )
elseif mode == 1 then
gameMapPanel : setKeepAspectRatio ( false )
gameMapPanel : setLimitVisibleRange ( true )
gameMapPanel : setZoom ( 11 )
gameMapPanel : setVisibleDimension ( { width = 15 , height = 11 } )
elseif mode == 2 then
gameMapPanel : setLimitVisibleRange ( limitZoom )
gameMapPanel : setZoom ( 11 )
gameMapPanel : setVisibleDimension ( { width = 15 , height = 11 } )
gameMapPanel : fill ( ' parent ' )
gameRootPanel : fill ( ' parent ' )
gameLeftPanel : setImageColor ( ' alpha ' )
gameRightPanel : setImageColor ( ' alpha ' )
gameLeftPanel : setMarginTop ( 36 )
gameRightPanel : setMarginTop ( 36 )
gameLeftPanel : setOn ( true )
gameLeftPanel : setVisible ( true )
gameRightPanel : setOn ( true )
gameBottomPanel : setImageColor ( ' #00000099 ' )
modules.client_topmenu . getTopMenu ( ) : setImageColor ( ' #ffffff66 ' )
if not limitZoom then
g_game.changeMapAwareRange ( 24 , 20 )
end
end
currentViewMode = mode
end
function limitZoom ( )
limitZoom = true
gameMapPanel : setMaxZoomOut ( 11 )
gameMapPanel : setLimitVisibleRange ( true )
2013-01-21 22:36:53 +01:00
end