2013-01-08 06:17:01 +13:00
WALK_STEPS_RETRY = 10
2012-07-24 02:30:08 -03:00
gameRootPanel = nil
gameMapPanel = nil
gameRightPanel = nil
2021-07-22 20:33:54 +02:00
gameRightExtraPanel = nil
2012-07-24 02:30:08 -03:00
gameLeftPanel = nil
2021-07-23 21:25:47 +02:00
gameSelectedPanel = nil
panelsList = { }
panelsRadioGroup = nil
2012-07-24 02:30:08 -03:00
gameBottomPanel = nil
2017-11-19 02:00:02 +01:00
showTopMenuButton = nil
2012-07-24 02:30:08 -03:00
logoutButton = nil
mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
2012-10-10 01:25:50 +02:00
bottomSplitter = nil
2013-11-12 23:35:05 +01:00
limitedZoom = false
2013-01-24 17:15:07 -02:00
currentViewMode = 0
2013-01-26 18:10:30 -02:00
smartWalkDirs = { }
smartWalkDir = nil
2021-07-25 18:22:56 +02:00
firstStep = false
2014-07-13 22:27:09 +12:00
hookedMenuOptions = { }
2017-11-16 18:58:58 +01:00
lastDirTime = g_clock.millis ( )
2012-12-30 06:41:14 +13:00
2012-07-24 02:30:08 -03:00
function init ( )
2021-07-19 19:24:59 -03:00
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
2022-04-29 23:14:24 -03:00
connect ( g_app , {
onRun = load ,
onExit = save
} )
2021-07-19 19:24:59 -03:00
gameRootPanel = g_ui.displayUI ( ' gameinterface ' )
gameRootPanel : hide ( )
gameRootPanel : lower ( )
gameRootPanel.onGeometryChange = updateStretchShrink
gameRootPanel.onFocusChange = stopSmartWalk
mouseGrabberWidget = gameRootPanel : getChildById ( ' mouseGrabber ' )
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
bottomSplitter = gameRootPanel : getChildById ( ' bottomSplitter ' )
gameMapPanel = gameRootPanel : getChildById ( ' gameMapPanel ' )
gameRightPanel = gameRootPanel : getChildById ( ' gameRightPanel ' )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel = gameRootPanel : getChildById ( ' gameRightExtraPanel ' )
2021-07-19 19:24:59 -03:00
gameLeftPanel = gameRootPanel : getChildById ( ' gameLeftPanel ' )
gameBottomPanel = gameRootPanel : getChildById ( ' gameBottomPanel ' )
2021-07-23 21:25:47 +02:00
2022-04-29 23:14:24 -03:00
panelsList = { {
panel = gameRightPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectRightColumn ' )
} , {
panel = gameRightExtraPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectRightExtraColumn ' )
} , {
panel = gameLeftPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectLeftColumn ' )
} }
2021-07-23 21:25:47 +02:00
panelsRadioGroup = UIRadioGroup.create ( )
2022-04-29 23:14:24 -03:00
for k , v in pairs ( panelsList ) do
2021-07-23 21:25:47 +02:00
panelsRadioGroup : addWidget ( v.checkbox )
2022-04-29 23:14:24 -03:00
connect ( v.checkbox , {
onCheckChange = onSelectPanel
} )
2021-07-23 21:25:47 +02:00
end
panelsRadioGroup : selectWidget ( panelsList [ 1 ] . checkbox )
2022-04-29 23:14:24 -03:00
connect ( gameLeftPanel , {
onVisibilityChange = onExtraPanelVisibilityChange
} )
connect ( gameRightExtraPanel , {
onVisibilityChange = onExtraPanelVisibilityChange
} )
2021-07-19 19:24:59 -03:00
2022-04-29 23:14:24 -03:00
logoutButton = modules.client_topmenu . addLeftButton ( ' logoutButton ' , tr ( ' Exit ' ) , ' /images/topbuttons/logout ' ,
2021-07-19 19:24:59 -03:00
tryLogout , true )
showTopMenuButton = gameMapPanel : getChildById ( ' showTopMenuButton ' )
2022-08-17 12:51:56 -03:00
showTopMenuButton.onClick = function ( )
modules.client_topmenu . toggle ( )
end
2021-07-19 19:24:59 -03:00
bindKeys ( )
2022-08-17 12:51:56 -03:00
if g_game.isOnline ( ) then
show ( )
end
2012-08-25 16:11:54 -03:00
end
2021-07-23 21:25:47 +02:00
function onSelectPanel ( self , checked )
if checked then
2022-04-29 23:14:24 -03:00
for k , v in pairs ( panelsList ) do
2021-07-23 21:25:47 +02:00
if v.checkbox == self then
gameSelectedPanel = v.panel
break
end
end
end
end
2012-08-25 16:11:54 -03:00
function bindKeys ( )
2023-02-13 19:41:06 -03:00
gameRootPanel : setAutoRepeatDelay ( 50 )
2021-07-19 19:24:59 -03:00
bindWalkKey ( ' Up ' , North )
bindWalkKey ( ' Right ' , East )
bindWalkKey ( ' Down ' , South )
bindWalkKey ( ' Left ' , West )
bindWalkKey ( ' Numpad8 ' , North )
bindWalkKey ( ' Numpad9 ' , NorthEast )
bindWalkKey ( ' Numpad6 ' , East )
bindWalkKey ( ' Numpad3 ' , SouthEast )
bindWalkKey ( ' Numpad2 ' , South )
bindWalkKey ( ' Numpad1 ' , SouthWest )
bindWalkKey ( ' Numpad4 ' , West )
bindWalkKey ( ' Numpad7 ' , NorthWest )
bindTurnKey ( ' Ctrl+Up ' , North )
bindTurnKey ( ' Ctrl+Right ' , East )
bindTurnKey ( ' Ctrl+Down ' , South )
bindTurnKey ( ' Ctrl+Left ' , West )
bindTurnKey ( ' Ctrl+Numpad8 ' , North )
bindTurnKey ( ' Ctrl+Numpad6 ' , East )
bindTurnKey ( ' Ctrl+Numpad2 ' , South )
bindTurnKey ( ' Ctrl+Numpad4 ' , West )
2022-08-17 12:51:56 -03:00
g_keyboard.bindKeyPress ( ' Escape ' , function ( )
g_game.cancelAttackAndFollow ( )
end , gameRootPanel )
g_keyboard.bindKeyPress ( ' Ctrl+= ' , function ( )
gameMapPanel : zoomIn ( )
end , gameRootPanel )
g_keyboard.bindKeyPress ( ' Ctrl+- ' , function ( )
gameMapPanel : zoomOut ( )
end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+Q ' , function ( )
tryLogout ( false )
end , gameRootPanel )
g_keyboard.bindKeyDown ( ' Ctrl+L ' , function ( )
tryLogout ( false )
end , gameRootPanel )
2021-07-23 23:28:17 +02:00
g_keyboard.bindKeyDown ( ' Alt+W ' , function ( )
2021-07-19 19:24:59 -03:00
g_map.cleanTexts ( )
modules.game_textmessage . clearMessages ( )
end , gameRootPanel )
2023-03-09 14:20:42 -03:00
if not g_app.isScaled ( ) then
g_keyboard.bindKeyDown ( ' Ctrl+. ' , nextViewMode , gameRootPanel )
end
2012-01-12 22:31:39 -02:00
end
2013-07-29 10:41:44 +12:00
function bindWalkKey ( key , dir )
2022-08-17 12:51:56 -03:00
g_keyboard.bindKeyDown ( key , function ( )
onWalkKeyDown ( dir )
end , gameRootPanel , true )
g_keyboard.bindKeyUp ( key , function ( )
changeWalkDir ( dir , true )
end , gameRootPanel , true )
g_keyboard.bindKeyPress ( key , function ( )
smartWalk ( dir )
end , gameRootPanel )
2013-07-29 10:41:44 +12:00
end
function unbindWalkKey ( key )
2021-07-19 19:24:59 -03:00
g_keyboard.unbindKeyDown ( key , gameRootPanel )
g_keyboard.unbindKeyUp ( key , gameRootPanel )
g_keyboard.unbindKeyPress ( key , gameRootPanel )
2013-07-29 10:41:44 +12:00
end
2017-11-16 18:58:58 +01:00
function bindTurnKey ( key , dir )
2021-07-19 19:24:59 -03:00
local function callback ( widget , code , repeatTicks )
2022-04-29 23:14:24 -03:00
if g_clock.millis ( ) - lastDirTime >= modules.client_options . getOption ( ' turnDelay ' ) then
2021-07-19 19:24:59 -03:00
g_game.turn ( dir )
changeWalkDir ( dir )
2017-11-16 18:58:58 +01:00
2021-07-19 19:24:59 -03:00
lastDirTime = g_clock.millis ( )
end
2017-11-16 18:58:58 +01:00
end
2021-07-19 19:24:59 -03:00
g_keyboard.bindKeyPress ( key , callback , gameRootPanel )
2017-11-16 18:58:58 +01:00
end
2022-08-17 12:51:56 -03:00
function unbindTurnKey ( key )
g_keyboard.unbindKeyPress ( key , gameRootPanel )
end
2021-07-23 23:28:17 +02:00
2012-07-24 02:30:08 -03:00
function terminate ( )
2021-07-19 19:24:59 -03:00
hide ( )
2013-01-18 16:49:41 -02:00
2021-07-19 19:24:59 -03:00
hookedMenuOptions = { }
2014-07-13 22:27:09 +12:00
2021-07-19 19:24:59 -03:00
stopSmartWalk ( )
2013-01-26 18:10:30 -02:00
2021-07-19 19:24:59 -03:00
disconnect ( g_game , {
onGameStart = onGameStart ,
onGameEnd = onGameEnd ,
onLoginAdvice = onLoginAdvice
} )
2013-01-07 04:04:49 +13:00
2022-04-29 23:14:24 -03:00
disconnect ( gameLeftPanel , {
onVisibilityChange = onExtraPanelVisibilityChange
} )
disconnect ( gameRightExtraPanel , {
onVisibilityChange = onExtraPanelVisibilityChange
} )
2012-03-18 10:34:39 -03:00
2022-04-29 23:14:24 -03:00
for k , v in pairs ( panelsList ) do
disconnect ( v.checkbox , {
onCheckChange = onSelectPanel
} )
2021-07-23 21:25:47 +02:00
end
2021-07-19 19:24:59 -03:00
logoutButton : destroy ( )
gameRootPanel : destroy ( )
2012-01-12 22:31:39 -02:00
end
2013-01-18 18:27:29 +13:00
function onGameStart ( )
2021-07-19 19:24:59 -03:00
show ( )
2013-01-18 18:27:29 +13:00
2021-07-19 19:24:59 -03:00
-- open tibia has delay in auto walking
if not g_game.isOfficialTibia ( ) then
g_game.enableFeature ( GameForceFirstAutoWalkStep )
else
g_game.disableFeature ( GameForceFirstAutoWalkStep )
end
2013-01-18 18:27:29 +13:00
end
function onGameEnd ( )
2021-07-19 19:24:59 -03:00
hide ( )
2013-01-18 18:27:29 +13:00
end
2012-07-24 02:30:08 -03:00
function show ( )
2022-04-29 23:14:24 -03:00
connect ( g_app , {
onClose = tryExit
} )
2021-07-19 19:24:59 -03:00
modules.client_background . hide ( )
gameRootPanel : show ( )
gameRootPanel : focus ( )
gameMapPanel : followCreature ( g_game.getLocalPlayer ( ) )
2023-03-09 14:20:42 -03:00
2021-07-19 19:24:59 -03:00
updateStretchShrink ( )
logoutButton : setTooltip ( tr ( ' Logout ' ) )
2023-03-09 14:20:42 -03:00
setupViewMode ( 0 )
if g_app.isScaled ( ) then
setupViewMode ( 1 )
setupViewMode ( 2 )
end
2021-07-19 19:24:59 -03:00
addEvent ( function ( )
if not limitedZoom or g_game.isGM ( ) then
gameMapPanel : setMaxZoomOut ( 513 )
gameMapPanel : setLimitVisibleRange ( false )
else
gameMapPanel : setMaxZoomOut ( 11 )
gameMapPanel : setLimitVisibleRange ( true )
end
2023-03-09 14:20:42 -03:00
2021-07-19 19:24:59 -03:00
end )
2012-03-18 10:34:39 -03:00
end
2012-01-11 23:21:59 -02:00
2012-07-24 02:30:08 -03:00
function hide ( )
2023-03-09 14:20:42 -03:00
setupViewMode ( 0 )
2022-04-29 23:14:24 -03:00
disconnect ( g_app , {
onClose = tryExit
} )
2021-07-19 19:24:59 -03:00
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 ( )
2012-03-18 10:34:39 -03:00
end
2012-01-11 23:21:59 -02:00
2013-02-14 13:54:33 -02:00
function save ( )
2021-07-19 19:24:59 -03:00
local settings = { }
settings.splitterMarginBottom = bottomSplitter : getMarginBottom ( )
g_settings.setNode ( ' game_interface ' , settings )
2013-02-14 13:54:33 -02:00
end
function load ( )
2021-07-19 19:24:59 -03:00
local settings = g_settings.getNode ( ' game_interface ' )
if settings then
2022-08-17 12:51:56 -03:00
if settings.splitterMarginBottom then
bottomSplitter : setMarginBottom ( settings.splitterMarginBottom )
end
2013-02-14 13:54:33 -02:00
end
end
2022-08-17 12:51:56 -03:00
function onLoginAdvice ( message )
displayInfoBox ( tr ( ' For Your Information ' ) , message )
end
2012-09-05 16:53:48 -03:00
2012-07-26 22:19:34 +12:00
function forceExit ( )
2021-07-19 19:24:59 -03:00
g_game.cancelLogin ( )
scheduleEvent ( exit , 10 )
return true
2012-01-09 18:54:37 -02:00
end
2012-07-24 02:30:08 -03:00
function tryExit ( )
2022-08-17 12:51:56 -03:00
if exitWindow then
return true
end
2012-07-13 04:45:22 +12:00
2021-07-19 19:24:59 -03:00
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
2012-08-12 20:27:41 -03:00
2021-07-19 19:24:59 -03:00
exitWindow = displayGeneralBox ( tr ( ' Exit ' ) , tr (
2022-04-29 23:14:24 -03:00
' 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. ' ) ,
2021-07-19 19:24:59 -03:00
{
2022-04-29 23:14:24 -03:00
{
text = tr ( ' Force Exit ' ) ,
callback = exitFunc
} ,
{
text = tr ( ' Logout ' ) ,
callback = logoutFunc
} ,
{
text = tr ( ' Cancel ' ) ,
callback = cancelFunc
} ,
2021-07-19 19:24:59 -03:00
anchor = AnchorHorizontalCenter
} , logoutFunc , cancelFunc )
2012-07-15 11:28:15 -03:00
2021-07-19 19:24:59 -03:00
return true
2012-07-13 04:45:22 +12:00
end
2013-07-07 05:36:56 +12:00
function tryLogout ( prompt )
2022-08-17 12:51:56 -03:00
if type ( prompt ) ~= ' boolean ' then
prompt = true
end
2021-07-19 19:24:59 -03:00
if not g_game.isOnline ( ) then
exit ( )
return
2013-03-13 20:55:20 -03:00
end
2013-07-07 05:36:56 +12:00
2022-08-17 12:51:56 -03:00
if logoutWindow then
return
end
2021-07-19 19:24:59 -03:00
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
2013-03-13 20:55:20 -03:00
end
2012-07-15 11:28:15 -03:00
2021-07-19 19:24:59 -03:00
local noCallback = function ( )
logoutWindow : destroy ( )
logoutWindow = nil
end
2013-07-07 05:36:56 +12:00
2021-07-19 19:24:59 -03:00
if prompt then
logoutWindow = displayGeneralBox ( tr ( ' Logout ' ) , tr ( msg ) , {
2022-04-29 23:14:24 -03:00
{
text = tr ( ' Yes ' ) ,
callback = yesCallback
} ,
{
text = tr ( ' No ' ) ,
callback = noCallback
} ,
2021-07-19 19:24:59 -03:00
anchor = AnchorHorizontalCenter
} , yesCallback , noCallback )
else
yesCallback ( )
end
2012-07-13 04:45:22 +12:00
end
2013-01-26 20:12:00 -02:00
function stopSmartWalk ( )
2021-07-19 19:24:59 -03:00
smartWalkDirs = { }
smartWalkDir = nil
2013-01-23 20:31:28 +13:00
end
2021-07-25 22:17:25 +02:00
function onWalkKeyDown ( dir )
2021-08-06 00:14:33 +02:00
if modules.client_options . getOption ( ' autoChaseOverride ' ) then
2022-08-17 12:51:56 -03:00
if g_game.isAttacking ( ) and g_game.getChaseMode ( ) == ChaseOpponent then
g_game.setChaseMode ( DontChase )
end
2021-08-06 00:14:33 +02:00
end
2021-07-25 22:17:25 +02:00
firstStep = true
changeWalkDir ( dir )
end
2013-01-26 18:10:30 -02:00
function changeWalkDir ( dir , pop )
2022-08-17 12:51:56 -03:00
while table.removevalue ( smartWalkDirs , dir ) do
end
2021-07-19 19:24:59 -03:00
if pop then
if # smartWalkDirs == 0 then
stopSmartWalk ( )
return
end
else
table.insert ( smartWalkDirs , 1 , dir )
end
smartWalkDir = smartWalkDirs [ 1 ]
if modules.client_options . getOption ( ' smartWalk ' ) and # smartWalkDirs > 1 then
for _ , d in pairs ( smartWalkDirs ) do
2022-04-29 23:14:24 -03:00
if ( smartWalkDir == North and d == West ) or ( smartWalkDir == West and d == North ) then
2021-07-19 19:24:59 -03:00
smartWalkDir = NorthWest
break
2022-04-29 23:14:24 -03:00
elseif ( smartWalkDir == North and d == East ) or ( smartWalkDir == East and d == North ) then
2021-07-19 19:24:59 -03:00
smartWalkDir = NorthEast
break
2022-04-29 23:14:24 -03:00
elseif ( smartWalkDir == South and d == West ) or ( smartWalkDir == West and d == South ) then
2021-07-19 19:24:59 -03:00
smartWalkDir = SouthWest
break
2022-04-29 23:14:24 -03:00
elseif ( smartWalkDir == South and d == East ) or ( smartWalkDir == East and d == South ) then
2021-07-19 19:24:59 -03:00
smartWalkDir = SouthEast
break
end
end
end
2013-01-26 18:10:30 -02:00
end
2012-12-30 06:41:14 +13:00
2013-01-26 21:18:07 -02:00
function smartWalk ( dir )
2022-08-17 12:51:56 -03:00
if g_keyboard.getModifiers ( ) ~= KeyboardNoModifier then
return false
end
2020-12-24 14:33:48 -03:00
2021-07-19 19:24:59 -03:00
local dire = smartWalkDir or dir
2021-07-25 18:22:56 +02:00
g_game.walk ( dire , firstStep )
firstStep = false
2021-07-19 19:24:59 -03:00
return true
2012-08-25 16:11:54 -03:00
end
2013-01-26 18:10:30 -02:00
function updateStretchShrink ( )
2022-04-29 23:14:24 -03:00
if modules.client_options . getOption ( ' dontStretchShrink ' ) and not alternativeView then
gameMapPanel : setVisibleDimension ( {
width = 15 ,
height = 11
} )
2021-07-19 19:24:59 -03:00
-- Set gameMapPanel size to height = 11 * 32 + 2
2022-04-29 23:14:24 -03:00
bottomSplitter : setMarginBottom ( bottomSplitter : getMarginBottom ( ) + ( gameMapPanel : getHeight ( ) - 32 * 11 ) - 10 )
2021-07-19 19:24:59 -03:00
end
2012-08-25 16:11:54 -03:00
end
2012-07-24 02:30:08 -03:00
function onMouseGrabberRelease ( self , mousePosition , mouseButton )
2022-08-17 12:51:56 -03:00
if selectedThing == nil then
return false
end
2021-07-19 19:24:59 -03:00
if mouseButton == MouseLeftButton then
2022-04-29 23:14:24 -03:00
local clickedWidget = gameRootPanel : recursiveGetChildByPos ( mousePosition , false )
2021-07-19 19:24:59 -03:00
if clickedWidget then
if selectedType == ' use ' then
onUseWith ( clickedWidget , mousePosition )
elseif selectedType == ' trade ' then
onTradeWith ( clickedWidget , mousePosition )
end
end
2012-03-28 20:19:28 -03:00
end
2012-04-24 19:09:48 -03:00
2021-07-19 19:24:59 -03:00
selectedThing = nil
g_mouse.popCursor ( ' target ' )
self : ungrabMouse ( )
return true
2012-03-28 20:19:28 -03:00
end
2012-07-24 02:30:08 -03:00
function onUseWith ( clickedWidget , mousePosition )
2021-07-19 19:24:59 -03:00
if clickedWidget : getClassName ( ) == ' UIGameMap ' then
local tile = clickedWidget : getTile ( mousePosition )
if tile then
if selectedThing : isFluidContainer ( ) or selectedThing : isMultiUse ( ) then
g_game.useWith ( selectedThing , tile : getTopMultiUseThing ( ) )
else
g_game.useWith ( selectedThing , tile : getTopUseThing ( ) )
end
end
2022-04-29 23:14:24 -03:00
elseif clickedWidget : getClassName ( ) == ' UIItem ' and not clickedWidget : isVirtual ( ) then
2021-07-19 19:24:59 -03:00
g_game.useWith ( selectedThing , clickedWidget : getItem ( ) )
elseif clickedWidget : getClassName ( ) == ' UICreatureButton ' then
local creature = clickedWidget : getCreature ( )
2022-08-17 12:51:56 -03:00
if creature then
g_game.useWith ( selectedThing , creature )
end
2012-08-26 04:05:33 +12:00
end
2012-04-24 19:09:48 -03:00
end
2012-07-24 02:30:08 -03:00
function onTradeWith ( clickedWidget , mousePosition )
2021-07-19 19:24:59 -03:00
if clickedWidget : getClassName ( ) == ' UIGameMap ' then
local tile = clickedWidget : getTile ( mousePosition )
2022-08-17 12:51:56 -03:00
if tile then
g_game.requestTrade ( selectedThing , tile : getTopCreature ( ) )
end
2021-07-19 19:24:59 -03:00
elseif clickedWidget : getClassName ( ) == ' UICreatureButton ' then
local creature = clickedWidget : getCreature ( )
2022-08-17 12:51:56 -03:00
if creature then
g_game.requestTrade ( selectedThing , creature )
end
2017-10-22 23:21:02 +02:00
end
2012-04-24 19:09:48 -03:00
end
2012-07-24 02:30:08 -03:00
function startUseWith ( thing )
2022-08-17 12:51:56 -03:00
if not thing then
return
end
2021-07-19 19:24:59 -03:00
if g_ui.isMouseGrabbed ( ) then
if selectedThing then
selectedThing = thing
selectedType = ' use '
end
return
2013-02-04 16:33:34 -02:00
end
2021-07-19 19:24:59 -03:00
selectedType = ' use '
selectedThing = thing
mouseGrabberWidget : grabMouse ( )
g_mouse.pushCursor ( ' target ' )
2012-04-24 19:09:48 -03:00
end
2012-07-24 02:30:08 -03:00
function startTradeWith ( thing )
2022-08-17 12:51:56 -03:00
if not thing then
return
end
2021-07-19 19:24:59 -03:00
if g_ui.isMouseGrabbed ( ) then
if selectedThing then
selectedThing = thing
selectedType = ' trade '
end
return
2013-02-04 16:33:34 -02:00
end
2021-07-19 19:24:59 -03:00
selectedType = ' trade '
selectedThing = thing
mouseGrabberWidget : grabMouse ( )
g_mouse.pushCursor ( ' target ' )
2012-03-28 20:19:28 -03:00
end
2014-07-13 22:57:45 +12:00
function isMenuHookCategoryEmpty ( category )
2022-08-17 12:51:56 -03:00
if category then
for _ , opt in pairs ( category ) do
if opt then
return false
end
end
end
2021-07-19 19:24:59 -03:00
return true
2014-07-13 22:57:45 +12:00
end
2014-07-13 22:27:09 +12:00
function addMenuHook ( category , name , callback , condition , shortcut )
2022-08-17 12:51:56 -03:00
if not hookedMenuOptions [ category ] then
hookedMenuOptions [ category ] = { }
end
2021-07-19 19:24:59 -03:00
hookedMenuOptions [ category ] [ name ] = {
callback = callback ,
condition = condition ,
shortcut = shortcut
}
2014-07-13 22:27:09 +12:00
end
2014-07-13 22:39:56 +12:00
function removeMenuHook ( category , name )
2021-07-19 19:24:59 -03:00
if not name then
hookedMenuOptions [ category ] = { }
2012-01-03 20:27:31 -02:00
else
2021-07-19 19:24:59 -03:00
hookedMenuOptions [ category ] [ name ] = nil
2012-01-03 20:27:31 -02:00
end
2021-07-19 19:24:59 -03:00
end
2012-01-11 23:21:59 -02:00
2021-07-19 19:24:59 -03:00
function createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2022-08-17 12:51:56 -03:00
if not g_game.isOnline ( ) then
return
end
2014-07-15 23:19:08 +02:00
2021-07-19 19:24:59 -03:00
local menu = g_ui.createWidget ( ' PopupMenu ' )
menu : setGameMenu ( true )
2012-01-11 23:21:59 -02:00
2021-07-19 19:24:59 -03:00
local classic = modules.client_options . getOption ( ' classicControl ' )
local shortcut = nil
2012-01-11 23:21:59 -02:00
2021-07-19 19:24:59 -03:00
if not classic then
shortcut = ' (Shift) '
else
shortcut = nil
end
2022-08-17 12:51:56 -03:00
if lookThing then
menu : addOption ( tr ( ' Look ' ) , function ( )
g_game.look ( lookThing )
end , shortcut )
end
2012-01-11 23:21:59 -02:00
2021-07-19 19:24:59 -03:00
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 )
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Open in new window ' ) , function ( )
g_game.open ( useThing )
end )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Open ' ) , function ( )
g_game.open ( useThing )
end , shortcut )
2021-07-19 19:24:59 -03:00
end
2012-08-25 17:02:07 +12:00
else
2021-07-19 19:24:59 -03:00
if useThing : isMultiUse ( ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Use with ... ' ) , function ( )
startUseWith ( useThing )
end , shortcut )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Use ' ) , function ( )
g_game.use ( useThing )
end , shortcut )
2021-07-19 19:24:59 -03:00
end
2012-08-25 17:02:07 +12:00
end
2012-01-11 23:21:59 -02:00
2022-08-17 12:51:56 -03:00
if useThing : isRotateable ( ) then
menu : addOption ( tr ( ' Rotate ' ) , function ( )
g_game.rotate ( useThing )
end )
end
2014-01-18 15:09:26 +01:00
2023-02-10 21:14:35 -03:00
local onWrapItem = function ( )
g_game.wrap ( useThing )
end
2022-12-26 14:32:23 -03:00
if useThing : isWrapable ( ) then
menu : addOption ( tr ( ' Wrap ' ) , onWrapItem )
end
if useThing : isUnwrapable ( ) then
2023-02-10 21:14:35 -03:00
menu : addOption ( tr ( ' Unwrap ' ) , onWrapItem )
2022-12-26 14:32:23 -03:00
end
2022-04-29 23:14:24 -03:00
if g_game.getFeature ( GameBrowseField ) and useThing : getPosition ( ) . x ~= 0xffff then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Browse Field ' ) , function ( )
g_game.browseField ( useThing : getPosition ( ) )
end )
2013-07-03 14:25:18 +02:00
end
2021-07-19 19:24:59 -03:00
end
2012-01-11 23:21:59 -02:00
2022-04-29 23:14:24 -03:00
if lookThing and not lookThing : isCreature ( ) and not lookThing : isNotMoveable ( ) and lookThing : isPickupable ( ) then
2012-07-26 03:10:28 -03:00
menu : addSeparator ( )
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Trade with ... ' ) , function ( )
startTradeWith ( lookThing )
end )
2021-07-19 19:24:59 -03:00
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 )
2012-07-26 03:10:28 -03:00
end
2021-07-19 19:24:59 -03:00
end
if creatureThing then
local localPlayer = g_game.getLocalPlayer ( )
menu : addSeparator ( )
if creatureThing : isLocalPlayer ( ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Set Outfit ' ) , function ( )
g_game.requestOutfit ( )
end )
2022-08-17 02:44:09 -03:00
2022-08-15 19:29:51 -04:00
if g_game.getFeature ( GamePrey ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Prey Dialog ' ) , function ( )
modules.game_prey . show ( )
end )
2022-08-17 02:44:09 -03:00
end
2021-07-19 19:24:59 -03:00
if g_game.getFeature ( GamePlayerMounts ) then
if not localPlayer : isMounted ( ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Mount ' ) , function ( )
localPlayer : mount ( )
end )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Dismount ' ) , function ( )
localPlayer : dismount ( )
end )
2021-07-19 19:24:59 -03:00
end
end
if creatureThing : isPartyMember ( ) then
if creatureThing : isPartyLeader ( ) then
if creatureThing : isPartySharedExperienceActive ( ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Disable Shared Experience ' ) , function ( )
g_game.partyShareExperience ( false )
end )
2021-07-19 19:24:59 -03:00
else
2022-04-29 23:14:24 -03:00
menu : addOption ( tr ( ' Enable Shared Experience ' ) , function ( )
2021-07-19 19:24:59 -03:00
g_game.partyShareExperience ( true )
end )
end
end
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Leave Party ' ) , function ( )
g_game.partyLeave ( )
end )
2021-07-19 19:24:59 -03:00
end
2013-01-26 18:10:30 -02:00
else
2021-07-19 19:24:59 -03:00
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
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Attack ' ) , function ( )
g_game.attack ( creatureThing )
end , shortcut )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Stop Attack ' ) , function ( )
g_game.cancelAttack ( )
end , shortcut )
2021-07-19 19:24:59 -03:00
end
if g_game.getFollowingCreature ( ) ~= creatureThing then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Follow ' ) , function ( )
g_game.follow ( creatureThing )
end )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Stop Follow ' ) , function ( )
g_game.cancelFollow ( )
end )
2021-07-19 19:24:59 -03:00
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 )
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Exclude from private chat ' ) , function ( )
g_game.excludeFromOwnChannel ( creatureName )
end ) -- [TODO] must be removed after message's popup labels been implemented
2021-07-19 19:24:59 -03:00
end
if not localPlayer : hasVip ( creatureName ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Add to VIP list ' ) , function ( )
g_game.addVip ( creatureName )
end )
2021-07-19 19:24:59 -03:00
end
if modules.game_console . isIgnored ( creatureName ) then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Unignore ' ) .. ' ' .. creatureName , function ( )
modules.game_console . removeIgnoredPlayer ( creatureName )
end )
2021-07-19 19:24:59 -03:00
else
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Ignore ' ) .. ' ' .. creatureName , function ( )
modules.game_console . addIgnoredPlayer ( creatureName )
end )
2021-07-19 19:24:59 -03:00
end
local localPlayerShield = localPlayer : getShield ( )
local creatureShield = creatureThing : getShield ( )
2022-04-29 23:14:24 -03:00
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
2021-07-19 19:24:59 -03:00
if creatureShield == ShieldWhiteYellow then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Join %s \' s Party ' , creatureThing : getName ( ) ) , function ( )
g_game.partyJoin ( creatureThing : getId ( ) )
end )
2021-07-19 19:24:59 -03:00
else
menu : addOption ( tr ( ' Invite to Party ' ) , function ( )
g_game.partyInvite ( creatureThing : getId ( ) )
end )
end
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Revoke %s \' s Invitation ' , creatureThing : getName ( ) ) , function ( )
2021-07-19 19:24:59 -03:00
g_game.partyRevokeInvitation ( creatureThing : getId ( ) )
end )
end
2022-04-29 23:14:24 -03:00
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or
localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
2021-07-19 19:24:59 -03:00
if creatureShield == ShieldWhiteBlue then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Revoke %s \' s Invitation ' , creatureThing : getName ( ) ) , function ( )
2021-07-19 19:24:59 -03:00
g_game.partyRevokeInvitation ( creatureThing : getId ( ) )
end )
2022-04-29 23:14:24 -03:00
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield ==
ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Pass Leadership to %s ' , creatureThing : getName ( ) ) , function ( )
2021-07-19 19:24:59 -03:00
g_game.partyPassLeadership ( creatureThing : getId ( ) )
end )
else
menu : addOption ( tr ( ' Invite to Party ' ) , function ( )
g_game.partyInvite ( creatureThing : getId ( ) )
end )
end
end
end
2013-01-26 18:10:30 -02:00
end
2012-07-26 03:10:28 -03:00
2022-04-29 23:14:24 -03:00
if modules.game_ruleviolation . hasWindowAccess ( ) and creatureThing : isPlayer ( ) then
2021-07-19 19:24:59 -03:00
menu : addSeparator ( )
menu : addOption ( tr ( ' Rule Violation ' ) , function ( )
modules.game_ruleviolation . show ( creatureThing : getName ( ) )
end )
2012-01-10 21:38:32 -02:00
end
2012-01-03 20:27:31 -02:00
2021-07-19 19:24:59 -03:00
menu : addSeparator ( )
2022-08-17 12:51:56 -03:00
menu : addOption ( tr ( ' Copy Name ' ) , function ( )
g_window.setClipboardText ( creatureThing : getName ( ) )
end )
2012-05-01 03:49:48 -03:00
end
2012-06-09 10:00:08 -03:00
2021-07-19 19:24:59 -03:00
-- hooked menu options
for _ , category in pairs ( hookedMenuOptions ) do
if not isMenuHookCategoryEmpty ( category ) then
menu : addSeparator ( )
for name , opt in pairs ( category ) do
2022-04-29 23:14:24 -03:00
if opt and opt.condition ( menuPosition , lookThing , useThing , creatureThing ) then
2021-07-19 19:24:59 -03:00
menu : addOption ( name , function ( )
2022-04-29 23:14:24 -03:00
opt.callback ( menuPosition , lookThing , useThing , creatureThing )
2021-07-19 19:24:59 -03:00
end , opt.shortcut )
end
end
2014-07-13 22:57:45 +12:00
end
2014-07-13 22:27:09 +12:00
end
2021-07-19 19:24:59 -03:00
menu : display ( menuPosition )
2012-01-03 18:41:00 -02:00
end
2012-01-12 22:31:39 -02:00
2022-04-29 23:14:24 -03:00
function processMouseAction ( menuPosition , mouseButton , autoWalkPos , lookThing , useThing , creatureThing , attackCreature )
2021-07-19 19:24:59 -03:00
local keyboardModifiers = g_keyboard.getModifiers ( )
if not modules.client_options . getOption ( ' classicControl ' ) then
2022-04-29 23:14:24 -03:00
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
2021-07-19 19:24:59 -03:00
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
2022-04-29 23:14:24 -03:00
elseif useThing and useThing : isContainer ( ) and keyboardModifiers == KeyboardCtrlShiftModifier and
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
2021-07-25 00:09:41 +02:00
g_game.open ( useThing )
return true
2021-07-19 19:24:59 -03:00
elseif attackCreature and g_keyboard.isAltPressed ( ) and
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.attack ( attackCreature )
return true
2022-04-29 23:14:24 -03:00
elseif creatureThing and creatureThing : getPosition ( ) . z == autoWalkPos.z and g_keyboard.isAltPressed ( ) and
2021-07-19 19:24:59 -03:00
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.attack ( creatureThing )
return true
2012-03-18 10:34:39 -03:00
end
2021-07-19 19:24:59 -03:00
-- classic control
else
2022-04-29 23:14:24 -03:00
if useThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and
not g_mouse.isPressed ( MouseLeftButton ) then
2021-07-19 19:24:59 -03:00
local player = g_game.getLocalPlayer ( )
if attackCreature and attackCreature ~= player then
g_game.attack ( attackCreature )
return true
2022-04-29 23:14:24 -03:00
elseif creatureThing and creatureThing ~= player and creatureThing : getPosition ( ) . z == autoWalkPos.z then
2021-07-19 19:24:59 -03:00
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
2022-04-29 23:14:24 -03:00
elseif useThing and useThing : isContainer ( ) and keyboardModifiers == KeyboardCtrlShiftModifier and
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
2021-07-25 00:09:41 +02:00
g_game.open ( useThing )
return true
2021-07-19 19:24:59 -03:00
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.look ( lookThing )
return true
2022-04-29 23:14:24 -03:00
elseif lookThing and ( ( g_mouse.isPressed ( MouseLeftButton ) and mouseButton == MouseRightButton ) or
( g_mouse.isPressed ( MouseRightButton ) and mouseButton == MouseLeftButton ) ) then
2021-07-19 19:24:59 -03:00
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
2022-04-29 23:14:24 -03:00
elseif creatureThing and creatureThing : getPosition ( ) . z == autoWalkPos.z and g_keyboard.isAltPressed ( ) and
2021-07-19 19:24:59 -03:00
( mouseButton == MouseLeftButton or mouseButton == MouseRightButton ) then
g_game.attack ( creatureThing )
return true
2012-03-18 10:34:39 -03:00
end
2021-07-19 19:24:59 -03:00
end
local player = g_game.getLocalPlayer ( )
player : stopAutoWalk ( )
2022-04-29 23:14:24 -03:00
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
2021-07-19 19:24:59 -03:00
player : autoWalk ( autoWalkPos )
2013-01-25 18:51:14 -02:00
return true
2021-07-19 19:24:59 -03:00
end
2012-07-05 02:40:21 -03:00
2021-07-19 19:24:59 -03:00
return false
2012-03-18 10:34:39 -03:00
end
2012-07-24 02:30:08 -03:00
function moveStackableItem ( item , toPos )
2022-08-17 12:51:56 -03:00
if countWindow then
return
end
2021-07-25 00:04:40 +02:00
if g_keyboard.isShiftPressed ( ) then
2021-07-19 19:24:59 -03:00
g_game.move ( item , toPos , 1 )
return
2021-07-25 00:04:40 +02:00
elseif g_keyboard.isCtrlPressed ( ) ~= modules.client_options . getOption ( ' moveStack ' ) then
g_game.move ( item , toPos , item : getCount ( ) )
return
2021-07-19 19:24:59 -03:00
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
2012-08-31 20:33:51 -03:00
spinbox.onValueChange = spinBoxValueChange
2012-03-29 10:45:40 -03:00
2021-07-19 19:24:59 -03:00
local check = function ( )
if spinbox.firstEdit then
spinbox : setValue ( spinbox : getMaximum ( ) )
spinbox.firstEdit = false
end
end
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' Up ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
2023-02-11 14:43:46 -03:00
spinbox : upSpin ( )
2021-07-19 19:24:59 -03:00
end , spinbox )
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' Down ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
2023-02-11 14:43:46 -03:00
spinbox : downSpin ( )
2021-07-19 19:24:59 -03:00
end , spinbox )
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' Right ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
2023-02-11 14:43:46 -03:00
spinbox : upSpin ( )
2021-07-19 19:24:59 -03:00
end , spinbox )
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' Left ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
2023-02-11 14:43:46 -03:00
spinbox : downSpin ( )
2021-07-19 19:24:59 -03:00
end , spinbox )
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' PageUp ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
spinbox : setValue ( spinbox : getValue ( ) + 10 )
end , spinbox )
2022-04-29 23:14:24 -03:00
g_keyboard.bindKeyPress ( ' PageDown ' , function ( )
2021-07-19 19:24:59 -03:00
check ( )
spinbox : setValue ( spinbox : getValue ( ) - 10 )
end , spinbox )
scrollbar.onValueChange = function ( self , value )
itembox : setItemCount ( value )
spinbox.onValueChange = nil
spinbox : setValue ( value )
spinbox.onValueChange = spinBoxValueChange
end
2012-03-29 10:45:40 -03:00
2021-07-19 19:24:59 -03:00
local okButton = countWindow : getChildById ( ' buttonOk ' )
local moveFunc = function ( )
g_game.move ( item , toPos , itembox : getItemCount ( ) )
okButton : getParent ( ) : destroy ( )
countWindow = nil
2021-07-24 20:53:57 +02:00
modules.game_hotkeys . enableHotkeys ( true )
2021-07-19 19:24:59 -03:00
end
local cancelButton = countWindow : getChildById ( ' buttonCancel ' )
local cancelFunc = function ( )
cancelButton : getParent ( ) : destroy ( )
countWindow = nil
2021-07-24 20:53:57 +02:00
modules.game_hotkeys . enableHotkeys ( true )
2021-07-19 19:24:59 -03:00
end
2012-07-15 11:28:15 -03:00
2021-07-19 19:24:59 -03:00
countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc
2012-03-29 10:45:40 -03:00
2021-07-19 19:24:59 -03:00
okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
2021-07-24 20:53:57 +02:00
modules.game_hotkeys . enableHotkeys ( false )
2012-03-18 10:34:39 -03:00
end
2022-08-17 12:51:56 -03:00
function getRootPanel ( )
return gameRootPanel
end
2012-03-18 10:34:39 -03:00
2022-08-17 12:51:56 -03:00
function getMapPanel ( )
return gameMapPanel
end
2012-03-18 10:34:39 -03:00
2022-08-17 12:51:56 -03:00
function getRightPanel ( )
return gameRightPanel
end
2012-03-18 10:34:39 -03:00
2022-08-17 12:51:56 -03:00
function getLeftPanel ( )
return gameLeftPanel
end
2012-07-24 02:30:08 -03:00
2022-08-17 12:51:56 -03:00
function getRightExtraPanel ( )
return gameRightExtraPanel
end
2021-07-22 20:33:54 +02:00
2022-08-17 12:51:56 -03:00
function getSelectedPanel ( )
return gameSelectedPanel
end
2021-07-23 21:25:47 +02:00
2022-08-17 12:51:56 -03:00
function getBottomPanel ( )
return gameBottomPanel
end
2021-07-19 19:24:59 -03:00
2022-08-17 12:51:56 -03:00
function getShowTopMenuButton ( )
return showTopMenuButton
end
2017-11-19 02:00:02 +01:00
2021-07-23 21:37:16 +02:00
function findContentPanelAvailable ( child , minContentHeight )
if gameSelectedPanel : isVisible ( ) and gameSelectedPanel : fits ( child , minContentHeight , 0 ) >= 0 then
return gameSelectedPanel
end
2022-04-29 23:14:24 -03:00
for k , v in pairs ( panelsList ) do
2021-07-23 21:37:16 +02:00
if v.panel ~= gameSelectedPanel and v.panel : isVisible ( ) and v.panel : fits ( child , minContentHeight , 0 ) >= 0 then
return v.panel
end
end
return gameSelectedPanel
end
2021-07-22 20:33:54 +02:00
function onExtraPanelVisibilityChange ( extraPanel , visible )
2021-07-23 21:25:47 +02:00
if not visible then
2021-07-24 19:28:08 +02:00
-- move children to right panel
2021-07-23 21:25:47 +02:00
if g_game.isOnline ( ) then
local children = extraPanel : getChildren ( )
2022-08-17 12:51:56 -03:00
for i = 1 , # children do
children [ i ] : setParent ( gameRightPanel )
end
2021-07-23 21:25:47 +02:00
end
2021-07-24 19:28:08 +02:00
-- unselect hiding panel
2022-08-17 12:51:56 -03:00
if extraPanel == getSelectedPanel ( ) then
panelsRadioGroup : selectWidget ( panelsList [ 1 ] . checkbox )
end
2021-07-23 21:25:47 +02:00
2021-07-24 19:28:08 +02:00
-- hide checkbox of hidden panel
2022-08-17 12:51:56 -03:00
for k , v in pairs ( panelsList ) do
if v.panel == extraPanel then
v.checkbox : setVisible ( false )
end
end
2021-07-24 19:28:08 +02:00
-- if there is only the right panel visible, hide its checkbox too
if not gameRightExtraPanel : isVisible ( ) and not gameLeftPanel : isVisible ( ) then
panelsList [ 1 ] . checkbox : setVisible ( false )
end
2021-07-23 21:25:47 +02:00
else
2021-07-24 19:28:08 +02:00
-- this means that, besided the right panel, there is another panel visible
-- so we'll enable the checkboxes from the one at right, and the one being shown
2022-08-17 12:51:56 -03:00
for k , v in pairs ( panelsList ) do
if v.panel == extraPanel then
v.checkbox : setVisible ( true )
end
end
2021-07-24 19:28:08 +02:00
panelsList [ 1 ] . checkbox : setVisible ( true )
2012-07-24 02:30:08 -03:00
end
2012-12-29 05:15:57 +13:00
end
2013-01-21 19:36:53 -02:00
2022-08-17 12:51:56 -03:00
function nextViewMode ( )
setupViewMode ( ( currentViewMode + 1 ) % 3 )
end
2013-01-24 17:15:07 -02:00
2022-07-04 19:46:30 -03:00
function setupViewMode ( mode )
2022-08-17 12:51:56 -03:00
if mode == currentViewMode then
return
end
2021-07-19 19:24:59 -03:00
if currentViewMode == 2 then
gameMapPanel : addAnchor ( AnchorLeft , ' gameLeftPanel ' , AnchorRight )
gameMapPanel : addAnchor ( AnchorRight , ' gameRightPanel ' , AnchorLeft )
2021-07-22 20:33:54 +02:00
gameMapPanel : addAnchor ( AnchorRight , ' gameRightExtraPanel ' , AnchorLeft )
2021-07-19 19:24:59 -03:00
gameMapPanel : addAnchor ( AnchorBottom , ' gameBottomPanel ' , AnchorTop )
gameRootPanel : addAnchor ( AnchorTop , ' topMenu ' , AnchorBottom )
gameLeftPanel : setOn ( modules.client_options . getOption ( ' showLeftPanel ' ) )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setOn ( modules.client_options . getOption ( ' showRightExtraPanel ' ) )
2021-07-19 19:24:59 -03:00
gameLeftPanel : setImageColor ( ' white ' )
gameRightPanel : setImageColor ( ' white ' )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setImageColor ( ' white ' )
2021-07-19 19:24:59 -03:00
gameLeftPanel : setMarginTop ( 0 )
gameRightPanel : setMarginTop ( 0 )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setMarginTop ( 0 )
2021-07-19 19:24:59 -03:00
gameBottomPanel : setImageColor ( ' white ' )
modules.client_topmenu . getTopMenu ( ) : setImageColor ( ' white ' )
end
if mode == 0 then
gameMapPanel : setKeepAspectRatio ( true )
gameMapPanel : setLimitVisibleRange ( false )
gameMapPanel : setZoom ( 11 )
2022-04-29 23:14:24 -03:00
gameMapPanel : setVisibleDimension ( {
width = 15 ,
height = 11
} )
2021-07-19 19:24:59 -03:00
elseif mode == 1 then
gameMapPanel : setKeepAspectRatio ( false )
gameMapPanel : setLimitVisibleRange ( true )
gameMapPanel : setZoom ( 11 )
2022-04-29 23:14:24 -03:00
gameMapPanel : setVisibleDimension ( {
width = 15 ,
height = 11
} )
2021-07-19 19:24:59 -03:00
elseif mode == 2 then
local limit = limitedZoom and not g_game.isGM ( )
gameMapPanel : setLimitVisibleRange ( limit )
gameMapPanel : setZoom ( 11 )
2022-04-29 23:14:24 -03:00
gameMapPanel : setVisibleDimension ( {
width = 15 ,
height = 11
} )
2021-07-19 19:24:59 -03:00
gameMapPanel : fill ( ' parent ' )
gameRootPanel : fill ( ' parent ' )
gameLeftPanel : setImageColor ( ' alpha ' )
gameRightPanel : setImageColor ( ' alpha ' )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setImageColor ( ' alpha ' )
gameLeftPanel : setMarginTop ( modules.client_topmenu . getTopMenu ( ) : getHeight ( ) - gameLeftPanel : getPaddingTop ( ) )
gameRightPanel : setMarginTop ( modules.client_topmenu . getTopMenu ( ) : getHeight ( ) - gameRightPanel : getPaddingTop ( ) )
2022-04-29 23:14:24 -03:00
gameRightExtraPanel : setMarginTop ( modules.client_topmenu . getTopMenu ( ) : getHeight ( ) -
gameRightExtraPanel : getPaddingTop ( ) )
2021-07-19 19:24:59 -03:00
gameLeftPanel : setOn ( true )
gameLeftPanel : setVisible ( true )
gameRightPanel : setOn ( true )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setOn ( true )
gameRightExtraPanel : setVisible ( true )
2021-07-19 19:24:59 -03:00
gameMapPanel : setOn ( true )
gameBottomPanel : setImageColor ( ' #ffffff88 ' )
modules.client_topmenu . getTopMenu ( ) : setImageColor ( ' #ffffff66 ' )
end
currentViewMode = mode
end
2022-08-17 12:51:56 -03:00
function limitZoom ( )
limitedZoom = true
end