diff --git a/res/layouts/pages/settings_controls.xml.lua b/res/layouts/pages/settings_controls.xml.lua index ad8491ad..df6fe20b 100644 --- a/res/layouts/pages/settings_controls.xml.lua +++ b/res/layouts/pages/settings_controls.xml.lua @@ -1,3 +1,12 @@ +local WARNING_COLORS = { + {252, 200, 149, 255}, + {246, 233, 44, 255}, + {250, 151, 75, 255}, + {250, 75, 139, 255}, + {208, 104, 107, 255} +} + +local GENERAL_WARNING_COLOR = {208, 138, 0, 255} function refresh_search() local search_text = document.search_textbox.text @@ -40,6 +49,48 @@ function change_sensitivity(val) refresh_sensitivity() end +function refresh_binding_labels() + local prev_bindings = {} + local conflicts_colors = {} + local available_colors = table.copy(WARNING_COLORS) + + local bindings = input.get_bindings() + table.sort(bindings, function(a, b) return a > b end) + + for _, bind_name in pairs(bindings) do + local key = input.get_binding_text(bind_name) + local prev = prev_bindings[key] + if prev then + local color = GENERAL_WARNING_COLOR + local conflict_color = conflicts_colors[key] + if conflict_color then + color = conflict_color + elseif #available_colors > 0 then + color = available_colors[1] + conflicts_colors[key] = color + table.remove(available_colors, 1) + end + + local tooltip = gui.str("settings.Conflict", "settings") + + local prev_bindmark = "bindmark_" .. prev + local cur_bindmark = "bindmark_" .. bind_name + document[prev_bindmark].visible = true + document[cur_bindmark].visible = true + + document[prev_bindmark].color = color + document[cur_bindmark].color = color + + document["bind_" .. prev].tooltip = tooltip + document["bind_" .. bind_name].tooltip = tooltip + else + document["bindmark_" .. bind_name].visible = false + document["bind_" .. bind_name].tooltip = '' + prev_bindings[key] = bind_name + end + end +end + function on_open() document.sensitivity_track.value = core.get_setting("camera.sensitivity") refresh_sensitivity() @@ -52,4 +103,8 @@ function on_open() id=name, name=gui.str(name) })) end + + document.bindings_panel:setInterval(100, function () + refresh_binding_labels() + end) end