mutators: notify about all mutators when disabling;

Make "no mutators" text into its own widget
Fix checkbox click sound
No longer try to disable mutators every update when not hosting
This commit is contained in:
UnShame 2018-02-23 00:59:21 +03:00
parent 99093eddcf
commit 36989758f3
4 changed files with 106 additions and 35 deletions

View file

@ -31,7 +31,8 @@ local mutators_view = {
-- Setup custom widgets -- Setup custom widgets
self.widgets = { self.widgets = {
banner_mutators = UIWidget.init(definitions.new_widgets.banner_mutators_widget), banner_mutators = UIWidget.init(definitions.new_widgets.banner_mutators_widget),
mutators_button = UIWidget.init(definitions.new_widgets.mutators_button_widget) mutators_button = UIWidget.init(definitions.new_widgets.mutators_button_widget),
no_mutators_text = UIWidget.init(definitions.new_widgets.no_mutators_text_widget)
} }
for i = 1, PER_PAGE do for i = 1, PER_PAGE do
@ -199,7 +200,7 @@ local mutators_view = {
-- Click event -- Click event
if hotspot.on_release then if hotspot.on_release then
self.map_view:play_sound("Play_hud_hover") self.map_view:play_sound("Play_hud_select")
if mutator:is_enabled() then if mutator:is_enabled() then
mutator:disable() mutator:disable()
else else
@ -214,27 +215,11 @@ local mutators_view = {
local checkbox = self.mutator_checkboxes[1] local checkbox = self.mutator_checkboxes[1]
if #mutators == 0 then if #mutators == 0 then
widgets.adventure["mutator_checkbox_" .. 1] = checkbox widgets.adventure["no_mutators_text"] = self.widgets.no_mutators_text
widgets.survival["mutator_checkbox_" .. 1] = checkbox widgets.survival["no_mutators_text"] = self.widgets.no_mutators_text
checkbox.style.setting_text.text_color = Colors.get_color_table_with_alpha("slate_gray", 255)
checkbox.style.setting_text_hover.text_color = Colors.get_color_table_with_alpha("slate_gray", 255)
checkbox.style.checkbox_style.color = Colors.get_color_table_with_alpha("slate_gray", 255)
checkbox.content.setting_text = "No mutators installed"
checkbox.content.tooltip_text = "Subscribe to mods and mutators on the workshop"
checkbox.style.checkbox_style.offset[1] = -10000
checkbox.style.setting_text.horizontal_alignment = "center"
checkbox.style.setting_text_hover.horizontal_alignment = "center"
checkbox.style.setting_text.offset[1] = 0
checkbox.style.setting_text_hover.offset[1] = 0
else else
checkbox.style.checkbox_style.offset[1] = 0 widgets.adventure["no_mutators_text"] = nil
checkbox.style.setting_text.horizontal_alignment = "left" widgets.survival["no_mutators_text"] = nil
checkbox.style.setting_text_hover.horizontal_alignment = "left"
checkbox.style.setting_text.offset[1] = 24
checkbox.style.setting_text_hover.offset[1] = 24
end end
end, end,
@ -242,7 +227,7 @@ local mutators_view = {
activate = function(self) activate = function(self)
if not self.initialized or not self.map_view.active or self.active then return end if not self.initialized or not self.map_view.active or self.active then return end
-- Hiding widgets -- Widgets
local widgets = self.map_view.normal_settings_widget_types local widgets = self.map_view.normal_settings_widget_types
widgets.adventure.level_preview = nil widgets.adventure.level_preview = nil
@ -257,10 +242,10 @@ local mutators_view = {
self.map_view.ui_scenegraph.banner_level_text.position[2] = -10000 self.map_view.ui_scenegraph.banner_level_text.position[2] = -10000
-- Update steppers -- Update steppers
self.map_view.steppers.level.widget.style.setting_text.offset[2] = -10000
self.map_view.steppers.level.widget.style.hover_texture.offset[2] = -10000
local level_stepper_widget = self.map_view.steppers.level.widget local level_stepper_widget = self.map_view.steppers.level.widget
local num_pages = math.ceil(#mutators/PER_PAGE) local num_pages = math.ceil(#mutators/PER_PAGE)
level_stepper_widget.style.setting_text.offset[2] = -10000
level_stepper_widget.style.hover_texture.offset[2] = -10000
level_stepper_widget.content.left_button_hotspot.disable_button = num_pages <= 1 level_stepper_widget.content.left_button_hotspot.disable_button = num_pages <= 1
level_stepper_widget.content.right_button_hotspot.disable_button = num_pages <= 1 level_stepper_widget.content.right_button_hotspot.disable_button = num_pages <= 1
@ -275,7 +260,7 @@ local mutators_view = {
self.active = false self.active = false
-- Showing widgets -- Widgets
local widgets = self.map_view.normal_settings_widget_types local widgets = self.map_view.normal_settings_widget_types
widgets.adventure.level_preview = self.saved_widgets.level_preview widgets.adventure.level_preview = self.saved_widgets.level_preview
@ -286,6 +271,9 @@ local mutators_view = {
widgets.survival.level_preview_text = self.saved_widgets.level_preview widgets.survival.level_preview_text = self.saved_widgets.level_preview
widgets.survival.banner_mutators = nil widgets.survival.banner_mutators = nil
widgets.adventure["no_mutators_text"] = nil
widgets.survival["no_mutators_text"] = nil
-- "Mission" banner position -- "Mission" banner position
self.map_view.ui_scenegraph.banner_level_text.position[2] = 0 self.map_view.ui_scenegraph.banner_level_text.position[2] = 0

View file

@ -37,6 +37,21 @@ scenegraph_definition.banner_mutators_text = {
} }
} }
scenegraph_definition.no_mutators_text = {
vertical_alignment = "center",
parent = "banner_party",
horizontal_alignment = "center",
size = {
310,
30
},
position = {
0,
520,
1
}
}
local new_widgets = { local new_widgets = {
@ -179,6 +194,68 @@ local new_widgets = {
} }
}, },
scenegraph_id = "mutators_button" scenegraph_id = "mutators_button"
},
no_mutators_text_widget = {
element = {
passes = {
{
style_id = "text",
pass_type = "text",
text_id = "text"
},
{
pass_type = "hotspot",
content_id = "tooltip_hotspot"
},
{
style_id = "tooltip_text",
pass_type = "tooltip_text",
text_id = "tooltip_text",
content_check_function = function (ui_content)
return ui_content.tooltip_hotspot.is_hover
end
}
}
},
content = {
text = "No mutators installed",
tooltip_text = "Subscribe to mods and mutators on the workshop",
tooltip_hotspot = {},
color = Colors.get_color_table_with_alpha("slate_gray", 255)
},
style = {
text = {
vertical_alignment = "center",
font_size = 22,
localize = false,
horizontal_alignment = "center",
word_wrap = true,
font_type = "hell_shark",
text_color = Colors.get_color_table_with_alpha("slate_gray", 255),
offset = {
0,
2,
4
}
},
tooltip_text = {
font_size = 24,
max_width = 500,
localize = false,
horizontal_alignment = "left",
vertical_alignment = "top",
font_type = "hell_shark",
text_color = Colors.get_color_table_with_alpha("white", 255),
line_colors = {},
offset = {
0,
0,
50
}
}
},
scenegraph_id = "no_mutators_text"
} }
} }

