2 new chat commands (untested)

Fixed some minor keybinds bugs
Now user can interract with settings widgets only inside allowed area
This commit is contained in:
Azumgi 2018-02-02 22:55:06 +03:00
parent fe222fe57e
commit 8d57fd3c44
4 changed files with 198 additions and 100 deletions

View file

@ -30,3 +30,57 @@ vmf.hook_chat_manager = function()
vmf:hook("ChatManager.register_channel", hook_send_unsent_messages)
end
end
-- ####################################################################################################################
-- ##### VMFMod #######################################################################################################
-- ####################################################################################################################
VMFMod.chat_broadcast = function(self, message)
local chat = Managers.chat
if chat and chat:has_channel(1) then
local channel_id = 1
local my_peer_id = chat.my_peer_id
local localization_param = ""
local is_system_message = true
local pop_chat = true
local is_dev = false
if chat.is_server then
local members = chat:channel_members(channel_id)
for _, member in pairs(members) do
if member ~= my_peer_id then
RPC.rpc_chat_message(member, channel_id, my_peer_id, message, localization_param, is_system_message, pop_chat, is_dev)
end
end
else
local host_peer_id = chat.host_peer_id
if host_peer_id then
RPC.rpc_chat_message(host_peer_id, channel_id, my_peer_id, message, localization_param, is_system_message, pop_chat, is_dev)
end
end
message = Localize(message)
chat:_add_message_to_list(channel_id, "SYSTEM", message, is_system_message, pop_chat, is_dev)
end
end
VMFMod.chat_whisper = function(self, peer_id, message)
local chat = Managers.chat
if chat and chat:has_channel(1) and chat.is_server then
local channel_id = 1
local my_peer_id = chat.my_peer_id
local localization_param = ""
local is_system_message = true
local pop_chat = true
local is_dev = false
RPC.rpc_chat_message(peer_id, channel_id, my_peer_id, message, localization_param, is_system_message, pop_chat, is_dev)
end
end

View file

@ -241,9 +241,9 @@ vmf.check_custom_menus_close_keybinds = function(dt)
local close_menu = false
if not opening_keybind_is_pressed then
if input_service:get(close_keybind[1]) and
(not close_keybind[3] and not input_service:get("ctrl") or close_keybind[3] and input_service:get("ctrl")) and
(not close_keybind[4] and not input_service:get("alt") or close_keybind[4] and input_service:get("alt")) and
(not close_keybind[5] and not input_service:get("shift") or close_keybind[5] and input_service:get("shift")) then
(not close_keybind[2] and not input_service:get("ctrl") or close_keybind[2] and input_service:get("ctrl")) and
(not close_keybind[3] and not input_service:get("alt") or close_keybind[3] and input_service:get("alt")) and
(not close_keybind[4] and not input_service:get("shift") or close_keybind[4] and input_service:get("shift")) then
close_menu = not ingame_ui.views[ingame_ui.current_view]:input_service():is_blocked()
end

View file

@ -289,15 +289,20 @@ vmf.check_pressed_keybinds = function()
if (not binding_info[3] and not input_service:get("ctrl") or binding_info[3] and input_service:get("ctrl")) and
(not binding_info[4] and not input_service:get("alt") or binding_info[4] and input_service:get("alt")) and
(not binding_info[5] and not input_service:get("shift") or binding_info[5] and input_service:get("shift")) then
--@TODO: add pcall, also check for suspending, and perhaps add "toggle" event
if not pcall(get_mod(binding_info[1])[binding_info[2]]) then
--@TODO: also check for suspending, and perhaps add "toggle" event
local action_exists, action_function = pcall(function() return get_mod(binding_info[1])[binding_info[2]] end)
if action_exists then
local success, error_message = pcall(action_function)
if not success then
get_mod(binding_info[1]):echo("ERROR(keybindings) in function '" .. tostring(binding_info[2]) .. "': " .. tostring(error_message), true)
end
else
get_mod(binding_info[1]):echo("ERROR(keybindings): function '" .. tostring(binding_info[2]) .. "' wasn't found.", true)
end
key_has_active_keybind = true
--table.dump(optimized_keybinds, "optimized_keybinds", 2)
vmf.activated_pressed_key = key
end
end

View file

