Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
1,964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.45 KB | None | 0 0
  1. WALK_STEPS_RETRY = 10
  2.  
  3. gameRootPanel = nil
  4. gameMapPanel = nil
  5. gameRightPanel = nil
  6. gameLeftPanel = nil
  7. gameBottomPanel = nil
  8. logoutButton = nil
  9. mouseGrabberWidget = nil
  10. countWindow = nil
  11. logoutWindow = nil
  12. exitWindow = nil
  13. bottomSplitter = nil
  14. limitedZoom = false
  15. currentViewMode = 0
  16. smartWalkDirs = {}
  17. smartWalkDir = nil
  18. walkFunction = nil
  19. hookedMenuOptions = {}
  20.  
  21. function init()
  22. g_ui.importStyle('styles/countwindow')
  23.  
  24. connect(g_game, {
  25. onGameStart = onGameStart,
  26. onGameEnd = onGameEnd,
  27. onLoginAdvice = onLoginAdvice,
  28. }, true)
  29.  
  30. -- Call load AFTER game window has been created and
  31. -- resized to a stable state, otherwise the saved
  32. -- settings can get overridden by false onGeometryChange
  33. -- events
  34. connect(g_app, {
  35. onRun = load,
  36. onExit = save
  37. })
  38.  
  39. gameRootPanel = g_ui.displayUI('gameinterface')
  40. gameRootPanel:hide()
  41. gameRootPanel:lower()
  42. gameRootPanel.onGeometryChange = updateStretchShrink
  43. gameRootPanel.onFocusChange = stopSmartWalk
  44.  
  45. mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
  46. mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
  47.  
  48. bottomSplitter = gameRootPanel:getChildById('bottomSplitter')
  49. gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
  50. gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
  51. gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
  52. gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
  53. connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
  54.  
  55. logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'),
  56. '/images/topbuttons/logout', tryLogout, true)
  57.  
  58. setupViewMode(currentViewMode + 1)
  59.  
  60. bindKeys()
  61.  
  62. if g_game.isOnline() then
  63. show()
  64. end
  65. end
  66.  
  67. function bindKeys()
  68. gameRootPanel:setAutoRepeatDelay(200)
  69.  
  70. bindWalkKey('Up', North)
  71. bindWalkKey('Right', East)
  72. bindWalkKey('Down', South)
  73. bindWalkKey('Left', West)
  74. bindWalkKey('Numpad8', North)
  75. bindWalkKey('Numpad9', NorthEast)
  76. bindWalkKey('Numpad6', East)
  77. bindWalkKey('Numpad3', SouthEast)
  78. bindWalkKey('Numpad2', South)
  79. bindWalkKey('Numpad1', SouthWest)
  80. bindWalkKey('Numpad4', West)
  81. bindWalkKey('Numpad7', NorthWest)
  82.  
  83. g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
  84. g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
  85. g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
  86. g_keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
  87. g_keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
  88. g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
  89. g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
  90. g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
  91. g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
  92. g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel)
  93. g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel)
  94. g_keyboard.bindKeyDown('Ctrl+Q', function() tryLogout(false) end, gameRootPanel)
  95. g_keyboard.bindKeyDown('Ctrl+L', function() tryLogout(false) end, gameRootPanel)
  96. g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
  97. g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel)
  98. end
  99.  
  100. function bindWalkKey(key, dir)
  101. g_keyboard.bindKeyDown(key, function() changeWalkDir(dir) end, gameRootPanel, true)
  102. g_keyboard.bindKeyUp(key, function() changeWalkDir(dir, true) end, gameRootPanel, true)
  103. g_keyboard.bindKeyPress(key, function() smartWalk(dir) end, gameRootPanel)
  104. end
  105.  
  106. function unbindWalkKey(key)
  107. g_keyboard.unbindKeyDown(key, gameRootPanel)
  108. g_keyboard.unbindKeyUp(key, gameRootPanel)
  109. g_keyboard.unbindKeyPress(key, gameRootPanel)
  110. end
  111.  
  112. function terminate()
  113. hide()
  114.  
  115. hookedMenuOptions = {}
  116.  
  117. stopSmartWalk()
  118.  
  119. disconnect(g_game, {
  120. onGameStart = onGameStart,
  121. onGameEnd = onGameEnd,
  122. onLoginAdvice = onLoginAdvice
  123. })
  124.  
  125. disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
  126.  
  127. logoutButton:destroy()
  128. gameRootPanel:destroy()
  129. end
  130.  
  131. function onGameStart()
  132. show()
  133.  
  134. -- open tibia has delay in auto walking
  135. if not g_game.isOfficialTibia() then
  136. g_game.enableFeature(GameForceFirstAutoWalkStep)
  137. else
  138. g_game.disableFeature(GameForceFirstAutoWalkStep)
  139. end
  140. end
  141.  
  142. function onGameEnd()
  143. setupViewMode(0)
  144. hide()
  145. end
  146.  
  147. function show()
  148. connect(g_app, { onClose = tryExit })
  149. modules.client_background.hide()
  150. gameRootPanel:show()
  151. gameRootPanel:focus()
  152. gameMapPanel:followCreature(g_game.getLocalPlayer())
  153. setupViewMode(currentViewMode + 1)
  154. updateStretchShrink()
  155. logoutButton:setTooltip(tr('Logout'))
  156.  
  157. addEvent(function()
  158. if not limitedZoom or g_game.isGM() then
  159. gameMapPanel:setMaxZoomOut(513)
  160. gameMapPanel:setLimitVisibleRange(false)
  161. else
  162. gameMapPanel:setMaxZoomOut(11)
  163. gameMapPanel:setLimitVisibleRange(true)
  164. end
  165. end)
  166. end
  167.  
  168. function hide()
  169. disconnect(g_app, { onClose = tryExit })
  170. logoutButton:setTooltip(tr('Exit'))
  171.  
  172. if logoutWindow then
  173. logoutWindow:destroy()
  174. logoutWindow = nil
  175. end
  176. if exitWindow then
  177. exitWindow:destroy()
  178. exitWindow = nil
  179. end
  180. if countWindow then
  181. countWindow:destroy()
  182. countWindow = nil
  183. end
  184. gameRootPanel:hide()
  185. modules.client_background.show()
  186. end
  187.  
  188. function save()
  189. local settings = {}
  190. settings.splitterMarginBottom = bottomSplitter:getMarginBottom()
  191. g_settings.setNode('game_interface', settings)
  192. end
  193.  
  194. function load()
  195. local settings = g_settings.getNode('game_interface')
  196. if settings then
  197. if settings.splitterMarginBottom then
  198. bottomSplitter:setMarginBottom(settings.splitterMarginBottom)
  199. end
  200. end
  201. end
  202.  
  203. function onLoginAdvice(message)
  204. displayInfoBox(tr("For Your Information"), message)
  205. end
  206.  
  207. function forceExit()
  208. g_game.cancelLogin()
  209. scheduleEvent(exit, 10)
  210. return true
  211. end
  212.  
  213. function tryExit()
  214. if exitWindow then
  215. return true
  216. end
  217.  
  218. local exitFunc = function() g_game.safeLogout() forceExit() end
  219. local logoutFunc = function() g_game.safeLogout() exitWindow:destroy() exitWindow = nil end
  220. local cancelFunc = function() exitWindow:destroy() exitWindow = nil end
  221.  
  222. 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."),
  223. { { text=tr('Force Exit'), callback=exitFunc },
  224. { text=tr('Logout'), callback=logoutFunc },
  225. { text=tr('Cancel'), callback=cancelFunc },
  226. anchor=AnchorHorizontalCenter }, logoutFunc, cancelFunc)
  227.  
  228. return true
  229. end
  230.  
  231. function tryLogout(prompt)
  232. if type(prompt) ~= "boolean" then
  233. prompt = true
  234. end
  235. if not g_game.isOnline() then
  236. exit()
  237. return
  238. end
  239.  
  240. if logoutWindow then
  241. return
  242. end
  243.  
  244. local msg, yesCallback
  245. if not g_game.isConnectionOk() then
  246. msg = 'Your connection is failing, if you logout now your character will be still online, do you want to force logout?'
  247.  
  248. yesCallback = function()
  249. g_game.forceLogout()
  250. if logoutWindow then
  251. logoutWindow:destroy()
  252. logoutWindow=nil
  253. end
  254. end
  255. else
  256. msg = 'Are you sure you want to logout?'
  257.  
  258. yesCallback = function()
  259. g_game.safeLogout()
  260. if logoutWindow then
  261. logoutWindow:destroy()
  262. logoutWindow=nil
  263. end
  264. end
  265. end
  266.  
  267. local noCallback = function()
  268. logoutWindow:destroy()
  269. logoutWindow=nil
  270. end
  271.  
  272. if prompt then
  273. logoutWindow = displayGeneralBox(tr('Logout'), tr(msg), {
  274. { text=tr('Yes'), callback=yesCallback },
  275. { text=tr('No'), callback=noCallback },
  276. anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
  277. else
  278. yesCallback()
  279. end
  280. end
  281.  
  282. function stopSmartWalk()
  283. smartWalkDirs = {}
  284. smartWalkDir = nil
  285. end
  286.  
  287. function changeWalkDir(dir, pop)
  288. while table.removevalue(smartWalkDirs, dir) do end
  289. if pop then
  290. if #smartWalkDirs == 0 then
  291. stopSmartWalk()
  292. return
  293. end
  294. else
  295. table.insert(smartWalkDirs, 1, dir)
  296. end
  297.  
  298. smartWalkDir = smartWalkDirs[1]
  299. if modules.client_options.getOption('smartWalk') and #smartWalkDirs > 1 then
  300. for _,d in pairs(smartWalkDirs) do
  301. if (smartWalkDir == North and d == West) or (smartWalkDir == West and d == North) then
  302. smartWalkDir = NorthWest
  303. break
  304. elseif (smartWalkDir == North and d == East) or (smartWalkDir == East and d == North) then
  305. smartWalkDir = NorthEast
  306. break
  307. elseif (smartWalkDir == South and d == West) or (smartWalkDir == West and d == South) then
  308. smartWalkDir = SouthWest
  309. break
  310. elseif (smartWalkDir == South and d == East) or (smartWalkDir == East and d == South) then
  311. smartWalkDir = SouthEast
  312. break
  313. end
  314. end
  315. end
  316. end
  317.  
  318. function smartWalk(dir)
  319. if g_keyboard.getModifiers() == KeyboardNoModifier then
  320. local func = walkFunction
  321. if not func then
  322. if modules.client_options.getOption('dashWalk') then
  323. func = g_game.dashWalk
  324. else
  325. func = g_game.walk
  326. end
  327. end
  328. local dire = smartWalkDir or dir
  329. func(dire)
  330. return true
  331. end
  332. return false
  333. end
  334.  
  335. function updateStretchShrink()
  336. if modules.client_options.getOption('dontStretchShrink') and not alternativeView then
  337. gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
  338.  
  339. -- Set gameMapPanel size to height = 11 * 32 + 2
  340. bottomSplitter:setMarginBottom(bottomSplitter:getMarginBottom() + (gameMapPanel:getHeight() - 32 * 11) - 10)
  341. end
  342. end
  343.  
  344. function onMouseGrabberRelease(self, mousePosition, mouseButton)
  345. if selectedThing == nil then return false end
  346. if mouseButton == MouseLeftButton then
  347. local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
  348. if clickedWidget then
  349. if selectedType == 'use' then
  350. onUseWith(clickedWidget, mousePosition)
  351. elseif selectedType == 'trade' then
  352. onTradeWith(clickedWidget, mousePosition)
  353. end
  354. end
  355. end
  356.  
  357. selectedThing = nil
  358. g_mouse.popCursor('target')
  359. self:ungrabMouse()
  360. return true
  361. end
  362.  
  363. function onUseWith(clickedWidget, mousePosition)
  364. if clickedWidget:getClassName() == 'UIGameMap' then
  365. local tile = clickedWidget:getTile(mousePosition)
  366. if tile then
  367. if selectedThing:isFluidContainer() or selectedThing:isMultiUse() then
  368. g_game.useWith(selectedThing, tile:getTopMultiUseThing())
  369. else
  370. g_game.useWith(selectedThing, tile:getTopUseThing())
  371. end
  372. end
  373. elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
  374. g_game.useWith(selectedThing, clickedWidget:getItem())
  375. elseif clickedWidget:getClassName() == 'UICreatureButton' then
  376. local creature = clickedWidget:getCreature()
  377. if creature then
  378. g_game.useWith(selectedThing, creature)
  379. end
  380. end
  381. end
  382.  
  383. function onTradeWith(clickedWidget, mousePosition)
  384. if clickedWidget:getClassName() == 'UIGameMap' then
  385. local tile = clickedWidget:getTile(mousePosition)
  386. if tile then
  387. g_game.requestTrade(selectedThing, tile:getTopCreature())
  388. end
  389. end
  390. end
  391.  
  392. function startUseWith(thing)
  393. if not thing then return end
  394. if g_ui.isMouseGrabbed() then
  395. if selectedThing then
  396. selectedThing = thing
  397. selectedType = 'use'
  398. end
  399. return
  400. end
  401. selectedType = 'use'
  402. selectedThing = thing
  403. mouseGrabberWidget:grabMouse()
  404. g_mouse.pushCursor('target')
  405. end
  406.  
  407. function startTradeWith(thing)
  408. if not thing then return end
  409. if g_ui.isMouseGrabbed() then
  410. if selectedThing then
  411. selectedThing = thing
  412. selectedType = 'trade'
  413. end
  414. return
  415. end
  416. selectedType = 'trade'
  417. selectedThing = thing
  418. mouseGrabberWidget:grabMouse()
  419. g_mouse.pushCursor('target')
  420. end
  421.  
  422. function isMenuHookCategoryEmpty(category)
  423. if category then
  424. for _,opt in pairs(category) do
  425. if opt then return false end
  426. end
  427. end
  428. return true
  429. end
  430.  
  431. function addMenuHook(category, name, callback, condition, shortcut)
  432. if not hookedMenuOptions[category] then
  433. hookedMenuOptions[category] = {}
  434. end
  435. hookedMenuOptions[category][name] = {
  436. callback = callback,
  437. condition = condition,
  438. shortcut = shortcut
  439. }
  440. end
  441.  
  442. function removeMenuHook(category, name)
  443. if not name then
  444. hookedMenuOptions[category] = {}
  445. else
  446. hookedMenuOptions[category][name] = nil
  447. end
  448. end
  449.  
  450. function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
  451. if not g_game.isOnline() then return end
  452.  
  453. local menu = g_ui.createWidget('PopupMenu')
  454. menu:setGameMenu(true)
  455.  
  456. local classic = modules.client_options.getOption('classicControl')
  457. local shortcut = nil
  458.  
  459. if not classic then shortcut = '(Shift)' else shortcut = nil end
  460. if lookThing then
  461. menu:addOption(tr('Look'), function() g_game.look(lookThing) end, shortcut)
  462. end
  463.  
  464. if not classic then shortcut = '(Ctrl)' else shortcut = nil end
  465. if useThing then
  466. if useThing:isContainer() then
  467. if useThing:getParentContainer() then
  468. menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end, shortcut)
  469. menu:addOption(tr('Open in new window'), function() g_game.open(useThing) end)
  470. else
  471. menu:addOption(tr('Open'), function() g_game.open(useThing) end, shortcut)
  472. end
  473. else
  474. if useThing:isMultiUse() then
  475. menu:addOption(tr('Use with ...'), function() startUseWith(useThing) end, shortcut)
  476. else
  477. menu:addOption(tr('Use'), function() g_game.use(useThing) end, shortcut)
  478. end
  479. end
  480.  
  481. if useThing:isRotateable() then
  482. menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
  483. end
  484.  
  485. if g_game.getFeature(GameBrowseField) and useThing:getPosition().x ~= 0xffff then
  486. menu:addOption(tr('Browse Field'), function() g_game.browseField(useThing:getPosition()) end)
  487. end
  488. end
  489.  
  490. if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
  491. menu:addSeparator()
  492. menu:addOption(tr('Trade with ...'), function() startTradeWith(lookThing) end)
  493. end
  494.  
  495. if lookThing then
  496. local parentContainer = lookThing:getParentContainer()
  497. if parentContainer and parentContainer:hasParent() then
  498. menu:addOption(tr('Move up'), function() g_game.moveToParentContainer(lookThing, lookThing:getCount()) end)
  499. end
  500. end
  501.  
  502. if creatureThing then
  503. local localPlayer = g_game.getLocalPlayer()
  504. menu:addSeparator()
  505.  
  506. if creatureThing:isLocalPlayer() then
  507. menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end)
  508.  
  509. if g_game.getFeature(GamePlayerMounts) then
  510. if not localPlayer:isMounted() then
  511. menu:addOption(tr('Mount'), function() localPlayer:mount() end)
  512. else
  513. menu:addOption(tr('Dismount'), function() localPlayer:dismount() end)
  514. end
  515. end
  516.  
  517. if creatureThing:isPartyMember() then
  518. if creatureThing:isPartyLeader() then
  519. if creatureThing:isPartySharedExperienceActive() then
  520. menu:addOption(tr('Disable Shared Experience'), function() g_game.partyShareExperience(false) end)
  521. else
  522. menu:addOption(tr('Enable Shared Experience'), function() g_game.partyShareExperience(true) end)
  523. end
  524. end
  525. menu:addOption(tr('Leave Party'), function() g_game.partyLeave() end)
  526. end
  527.  
  528. else
  529. local localPosition = localPlayer:getPosition()
  530. if not classic then shortcut = '(Alt)' else shortcut = nil end
  531. if creatureThing:getPosition().z == localPosition.z then
  532. if g_game.getAttackingCreature() ~= creatureThing then
  533. menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end, shortcut)
  534. else
  535. menu:addOption(tr('Stop Attack'), function() g_game.cancelAttack() end, shortcut)
  536. end
  537.  
  538. if g_game.getFollowingCreature() ~= creatureThing then
  539. menu:addOption(tr('Follow'), function() g_game.follow(creatureThing) end)
  540. else
  541. menu:addOption(tr('Stop Follow'), function() g_game.cancelFollow() end)
  542. end
  543. end
  544.  
  545. if creatureThing:isPlayer() then
  546. menu:addSeparator()
  547. local creatureName = creatureThing:getName()
  548. menu:addOption(tr('Message to %s', creatureName), function() g_game.openPrivateChannel(creatureName) end)
  549. if modules.game_console.getOwnPrivateTab() then
  550. menu:addOption(tr('Invite to private chat'), function() g_game.inviteToOwnChannel(creatureName) end)
  551. menu:addOption(tr('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end) -- [TODO] must be removed after message's popup labels been implemented
  552. end
  553. if not localPlayer:hasVip(creatureName) then
  554. menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end)
  555. end
  556.  
  557. if modules.game_console.isIgnored(creatureName) then
  558. menu:addOption(tr('Unignore') .. ' ' .. creatureName, function() modules.game_console.removeIgnoredPlayer(creatureName) end)
  559. else
  560. menu:addOption(tr('Ignore') .. ' ' .. creatureName, function() modules.game_console.addIgnoredPlayer(creatureName) end)
  561. end
  562.  
  563. local localPlayerShield = localPlayer:getShield()
  564. local creatureShield = creatureThing:getShield()
  565.  
  566. if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
  567. if creatureShield == ShieldWhiteYellow then
  568. menu:addOption(tr('Join %s\'s Party', creatureThing:getName()), function() g_game.partyJoin(creatureThing:getId()) end)
  569. else
  570. menu:addOption(tr('Invite to Party'), function() g_game.partyInvite(creatureThing:getId()) end)
  571. end
  572. elseif localPlayerShield == ShieldWhiteYellow then
  573. if creatureShield == ShieldWhiteBlue then
  574. menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
  575. end
  576. elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
  577. if creatureShield == ShieldWhiteBlue then
  578. menu:addOption(tr('Revoke %s\'s Invitation', creatureThing:getName()), function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
  579. elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
  580. menu:addOption(tr('Pass Leadership to %s', creatureThing:getName()), function() g_game.partyPassLeadership(creatureThing:getId()) end)
  581. else
  582. menu:addOption(tr('Invite to Party'), function() g_game.partyInvite(creatureThing:getId()) end)
  583. end
  584. end
  585. end
  586. end
  587.  
  588. if modules.game_ruleviolation.hasWindowAccess() and creatureThing:isPlayer() then
  589. menu:addSeparator()
  590. menu:addOption(tr('Rule Violation'), function() modules.game_ruleviolation.show(creatureThing:getName()) end)
  591. end
  592.  
  593. menu:addSeparator()
  594. menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
  595. end
  596.  
  597. -- hooked menu options
  598. for _,category in pairs(hookedMenuOptions) do
  599. if not isMenuHookCategoryEmpty(category) then
  600. menu:addSeparator()
  601. for name,opt in pairs(category) do
  602. if opt and opt.condition(menuPosition, lookThing, useThing, creatureThing) then
  603. menu:addOption(name, function() opt.callback(menuPosition,
  604. lookThing, useThing, creatureThing) end, opt.shortcut)
  605. end
  606. end
  607. end
  608. end
  609.  
  610. menu:display(menuPosition)
  611. end
  612.  
  613. function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, attackCreature)
  614. local keyboardModifiers = g_keyboard.getModifiers()
  615.  
  616. if not modules.client_options.getOption('classicControl') then
  617. if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
  618. createThingMenu(menuPosition, lookThing, useThing, creatureThing)
  619. return true
  620. elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  621. g_game.look(lookThing)
  622. return true
  623. elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  624. if useThing:isContainer() then
  625. if useThing:getParentContainer() then
  626. g_game.open(useThing, useThing:getParentContainer())
  627. else
  628. g_game.open(useThing)
  629. end
  630. return true
  631. elseif useThing:isMultiUse() then
  632. startUseWith(useThing)
  633. return true
  634. else
  635. g_game.use(useThing)
  636. return true
  637. end
  638. return true
  639. elseif attackCreature and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  640. g_game.attack(attackCreature)
  641. return true
  642. elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  643. g_game.attack(creatureThing)
  644. return true
  645. end
  646.  
  647. -- classic control
  648. else
  649. if useThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
  650. local player = g_game.getLocalPlayer()
  651. if attackCreature and attackCreature ~= player then
  652. g_game.attack(attackCreature)
  653. return true
  654. elseif creatureThing and creatureThing ~= player and creatureThing:getPosition().z == autoWalkPos.z then
  655. g_game.attack(creatureThing)
  656. return true
  657. elseif useThing:isContainer() then
  658. if useThing:getParentContainer() then
  659. g_game.open(useThing, useThing:getParentContainer())
  660. return true
  661. else
  662. g_game.open(useThing)
  663. return true
  664. end
  665. elseif useThing:isMultiUse() then
  666. startUseWith(useThing)
  667. return true
  668. else
  669. g_game.use(useThing)
  670. return true
  671. end
  672. return true
  673. elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  674. g_game.look(lookThing)
  675. return true
  676. elseif lookThing and ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or (g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
  677. g_game.look(lookThing)
  678. return true
  679. elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  680. createThingMenu(menuPosition, lookThing, useThing, creatureThing)
  681. return true
  682. elseif attackCreature and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  683. g_game.attack(attackCreature)
  684. return true
  685. elseif creatureThing and creatureThing:getPosition().z == autoWalkPos.z and g_keyboard.isAltPressed() and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
  686. g_game.attack(creatureThing)
  687. return true
  688. end
  689. end
  690.  
  691.  
  692. local player = g_game.getLocalPlayer()
  693. player:stopAutoWalk()
  694.  
  695. if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
  696. player:autoWalk(autoWalkPos)
  697. return true
  698. end
  699.  
  700. return false
  701. end
  702.  
  703. function moveStackableItem(item, toPos)
  704. if countWindow then
  705. return
  706. end
  707. if g_keyboard.isCtrlPressed() then
  708. g_game.move(item, toPos, item:getCount())
  709. return
  710. elseif g_keyboard.isShiftPressed() then
  711. g_game.move(item, toPos, 1)
  712. return
  713. end
  714. local count = item:getCount()
  715.  
  716. countWindow = g_ui.createWidget('CountWindow', rootWidget)
  717. local itembox = countWindow:getChildById('item')
  718. local scrollbar = countWindow:getChildById('countScrollBar')
  719. itembox:setItemId(item:getId())
  720. itembox:setItemCount(count)
  721. scrollbar:setMaximum(count)
  722. scrollbar:setMinimum(1)
  723. scrollbar:setValue(count)
  724.  
  725. local spinbox = countWindow:getChildById('spinBox')
  726. spinbox:setMaximum(count)
  727. spinbox:setMinimum(0)
  728. spinbox:setValue(0)
  729. spinbox:hideButtons()
  730. spinbox:focus()
  731. spinbox.firstEdit = true
  732.  
  733. local spinBoxValueChange = function(self, value)
  734. spinbox.firstEdit = false
  735. scrollbar:setValue(value)
  736. end
  737. spinbox.onValueChange = spinBoxValueChange
  738.  
  739. local check = function()
  740. if spinbox.firstEdit then
  741. spinbox:setValue(spinbox:getMaximum())
  742. spinbox.firstEdit = false
  743. end
  744. end
  745. g_keyboard.bindKeyPress("Up", function() check() spinbox:up() end, spinbox)
  746. g_keyboard.bindKeyPress("Down", function() check() spinbox:down() end, spinbox)
  747. g_keyboard.bindKeyPress("Right", function() check() spinbox:up() end, spinbox)
  748. g_keyboard.bindKeyPress("Left", function() check() spinbox:down() end, spinbox)
  749. g_keyboard.bindKeyPress("PageUp", function() check() spinbox:setValue(spinbox:getValue()+10) end, spinbox)
  750. g_keyboard.bindKeyPress("PageDown", function() check() spinbox:setValue(spinbox:getValue()-10) end, spinbox)
  751.  
  752. scrollbar.onValueChange = function(self, value)
  753. itembox:setItemCount(value)
  754. spinbox.onValueChange = nil
  755. spinbox:setValue(value)
  756. spinbox.onValueChange = spinBoxValueChange
  757. end
  758.  
  759. local okButton = countWindow:getChildById('buttonOk')
  760. local moveFunc = function()
  761. g_game.move(item, toPos, itembox:getItemCount())
  762. okButton:getParent():destroy()
  763. countWindow = nil
  764. end
  765. local cancelButton = countWindow:getChildById('buttonCancel')
  766. local cancelFunc = function()
  767. cancelButton:getParent():destroy()
  768. countWindow = nil
  769. end
  770.  
  771. countWindow.onEnter = moveFunc
  772. countWindow.onEscape = cancelFunc
  773.  
  774. okButton.onClick = moveFunc
  775. cancelButton.onClick = cancelFunc
  776. end
  777.  
  778. function getRootPanel()
  779. return gameRootPanel
  780. end
  781.  
  782. function getMapPanel()
  783. return gameMapPanel
  784. end
  785.  
  786. function getRightPanel()
  787. return gameRightPanel
  788. end
  789.  
  790. function getLeftPanel()
  791. return gameLeftPanel
  792. end
  793.  
  794. function getBottomPanel()
  795. return gameBottomPanel
  796. end
  797.  
  798. function onLeftPanelVisibilityChange(leftPanel, visible)
  799. if not visible and g_game.isOnline() then
  800. local children = leftPanel:getChildren()
  801. for i=1,#children do
  802. children[i]:setParent(gameRightPanel)
  803. end
  804. end
  805. end
  806.  
  807. function nextViewMode()
  808. setupViewMode((currentViewMode + 1) % 3)
  809. end
  810.  
  811. function setupViewMode(mode)
  812. if mode == currentViewMode then return end
  813.  
  814. if currentViewMode == 2 then
  815. gameMapPanel:addAnchor(AnchorLeft, 'gameLeftPanel', AnchorRight)
  816. gameMapPanel:addAnchor(AnchorRight, 'gameRightPanel', AnchorLeft)
  817. gameMapPanel:addAnchor(AnchorBottom, 'gameBottomPanel', AnchorTop)
  818. gameRootPanel:addAnchor(AnchorTop, 'topMenu', AnchorBottom)
  819. gameLeftPanel:setOn(modules.client_options.getOption('showLeftPanel'))
  820. gameLeftPanel:setImageColor('white')
  821. gameRightPanel:setImageColor('white')
  822. gameLeftPanel:setMarginTop(0)
  823. gameRightPanel:setMarginTop(0)
  824. gameBottomPanel:setImageColor('white')
  825. modules.client_topmenu.getTopMenu():setImageColor('white')
  826. g_game.changeMapAwareRange(18, 14)
  827. end
  828.  
  829. if mode == 0 then
  830. gameMapPanel:setKeepAspectRatio(true)
  831. gameMapPanel:setLimitVisibleRange(false)
  832. gameMapPanel:setZoom(11)
  833. gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
  834. elseif mode == 1 then
  835. gameMapPanel:setKeepAspectRatio(false)
  836. gameMapPanel:setLimitVisibleRange(true)
  837. gameMapPanel:setZoom(11)
  838. gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
  839. elseif mode == 2 then
  840. local limit = limitedZoom and not g_game.isGM()
  841. gameMapPanel:setLimitVisibleRange(limit)
  842. gameMapPanel:setZoom(15) -- Aqui eu botei 15, e nas sources eu coloquei X 20 Y 20, Edite como quiser, é o zoom do client
  843. gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
  844. gameMapPanel:fill('parent')
  845. gameRootPanel:fill('parent')
  846. gameLeftPanel:setImageColor('alpha')
  847. gameRightPanel:setImageColor('alpha')
  848. gameLeftPanel:setMarginTop(modules.client_topmenu.getTopMenu()
  849. :getHeight() - gameLeftPanel:getPaddingTop())
  850. gameRightPanel:setMarginTop(modules.client_topmenu.getTopMenu()
  851. :getHeight() - gameRightPanel:getPaddingTop())
  852. gameLeftPanel:setOn(true)
  853. gameLeftPanel:setVisible(true)
  854. gameRightPanel:setOn(true)
  855. gameMapPanel:setOn(true)
  856. gameBottomPanel:setImageColor('#ffffff88')
  857. modules.client_topmenu.getTopMenu():setImageColor('#ffffff66')
  858. if not limit then
  859. g_game.changeMapAwareRange(24, 20)
  860. end
  861. end
  862.  
  863. currentViewMode = mode
  864. end
  865.  
  866. function limitZoom()
  867. limitedZoom = true
  868. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement