-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathgameinterface.lua
1376 lines (1229 loc) · 44.4 KB
/
gameinterface.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
gameRootPanel = nil
gameMapPanel = nil
gameMainRightPanel = nil
gameRightPanel = nil
gameRightExtraPanel = nil
gameLeftPanel = nil
gameLeftExtraPanel = nil
gameSelectedPanel = nil
panelsList = {}
panelsRadioGroup = nil
gameTopPanel = nil
gameBottomStatsBarPanel = nil
gameBottomPanel = nil
showTopMenuButton = nil
logoutButton = nil
logOutMainButton = nil
mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
bottomSplitter = nil
limitedZoom = false
currentViewMode = 0
leftIncreaseSidePanels = nil
leftDecreaseSidePanels = nil
rightIncreaseSidePanels = nil
rightDecreaseSidePanels = nil
hookedMenuOptions = {}
local lastStopAction = 0
function init()
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
if g_app.hasUpdater() then
connect(g_app, {
onUpdateFinished = load,
})
else
connect(g_app, {
onRun = load,
})
end
connect(g_app, {
onExit = save
})
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')
gameMainRightPanel = gameRootPanel:getChildById('gameMainRightPanel')
gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
gameRightExtraPanel = gameRootPanel:getChildById('gameRightExtraPanel')
gameLeftExtraPanel = gameRootPanel:getChildById('gameLeftExtraPanel')
gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
gameTopPanel = gameRootPanel:getChildById('gameTopPanel')
gameBottomStatsBarPanel = gameRootPanel:getChildById('gameBottomStatsBarPanel')
leftIncreaseSidePanels = gameRootPanel:getChildById('leftIncreaseSidePanels')
leftDecreaseSidePanels = gameRootPanel:getChildById('leftDecreaseSidePanels')
rightIncreaseSidePanels = gameRootPanel:getChildById('rightIncreaseSidePanels')
rightDecreaseSidePanels = gameRootPanel:getChildById('rightDecreaseSidePanels')
leftIncreaseSidePanels:setEnabled(not modules.client_options.getOption('showLeftExtraPanel'))
if g_platform.isMobile() then
leftDecreaseSidePanels:setEnabled(false)
else
leftDecreaseSidePanels:setEnabled(true)
end
rightIncreaseSidePanels:setEnabled(not modules.client_options.getOption('showRightExtraPanel'))
rightDecreaseSidePanels:setEnabled(modules.client_options.getOption('showRightExtraPanel'))
if g_platform.isMobile() then
gameRightPanel:setMarginBottom(150)
gameLeftPanel:setMarginBottom(150)
end
panelsList = { {
panel = gameRightPanel,
checkbox = gameRootPanel:getChildById('gameSelectRightColumn')
}, {
panel = gameRightExtraPanel,
checkbox = gameRootPanel:getChildById('gameSelectRightExtraColumn')
}, {
panel = gameLeftPanel,
checkbox = gameRootPanel:getChildById('gameSelectLeftColumn')
}, {
panel = gameLeftExtraPanel,
checkbox = gameRootPanel:getChildById('gameSelectLeftExtraColumn')
} }
panelsRadioGroup = UIRadioGroup.create()
for k, v in pairs(panelsList) do
panelsRadioGroup:addWidget(v.checkbox)
connect(v.checkbox, {
onCheckChange = onSelectPanel
})
end
panelsRadioGroup:selectWidget(panelsList[1].checkbox)
logoutButton = modules.client_topmenu.addTopRightToggleButton('logoutButton', tr('Exit'), '/images/topbuttons/logout',
tryLogout, true)
showTopMenuButton = gameMapPanel:getChildById('showTopMenuButton')
showTopMenuButton.onClick = function()
modules.client_topmenu.toggle()
end
bindKeys()
if g_game.isOnline() then
show()
end
StatsBar.init()
end
function bindKeys()
gameRootPanel:setAutoRepeatDelay(50)
g_keyboard.bindKeyPress('Ctrl+=', function()
gameMapPanel:zoomIn()
end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+-', function()
gameMapPanel:zoomOut()
end, gameRootPanel)
Keybind.new("Movement", "Stop All Actions", "Escape", "", true)
Keybind.bind("Movement", "Stop All Actions", {
{
type = KEY_PRESS,
callback = function()
if lastStopAction + 50 > g_clock.millis() then return end
lastStopAction = g_clock.millis()
g_game.cancelAttackAndFollow()
end,
}
}, gameRootPanel)
Keybind.new("Misc", "Logout", "Ctrl+L", "Ctrl+Q")
Keybind.bind("Misc", "Logout", {
{
type = KEY_PRESS,
callback = function() tryLogout(false) end,
}
}, gameRootPanel)
Keybind.new("UI", "Clear All Texts", "Ctrl+W", "")
Keybind.bind("UI", "Clear All Texts", {
{
type = KEY_DOWN,
callback = function()
g_map.cleanTexts()
modules.game_textmessage.clearMessages()
end,
}
}, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel)
end
function terminate()
StatsBar.terminate()
hide()
if g_app.hasUpdater() then
disconnect(g_app, {
onUpdateFinished = load,
})
else
disconnect(g_app, {
onRun = load,
})
end
disconnect(g_app, {
onExit = save,
})
hookedMenuOptions = {}
disconnect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
onLoginAdvice = onLoginAdvice
})
for k, v in pairs(panelsList) do
disconnect(v.checkbox, {
onCheckChange = onSelectPanel
})
end
logoutButton:destroy()
gameRootPanel:destroy()
Keybind.delete("Movement", "Stop All Actions")
Keybind.delete("Misc", "Logout")
Keybind.delete("UI", "Clear All Texts")
end
function onGameStart()
show()
leftIncreaseSidePanels:setEnabled(not modules.client_options.getOption('showLeftExtraPanel'))
if g_platform.isMobile() then
leftDecreaseSidePanels:setEnabled(false)
else
leftDecreaseSidePanels:setEnabled(true)
end
rightIncreaseSidePanels:setEnabled(not modules.client_options.getOption('showRightExtraPanel'))
rightDecreaseSidePanels:setEnabled(modules.client_options.getOption('showRightExtraPanel'))
if g_platform.isMobile() then
gameRightPanel:setMarginBottom(150)
gameLeftPanel:setMarginBottom(150)
end
end
function onGameEnd()
hide()
end
function show()
connect(g_app, {
onClose = tryExit
})
modules.client_background.hide()
gameRootPanel:show()
gameRootPanel:focus()
gameMapPanel:followCreature(g_game.getLocalPlayer())
updateStretchShrink()
logoutButton:setTooltip(tr('Logout'))
setupViewMode(0)
if g_platform.isMobile() then
setupViewMode(1)
setupViewMode(2)
end
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)
end
function hide()
setupViewMode(0)
disconnect(g_app, {
onClose = tryExit
})
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()
end
function save()
local settings = {}
settings.splitterMarginBottom = bottomSplitter:getMarginBottom()
g_settings.setNode('game_interface', settings)
end
function load()
local settings = g_settings.getNode('game_interface')
if settings then
if settings.splitterMarginBottom then
bottomSplitter:setMarginBottom(settings.splitterMarginBottom)
end
end
end
function onLoginAdvice(message)
displayInfoBox(tr('For Your Information'), message)
end
function forceExit()
g_game.cancelLogin()
scheduleEvent(exit, 10)
return true
end
function tryExit()
if exitWindow then
return true
end
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
exitWindow = displayGeneralBox(tr('Exit'), tr(
'If you shut down the program, your character might stay in the game.\nClick on \'Logout\' to ensure that you character leaves the game properly.\nClick on \'Exit\' if you want to exit the program without logging out your character.'),
{
{
text = tr('Cancel'),
callback = cancelFunc
},
{
text = tr('Logout'),
callback = logoutFunc
},
{
text = tr('Force Exit'),
callback = exitFunc
},
anchor = AnchorHorizontalCenter
}, logoutFunc, cancelFunc)
return true
end
function tryLogout(prompt)
if type(prompt) ~= 'boolean' then
prompt = true
end
if not g_game.isOnline() then
exit()
return
end
if logoutWindow then
return
end
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
end
local noCallback = function()
logoutWindow:destroy()
logoutWindow = nil
end
if prompt then
logoutWindow = displayGeneralBox(tr('Logout'), tr(msg), {
{
text = tr('No'),
callback = noCallback
},
{
text = tr('Yes'),
callback = yesCallback
},
anchor = AnchorHorizontalCenter
}, yesCallback, noCallback)
else
yesCallback()
end
end
function updateStretchShrink()
if modules.client_options.getOption('dontStretchShrink') and not alternativeView then
gameMapPanel:setVisibleDimension({
width = 15,
height = 11
})
-- Set gameMapPanel size to height = 11 * 32 + 2
bottomSplitter:setMarginBottom(bottomSplitter:getMarginBottom() + (gameMapPanel:getHeight() - 32 * 11) - 10)
end
end
function onMouseGrabberRelease(self, mousePosition, mouseButton)
if selectedThing == nil then
return false
end
if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then
if selectedType == 'use' then
onUseWith(clickedWidget, mousePosition)
elseif selectedType == 'trade' then
onTradeWith(clickedWidget, mousePosition)
end
end
end
selectedThing = nil
g_mouse.popCursor('target')
self:ungrabMouse()
return true
end
function onUseWith(clickedWidget, mousePosition)
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
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(selectedThing, clickedWidget:getItem())
elseif clickedWidget:getClassName() == 'UICreatureButton' then
local creature = clickedWidget:getCreature()
if creature then
g_game.useWith(selectedThing, creature)
end
end
end
function onTradeWith(clickedWidget, mousePosition)
if clickedWidget:getClassName() == 'UIGameMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.requestTrade(selectedThing, tile:getTopCreature())
end
elseif clickedWidget:getClassName() == 'UICreatureButton' then
local creature = clickedWidget:getCreature()
if creature then
g_game.requestTrade(selectedThing, creature)
end
end
end
function startUseWith(thing)
if not thing then
return
end
if g_ui.isMouseGrabbed() then
if selectedThing then
selectedThing = thing
selectedType = 'use'
end
return
end
selectedType = 'use'
selectedThing = thing
mouseGrabberWidget:grabMouse()
g_mouse.pushCursor('target')
end
function startTradeWith(thing)
if not thing then
return
end
if g_ui.isMouseGrabbed() then
if selectedThing then
selectedThing = thing
selectedType = 'trade'
end
return
end
selectedType = 'trade'
selectedThing = thing
mouseGrabberWidget:grabMouse()
g_mouse.pushCursor('target')
end
function isMenuHookCategoryEmpty(category)
if category then
for _, opt in pairs(category) do
if opt then
return false
end
end
end
return true
end
function addMenuHook(category, name, callback, condition, shortcut)
if not hookedMenuOptions[category] then
hookedMenuOptions[category] = {}
end
hookedMenuOptions[category][name] = {
callback = callback,
condition = condition,
shortcut = shortcut
}
end
function removeMenuHook(category, name)
if not name then
hookedMenuOptions[category] = {}
else
hookedMenuOptions[category][name] = nil
end
end
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if not g_game.isOnline() then
return
end
local menu = g_ui.createWidget('PopupMenu')
menu:setGameMenu(true)
local classic = modules.client_options.getOption('classicControl')
local mobile = g_platform.isMobile()
local shortcut = nil
if not classic and not mobile then
shortcut = '(Shift)'
else
shortcut = nil
end
if lookThing then
menu:addOption(tr('Look'), function()
g_game.look(lookThing)
end, shortcut)
end
if not classic and not mobile 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)
menu:addOption(tr('Open in new window'), function()
g_game.open(useThing)
end)
else
menu:addOption(tr('Open'), function()
g_game.open(useThing)
end, shortcut)
end
else
if useThing:isMultiUse() then
menu:addOption(tr('Use with ...'), function()
startUseWith(useThing)
end, shortcut)
else
menu:addOption(tr('Use'), function()
g_game.use(useThing)
end, shortcut)
end
end
if useThing:isRotateable() then
menu:addOption(tr('Rotate'), function()
g_game.rotate(useThing)
end)
end
local onWrapItem = function()
g_game.wrap(useThing)
end
if useThing:isWrapable() then
menu:addOption(tr('Wrap'), onWrapItem)
end
if useThing:isUnwrapable() then
menu:addOption(tr('Unwrap'), onWrapItem)
end
if g_game.getFeature(GameBrowseField) and useThing:getPosition().x ~= 0xffff then
menu:addOption(tr('Browse Field'), function()
g_game.browseField(useThing:getPosition())
end)
end
end
if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
menu:addSeparator()
menu:addOption(tr('Trade with ...'), function()
startTradeWith(lookThing)
end)
end
if lookThing then
local parentContainer = lookThing:getParentContainer()
if parentContainer and parentContainer:hasParent() then
menu:addOption(tr('Move up'), function()
g_game.moveToParentContainer(lookThing, lookThing:getCount())
end)
end
end
if creatureThing then
local localPlayer = g_game.getLocalPlayer()
menu:addSeparator()
if creatureThing:isLocalPlayer() then
menu:addOption(tr(g_game.getClientVersion() >= 1000 and "Customise Character" or "Set Outfit"), function()
g_game.requestOutfit()
end)
if g_game.getFeature(GamePrey) then
menu:addOption(tr('Prey Dialog'), function()
modules.game_prey.show()
end)
end
if g_game.getFeature(GamePlayerMounts) then
if not localPlayer:isMounted() then
menu:addOption(tr('Mount'), function()
localPlayer:mount()
end)
else
menu:addOption(tr('Dismount'), function()
localPlayer:dismount()
end)
end
end
if creatureThing:isPartyMember() then
if creatureThing:isPartyLeader() then
if creatureThing:isPartySharedExperienceActive() then
menu:addOption(tr('Disable Shared Experience'), function()
g_game.partyShareExperience(false)
end)
else
menu:addOption(tr('Enable Shared Experience'), function()
g_game.partyShareExperience(true)
end)
end
end
menu:addOption(tr('Leave Party'), function()
g_game.partyLeave()
end)
end
else
local localPosition = localPlayer:getPosition()
if not classic and not mobile then
shortcut = '(Alt)'
else
shortcut = nil
end
if creatureThing:getPosition().z == localPosition.z then
if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption(tr('Attack'), function()
g_game.attack(creatureThing)
end, shortcut)
else
menu:addOption(tr('Stop Attack'), function()
g_game.cancelAttack()
end, shortcut)
end
if g_game.getFollowingCreature() ~= creatureThing then
menu:addOption(tr('Follow'), function()
g_game.follow(creatureThing)
end)
else
menu:addOption(tr('Stop Follow'), function()
g_game.cancelFollow()
end)
end
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)
menu:addOption(tr('Exclude from private chat'), function()
g_game.excludeFromOwnChannel(creatureName)
end) -- [TODO] must be removed after message's popup labels been implemented
end
if not localPlayer:hasVip(creatureName) then
menu:addOption(tr('Add to VIP list'), function()
g_game.addVip(creatureName)
end)
end
if modules.game_console.isIgnored(creatureName) then
menu:addOption(tr('Unignore') .. ' ' .. creatureName, function()
modules.game_console.removeIgnoredPlayer(creatureName)
end)
else
menu:addOption(tr('Ignore') .. ' ' .. creatureName, function()
modules.game_console.addIgnoredPlayer(creatureName)
end)
end
local localPlayerShield = localPlayer:getShield()
local creatureShield = creatureThing:getShield()
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
if creatureShield == ShieldWhiteYellow then
menu:addOption(tr('Join %s\'s Party', creatureThing:getName()), function()
g_game.partyJoin(creatureThing:getId())
end)
else
menu:addOption(tr('Invite to Party'), function()
g_game.partyInvite(creatureThing:getId())
end)
end
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function()
g_game.partyRevokeInvitation(creatureThing:getId())
end)
end
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or
localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
if creatureShield == ShieldWhiteBlue then
menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function()
g_game.partyRevokeInvitation(creatureThing:getId())
end)
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield ==
ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
menu:addOption(tr('Pass Leadership to %s', creatureThing:getName()), function()
g_game.partyPassLeadership(creatureThing:getId())
end)
else
menu:addOption(tr('Invite to Party'), function()
g_game.partyInvite(creatureThing:getId())
end)
end
end
end
end
if modules.game_ruleviolation.hasWindowAccess() and creatureThing:isPlayer() then
menu:addSeparator()
menu:addOption(tr('Rule Violation'), function()
modules.game_ruleviolation.show(creatureThing:getName())
end)
end
menu:addSeparator()
menu:addOption(tr('Copy Name'), function()
g_window.setClipboardText(creatureThing:getName())
end)
end
-- hooked menu options
for _, category in pairs(hookedMenuOptions) do
if not isMenuHookCategoryEmpty(category) then
menu:addSeparator()
for name, opt in pairs(category) do
if opt and opt.condition(menuPosition, lookThing, useThing, creatureThing) then
menu:addOption(name, function()
opt.callback(menuPosition, lookThing, useThing, creatureThing)
end, opt.shortcut)
end
end
end
end
if modules.game_bot and useThing and useThing:isItem() then
menu:addSeparator()
local useThingId = useThing:getId()
menu:addOption("ID: " .. useThingId, function() g_window.setClipboardText(useThingId) end)
end
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
menu:display(menuPosition)
end
function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, attackCreature)
local keyboardModifiers = g_keyboard.getModifiers()
if g_platform.isMobile() then
if mouseButton == MouseRightButton then
createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
end
local shortcut = modules.game_shortcuts.getShortcut()
if shortcut == "look" then
if lookThing then
modules.game_shortcuts.resetShortcuts()
g_game.look(lookThing)
return true
end
return true
elseif shortcut == "use" then
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
end
return true
elseif shortcut == "attack" then
if attackCreature and attackCreature ~= player then
modules.game_shortcuts.resetShortcuts()
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing ~= player and creatureThing:getPosition().z == autoWalkPos.z then
modules.game_shortcuts.resetShortcuts()
g_game.attack(creatureThing)
return true
end
return true
elseif shortcut == "follow" then
if attackCreature and attackCreature ~= player then
modules.game_shortcuts.resetShortcuts()
g_game.follow(attackCreature)
return true
elseif creatureThing and creatureThing ~= player and creatureThing:getPosition().z == autoWalkPos.z then
modules.game_shortcuts.resetShortcuts()
g_game.follow(creatureThing)
return true
end
return true
elseif not autoWalkPos and useThing then
createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
end
elseif not modules.client_options.getOption('classicControl') then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
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
elseif useThing and useThing:isContainer() and keyboardModifiers == KeyboardCtrlShiftModifier and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.open(useThing)
return true
elseif attackCreature and g_keyboard.isAltPressed() and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(creatureThing)
return true
end
-- classic control
else
if useThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and
not g_mouse.isPressed(MouseLeftButton) then
local player = g_game.getLocalPlayer()
if attackCreature and attackCreature ~= player then
g_game.attack(attackCreature)
return true
elseif creatureThing and creatureThing ~= player and creatureThing:getPosition().z == autoWalkPos.z then
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
elseif useThing and useThing:isContainer() and keyboardModifiers == KeyboardCtrlShiftModifier and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.open(useThing)
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.look(lookThing)
return true
elseif lookThing and ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
(g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
g_game.look(lookThing)
return true
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
elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and
(mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.attack(creatureThing)
return true
end
end
local player = g_game.getLocalPlayer()
player:stopAutoWalk()
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
player:autoWalk(autoWalkPos)
if g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent then
g_game.setChaseMode(DontChase)
return true
end
return true