From 22c1c7d03c3fd58c8bd4cd9b6200226511d8d379 Mon Sep 17 00:00:00 2001 From: Quboid Date: Fri, 7 Oct 2022 18:50:32 +0100 Subject: [PATCH] - Updated translations - Improved QCommon support --- Picker/Localization/Localize.Designer.cs | 9 ++ Picker/Localization/Localize.resx | 3 + Picker/Mod.cs | 22 ++- Picker/OptionsKeymapping.cs | 171 +---------------------- Picker/Picker.csproj | 1 + 5 files changed, 26 insertions(+), 180 deletions(-) diff --git a/Picker/Localization/Localize.Designer.cs b/Picker/Localization/Localize.Designer.cs index 8710120..bc2950d 100644 --- a/Picker/Localization/Localize.Designer.cs +++ b/Picker/Localization/Localize.Designer.cs @@ -60,6 +60,15 @@ internal Localize() { } } + /// + /// Looks up a localized string similar to Press Any Key. + /// + internal static string key_pressAnyKey { + get { + return ResourceManager.GetString("key_pressAnyKey", resourceCulture); + } + } + /// /// Looks up a localized string similar to Toggle Tool. /// diff --git a/Picker/Localization/Localize.resx b/Picker/Localization/Localize.resx index 7ad1148..e1d948a 100644 --- a/Picker/Localization/Localize.resx +++ b/Picker/Localization/Localize.resx @@ -158,4 +158,7 @@ Hold Control while clicking to invert this behaviour. Use UnifiedUI Do not translate 'UnifiedUI' + + Press Any Key + \ No newline at end of file diff --git a/Picker/Mod.cs b/Picker/Mod.cs index e5af01c..02dd30f 100644 --- a/Picker/Mod.cs +++ b/Picker/Mod.cs @@ -165,7 +165,7 @@ public void OnSettingsUI(UIHelperBase helper) group.AddSpace(10); - ((UIPanel)((UIHelper)group).self).gameObject.AddComponent(); + ((UIPanel)((UIHelper)group).self).gameObject.AddComponent(); UIPanel panel = ((UIHelper)group).self as UIPanel; group.AddSpace(20); @@ -265,28 +265,22 @@ internal static int GetMoveItVersion() return 1; } - private static int _isRicoEnabled = -1; + private static bool? _isRicoEnabled = null; internal static bool IsRicoEnabled { get { - if (_isRicoEnabled == -1) + if (_isRicoEnabled == null) { - foreach (PluginManager.PluginInfo plugin in PluginManager.instance.GetPluginsInfo()) + _isRicoEnabled = false; + if (QCommon.GetAssembly("ploppablerico", "ploppablerico") != null) { - foreach (Assembly assembly in plugin.GetAssemblies()) - { - if (assembly.GetName().Name.ToLower() == "ploppablerico") - { - Debug.Log("Ploppable RICO found"); - _isRicoEnabled = plugin.isEnabled ? 1 : 0; - return _isRicoEnabled == 1; - } - } + _isRicoEnabled = true; } + Debug.Log($"Picker: PloppableRICO detected? {_isRicoEnabled}"); } - return _isRicoEnabled == 1; + return (bool)_isRicoEnabled; } } diff --git a/Picker/OptionsKeymapping.cs b/Picker/OptionsKeymapping.cs index f60d5bf..03b6e3f 100644 --- a/Picker/OptionsKeymapping.cs +++ b/Picker/OptionsKeymapping.cs @@ -1,180 +1,19 @@ using ColossalFramework; -using ColossalFramework.Globalization; -using ColossalFramework.UI; using Picker.Localization; -using System.Reflection; +using QCommonLib; using UnityEngine; -// Based on Move It's code namespace Picker { - public class OptionsKeymappingMain : OptionsKeymapping + public class OptionsKeymapping : QKeybinding { - private void Awake() - { - AddKeymapping(Localize.keybind_ToggleTool, toggleTool); - } - } - - public class OptionsKeymapping : UICustomControl - { - protected static readonly string kKeyBindingTemplate = "KeyBindingTemplate"; - - protected SavedInputKey m_EditingBinding; - - protected string m_EditingBindingCategory; - public static readonly SavedInputKey toggleTool = new SavedInputKey("toggleTool", Picker.settingsFileName, SavedInputKey.Encode(KeyCode.T, false, false, false), true); - protected int count = 0; - - protected void AddKeymapping(string label, SavedInputKey savedInputKey) - { - UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel; - if (count++ % 2 == 1) uIPanel.backgroundSprite = null; - - UILabel uILabel = uIPanel.Find("Name"); - UIButton uIButton = uIPanel.Find("Binding"); - uIButton.eventKeyDown += new KeyPressHandler(this.OnBindingKeyDown); - uIButton.eventMouseDown += new MouseEventHandler(this.OnBindingMouseDown); - - uILabel.text = label; - uIButton.text = savedInputKey.ToLocalizedString("KEYNAME"); - uIButton.objectUserData = savedInputKey; - } - - protected bool IsModifierKey(KeyCode code) + protected override void Awake() { - return code == KeyCode.LeftControl || code == KeyCode.RightControl || code == KeyCode.LeftShift || code == KeyCode.RightShift || code == KeyCode.LeftAlt || code == KeyCode.RightAlt; - } - - protected bool IsControlDown() - { - return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); - } - - protected bool IsShiftDown() - { - return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); - } + PressAnyKeyStr = Localize.key_pressAnyKey; - protected bool IsAltDown() - { - return Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); - } - - protected bool IsUnbindableMouseButton(UIMouseButton code) - { - return code == UIMouseButton.Left || code == UIMouseButton.Right; - } - - protected KeyCode ButtonToKeycode(UIMouseButton button) - { - if (button == UIMouseButton.Left) - { - return KeyCode.Mouse0; - } - if (button == UIMouseButton.Right) - { - return KeyCode.Mouse1; - } - if (button == UIMouseButton.Middle) - { - return KeyCode.Mouse2; - } - if (button == UIMouseButton.Special0) - { - return KeyCode.Mouse3; - } - if (button == UIMouseButton.Special1) - { - return KeyCode.Mouse4; - } - if (button == UIMouseButton.Special2) - { - return KeyCode.Mouse5; - } - if (button == UIMouseButton.Special3) - { - return KeyCode.Mouse6; - } - return KeyCode.None; - } - - protected void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p) - { - if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode)) - { - p.Use(); - UIView.PopModal(); - KeyCode keycode = p.keycode; - InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt); - if (p.keycode == KeyCode.Backspace) - { - inputKey = SavedInputKey.Empty; - } - this.m_EditingBinding.value = inputKey; - UITextComponent uITextComponent = p.source as UITextComponent; - uITextComponent.text = this.m_EditingBinding.ToLocalizedString("KEYNAME"); - this.m_EditingBinding = null; - this.m_EditingBindingCategory = string.Empty; - } - } - - protected void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p) - { - if (this.m_EditingBinding == null) - { - p.Use(); - this.m_EditingBinding = (SavedInputKey)p.source.objectUserData; - this.m_EditingBindingCategory = p.source.stringUserData; - UIButton uIButton = p.source as UIButton; - uIButton.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3); - uIButton.text = "Press any key"; - p.source.Focus(); - UIView.PushModal(p.source); - } - else if (!this.IsUnbindableMouseButton(p.buttons)) - { - p.Use(); - UIView.PopModal(); - InputKey inputKey = SavedInputKey.Encode(this.ButtonToKeycode(p.buttons), this.IsControlDown(), this.IsShiftDown(), this.IsAltDown()); - - this.m_EditingBinding.value = inputKey; - UIButton uIButton2 = p.source as UIButton; - uIButton2.text = this.m_EditingBinding.ToLocalizedString("KEYNAME"); - uIButton2.buttonsMask = UIMouseButton.Left; - this.m_EditingBinding = null; - this.m_EditingBindingCategory = string.Empty; - } - } - - protected InputKey GetDefaultEntry(string entryName) - { - FieldInfo field = typeof(DefaultSettings).GetField(entryName, BindingFlags.Static | BindingFlags.Public); - if (field == null) - { - return 0; - } - object value = field.GetValue(null); - if (value is InputKey) - { - return (InputKey)value; - } - return 0; - } - - protected void RefreshKeyMapping() - { - foreach (UIComponent current in component.GetComponentsInChildren()) - { - UITextComponent uITextComponent = current.Find("Binding"); - SavedInputKey savedInputKey = (SavedInputKey)uITextComponent.objectUserData; - if (this.m_EditingBinding != savedInputKey) - { - uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME"); - } - } + AddKeymapping(Localize.keybind_ToggleTool, toggleTool); } } } \ No newline at end of file diff --git a/Picker/Picker.csproj b/Picker/Picker.csproj index e07538b..02ffbf5 100644 --- a/Picker/Picker.csproj +++ b/Picker/Picker.csproj @@ -98,6 +98,7 @@ ResXFileCodeGenerator Localize.Designer.cs + Designer