View file

@ -41,7 +41,6 @@ local function set_lobby_data()
Managers.matchmaking.lobby:set_lobby_data(lobby_data) Managers.matchmaking.lobby:set_lobby_data(lobby_data)
end end
-- Return a function for chat system to only send messages to specific client
local function get_peer_id_from_cookie(client_cookie) local function get_peer_id_from_cookie(client_cookie)
local peer_id = tostring(client_cookie) local peer_id = tostring(client_cookie)
for _ = 1, 3 do for _ = 1, 3 do

View file

@ -9,6 +9,7 @@ manager:localization("localization/mutator_manager")
manager.mutators = {} manager.mutators = {}
local mutators = manager.mutators local mutators = manager.mutators
-- Table of mutators' configs by name
local mutators_config = {} local mutators_config = {}
local default_config = manager:dofile("scripts/mods/vmf/modules/mutators/mutator_default_config") local default_config = manager:dofile("scripts/mods/vmf/modules/mutators/mutator_default_config")
@ -26,6 +27,9 @@ local mutators_sequence = {
-- So we don't sort after each one is added -- So we don't sort after each one is added
local mutators_sorted = false local mutators_sorted = false
-- So we don't have to check when player isn't hosting
local all_mutators_disabled = false
--[[ --[[
PRIVATE METHODS PRIVATE METHODS
@ -244,7 +248,8 @@ end
-- Disables mutators that cannot be enabled right now -- Disables mutators that cannot be enabled right now
manager.disable_impossible_mutators = function(notify, everybody, reason) manager.disable_impossible_mutators = function(notify, everybody, reason)
local disabled_mutators = {} local disabled_mutators = {}
for _, mutator in pairs(mutators) do for i = #mutators, 1, -1 do
local mutator = mutators[i]
if mutator:is_enabled() and not mutator:can_be_enabled() then if mutator:is_enabled() and not mutator:can_be_enabled() then
mutator:disable() mutator:disable()
table.insert(disabled_mutators, mutator) table.insert(disabled_mutators, mutator)
@ -263,13 +268,6 @@ manager.disable_impossible_mutators = function(notify, everybody, reason)
return disabled_mutators return disabled_mutators
end end
-- Check if player is still hosting
manager.update = function()
if not player_is_server() then
manager.disable_impossible_mutators(true, false, "because you're no longer the host")
end
end
-- Appends, prepends and replaces the string with mutator titles -- Appends, prepends and replaces the string with mutator titles
manager.add_mutator_titles_to_string = function(_mutators, str, separator, short) manager.add_mutator_titles_to_string = function(_mutators, str, separator, short)
@ -312,6 +310,14 @@ manager.add_mutator_titles_to_string = function(_mutators, str, separator, short
return new_str return new_str
end end
-- Check if player is still hosting
manager.update = function()
if not all_mutators_disabled and not player_is_server() then
manager.disable_impossible_mutators(true, false, "because you're no longer the host")
all_mutators_disabled = true
end
end
--[[ --[[
MUTATOR'S OWN METHODS MUTATOR'S OWN METHODS
@ -320,6 +326,7 @@ end
-- Enables mutator -- Enables mutator
local function enable_mutator(self) local function enable_mutator(self)
set_mutator_state(self, true) set_mutator_state(self, true)
all_mutators_disabled = false
end end
-- Disables mutator -- Disables mutator