2012-07-24 02:30:08 -03:00
gameRootPanel = nil
gameMapPanel = nil
2024-06-21 18:10:07 -03:00
gameMainRightPanel = nil
2012-07-24 02:30:08 -03:00
gameRightPanel = nil
2021-07-22 20:33:54 +02:00
gameRightExtraPanel = nil
2012-07-24 02:30:08 -03:00
gameLeftPanel = nil
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel = nil
2021-07-23 21:25:47 +02:00
gameSelectedPanel = nil
panelsList = { }
panelsRadioGroup = nil
2024-06-21 18:10:07 -03:00
gameTopPanel = nil
2024-06-28 14:45:01 -03:00
gameBottomStatsBarPanel = 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
2024-06-21 18:10:07 -03:00
logOutMainButton = nil
2012-07-24 02:30:08 -03:00
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
2024-06-21 18:10:07 -03:00
leftIncreaseSidePanels = nil
leftDecreaseSidePanels = nil
rightIncreaseSidePanels = nil
rightDecreaseSidePanels = nil
2025-10-25 04:28:51 -03:00
gameBottomActionPanel = nil
gameLeftActionPanel = nil
gameRightActionPanel = nil
gameBottomLockPanel = nil
gameRightLockPanel = nil
gameLeftLockPanel = nil
2014-07-13 22:27:09 +12:00
hookedMenuOptions = { }
2025-10-13 10:18:54 -07:00
focusReason = { }
2025-01-23 18:41:28 -03:00
local lastStopAction = 0
2025-04-12 20:33:19 -04:00
local mobileConfig = {
mobileWidthJoystick = 0 ,
mobileWidthShortcuts = 0 ,
mobileHeightJoystick = 0 ,
mobileHeightShortcuts = 0
}
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 ' )
2025-12-30 16:40:47 -03:00
g_ui.importStyle ( ' styles/countStashWindow ' )
2021-07-19 19:24:59 -03:00
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
2023-05-11 11:38:24 -03:00
if g_app.hasUpdater ( ) then
connect ( g_app , {
onUpdateFinished = load ,
} )
else
connect ( g_app , {
onRun = load ,
} )
end
2022-04-29 23:14:24 -03:00
connect ( g_app , {
onExit = save
} )
2021-07-19 19:24:59 -03:00
gameRootPanel = g_ui.displayUI ( ' gameinterface ' )
gameRootPanel : hide ( )
gameRootPanel : lower ( )
gameRootPanel.onGeometryChange = updateStretchShrink
mouseGrabberWidget = gameRootPanel : getChildById ( ' mouseGrabber ' )
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
bottomSplitter = gameRootPanel : getChildById ( ' bottomSplitter ' )
gameMapPanel = gameRootPanel : getChildById ( ' gameMapPanel ' )
2024-06-21 18:10:07 -03:00
gameMainRightPanel = gameRootPanel : getChildById ( ' gameMainRightPanel ' )
2021-07-19 19:24:59 -03:00
gameRightPanel = gameRootPanel : getChildById ( ' gameRightPanel ' )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel = gameRootPanel : getChildById ( ' gameRightExtraPanel ' )
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel = gameRootPanel : getChildById ( ' gameLeftExtraPanel ' )
2021-07-19 19:24:59 -03:00
gameLeftPanel = gameRootPanel : getChildById ( ' gameLeftPanel ' )
gameBottomPanel = gameRootPanel : getChildById ( ' gameBottomPanel ' )
2024-06-21 18:10:07 -03:00
gameTopPanel = gameRootPanel : getChildById ( ' gameTopPanel ' )
2024-06-28 14:45:01 -03:00
gameBottomStatsBarPanel = gameRootPanel : getChildById ( ' gameBottomStatsBarPanel ' )
2024-06-21 18:10:07 -03:00
leftIncreaseSidePanels = gameRootPanel : getChildById ( ' leftIncreaseSidePanels ' )
leftDecreaseSidePanels = gameRootPanel : getChildById ( ' leftDecreaseSidePanels ' )
rightIncreaseSidePanels = gameRootPanel : getChildById ( ' rightIncreaseSidePanels ' )
rightDecreaseSidePanels = gameRootPanel : getChildById ( ' rightDecreaseSidePanels ' )
2025-10-25 04:28:51 -03:00
gameBottomActionPanel = gameRootPanel : getChildById ( ' gameBottomActionPanel ' )
gameRightActionPanel = gameRootPanel : getChildById ( ' gameRightActionPanel ' )
gameLeftActionPanel = gameRootPanel : getChildById ( ' gameLeftActionPanel ' )
gameBottomLockPanel = gameRootPanel : recursiveGetChildById ( ' bottomLock ' )
gameRightLockPanel = gameRootPanel : recursiveGetChildById ( ' rightLock ' )
gameLeftLockPanel = gameRootPanel : recursiveGetChildById ( ' leftLock ' )
2025-12-30 16:40:47 -03:00
2024-06-21 18:10:07 -03:00
leftIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showLeftExtraPanel ' ) )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
leftDecreaseSidePanels : setEnabled ( false )
else
2026-01-06 11:48:00 -03:00
local hasLeftPanels = modules.client_options . getOption ( ' showLeftPanel ' ) or
modules.client_options . getOption ( ' showLeftExtraPanel ' )
leftDecreaseSidePanels : setEnabled ( hasLeftPanels )
2024-12-30 13:59:43 -03:00
end
2024-06-21 18:10:07 -03:00
rightIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showRightExtraPanel ' ) )
rightDecreaseSidePanels : setEnabled ( modules.client_options . getOption ( ' showRightExtraPanel ' ) )
2021-07-23 21:25:47 +02:00
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
2023-05-11 11:38:24 -03:00
panelsList = { {
2022-04-29 23:14:24 -03:00
panel = gameRightPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectRightColumn ' )
} , {
panel = gameRightExtraPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectRightExtraColumn ' )
} , {
panel = gameLeftPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectLeftColumn ' )
2024-08-28 00:16:21 -03:00
} , {
2024-06-21 18:10:07 -03:00
panel = gameLeftExtraPanel ,
checkbox = gameRootPanel : getChildById ( ' gameSelectLeftExtraColumn ' )
2023-05-11 11:38:24 -03:00
} }
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 )
2024-06-21 18:10:07 -03:00
logoutButton = modules.client_topmenu . addTopRightToggleButton ( ' logoutButton ' , tr ( ' Exit ' ) , ' /images/topbuttons/logout ' ,
2023-05-11 11:38:24 -03:00
tryLogout , true )
2021-07-19 19:24:59 -03:00
2025-10-13 10:18:54 -07:00
gameMapPanel.onClick = toggleInternalFocus
gameRightPanel.onClick = toggleInternalFocus
gameRightExtraPanel.onClick = toggleInternalFocus
gameLeftExtraPanel.onClick = toggleInternalFocus
gameLeftPanel.onClick = toggleInternalFocus
gameBottomPanel.onClick = toggleInternalFocus
2021-07-19 19:24:59 -03:00
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
2024-06-21 18:10:07 -03:00
StatsBar.init ( )
2021-07-23 21:25:47 +02:00
end
2012-08-25 16:11:54 -03:00
function bindKeys ( )
2024-10-15 17:31:51 -03:00
gameRootPanel : setAutoRepeatDelay ( 50 )
2021-07-19 19:24:59 -03:00
2022-08-17 12:51:56 -03:00
g_keyboard.bindKeyPress ( ' Ctrl+= ' , function ( )
gameMapPanel : zoomIn ( )
end , gameRootPanel )
g_keyboard.bindKeyPress ( ' Ctrl+- ' , function ( )
gameMapPanel : zoomOut ( )
end , gameRootPanel )
2024-12-17 18:27:38 -03:00
2025-01-23 18:41:28 -03:00
Keybind.new ( " Movement " , " Stop All Actions " , " Escape " , " " , true )
2024-12-17 18:27:38 -03:00
Keybind.bind ( " Movement " , " Stop All Actions " , {
{
2025-01-14 16:47:32 +01:00
type = KEY_PRESS ,
callback = function ( )
2025-01-23 18:41:28 -03:00
if lastStopAction + 50 > g_clock.millis ( ) then return end
lastStopAction = g_clock.millis ( )
2025-01-14 16:47:32 +01:00
g_game.cancelAttackAndFollow ( )
end ,
2024-12-17 18:27:38 -03:00
}
2025-01-14 16:47:32 +01:00
} , gameRootPanel )
2024-12-17 18:27:38 -03:00
Keybind.new ( " Misc " , " Logout " , " Ctrl+L " , " Ctrl+Q " )
Keybind.bind ( " Misc " , " Logout " , {
{
2025-01-14 16:47:32 +01:00
type = KEY_PRESS ,
callback = function ( ) tryLogout ( false ) end ,
2024-12-17 18:27:38 -03:00
}
2025-01-14 16:47:32 +01:00
} , gameRootPanel )
2024-12-17 18:27:38 -03:00
Keybind.new ( " UI " , " Clear All Texts " , " Ctrl+W " , " " )
Keybind.bind ( " UI " , " Clear All Texts " , {
{
2025-01-14 16:47:32 +01:00
type = KEY_DOWN ,
callback = function ( )
g_map.cleanTexts ( )
modules.game_textmessage . clearMessages ( )
end ,
2024-12-17 18:27:38 -03:00
}
2025-01-14 16:47:32 +01:00
} , gameRootPanel )
2023-03-09 14:20:42 -03:00
2024-08-28 00:16:21 -03:00
g_keyboard.bindKeyDown ( ' Ctrl+. ' , nextViewMode , gameRootPanel )
2012-01-12 22:31:39 -02:00
end
2012-07-24 02:30:08 -03:00
function terminate ( )
2024-06-21 18:10:07 -03:00
StatsBar.terminate ( )
2021-07-19 19:24:59 -03:00
hide ( )
2023-05-11 11:38:24 -03:00
if g_app.hasUpdater ( ) then
disconnect ( g_app , {
onUpdateFinished = load ,
} )
else
disconnect ( g_app , {
onRun = load ,
} )
end
disconnect ( g_app , {
onExit = save ,
} )
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
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
for k , v in pairs ( panelsList ) do
disconnect ( v.checkbox , {
onCheckChange = onSelectPanel
} )
2021-07-23 21:25:47 +02:00
end
2024-08-28 00:16:21 -03:00
2021-07-19 19:24:59 -03:00
logoutButton : destroy ( )
gameRootPanel : destroy ( )
2024-12-17 18:27:38 -03:00
Keybind.delete ( " Movement " , " Stop All Actions " )
Keybind.delete ( " Misc " , " Logout " )
Keybind.delete ( " UI " , " Clear All Texts " )
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
2024-12-30 13:59:43 -03:00
leftIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showLeftExtraPanel ' ) )
if g_platform.isMobile ( ) then
leftDecreaseSidePanels : setEnabled ( false )
2021-07-19 19:24:59 -03:00
else
2026-01-06 11:48:00 -03:00
local hasLeftPanels = modules.client_options . getOption ( ' showLeftPanel ' ) or
modules.client_options . getOption ( ' showLeftExtraPanel ' )
leftDecreaseSidePanels : setEnabled ( hasLeftPanels )
2021-07-19 19:24:59 -03:00
end
2024-06-21 18:10:07 -03:00
rightIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showRightExtraPanel ' ) )
rightDecreaseSidePanels : setEnabled ( modules.client_options . getOption ( ' showRightExtraPanel ' ) )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
2026-01-06 11:48:00 -03:00
-- Initialize horizontal left panel based on saved option
showLeftHorizontalPanel ( modules.client_options . getOption ( ' showHorizontalLeftPanel ' ) )
-- Initialize horizontal right panel based on saved option
showRightHorizontalPanel ( modules.client_options . getOption ( ' showHorizontalRightPanel ' ) )
-- Auto-fit gameMainRightPanel height after all modules loaded
scheduleEvent ( function ( )
if gameMainRightPanel and gameMainRightPanel.fitAllChildren then
gameMainRightPanel : fitAllChildren ( )
end
end , 100 )
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 )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
mobileConfig.mobileWidthJoystick = modules.game_joystick . getPanel ( ) : getWidth ( )
mobileConfig.mobileWidthShortcuts = modules.game_shortcuts . getPanel ( ) : getWidth ( )
mobileConfig.mobileHeightJoystick = modules.game_joystick . getPanel ( ) : getHeight ( )
mobileConfig.mobileHeightShortcuts = modules.game_shortcuts . getPanel ( ) : getHeight ( )
2024-12-30 13:59:43 -03:00
setupViewMode ( 1 )
setupViewMode ( 2 )
end
2023-03-09 14:20:42 -03:00
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
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 (
2023-05-11 11:38: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. ' ) ,
2022-04-29 23:14:24 -03:00
{
2023-05-11 11:38:24 -03:00
{
2024-06-21 18:10:07 -03:00
text = tr ( ' Cancel ' ) ,
callback = cancelFunc
2023-05-11 11:38:24 -03:00
} ,
{
text = tr ( ' Logout ' ) ,
callback = logoutFunc
} ,
{
2024-06-21 18:10:07 -03:00
text = tr ( ' Force Exit ' ) ,
callback = exitFunc
2023-05-11 11:38:24 -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 =
2023-05-11 11:38:24 -03:00
' Your connection is failing, if you logout now your character will be still online, do you want to force logout? '
2021-07-19 19:24:59 -03:00
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 ( ' No ' ) ,
callback = noCallback
} ,
2024-06-21 18:10:07 -03:00
{
text = tr ( ' Yes ' ) ,
callback = yesCallback
} ,
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 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
2025-12-30 16:40:47 -03:00
-- Update action bar layout when window geometry changes
2025-11-07 09:41:04 -08:00
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
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 ' )
2025-09-27 09:15:04 -07:00
local smartLeftClick = modules.client_options . getOption ( ' smartLeftClick ' )
2024-12-30 13:59:43 -03:00
local mobile = g_platform.isMobile ( )
2021-07-19 19:24:59 -03:00
local shortcut = nil
2012-01-11 23:21:59 -02:00
2025-09-27 09:15:04 -07:00
if not classic and not mobile and not smartLeftClick then
2021-07-19 19:24:59 -03:00
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 )
2026-01-06 11:48:00 -03:00
if lookThing and not lookThing : isCreature ( ) and not lookThing : isNotMoveable ( ) and lookThing : isPickupable ( ) then
menu : addOption ( tr ( ' Inspect ' ) , function ( ) g_game.inspectionNormalObject ( lookThing : getPosition ( ) ) end )
menu : addOption ( tr ( ' Cyclopedia ' ) ,
function ( ) modules.game_cyclopedia . Cyclopedia.Items . onRedirect ( lookThing : getId ( ) ) end )
if lookThing : getProficiencyId ( ) > 0 then
menu : addOption ( tr ( ' Weapon Proficiency ' ) ,
function ( ) modules.game_proficiency . requestOpenWindow ( lookThing ) end )
end
end
2022-08-17 12:51:56 -03:00
end
2012-01-11 23:21:59 -02:00
2024-12-30 13:59:43 -03:00
if not classic and not mobile then
2021-07-19 19:24:59 -03:00
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
2026-01-06 11:48:00 -03:00
local rewards = { 19250 }
if table.contains ( rewards , useThing : getId ( ) ) then
menu : addOption ( tr ( ' Collect all ' ) ,
function ( )
g_game.requestRewardChestCollect ( useThing : getPosition ( ) , useThing : getId ( ) ,
useThing : getStackPos ( ) )
end )
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
2025-02-14 21:24:52 -03:00
if useThing : isLyingCorpse ( ) and g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot and useThing : getPosition ( ) . x ~= 0xffff then
menu.addOption ( menu , tr ( " Loot corpse " ) , function ( )
g_game.sendQuickLoot ( 1 , useThing )
end )
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
2024-06-21 18:10:07 -03:00
menu : addOption ( tr ( g_game.getClientVersion ( ) >= 1000 and " Customise Character " or " Set Outfit " ) , function ( )
2022-08-17 12:51:56 -03:00
g_game.requestOutfit ( )
end )
2024-08-28 00:16:21 -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 ( )
2024-12-30 13:59:43 -03:00
if not classic and not mobile then
2021-07-19 19:24:59 -03:00
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
2025-01-24 08:50:36 -03:00
if modules.game_bot and useThing and useThing : isItem ( ) then
2023-11-21 22:27:20 -03:00
menu : addSeparator ( )
local useThingId = useThing : getId ( )
2025-01-14 16:47:32 +01:00
menu : addOption ( " ID: " .. useThingId , function ( ) g_window.setClipboardText ( useThingId ) end )
2023-11-21 22:27:20 -03:00
end
2024-08-12 09:33:42 -04:00
if g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot and lookThing and not lookThing : isCreature ( ) and lookThing : isPickupable ( ) then
local quickLoot = modules.game_quickloot . QuickLoot
menu.addSeparator ( menu )
if lookThing : isContainer ( ) then
menu.addOption ( menu , tr ( " Manage Loot Containers " ) , function ( )
quickLoot.toggle ( )
end )
end
local lootExists = quickLoot.lootExists ( lookThing : getId ( ) )
local optionText = lootExists and " Remove from " or " Add to "
local actionFunction = lootExists and quickLoot.removeLootList or quickLoot.addLootList
menu.addOption ( menu , tr ( optionText .. " loot list " ) , function ( )
actionFunction ( lookThing : getId ( ) )
end )
end
2026-01-06 11:48:00 -03:00
if g_game.getClientVersion ( ) >= 1410 then
2025-12-30 16:40:47 -03:00
if lookThing and not lookThing : isCreature ( ) and not lookThing : isNotMoveable ( ) and lookThing : isPickupable ( ) then
local player = g_game.getLocalPlayer ( )
if player and player : isSupplyStashAvailable ( ) then
local itemTier = lookThing : getTier ( ) or 0
if itemTier <= 0 then
2026-01-06 11:48:00 -03:00
if not isGoldCoin ( useThing : getId ( ) ) and useThing : isMarketable ( ) then
menu : addSeparator ( )
menu : addOption ( tr ( " Stow " ) , function ( )
stashItem ( lookThing )
end )
menu : addOption ( tr ( " Stow all items of this type " ) , function ( )
g_game.stashStowItem ( lookThing : getPosition ( ) , lookThing : getId ( ) , 0 ,
lookThing : getStackPos ( ) , SUPPLY_STASH_ACTION_STOW_STACK )
end )
end
2025-12-30 16:40:47 -03:00
local isContainer = lookThing : isContainer ( )
if isContainer then
menu : addOption ( tr ( ' Stow container \' s content ' ) , function ( )
2026-01-06 11:48:00 -03:00
if modules.client_options . getOption ( ' stowContainer ' ) then
modules.game_stash . stowContainerContent ( useThing , nil ,
false )
else
g_game.stashStowItem ( lookThing : getPosition ( ) , lookThing : getId ( ) , 0 ,
lookThing : getStackPos ( ) , SUPPLY_STASH_ACTION_STOW_CONTAINER )
end
2025-12-30 16:40:47 -03:00
end )
end
end
end
end
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 ( )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
if mouseButton == MouseRightButton then
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2025-01-14 16:47:32 +01:00
return true
2024-12-30 13:59:43 -03:00
end
local shortcut = modules.game_shortcuts . getShortcut ( )
if shortcut == " look " then
2025-01-14 16:47:32 +01:00
if lookThing then
modules.game_shortcuts . resetShortcuts ( )
g_game.look ( lookThing )
return true
end
return true
2024-12-30 13:59:43 -03:00
elseif shortcut == " use " then
2025-01-14 16:47:32 +01:00
if useThing then
modules.game_shortcuts . resetShortcuts ( )
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
2024-12-30 13:59:43 -03:00
end
return true
2025-01-14 16:47:32 +01:00
elseif shortcut == " attack " then
if attackCreature and attackCreature ~= player then
modules.game_shortcuts . resetShortcuts ( )
g_game.attack ( attackCreature )
return true
2025-09-27 09:15:04 -07:00
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
2025-01-14 16:47:32 +01:00
modules.game_shortcuts . resetShortcuts ( )
g_game.attack ( creatureThing )
return true
end
2024-12-30 13:59:43 -03:00
return true
elseif shortcut == " follow " then
2025-01-14 16:47:32 +01:00
if attackCreature and attackCreature ~= player then
modules.game_shortcuts . resetShortcuts ( )
g_game.follow ( attackCreature )
return true
2025-09-27 09:15:04 -07:00
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
2025-01-14 16:47:32 +01:00
modules.game_shortcuts . resetShortcuts ( )
g_game.follow ( creatureThing )
return true
end
2024-12-30 13:59:43 -03:00
return true
elseif not autoWalkPos and useThing then
2025-01-14 16:47:32 +01:00
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
2024-12-30 13:59:43 -03:00
return true
end
elseif not modules.client_options . getOption ( ' classicControl ' ) then
2025-09-27 09:15:04 -07:00
local smartLeftClick = modules.client_options . getOption ( ' smartLeftClick ' )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if smartLeftClick and mouseButton == MouseLeftButton and keyboardModifiers == KeyboardNoModifier then
local player = g_game.getLocalPlayer ( )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Handle creature attacks first
if attackCreature and attackCreature ~= player then
g_game.attack ( attackCreature )
return true
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
g_game.attack ( creatureThing )
return true
elseif useThing then
-- Handle interactive items first, without looking at them
2025-10-02 22:36:25 -03:00
if useThing : isUsable ( ) then
2025-09-27 09:15:04 -07:00
-- Only use the item, don't look at it
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
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Standard handling for other usable items
-- For containers (including corpses), only execute quicklooting with Smart Left-Click
-- Exception: If container has a parent container, open it instead of quicklooting
if useThing : isContainer ( ) or useThing : isLyingCorpse ( ) then
-- Prioritize containers/corpses even if there are creatures on the same tile
if useThing : getParentContainer ( ) then
-- For containers inside other containers, we want to open them, not quickloot
g_game.open ( useThing , useThing : getParentContainer ( ) )
return true
elseif useThing : isPickupable ( ) then
-- For pickupable containers like quivers, backpacks, etc., open them instead of quicklooting
g_game.open ( useThing )
return true
elseif g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot then
-- For containers in the world (not inside another container), quickloot
g_game.sendQuickLoot ( 1 , useThing )
return true
end
elseif useThing : isMultiUse ( ) then
startUseWith ( useThing )
return true
else
local useResult = g_game.use ( useThing )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if useResult ~= nil then
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- If we couldn't use the item through any of the above methods,
-- but it's pickupable, try to pick it up (like in Classic Control mode)
if useThing : isPickupable ( ) then
g_game.move ( useThing , useThing : getPosition ( ) , 1 )
return true
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- If we couldn't use or pick up the item, try to walk to its position if possible
local position = useThing : getPosition ( )
if position and position.x ~= 0 and autoWalkPos then
local player = g_game.getLocalPlayer ( )
player : autoWalk ( autoWalkPos )
return true
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
return true
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Only look at things if no usable item was found
if lookThing and lookThing ~= useThing then
local lookPosition = lookThing : getPosition ( )
local lookTile = nil
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if lookPosition and lookPosition.x ~= 0 then
lookTile = g_map.getTile ( lookPosition )
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- For walkable tiles, we want to walk
if lookTile and lookTile : isWalkable ( ) and autoWalkPos then
local player = g_game.getLocalPlayer ( )
player : autoWalk ( autoWalkPos )
return true
else
-- Only look at the thing if we haven't used it already
g_game.look ( lookThing )
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if autoWalkPos then
local player = g_game.getLocalPlayer ( )
player : autoWalk ( autoWalkPos )
return true
end
end
2025-12-30 16:40:47 -03:00
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
2025-09-27 09:15:04 -07:00
local smartLeftClick = modules.client_options . getOption ( ' smartLeftClick ' )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if smartLeftClick then
local player = g_game.getLocalPlayer ( )
-- For containers in the world, Ctrl+Left Click opens them even if there's a creature
if ( useThing : isContainer ( ) or useThing : isLyingCorpse ( ) ) and not useThing : getParentContainer ( ) then
2021-07-19 19:24:59 -03:00
g_game.open ( useThing )
2025-09-27 09:15:04 -07:00
return true
else
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
return true
2021-07-19 19:24:59 -03:00
end
else
2025-09-27 09:15:04 -07:00
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
2021-07-19 19:24:59 -03:00
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
2025-09-27 09:15:04 -07:00
elseif creatureThing and autoWalkPos 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
2025-09-27 09:15:04 -07:00
local lootControlMode = modules.client_options . getOption ( ' lootControlMode ' )
local player = g_game.getLocalPlayer ( )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- ###############################
-- ### MODE 0: LOOT RIGHT CLICK ##
-- ###############################
if lootControlMode == 0 then
-- Right click with no modifiers: main loot functionality
if mouseButton == MouseRightButton and keyboardModifiers == KeyboardNoModifier then
-- Handle creature attacks first (match Smart Left-Click behavior)
if attackCreature and attackCreature ~= player then
g_game.attack ( attackCreature )
2021-07-19 19:24:59 -03:00
return true
2025-09-27 09:15:04 -07:00
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
g_game.attack ( creatureThing )
return true
elseif useThing then
-- For containers/corpses
if useThing : isContainer ( ) or useThing : isLyingCorpse ( ) then
-- For containers inside other containers, we want to open them
if useThing : getParentContainer ( ) then
g_game.open ( useThing , useThing : getParentContainer ( ) )
return true
elseif useThing : isPickupable ( ) then
-- For pickupable containers like quivers, backpacks, etc., open them instead of quicklooting
g_game.open ( useThing )
2025-11-07 09:40:57 -08:00
return true
2025-12-30 16:40:47 -03:00
elseif table.find ( { 3497 , 3498 , 3499 , 3500 , 3502 , 12902 } , useThing : getId ( ) ) then
2025-11-07 09:40:57 -08:00
-- For depot chests, lockers, depot boxes, inbox, etc., always open them
g_game.open ( useThing )
2025-09-27 09:15:04 -07:00
return true
elseif g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot then
-- For containers in the world, quickloot
g_game.sendQuickLoot ( 1 , useThing )
return true
2025-10-02 22:36:25 -03:00
else
g_game.open ( useThing )
return true
2025-09-27 09:15:04 -07:00
end
elseif useThing : isMultiUse ( ) then
startUseWith ( useThing )
return true
else
g_game.use ( useThing )
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Handle pickupable items if no container/corpse was handled
if lookThing and not lookThing : isCreature ( ) and lookThing : isPickupable ( ) then
g_game.move ( lookThing , lookThing : getPosition ( ) , 1 )
2021-07-19 19:24:59 -03:00
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- SHIFT+Right click: opens containers without quicklooting
if mouseButton == MouseRightButton and keyboardModifiers == KeyboardShiftModifier then
if useThing then
if useThing : isContainer ( ) or useThing : isLyingCorpse ( ) 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
end
end
2025-12-30 16:40:47 -03:00
-- #################################
-- ### MODE 1: LOOT SHIFT+RIGHT ###
-- #################################
2025-09-27 09:15:04 -07:00
elseif lootControlMode == 1 then
-- Right click with no modifiers: use or open containers
if mouseButton == MouseRightButton and keyboardModifiers == KeyboardNoModifier then
-- Handle creature attacks first
if attackCreature and attackCreature ~= player then
g_game.attack ( attackCreature )
return true
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
g_game.attack ( creatureThing )
return true
elseif useThing then
-- For containers
if useThing : isContainer ( ) or useThing : isLyingCorpse ( ) 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
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- SHIFT+Right click: quickloot on containers
if mouseButton == MouseRightButton and keyboardModifiers == KeyboardShiftModifier then
if useThing and ( useThing : isContainer ( ) or useThing : isLyingCorpse ( ) ) then
if g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot then
g_game.sendQuickLoot ( 1 , useThing )
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Handle pickupable items
if lookThing and not lookThing : isCreature ( ) and lookThing : isPickupable ( ) then
g_game.move ( lookThing , lookThing : getPosition ( ) , 1 )
return true
end
end
2025-12-30 16:40:47 -03:00
-- #############################
-- ### MODE 2: LOOT LEFT ###
-- #############################
2025-09-27 09:15:04 -07:00
elseif lootControlMode == 2 then
-- Left click with no modifiers: ONLY for loot functionality
if mouseButton == MouseLeftButton and keyboardModifiers == KeyboardNoModifier then
-- ONLY for quicklooting and picking up items, NOT for attacking
if useThing then
-- ONLY quickloot containers/corpses in the game world
if ( useThing : isContainer ( ) or useThing : isLyingCorpse ( ) ) and not useThing : getParentContainer ( ) then
-- Only handle containers that are in the game world (not in inventory)
2025-12-30 16:40:47 -03:00
if table.find ( { 3497 , 3498 , 3499 , 3500 , 3502 , 12902 } , useThing : getId ( ) ) then
2025-11-07 09:40:57 -08:00
-- For depot chests, lockers, depot boxes, inbox, etc., always open them
g_game.open ( useThing )
return true
elseif g_game.getFeature ( GameThingQuickLoot ) and modules.game_quickloot then
2025-09-27 09:15:04 -07:00
g_game.sendQuickLoot ( 1 , useThing )
return true
2025-10-02 22:36:25 -03:00
else
g_game.open ( useThing )
return true
2025-09-27 09:15:04 -07:00
end
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Handle pickupable items in the game world
if lookThing and not lookThing : isCreature ( ) and lookThing : isPickupable ( ) then
g_game.move ( lookThing , lookThing : getPosition ( ) , 1 )
return true
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Right click for Loot: Left mode - use items instead of showing context menu
if mouseButton == MouseRightButton and keyboardModifiers == KeyboardNoModifier then
-- Handle creature attacks first
if attackCreature and attackCreature ~= player then
g_game.attack ( attackCreature )
return true
elseif creatureThing and creatureThing ~= player and autoWalkPos and creatureThing : getPosition ( ) . z == autoWalkPos.z then
g_game.attack ( creatureThing )
return true
2025-12-30 16:40:47 -03:00
-- Use the item if it's a container in inventory or use other items
2025-09-27 09:15:04 -07:00
elseif useThing then
if useThing : isContainer ( ) or useThing : isLyingCorpse ( ) 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
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Only show context menu when no usable item is present
if not useThing then
createThingMenu ( menuPosition , lookThing , useThing , creatureThing )
return true
end
end
end
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
-- Common key combinations for all Classic Control modes
if useThing and useThing : isContainer ( ) and keyboardModifiers == KeyboardCtrlShiftModifier and
2022-04-29 23:14:24 -03:00
( 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
2023-05-11 11:38:24 -03:00
( 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
2025-09-27 09:15:04 -07:00
elseif creatureThing and autoWalkPos 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
2025-09-27 09:15:04 -07:00
-- In Classic Control with Loot: Left option, we want to avoid walking when trying to loot
local classicControl = modules.client_options . getOption ( ' classicControl ' )
local lootControlMode = modules.client_options . getOption ( ' lootControlMode ' )
2025-12-30 16:40:47 -03:00
2025-09-27 09:15:04 -07:00
if classicControl and lootControlMode == 2 then
-- Check if there's a corpse or item we should be looting instead of walking
-- If not, proceed with autowalk
local isCorpseOrContainer = useThing and ( useThing : isContainer ( ) or useThing : isLyingCorpse ( ) )
2025-12-30 16:40:47 -03:00
if not isCorpseOrContainer and
not ( lookThing and not lookThing : isCreature ( ) and lookThing : isPickupable ( ) ) then
2025-09-27 09:15:04 -07:00
player : autoWalk ( autoWalkPos )
if g_game.isAttacking ( ) and g_game.getChaseMode ( ) == ChaseOpponent then
g_game.setChaseMode ( DontChase )
end
end
else
player : autoWalk ( autoWalkPos )
if g_game.isAttacking ( ) and g_game.getChaseMode ( ) == ChaseOpponent then
g_game.setChaseMode ( DontChase )
end
2024-06-21 18:10:07 -03:00
end
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
2026-01-06 11:48:00 -03:00
function handleItemInteraction ( item , widget , callback )
2021-07-19 19:24:59 -03:00
local count = item : getCount ( )
2025-12-30 16:40:47 -03:00
widget.hotkeyBlock = modules.game_hotkeys . createHotkeyBlock ( " stackable_item_dialog " )
local itembox = widget : getChildById ( ' item ' )
local scrollbar = widget : getChildById ( ' countScrollBar ' )
2021-07-19 19:24:59 -03:00
itembox : setItemId ( item : getId ( ) )
itembox : setItemCount ( count )
scrollbar : setMaximum ( count )
scrollbar : setMinimum ( 1 )
scrollbar : setValue ( count )
2025-12-30 16:40:47 -03:00
local spinbox = widget : getChildById ( ' spinBox ' )
2021-07-19 19:24:59 -03:00
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
2026-01-06 11:48:00 -03:00
local function cleanupAndDestroy ( )
-- Unbind keyboard events
g_keyboard.unbindKeyPress ( ' Up ' , spinbox )
g_keyboard.unbindKeyPress ( ' Down ' , spinbox )
g_keyboard.unbindKeyPress ( ' Right ' , spinbox )
g_keyboard.unbindKeyPress ( ' Left ' , spinbox )
g_keyboard.unbindKeyPress ( ' PageUp ' , spinbox )
g_keyboard.unbindKeyPress ( ' PageDown ' , spinbox )
-- Clear callbacks to release references
spinbox.onValueChange = nil
scrollbar.onValueChange = nil
-- Re-enable hotkeys
if widget.hotkeyBlock then
modules.game_hotkeys . enableHotkeys ( widget.hotkeyBlock )
widget.hotkeyBlock = nil
end
-- Destroy the widget
widget : destroy ( )
end
local okButton = widget : getChildById ( ' buttonOk ' )
2021-07-19 19:24:59 -03:00
local moveFunc = function ( )
2026-01-06 11:48:00 -03:00
local itemCount = itembox : getItemCount ( )
cleanupAndDestroy ( )
callback ( itemCount )
2025-12-30 16:40:47 -03:00
widget = nil
2021-07-19 19:24:59 -03:00
end
2025-12-30 16:40:47 -03:00
local cancelButton = widget : getChildById ( ' buttonCancel ' )
2021-07-19 19:24:59 -03:00
local cancelFunc = function ( )
2026-01-06 11:48:00 -03:00
cleanupAndDestroy ( )
2025-12-30 16:40:47 -03:00
widget = nil
2021-07-19 19:24:59 -03:00
end
2012-07-15 11:28:15 -03:00
2025-12-30 16:40:47 -03:00
widget.onEnter = moveFunc
widget.onEscape = cancelFunc
2012-03-29 10:45:40 -03:00
2021-07-19 19:24:59 -03:00
okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
2012-03-18 10:34:39 -03:00
end
2024-08-28 00:16:21 -03:00
2025-12-30 16:40:47 -03:00
function stashItem ( item )
local count = item : getCount ( )
if count == 1 then
g_game.stashStowItem ( item : getPosition ( ) , item : getId ( ) , count ,
item : getStackPos ( ) , 0 )
return
end
countWindow = g_ui.createWidget ( ' CountStashWindow ' , rootWidget )
handleItemInteraction ( item , countWindow , function ( amount )
g_game.stashStowItem ( item : getPosition ( ) , item : getId ( ) , amount ,
item : getStackPos ( ) , 0 )
countWindow = nil
end )
end
function moveStackableItem ( item , toPos )
if countWindow then
return
end
if g_keyboard.isShiftPressed ( ) then
g_game.move ( item , toPos , 1 )
return
elseif g_keyboard.isCtrlPressed ( ) ~= modules.client_options . getOption ( ' moveStack ' ) then
g_game.move ( item , toPos , item : getCount ( ) )
return
end
countWindow = g_ui.createWidget ( ' CountWindow ' , rootWidget )
handleItemInteraction ( item , countWindow , function ( count )
g_game.move ( item , toPos , count )
countWindow = nil
end )
end
2024-06-21 18:10:07 -03:00
function onSelectPanel ( self , checked )
if checked then
for k , v in pairs ( panelsList ) do
if v.checkbox == self then
gameSelectedPanel = v.panel
break
end
end
end
end
2024-08-28 00:16:21 -03:00
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
2024-06-21 18:10:07 -03:00
function getMainRightPanel ( )
return gameMainRightPanel
end
2026-01-06 11:48:00 -03:00
function fitMainRightPanel ( )
if gameMainRightPanel and gameMainRightPanel.fitAllChildren then
gameMainRightPanel : fitAllChildren ( )
end
end
2022-08-17 12:51:56 -03:00
function getLeftPanel ( )
return gameLeftPanel
end
2012-07-24 02:30:08 -03:00
2026-01-06 11:48:00 -03:00
function getContainerPanel ( )
local containerPanel = g_settings.getNumber ( " containerPanel " )
if containerPanel >= 4 then
containerPanel = containerPanel - 4
return gameRightPanel : getChildByIndex ( math.min ( containerPanel , gameRightPanel : getChildCount ( ) ) )
end
if gameLeftPanel : getChildCount ( ) == 0 then
return getRightPanel ( )
end
return gameLeftPanel : getChildByIndex ( math.min ( containerPanel , gameLeftPanel : getChildCount ( ) ) )
end
2022-08-17 12:51:56 -03:00
function getRightExtraPanel ( )
return gameRightExtraPanel
end
2021-07-22 20:33:54 +02:00
2024-06-21 18:10:07 -03:00
function getLeftExtraPanel ( )
return gameLeftExtraPanel
end
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
2024-08-28 00:16:21 -03:00
2024-06-21 18:10:07 -03:00
function getGameTopStatsBar ( )
return gameTopPanel
end
2024-06-28 14:45:01 -03:00
function getGameBottomStatsBar ( )
return gameBottomStatsBarPanel
end
2024-06-21 18:10:07 -03:00
function getGameMapPanel ( )
return gameMapPanel
end
2017-11-19 02:00:02 +01:00
2025-10-25 04:28:51 -03:00
function getBottomActionPanel ( )
return gameBottomActionPanel
2025-12-30 16:40:47 -03:00
end
function getLeftActionPanel ( )
2025-10-25 04:28:51 -03:00
return gameLeftActionPanel
2025-12-30 16:40:47 -03:00
end
function getRightActionPanel ( )
2025-10-25 04:28:51 -03:00
return gameRightActionPanel
2025-12-30 16:40:47 -03:00
end
function getBottomLockPanel ( )
2025-10-25 04:28:51 -03:00
return gameBottomLockPanel
2025-12-30 16:40:47 -03:00
end
function getRightLockPanel ( )
2025-10-25 04:28:51 -03:00
return gameRightLockPanel
2025-12-30 16:40:47 -03:00
end
function getLeftLockPanel ( )
2025-10-25 04:28:51 -03:00
return gameLeftLockPanel
2025-12-30 16:40:47 -03:00
end
2025-10-25 04:28:51 -03:00
2025-12-30 16:40:47 -03:00
function getBottomSplitter ( )
2025-10-25 04:28:51 -03:00
return bottomSplitter
2025-12-30 16:40:47 -03:00
end
2021-07-23 21:37:16 +02:00
function findContentPanelAvailable ( child , minContentHeight )
2026-01-06 11:48:00 -03:00
-- Special restriction: only minimap can be placed in horizontalLeftPanel
local childId = child : getId ( )
local isMinimapWidget = ( childId == " minimapWindow " )
2024-06-21 18:10:07 -03:00
if gameSelectedPanel and gameSelectedPanel : isVisible ( ) and gameSelectedPanel : fits ( child , minContentHeight , 0 ) >= 0 then
2026-01-06 11:48:00 -03:00
-- Block non-minimap widgets from horizontalLeftPanel
if gameSelectedPanel : getId ( ) == " horizontalLeftPanel " and not isMinimapWidget then
-- Skip this panel, will try others below
else
return gameSelectedPanel
end
2021-07-23 21:37:16 +02:00
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
2026-01-06 11:48:00 -03:00
-- Block non-minimap widgets from horizontalLeftPanel
if v.panel : getId ( ) == " horizontalLeftPanel " and not isMinimapWidget then
-- Skip this panel
else
return v.panel
end
2021-07-23 21:37:16 +02:00
end
end
return gameSelectedPanel
end
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
2024-06-21 18:10:07 -03:00
leftIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showLeftExtraPanel ' ) )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
leftDecreaseSidePanels : setEnabled ( false )
2026-01-06 11:48:00 -03:00
else
local hasLeftPanels = modules.client_options . getOption ( ' showLeftPanel ' ) or
modules.client_options . getOption ( ' showLeftExtraPanel ' )
leftDecreaseSidePanels : setEnabled ( hasLeftPanels )
2024-12-30 13:59:43 -03:00
end
2024-06-21 18:10:07 -03:00
rightIncreaseSidePanels : setEnabled ( not modules.client_options . getOption ( ' showRightExtraPanel ' ) )
rightDecreaseSidePanels : setEnabled ( modules.client_options . getOption ( ' showRightExtraPanel ' ) )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
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 )
2024-08-28 21:49:41 -03:00
gameRootPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
2021-07-19 19:24:59 -03:00
gameLeftPanel : setOn ( modules.client_options . getOption ( ' showLeftPanel ' ) )
2021-07-22 20:33:54 +02:00
gameRightExtraPanel : setOn ( modules.client_options . getOption ( ' showRightExtraPanel ' ) )
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel : setOn ( modules.client_options . getOption ( ' showLeftExtraPanel ' ) )
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 ' )
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel : 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 )
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel : setMarginTop ( 0 )
2021-07-19 19:24:59 -03:00
gameBottomPanel : setImageColor ( ' white ' )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
2021-07-19 19:24:59 -03:00
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
} )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
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
} )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
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 ' )
2024-06-21 18:10:07 -03:00
gameLeftExtraPanel : setImageColor ( ' alpha ' )
2021-07-19 19:24:59 -03:00
gameLeftPanel : setOn ( true )
gameLeftPanel : setVisible ( true )
gameRightPanel : setOn ( true )
2024-12-30 13:59:43 -03:00
gameRightExtraPanel : setOn ( false )
gameRightExtraPanel : setVisible ( false )
gameLeftExtraPanel : setOn ( false )
gameLeftExtraPanel : setVisible ( false )
2021-07-19 19:24:59 -03:00
gameMapPanel : setOn ( true )
gameBottomPanel : setImageColor ( ' #ffffff88 ' )
2024-12-30 13:59:43 -03:00
if g_platform.isMobile ( ) then
2025-04-12 20:33:19 -04:00
gameRightPanel : setMarginBottom ( mobileConfig.mobileHeightShortcuts )
gameLeftPanel : setMarginBottom ( mobileConfig.mobileHeightJoystick )
2024-12-30 13:59:43 -03:00
end
2021-07-19 19:24:59 -03:00
end
currentViewMode = mode
2025-04-12 20:33:19 -04:00
testExtendedView ( mode )
2021-07-19 19:24:59 -03:00
end
2022-08-17 12:51:56 -03:00
function limitZoom ( )
limitedZoom = true
end
2024-06-21 18:10:07 -03:00
2024-06-28 14:45:01 -03:00
function updateStatsBar ( dimension , placement )
StatsBar.updateCurrentStats ( dimension , placement )
StatsBar.updateStatsBarOption ( )
2024-06-21 18:10:07 -03:00
end
function onIncreaseLeftPanels ( )
leftDecreaseSidePanels : setEnabled ( true )
if not modules.client_options . getOption ( ' showLeftPanel ' ) then
modules.client_options . setOption ( ' showLeftPanel ' , true )
2025-11-07 09:41:04 -08:00
-- Update action bars when left panel is shown
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-06-21 18:10:07 -03:00
return
end
if not modules.client_options . getOption ( ' showLeftExtraPanel ' ) then
modules.client_options . setOption ( ' showLeftExtraPanel ' , true )
leftIncreaseSidePanels : setEnabled ( false )
2026-01-06 11:48:00 -03:00
-- Update horizontal left panel width if active
if modules.client_options . getOption ( ' showHorizontalLeftPanel ' ) then
addEvent ( function ( )
setLeftHorizontalWidth ( )
end )
end
2025-11-07 09:41:04 -08:00
-- Update action bars when left extra panel is shown
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-06-21 18:10:07 -03:00
return
end
end
local function movePanel ( mainpanel )
for _ , widget in pairs ( mainpanel : getChildren ( ) ) do
if widget then
2024-08-28 00:16:21 -03:00
local panel = modules.game_interface . findContentPanelAvailable ( widget , widget : getMinimumHeight ( ) )
2024-06-21 18:10:07 -03:00
if panel then
if not panel : hasChild ( widget ) then
widget : close ( )
panel : addChild ( widget )
else
print ( " Error: Attempt to add a widget that already exists in the target panel " )
end
else
print ( " Warning: No suitable panel found for widget, unable to move " )
end
end
end
end
function onDecreaseLeftPanels ( )
leftIncreaseSidePanels : setEnabled ( true )
if modules.client_options . getOption ( ' showLeftExtraPanel ' ) then
modules.client_options . setOption ( ' showLeftExtraPanel ' , false )
movePanel ( gameLeftExtraPanel )
2025-01-14 16:47:32 +01:00
if g_platform.isMobile ( ) then
leftDecreaseSidePanels : setEnabled ( false )
end
2026-01-06 11:48:00 -03:00
-- Update horizontal left panel width if active
if modules.client_options . getOption ( ' showHorizontalLeftPanel ' ) then
addEvent ( function ( )
setLeftHorizontalWidth ( )
end )
end
2025-11-07 09:41:04 -08:00
-- Update action bars when left extra panel is hidden
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-06-21 18:10:07 -03:00
return
end
2024-12-30 13:59:43 -03:00
if not g_platform.isMobile ( ) then
if modules.client_options . getOption ( ' showLeftPanel ' ) then
2026-01-06 11:48:00 -03:00
-- Prevent closing left panel if horizontal left panel is active
if modules.client_options . getOption ( ' showHorizontalLeftPanel ' ) then
return
end
2024-12-30 13:59:43 -03:00
modules.client_options . setOption ( ' showLeftPanel ' , false )
movePanel ( gameLeftPanel )
leftDecreaseSidePanels : setEnabled ( false )
2025-11-07 09:41:04 -08:00
-- Update action bars when left panel is hidden
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-12-30 13:59:43 -03:00
return
end
2024-06-21 18:10:07 -03:00
end
end
function onIncreaseRightPanels ( )
rightIncreaseSidePanels : setEnabled ( false )
rightDecreaseSidePanels : setEnabled ( true )
modules.client_options . setOption ( ' showRightExtraPanel ' , true )
2026-01-06 11:48:00 -03:00
-- Update horizontal right panel width
addEvent ( function ( )
setRightHorizontalWidth ( )
end )
2025-11-07 09:41:04 -08:00
-- Update action bars when right extra panel is shown
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-06-21 18:10:07 -03:00
end
function onDecreaseRightPanels ( )
rightIncreaseSidePanels : setEnabled ( true )
rightDecreaseSidePanels : setEnabled ( false )
movePanel ( gameRightExtraPanel )
modules.client_options . setOption ( ' showRightExtraPanel ' , false )
2026-01-06 11:48:00 -03:00
-- Update horizontal right panel width
addEvent ( function ( )
setRightHorizontalWidth ( )
end )
2025-11-07 09:41:04 -08:00
-- Update action bars when right extra panel is hidden
if modules.game_actionbar and modules.game_actionbar . updateVisibleWidgetsExternal then
addEvent ( function ( )
modules.game_actionbar . updateVisibleWidgetsExternal ( )
end )
end
2024-06-21 18:10:07 -03:00
end
function setupOptionsMainButton ( )
if logOutMainButton then
return
end
2024-08-28 00:16:21 -03:00
logOutMainButton = modules.game_mainpanel . addSpecialToggleButton ( ' logoutButton ' , tr ( ' Exit ' ) ,
' /images/options/button_logout ' ,
tryLogout )
2024-06-21 18:10:07 -03:00
end
function checkAndOpenLeftPanel ( )
leftDecreaseSidePanels : setEnabled ( true )
if not modules.client_options . getOption ( ' showLeftPanel ' ) then
modules.client_options . setOption ( ' showLeftPanel ' , true )
return
end
2025-01-14 16:47:32 +01:00
end
2025-04-12 20:33:19 -04:00
function testExtendedView ( mode )
local extendedView = mode == 2
if extendedView then
2025-12-30 16:40:47 -03:00
local buttons = { leftIncreaseSidePanels , rightIncreaseSidePanels , rightDecreaseSidePanels ,
leftDecreaseSidePanels }
2025-04-12 20:33:19 -04:00
for _ , button in ipairs ( buttons ) do
button : hide ( )
end
if not g_platform.isMobile ( ) then
gameBottomPanel : breakAnchors ( )
gameBottomPanel : bindRectToParent ( )
gameBottomPanel : setDraggable ( true )
else
2025-12-30 16:40:47 -03:00
gameBottomPanel : setWidth ( g_window.getWidth ( ) - mobileConfig.mobileWidthJoystick -
mobileConfig.mobileWidthShortcuts )
2025-04-12 20:33:19 -04:00
gameBottomPanel : setPosition ( {
x = mobileConfig.mobileWidthJoystick ,
y = gameBottomPanel : getY ( )
} )
end
gameBottomPanel : getChildById ( ' rightResizeBorder ' ) : setMaximum ( gameBottomPanel : getWidth ( ) )
gameBottomPanel : getChildById ( ' bottomResizeBorder ' ) : enable ( )
gameBottomPanel : getChildById ( ' rightResizeBorder ' ) : enable ( )
gameMainRightPanel : setHeight ( 0 )
gameMainRightPanel : setImageColor ( ' alpha ' )
2025-10-25 04:28:51 -03:00
gameBottomPanel : addAnchor ( AnchorTop , ' gameBottomActionPanel ' , AnchorBottom )
gameBottomPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
2025-04-12 20:33:19 -04:00
else
-- Reset to normal view
2026-01-06 11:48:00 -03:00
-- gameMainRightPanel:setHeight(200)
2025-04-12 20:33:19 -04:00
gameMainRightPanel : setMarginTop ( 0 )
gameMainRightPanel : setImageColor ( ' white ' )
2026-01-06 11:48:00 -03:00
if gameMainRightPanel.fitAllChildren then
gameMainRightPanel : fitAllChildren ( )
else
-- opcional: deixa 0 e quem usa (módulos) ajusta
gameMainRightPanel : setHeight ( 0 )
end
2025-04-12 20:33:19 -04:00
2025-12-30 16:40:47 -03:00
local buttons = { leftIncreaseSidePanels , rightIncreaseSidePanels , rightDecreaseSidePanels ,
leftDecreaseSidePanels }
2025-04-12 20:33:19 -04:00
for _ , button in ipairs ( buttons ) do
button : setMarginTop ( 0 )
button : show ( )
end
-- Reset bottom panel
gameBottomPanel : setDraggable ( false )
-- Set anchors
if not g_platform.isMobile ( ) then
gameBottomPanel : breakAnchors ( )
gameBottomPanel : addAnchor ( AnchorLeft , ' gameLeftExtraPanel ' , AnchorRight )
gameBottomPanel : addAnchor ( AnchorRight , ' gameRightExtraPanel ' , AnchorLeft )
2025-10-25 04:28:51 -03:00
gameBottomPanel : addAnchor ( AnchorTop , ' gameBottomCooldownPanel ' , AnchorBottom )
2025-04-12 20:33:19 -04:00
gameBottomPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
gameBottomPanel : getChildById ( ' bottomResizeBorder ' ) : disable ( )
gameBottomPanel : getChildById ( ' rightResizeBorder ' ) : disable ( )
-- Move children back to gameMainRightPanel
local children = gameRightPanel : getChildren ( )
for _ , child in ipairs ( children ) do
if child.moveOnlyToMain then
child : setParent ( gameMainRightPanel )
end
end
end
2025-06-25 17:35:39 -04:00
addEvent ( function ( )
modules.game_console . setExtendedView ( extendedView )
modules.game_minimap . extendedView ( extendedView )
modules.game_healthinfo . extendedView ( extendedView )
modules.game_inventory . extendedView ( extendedView )
2025-04-12 20:33:19 -04:00
modules.client_topmenu . extendedView ( extendedView )
modules.game_mainpanel . toggleExtendedViewButtons ( extendedView )
2025-06-25 17:35:39 -04:00
end )
2025-04-12 20:33:19 -04:00
end
2025-10-13 10:18:54 -07:00
function toggleInternalFocus ( )
for reason , _ in pairs ( focusReason ) do
if reason == ' bosscooldown ' then
modules.game_analyser . toggleBossCDFocus ( false )
end
end
end
function isInternalLocked ( )
if not focusReason or table.empty ( focusReason ) then
return false
end
return true
end
function toggleFocus ( value , reason )
if not reason then
reason = ' '
end
if not value then
getBottomPanel ( ) : focus ( )
if not reason then
reason = ' '
end
focusReason [ reason ] = nil
else
focusReason [ reason ] = true
end
if not value and # focusReason ~= 0 then
return
end
gameRightPanel : setFocusable ( value )
gameLeftPanel : setFocusable ( value )
gameRightExtraPanel : setFocusable ( value )
gameLeftExtraPanel : setFocusable ( value )
2025-12-30 16:40:47 -03:00
end
2026-01-06 11:48:00 -03:00
function getHorizontalLeftPanel ( )
if not horizontalLeftPanel then
return createHorizontalLeftPanel ( )
end
return horizontalLeftPanel
end
function getHorizontalRightPanel ( )
if not horizontalRightPanel then
return createHorizontalRightPanel ( )
end
return horizontalRightPanel
end
function createHorizontalRightPanel ( )
if horizontalRightPanel then return horizontalRightPanel end
if not gameRootPanel then
return nil
end
-- Create the panel (GameSidePanel)
horizontalRightPanel = g_ui.createWidget ( ' GameSidePanel ' , gameRootPanel )
horizontalRightPanel : setId ( ' horizontalRightPanel ' )
horizontalRightPanel : addAnchor ( AnchorRight , ' parent ' , AnchorRight )
horizontalRightPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
horizontalRightPanel : setHeight ( 0 )
horizontalRightPanel : setWidth ( 0 )
horizontalRightPanel : setFocusable ( false )
horizontalRightPanel : setVisible ( true )
horizontalRightPanel : setPhantom ( true ) -- [FIX] Start as phantom when empty to allow drops through to panels below
return horizontalRightPanel
end
function createHorizontalLeftPanel ( )
if horizontalLeftPanel then return horizontalLeftPanel end
if not gameRootPanel then
return nil
end
-- Create the panel (GameSidePanel)
horizontalLeftPanel = g_ui.createWidget ( ' GameSidePanel ' , gameRootPanel )
horizontalLeftPanel : setId ( ' horizontalLeftPanel ' )
horizontalLeftPanel : addAnchor ( AnchorLeft , ' parent ' , AnchorLeft )
horizontalLeftPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
horizontalLeftPanel : setHeight ( 0 )
horizontalLeftPanel : setWidth ( 0 )
horizontalLeftPanel : setFocusable ( false )
horizontalLeftPanel : setVisible ( true )
horizontalLeftPanel : setPhantom ( true ) -- [FIX] Start as phantom when empty to allow drops through to panels below
return horizontalLeftPanel
end
function showRightHorizontalPanel ( visible )
-- Create panel dynamically if needed
local panel = horizontalRightPanel
if not panel then
panel = createHorizontalRightPanel ( )
end
if not panel then
return
end
if visible then
panel : setHeight ( 200 ) -- FIXED HEIGHT
setRightHorizontalWidth ( )
-- Adjust gameMainRightPanel to anchor below the horizontal panel
if gameMainRightPanel then
gameMainRightPanel : breakAnchors ( )
gameMainRightPanel : addAnchor ( AnchorRight , ' parent ' , AnchorRight )
gameMainRightPanel : addAnchor ( AnchorTop , ' horizontalRightPanel ' , AnchorBottom )
-- Auto-fit height after minimap moved to horizontal panel
scheduleEvent ( function ( )
if gameMainRightPanel and gameMainRightPanel.fitAllChildren then
gameMainRightPanel : fitAllChildren ( )
end
end , 50 )
end
-- Adjust extra panel if it exists
if gameRightExtraPanel then
gameRightExtraPanel : breakAnchors ( )
gameRightExtraPanel : addAnchor ( AnchorRight , ' gameRightPanel ' , AnchorLeft )
gameRightExtraPanel : addAnchor ( AnchorTop , ' horizontalRightPanel ' , AnchorBottom )
gameRightExtraPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
else
-- Move children from horizontal panel back to main right panel before hiding
if panel then
local children = panel : getChildren ( )
for _ , child in pairs ( children ) do
if child and gameMainRightPanel then
child : setParent ( gameMainRightPanel )
gameMainRightPanel : moveChildToIndex ( child , 1 )
end
end
end
-- Notify minimap to return to main panel with default height
if modules.game_minimap and modules.game_minimap . returnToMainPanel then
modules.game_minimap . returnToMainPanel ( )
end
panel : setHeight ( 0 )
panel : setWidth ( 0 )
-- Restore gameMainRightPanel to anchor to parent top
if gameMainRightPanel then
gameMainRightPanel : breakAnchors ( )
gameMainRightPanel : addAnchor ( AnchorRight , ' parent ' , AnchorRight )
gameMainRightPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
-- Auto-fit height after children moved back
if gameMainRightPanel.fitAllChildren then
gameMainRightPanel : fitAllChildren ( )
end
end
-- Restore extra panel
if gameRightExtraPanel then
gameRightExtraPanel : breakAnchors ( )
gameRightExtraPanel : addAnchor ( AnchorRight , ' gameRightPanel ' , AnchorLeft )
gameRightExtraPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
gameRightExtraPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
end
end
function showLeftHorizontalPanel ( visible )
-- Create panel dynamically if needed
local panel = horizontalLeftPanel
if not panel then
panel = createHorizontalLeftPanel ( )
end
if not panel then
return
end
if visible then
panel : setHeight ( 200 ) -- FIXED HEIGHT
setLeftHorizontalWidth ( )
-- Adjust gameLeftPanel to anchor below the horizontal panel
if gameLeftPanel then
gameLeftPanel : breakAnchors ( )
gameLeftPanel : addAnchor ( AnchorLeft , ' parent ' , AnchorLeft )
gameLeftPanel : addAnchor ( AnchorTop , ' horizontalLeftPanel ' , AnchorBottom )
gameLeftPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
-- Adjust extra panel if it exists
if gameLeftExtraPanel then
gameLeftExtraPanel : breakAnchors ( )
gameLeftExtraPanel : addAnchor ( AnchorLeft , ' gameLeftPanel ' , AnchorRight )
gameLeftExtraPanel : addAnchor ( AnchorTop , ' horizontalLeftPanel ' , AnchorBottom )
gameLeftExtraPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
else
-- NAO move children automaticamente - deixa o minimap gerenciar sua propria posicao
-- Apenas esconde o panel
panel : setHeight ( 0 )
panel : setWidth ( 0 )
-- Restore gameLeftPanel to anchor to parent top
if gameLeftPanel then
gameLeftPanel : breakAnchors ( )
gameLeftPanel : addAnchor ( AnchorLeft , ' parent ' , AnchorLeft )
gameLeftPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
gameLeftPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
-- Restore extra panel
if gameLeftExtraPanel then
gameLeftExtraPanel : breakAnchors ( )
gameLeftExtraPanel : addAnchor ( AnchorLeft , ' gameLeftPanel ' , AnchorRight )
gameLeftExtraPanel : addAnchor ( AnchorTop , ' parent ' , AnchorTop )
gameLeftExtraPanel : addAnchor ( AnchorBottom , ' parent ' , AnchorBottom )
end
end
end
-- Set horizontal panel width based on actual visible side panels width
function setRightHorizontalWidth ( )
if not horizontalRightPanel then return end
-- Calculate total width based on the RIGHT side panels that exist
-- The horizontal panel should span the same width as the vertical panels below it
local totalWidth = 0
-- Get width of gameRightPanel (main right sidebar)
if gameRightPanel and gameRightPanel : isOn ( ) and gameRightPanel : getWidth ( ) > 0 then
totalWidth = totalWidth + gameRightPanel : getWidth ( )
end
-- Add extra panel width if visible and on
if gameRightExtraPanel and gameRightExtraPanel : isOn ( ) and gameRightExtraPanel : getWidth ( ) > 0 then
totalWidth = totalWidth + gameRightExtraPanel : getWidth ( )
end
-- Fallback: if no width calculated, use default
if totalWidth == 0 then
totalWidth = 178 -- default single panel width
end
horizontalRightPanel : setWidth ( totalWidth )
end
function setLeftHorizontalWidth ( )
if not horizontalLeftPanel then return end
-- Calculate total width based on the LEFT side panels
local totalWidth = 0
-- Get width of gameLeftPanel (main left sidebar)
if gameLeftPanel and gameLeftPanel : isOn ( ) and gameLeftPanel : getWidth ( ) > 0 then
totalWidth = totalWidth + gameLeftPanel : getWidth ( )
end
-- Add extra panel width if visible and on
if gameLeftExtraPanel and gameLeftExtraPanel : isOn ( ) and gameLeftExtraPanel : getWidth ( ) > 0 then
totalWidth = totalWidth + gameLeftExtraPanel : getWidth ( )
end
-- Fallback: if no width calculated, use default
if totalWidth == 0 then
totalWidth = 178 -- default single panel width
end
horizontalLeftPanel : setWidth ( totalWidth )
-- Auto-resize minimap if it's in the horizontal panel
local children = horizontalLeftPanel : getChildren ( )
for _ , child in pairs ( children ) do
if child : getId ( ) == " minimapWindow " then
child : setWidth ( totalWidth )
break
end
end
end
-- Check if widgets overflow the horizontal panel and move them (RTC-style)
function checkHorizontalPanel ( widget )
if not widget then return end
local relativeHeight = 0
local totalHeight = widget : getHeight ( ) + 10 -- margin de erro
local moveWidgets = { }
local children = widget : getChildren ( )
for _ , child in pairs ( children ) do
relativeHeight = relativeHeight + child : getHeight ( )
if relativeHeight > totalHeight then
table.insert ( moveWidgets , child )
end
end
for _ , w in pairs ( moveWidgets ) do
if gameRightPanel then
addEvent ( function ( ) w : setParent ( gameRightPanel ) end )
end
end
end