@ -302,7 +302,7 @@ local function create_header_widget(widget_definition, scenegraph_id)
texture_id = "highlight_texture",
content_check_function = function (content)
return content.highlight_hotspot.is_hover
return content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -312,7 +312,7 @@ local function create_header_widget(widget_definition, scenegraph_id)
texture_id = "fav_icon_texture",
content_check_function = function (content)
return content.is_favorited or content.highlight_hotspot.is_hover
return content.is_favorited or content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -322,7 +322,7 @@ local function create_header_widget(widget_definition, scenegraph_id)
texture_id = "fav_arrow_texture",
content_check_function = function (content)
return content.is_favorited and content.highlight_hotspot.is_hover
return content.is_favorited and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -332,7 +332,7 @@ local function create_header_widget(widget_definition, scenegraph_id)
texture_id = "fav_arrow_texture",
content_check_function = function (content)
return content.is_favorited and content.highlight_hotspot.is_hover
return content.is_favorited and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -399,7 +399,11 @@ local function create_header_widget(widget_definition, scenegraph_id)
offset_function = function (ui_scenegraph, style, content, ui_renderer)
if content.highlight_hotspot.is_hover and content.tooltip_text then
local is_interactable = content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
if is_interactable then
if content.tooltip_text then
style.tooltip_text.cursor_offset = content.callback_fit_tooltip_to_the_screen(content, style.tooltip_text, ui_renderer)
end
@ -435,12 +439,13 @@ local function create_header_widget(widget_definition, scenegraph_id)
content.callback_mod_suspend_state_changed(mod_name, is_mod_suspended)
end
end
content.fav_icon_texture = content.is_favorited and "header_fav_icon_lit" or "header_fav_icon"
content.background_texture = content.is_widget_collapsed and "header_background_lit" or "header_background"
content.checkbox_texture = content.is_checkbox_checked and "checkbox_checked" or "checkbox_unchecked"
style.fav_arrow_up.color[1] = content.fav_arrow_up_hotspot.is_hover and 255 or 90
style.fav_arrow_down.color[1] = content.fav_arrow_down_hotspot.is_hover and 255 or 90
style.fav_arrow_up.color[1] = is_interactable and content.fav_arrow_up_hotspot.is_hover and 255 or 90
style.fav_arrow_down.color[1] = is_interactable and content.fav_arrow_down_hotspot.is_hover and 255 or 90
end
},
-- TOOLTIP
@ -450,7 +455,7 @@ local function create_header_widget(widget_definition, scenegraph_id)
text_id = "tooltip_text",
style_id = "tooltip_text",
content_check_function = function (content)
return content.tooltip_text and content.highlight_hotspot.is_hover
return content.tooltip_text and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
-- DEBUG
@ -644,7 +649,7 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
style_id = "highlight_texture",
texture_id = "highlight_texture",
content_check_function = function (content)
return content.highlight_hotspot.is_hover
return content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -677,7 +682,11 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
offset_function = function (ui_scenegraph, style, content, ui_renderer)
if content.highlight_hotspot.is_hover and content.tooltip_text then
local is_interactable = content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
if is_interactable then
if content.tooltip_text then
style.tooltip_text.cursor_offset = content.callback_fit_tooltip_to_the_screen(content, style.tooltip_text, ui_renderer)
end
@ -700,6 +709,7 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
content.callback_setting_changed(mod_name, setting_name, old_value, new_value)
end
end
content.checkbox_texture = content.is_checkbox_checked and "checkbox_checked" or "checkbox_unchecked"
end
@ -711,7 +721,7 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
text_id = "tooltip_text",
style_id = "tooltip_text",
content_check_function = function (content)
return content.tooltip_text and content.highlight_hotspot.is_hover
return content.tooltip_text and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
-- DEBUG
@ -886,7 +896,7 @@ local function create_stepper_widget(widget_definition, scenegraph_id)
style_id = "highlight_texture",
texture_id = "highlight_texture",
content_check_function = function (content)
return content.highlight_hotspot.is_hover
return content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -937,7 +947,11 @@ local function create_stepper_widget(widget_definition, scenegraph_id)
offset_function = function (ui_scenegraph, style, content, ui_renderer)
if content.highlight_hotspot.is_hover and content.tooltip_text then
local is_interactable = content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
if is_interactable then
if content.tooltip_text then
style.tooltip_text.cursor_offset = content.callback_fit_tooltip_to_the_screen(content, style.tooltip_text, ui_renderer)
end
@ -968,9 +982,10 @@ local function create_stepper_widget(widget_definition, scenegraph_id)
local new_value = content.options_values[new_option_number]
content.callback_setting_changed(mod_name, setting_name, old_value, new_value)
end
end
content.left_arrow_texture = content.left_arrow_hotspot.is_hover and "settings_arrow_clicked" or "settings_arrow_normal"
content.right_arrow_texture = content.right_arrow_hotspot.is_hover and "settings_arrow_clicked" or "settings_arrow_normal"
content.left_arrow_texture = is_interactable and content.left_arrow_hotspot.is_hover and "settings_arrow_clicked" or "settings_arrow_normal"
content.right_arrow_texture = is_interactable and content.right_arrow_hotspot.is_hover and "settings_arrow_clicked" or "settings_arrow_normal"
end
},
-- TOOLTIP
@ -980,7 +995,7 @@ local function create_stepper_widget(widget_definition, scenegraph_id)
text_id = "tooltip_text",
style_id = "tooltip_text",
content_check_function = function (content, style)
return content.tooltip_text and content.highlight_hotspot.is_hover
return content.tooltip_text and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
-- DEBUG
@ -1198,7 +1213,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
style_id = "highlight_texture",
texture_id = "highlight_texture",
content_check_function = function (content)
return content.highlight_hotspot.is_hover
return content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
{
@ -1231,6 +1246,10 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
offset_function = function (ui_scenegraph, style, content, ui_renderer)
local is_interactable = content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
if is_interactable then
if content.highlight_hotspot.is_hover and content.tooltip_text then
style.tooltip_text.cursor_offset = content.callback_fit_tooltip_to_the_screen(content, style.tooltip_text, ui_renderer)
end
@ -1246,6 +1265,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
if content.keybind_text_hotspot.on_release then
content.callback_change_setting_keybind_state(content, style)
end
end
if content.is_setting_keybind then
if content.callback_setting_keybind(content, style) then
@ -1254,7 +1274,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
return
end
style.keybind_text.text_color = content.keybind_text_hotspot.is_hover and Colors.get_color_table_with_alpha("white", 255) or Colors.get_color_table_with_alpha("cheeseburger", 255)
style.keybind_text.text_color = is_interactable and content.keybind_text_hotspot.is_hover and Colors.get_color_table_with_alpha("white", 255) or Colors.get_color_table_with_alpha("cheeseburger", 255)
end
},
-- TOOLTIP
@ -1264,7 +1284,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
text_id = "tooltip_text",
style_id = "tooltip_text",
content_check_function = function (content, style)
return content.tooltip_text and content.highlight_hotspot.is_hover
return content.tooltip_text and content.highlight_hotspot.is_hover and content.callback_is_cursor_inside_settings_list()
end
},
-- DEBUG
@ -1586,6 +1606,7 @@ VMFOptionsView.initialize_header_widget = function (self, definition, scenegraph
content.callback_mod_suspend_state_changed = callback(self, "callback_mod_suspend_state_changed")
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_is_cursor_inside_settings_list = callback(self, "callback_is_cursor_inside_settings_list")
return widget
end
@ -1599,6 +1620,7 @@ VMFOptionsView.initialize_checkbox_widget = function (self, definition, scenegra
content.callback_setting_changed = callback(self, "callback_setting_changed")
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_is_cursor_inside_settings_list = callback(self, "callback_is_cursor_inside_settings_list")
return widget
end
@ -1612,6 +1634,7 @@ VMFOptionsView.initialize_stepper_widget = function (self, definition, scenegrap
content.callback_setting_changed = callback(self, "callback_setting_changed")
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_is_cursor_inside_settings_list = callback(self, "callback_is_cursor_inside_settings_list")
return widget
end
@ -1627,6 +1650,7 @@ VMFOptionsView.initialize_keybind_widget = function (self, definition, scenegrap
content.callback_fit_tooltip_to_the_screen = callback(self, "callback_fit_tooltip_to_the_screen")
content.callback_change_setting_keybind_state = callback(self, "callback_change_setting_keybind_state")
content.callback_setting_keybind = callback(self, "callback_setting_keybind")
content.callback_is_cursor_inside_settings_list = callback(self, "callback_is_cursor_inside_settings_list")
return widget
end
@ -1685,6 +1709,23 @@ VMFOptionsView.callback_mod_suspend_state_changed = function (self, mod_name, is
end
VMFOptionsView.callback_is_cursor_inside_settings_list = function (self)
local input_service = self:input_service()
local cursor = input_service:get("cursor")
local mask_pos = Vector3.deprecated_copy(UISceneGraph.get_world_position(self.ui_scenegraph, "sg_settings_list_mask"))
local mask_size = UISceneGraph.get_size(self.ui_scenegraph, "sg_settings_list_mask")
local cursor_position = UIInverseScaleVectorToResolution(cursor)
local is_hover = math.point_is_inside_2d_box(cursor_position, mask_pos, mask_size)
if is_hover then
return true
end
end
VMFOptionsView.callback_fit_tooltip_to_the_screen = function (self, widget_content, widget_style, ui_renderer)
local cursor_offset_bottom = widget_style.cursor_offset_bottom
@ -1894,6 +1935,7 @@ VMFOptionsView.callback_change_setting_keybind_state = function (self, widget_co
end
end
VMFOptionsView.callback_setting_keybind = function (self, widget_content, widget_style)
if not widget_content.first_pressed_button and (Keyboard.any_pressed() or Mouse.any_pressed()) then
@ -2262,7 +2304,6 @@ end
-- ##### UPDATE #######################################################################################################
-- ####################################################################################################################
VMFOptionsView.update = function (self, dt)
if self.suspended then
return
@ -2275,9 +2316,7 @@ VMFOptionsView.update = function (self, dt)
self.draw_widgets(self, dt)
-- @TODO: get rid of this shit later. I guess
local input_manager = self.input_manager
local input_service = input_manager:get_service("vmf_options_menu")
local input_service = self:input_service()
if input_service.get(input_service, "toggle_menu") then
self.ingame_ui:handle_transition("exit_menu")
end