Reworked keybind widget and fixed some keybind system glitches

This commit is contained in:
Azumgi 2018-01-31 17:35:43 +03:00
parent ba16c75642
commit 1df935eed1
3 changed files with 100 additions and 97 deletions

1
vmf_source/gui/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.psd

View file

@ -9,7 +9,6 @@ vmf.keys = {
[9] = {"Tab", "tab", keyboard_buton_name(9)}, [9] = {"Tab", "tab", keyboard_buton_name(9)},
[13] = {"Enter", "enter", keyboard_buton_name(13)}, [13] = {"Enter", "enter", keyboard_buton_name(13)},
[20] = {"Caps Lock", "caps lock", keyboard_buton_name(20)}, [20] = {"Caps Lock", "caps lock", keyboard_buton_name(20)},
[27] = {"Esc", "esc", keyboard_buton_name(27)},
[32] = {"Space", "space", keyboard_buton_name(32)}, [32] = {"Space", "space", keyboard_buton_name(32)},
[33] = {"Page Up", "page up", keyboard_buton_name(33)}, [33] = {"Page Up", "page up", keyboard_buton_name(33)},
[34] = {"Page Down", "page down", keyboard_buton_name(34)}, [34] = {"Page Down", "page down", keyboard_buton_name(34)},
@ -121,15 +120,15 @@ vmf.keys = {
[256] = {"Num Enter", "numpad enter", keyboard_buton_name(256)} [256] = {"Num Enter", "numpad enter", keyboard_buton_name(256)}
}, },
mouse = { mouse = {
[0] = {"Mouse Left", "mouse_left", mouse_buton_name(0)}, [0] = {"Mouse Left", "mouse left", mouse_buton_name(0)},
[1] = {"Mouse Right", "mouse_right", mouse_buton_name(1)}, [1] = {"Mouse Right", "mouse right", mouse_buton_name(1)},
[2] = {"Mouse Middle", "mouse_middle", mouse_buton_name(2)}, [2] = {"Mouse Middle", "mouse middle", mouse_buton_name(2)},
[3] = {"Mouse Extra 1", "mouse_extra_1", mouse_buton_name(3)}, [3] = {"Mouse Extra 1", "mouse extra 1", mouse_buton_name(3)},
[4] = {"Mouse Extra 2", "mouse_extra_2", mouse_buton_name(4)}, [4] = {"Mouse Extra 2", "mouse extra 2", mouse_buton_name(4)},
[10] = {"Mouse Wheel Up", "mouse_wheel_up", mouse_buton_name(10)}, [10] = {"Mouse Wheel Up", "mouse wheel up", mouse_buton_name(10)},
[11] = {"Mouse Wheel Down", "mouse_wheel_down", mouse_buton_name(11)}, [11] = {"Mouse Wheel Down", "mouse wheel down", mouse_buton_name(11)},
[12] = {"Mouse Wheel Left", "mouse_wheel_left", mouse_buton_name(12)}, [12] = {"Mouse Wheel Left", "mouse wheel left", mouse_buton_name(12)},
[13] = {"Mouse Wheel Right", "mouse_wheel_right", mouse_buton_name(13)} [13] = {"Mouse Wheel Right", "mouse wheel right", mouse_buton_name(13)}
},--[[ -- will work on this if it will be needed },--[[ -- will work on this if it will be needed
gamepad = { gamepad = {
[0] = {"", "d_up", gamepad_buton_name(0)}, [0] = {"", "d_up", gamepad_buton_name(0)},
@ -215,14 +214,6 @@ local function apply_keybinds()
table.insert(optimized_keybinds[primary_key], {mod_name, action_name, key2, key3, key4}) table.insert(optimized_keybinds[primary_key], {mod_name, action_name, key2, key3, key4})
end end
end end
--VMFModsKeyMap.win32["whatever"] = {"keyboard", "'", "held"}
--Managers.input.stored_keymaps_data["VMFModsKeyMap"] = nil
--Managers.input.add_keymaps_data(Managers.input, VMFModsKeyMap, "VMFModsKeyMap")
table.dump(optimized_keybinds, "optimized_keybinds", 3)
end end
-- use it directly only for dedugging purposes, otherwise use keybind widget -- use it directly only for dedugging purposes, otherwise use keybind widget

View file

@ -1245,7 +1245,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
end end
if content.keybind_text_hotspot.on_release then if content.keybind_text_hotspot.on_release then
content.callback_start_setting_keybind(content, style) content.callback_change_setting_keybind_state(content, style)
end end
if content.is_setting_keybind then if content.is_setting_keybind then
@ -1626,7 +1626,7 @@ VMFOptionsView.initialize_keybind_widget = function (self, definition, scenegrap
content.callback_setting_changed = callback(self, "callback_setting_changed") content.callback_setting_changed = callback(self, "callback_setting_changed")
content.callback_hide_sub_widgets = callback(self, "callback_hide_sub_widgets") content.callback_hide_sub_widgets = callback(self, "callback_hide_sub_widgets")
content.callback_fit_tooltip_to_the_screen = callback(self, "callback_fit_tooltip_to_the_screen") content.callback_fit_tooltip_to_the_screen = callback(self, "callback_fit_tooltip_to_the_screen")
content.callback_start_setting_keybind = callback(self, "callback_start_setting_keybind") content.callback_change_setting_keybind_state = callback(self, "callback_change_setting_keybind_state")
content.callback_setting_keybind = callback(self, "callback_setting_keybind") content.callback_setting_keybind = callback(self, "callback_setting_keybind")
return widget return widget
@ -1849,39 +1849,22 @@ VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content)
end end
VMFOptionsView.callback_start_setting_keybind = function (self, widget_content, widget_style) VMFOptionsView.callback_change_setting_keybind_state = function (self, widget_content, widget_style)
self.input_manager:device_unblock_all_services("keyboard", 1) if not widget_content.is_setting_keybind then
self.input_manager:device_unblock_all_services("mouse", 1) self.input_manager:device_unblock_all_services("keyboard", 1)
self.input_manager:device_unblock_all_services("gamepad", 1) self.input_manager:device_unblock_all_services("mouse", 1)
self.input_manager:device_unblock_all_services("gamepad", 1)
self.input_manager:block_device_except_service("changing_setting", "keyboard", 1, "keybind") self.input_manager:block_device_except_service("changing_setting", "keyboard", 1, "keybind")
self.input_manager:block_device_except_service("changing_setting", "mouse", 1, "keybind") self.input_manager:block_device_except_service("changing_setting", "mouse", 1, "keybind")
self.input_manager:block_device_except_service("changing_setting", "gamepad", 1, "keybind") self.input_manager:block_device_except_service("changing_setting", "gamepad", 1, "keybind")
WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select") WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select")
widget_content.is_setting_keybind = true widget_content.is_setting_keybind = true
widget_content.keybind_text = "_" widget_style.keybind_text.text_color[1] = 100
widget_style.keybind_text.text_color[1] = 100 else
end
VMFOptionsView.callback_setting_keybind = function (self, widget_content, widget_style)
if (Mouse.any_released() and "mouse_" .. Mouse.button_name(Mouse.any_released()) == widget_content.first_pressed_button) or
(Keyboard.any_released() and Keyboard.button_name(Keyboard.any_released()) == widget_content.first_pressed_button) or
Keyboard.button(Keyboard.button_index("esc")) == 1 then
local keybind_string = ""
local first_key = true
widget_content.keybind_text = build_keybind_string(widget_content.keys)
widget_style.keybind_text.text_color[2] = 255
widget_content.first_pressed_button = nil
widget_content.first_pressed_button_type = nil
widget_content.is_setting_keybind = false
self.input_manager:device_unblock_all_services("keyboard", 1) self.input_manager:device_unblock_all_services("keyboard", 1)
self.input_manager:device_unblock_all_services("mouse", 1) self.input_manager:device_unblock_all_services("mouse", 1)
@ -1890,69 +1873,97 @@ VMFOptionsView.callback_setting_keybind = function (self, widget_content, widget
self.input_manager:block_device_except_service("vmf_options_menu", "mouse", 1) self.input_manager:block_device_except_service("vmf_options_menu", "mouse", 1)
self.input_manager:block_device_except_service("vmf_options_menu", "gamepad", 1) self.input_manager:block_device_except_service("vmf_options_menu", "gamepad", 1)
WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select") widget_content.is_setting_keybind = false
widget_style.keybind_text.text_color[2] = 255
get_mod(widget_content.mod_name):keybind(widget_content.setting_name, widget_content.action, widget_content.keys)
return true
end end
if Mouse.any_pressed() or Keyboard.any_pressed() then WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select")
end
local pressed_buttons = {} VMFOptionsView.callback_setting_keybind = function (self, widget_content, widget_style)
if not widget_content.first_pressed_button then if not widget_content.first_pressed_button and (Keyboard.any_pressed() or Mouse.any_pressed()) then
local first_pressed_button_info = nil local first_pressed_button_info = nil
local first_pressed_button_index = nil
local first_pressed_button_type = nil
if Keyboard.any_pressed() then if Keyboard.any_pressed() then
if Keyboard.button(Keyboard.button_index("left ctrl")) +
Keyboard.button(Keyboard.button_index("left alt")) +
Keyboard.button(Keyboard.button_index("left shift")) > 0 then
return
end
first_pressed_button_info = vmf.keys.keyboard[Keyboard.any_pressed()]
elseif Mouse.any_pressed() then first_pressed_button_info = vmf.keys.keyboard[Keyboard.any_pressed()]
first_pressed_button_index = Keyboard.any_pressed()
first_pressed_button_type = "keyboard"
first_pressed_button_info = vmf.keys.mouse[Mouse.any_pressed()] elseif Mouse.any_pressed() then
end
if not first_pressed_button_info then first_pressed_button_info = vmf.keys.mouse[Mouse.any_pressed()]
return first_pressed_button_index = Mouse.any_pressed()
end first_pressed_button_type = "mouse"
widget_content.first_pressed_button = first_pressed_button_info[2]
end end
if first_pressed_button_info then
widget_content.first_pressed_button = first_pressed_button_info[2]
widget_content.first_pressed_button_index = first_pressed_button_index
widget_content.first_pressed_button_type = first_pressed_button_type
end
end
local pressed_buttons = {}
local preview_string = ""
if widget_content.first_pressed_button then
table.insert(pressed_buttons, widget_content.first_pressed_button) table.insert(pressed_buttons, widget_content.first_pressed_button)
preview_string = vmf.readable_key_names[widget_content.first_pressed_button]
end
if Keyboard.button(Keyboard.button_index("left ctrl")) == 1 then
preview_string = preview_string .. " + Ctrl"
table.insert(pressed_buttons, "ctrl")
end
if Keyboard.button(Keyboard.button_index("left alt")) == 1 then
preview_string = preview_string .. " + Alt"
table.insert(pressed_buttons, "alt")
end
if Keyboard.button(Keyboard.button_index("left shift")) == 1 then
preview_string = preview_string .. " + Shift"
table.insert(pressed_buttons, "shift")
end
local preview_string = vmf.readable_key_names[widget_content.first_pressed_button] if preview_string ~= "" then
local special_buttons_pressed = false
if Keyboard.button(Keyboard.button_index("left ctrl")) == 1 then
preview_string = preview_string .. " + Ctrl"
special_buttons_pressed = true
table.insert(pressed_buttons, "ctrl")
end
if Keyboard.button(Keyboard.button_index("left alt")) == 1 then
preview_string = preview_string .. " + Alt"
special_buttons_pressed = true
table.insert(pressed_buttons, "alt")
end
if Keyboard.button(Keyboard.button_index("left shift")) == 1 then
preview_string = preview_string .. " + Shift"
special_buttons_pressed = true
table.insert(pressed_buttons, "shift")
end
if not special_buttons_pressed then
preview_string = preview_string .. " + [Ctrl/Alt/Shift]"
end
widget_content.keys = pressed_buttons widget_content.keys = pressed_buttons
widget_content.keybind_text = preview_string widget_content.keybind_text = preview_string
else
widget_content.keybind_text = "_"
end
if widget_content.first_pressed_button then
if (widget_content.first_pressed_button_type == "keyboard" and Keyboard.released(widget_content.first_pressed_button_index) or
widget_content.first_pressed_button_type == "mouse" and Mouse.released(widget_content.first_pressed_button_index)) then
widget_content.keybind_text = build_keybind_string(widget_content.keys)
widget_content.first_pressed_button = nil
widget_content.first_pressed_button_index = nil
widget_content.first_pressed_button_type = nil
get_mod(widget_content.mod_name):keybind(widget_content.setting_name, widget_content.action, widget_content.keys)
self:callback_change_setting_keybind_state(widget_content, widget_style)
return true
end
else
if Keyboard.released(Keyboard.button_index("esc")) then
widget_content.keys = {}
widget_content.keybind_text = build_keybind_string(widget_content.keys)
get_mod(widget_content.mod_name):keybind(widget_content.setting_name, widget_content.action, widget_content.keys)
self:callback_change_setting_keybind_state(widget_content, widget_style)
return true
end
end end
end end
@ -2495,7 +2506,7 @@ VMFMod.create_options = function (self, widgets_definition, is_mod_toggable, rea
if current_widget.widget_type == "keybind" then if current_widget.widget_type == "keybind" then
local keybind = self:get(current_widget.setting_name) local keybind = self:get(current_widget.setting_name)
new_widget_definition.keybind_text = build_keybind_string(keybind) new_widget_definition.keybind_text = build_keybind_string(keybind)
self:keybind(self._name, current_widget.action, keybind) self:keybind(current_widget.setting_name, current_widget.action, keybind)
end end
table.insert(mod_settings_list_widgets_definitions, new_widget_definition) table.insert(mod_settings_list_widgets_definitions, new_widget_definition)