Skip to content

Commit

Permalink
- Updated translations
Browse files Browse the repository at this point in the history
- Improved QCommon support
  • Loading branch information
Quboid committed Oct 7, 2022
1 parent c8d6c8c commit 22c1c7d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 180 deletions.
9 changes: 9 additions & 0 deletions Picker/Localization/Localize.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Picker/Localization/Localize.resx
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,7 @@ Hold Control while clicking to invert this behaviour.</value>
<value>Use UnifiedUI</value>
<comment>Do not translate 'UnifiedUI'</comment>
</data>
<data name="key_pressAnyKey" xml:space="preserve">
<value>Press Any Key</value>
</data>
</root>
22 changes: 8 additions & 14 deletions Picker/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void OnSettingsUI(UIHelperBase helper)

group.AddSpace(10);

((UIPanel)((UIHelper)group).self).gameObject.AddComponent<OptionsKeymappingMain>();
((UIPanel)((UIHelper)group).self).gameObject.AddComponent<OptionsKeymapping>();
UIPanel panel = ((UIHelper)group).self as UIPanel;

group.AddSpace(20);
Expand Down Expand Up @@ -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;
}
}

Expand Down
171 changes: 5 additions & 166 deletions Picker/OptionsKeymapping.cs
Original file line number Diff line number Diff line change
@@ -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<UILabel>("Name");
UIButton uIButton = uIPanel.Find<UIButton>("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<UIComponent>())
{
UITextComponent uITextComponent = current.Find<UITextComponent>("Binding");
SavedInputKey savedInputKey = (SavedInputKey)uITextComponent.objectUserData;
if (this.m_EditingBinding != savedInputKey)
{
uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
}
}
AddKeymapping(Localize.keybind_ToggleTool, toggleTool);
}
}
}
1 change: 1 addition & 0 deletions Picker/Picker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<EmbeddedResource Include="Localization\Localize.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localize.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Localization\Localize.ru.resx" />
<EmbeddedResource Include="Localization\Localize.th.resx" />
Expand Down

0 comments on commit 22c1c7d

Please sign in to comment.