Browse Source

Merge pull request #910 from diath/hotkey_turn_delay

Add turn and hotkey delay
Eduardo Bart 3 years ago
parent
commit
38e9e7c1ed
No account linked to committer's email address

+ 41
- 1
modules/client_options/game.otui View File

@@ -38,11 +38,51 @@ Panel
38 38
     id: displayText
39 39
     !text: tr('Display text messages')
40 40
 
41
+  Label
42
+    id: turnDelayLabel
43
+    !text: tr('Turn delay: %sms', 30)
44
+    anchors.left: parent.left
45
+    anchors.right: parent.right
46
+    anchors.top: prev.bottom
47
+    margin-top: 12
48
+    @onSetup: |
49
+      local value = modules.client_options.getOption('turnDelay')
50
+      self:setText(tr('Turn delay: %dms', value))
51
+
52
+  OptionScrollbar
53
+    id: turnDelay
54
+    anchors.left: parent.left
55
+    anchors.right: parent.right
56
+    anchors.top: prev.bottom
57
+    margin-top: 3
58
+    minimum: 30
59
+    maximum: 250
60
+
61
+  Label
62
+    id: hotkeyDelayLabel
63
+    !text: tr('Hotkey delay: %dms', 30)
64
+    anchors.left: parent.left
65
+    anchors.right: parent.right
66
+    anchors.top: prev.bottom
67
+    margin-top: 12
68
+    @onSetup: |
69
+      local value = modules.client_options.getOption('hotkeyDelay')
70
+      self:setText(tr('Hotkey delay: %dms', value))
71
+
72
+  OptionScrollbar
73
+    id: hotkeyDelay
74
+    anchors.left: parent.left
75
+    anchors.right: parent.right
76
+    anchors.top: prev.bottom
77
+    margin-top: 3
78
+    minimum: 30
79
+    maximum: 250
80
+
41 81
   Button
42 82
     id: changeLocale
43 83
     !text: tr('Change language')
44 84
     @onClick: modules.client_locales.createWindow()
45 85
     anchors.top: prev.bottom
46 86
     anchors.left: prev.left
47
-    margin-top: 5
87
+    margin-top: 12
48 88
     width: 120

+ 7
- 1
modules/client_options/options.lua View File

@@ -26,7 +26,9 @@ local defaultOptions = {
26 26
   displayNames = true,
27 27
   displayHealth = true,
28 28
   displayText = true,
29
-  dontStretchShrink = false
29
+  dontStretchShrink = false,
30
+  turnDelay = 50,
31
+  hotkeyDelay = 50,
30 32
 }
31 33
 
32 34
 local optionsWindow
@@ -228,6 +230,10 @@ function setOption(key, value, force)
228 230
     addEvent(function()
229 231
       modules.game_interface.updateStretchShrink()
230 232
     end)
233
+  elseif key == 'turnDelay' then
234
+    generalPanel:getChildById('turnDelayLabel'):setText(tr('Turn delay: %sms', value))
235
+  elseif key == 'hotkeyDelay' then
236
+    generalPanel:getChildById('hotkeyDelayLabel'):setText(tr('Hotkey delay: %sms', value))
231 237
   end
232 238
 
233 239
   -- change value for keybind updates

+ 7
- 0
modules/game_hotkeys/hotkeys_manager.lua View File

@@ -36,6 +36,7 @@ useRadioGroup = nil
36 36
 currentHotkeys = nil
37 37
 boundCombosCallback = {}
38 38
 hotkeysList = {}
39
+lastHotkeyTime = g_clock.millis()
39 40
 
40 41
 -- public functions
41 42
 function init()
@@ -374,6 +375,12 @@ function doKeyCombo(keyCombo)
374 375
   if not g_game.isOnline() then return end
375 376
   local hotKey = hotkeyList[keyCombo]
376 377
   if not hotKey then return end
378
+
379
+  if g_clock.millis() - lastHotkeyTime < modules.client_options.getOption('hotkeyDelay') then
380
+    return
381
+  end
382
+  lastHotkeyTime = g_clock.millis()
383
+
377 384
   if hotKey.itemId == nil then
378 385
     if not hotKey.value or #hotKey.value == 0 then return end
379 386
     if hotKey.autoSend then

+ 23
- 8
modules/game_interface/gameinterface.lua View File

@@ -17,6 +17,7 @@ smartWalkDirs = {}
17 17
 smartWalkDir = nil
18 18
 walkFunction = nil
19 19
 hookedMenuOptions = {}
20
+lastDirTime = g_clock.millis()
20 21
 
21 22
 function init()
22 23
   g_ui.importStyle('styles/countwindow')
@@ -80,14 +81,15 @@ function bindKeys()
80 81
   bindWalkKey('Numpad4', West)
81 82
   bindWalkKey('Numpad7', NorthWest)
82 83
 
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)
84
+  bindTurnKey('Ctrl+Up', North)
85
+  bindTurnKey('Ctrl+Right', East)
86
+  bindTurnKey('Ctrl+Down', South)
87
+  bindTurnKey('Ctrl+Left', West)
88
+  bindTurnKey('Ctrl+Numpad8', North)
89
+  bindTurnKey('Ctrl+Numpad6', East)
90
+  bindTurnKey('Ctrl+Numpad2', South)
91
+  bindTurnKey('Ctrl+Numpad4', West)
92
+
91 93
   g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
92 94
   g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel)
93 95
   g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel)
@@ -109,6 +111,19 @@ function unbindWalkKey(key)
109 111
   g_keyboard.unbindKeyPress(key, gameRootPanel)
110 112
 end
111 113
 
114
+function bindTurnKey(key, dir)
115
+  local function callback(widget, code, repeatTicks)
116
+    if g_clock.millis() - lastDirTime >= modules.client_options.getOption('turnDelay') then
117
+        g_game.turn(dir)
118
+        changeWalkDir(dir)
119
+
120
+        lastDirTime = g_clock.millis()
121
+    end
122
+  end
123
+
124
+  g_keyboard.bindKeyPress(key, callback, gameRootPanel)
125
+end
126
+
112 127
 function terminate()
113 128
   hide()
114 129
 

Loading…
Cancel
Save