Fix bogus handling of special keyboard characters everywhere else. Textfields now only accept valid characters, support right-delete.
This commit is contained in:
@@ -112,6 +112,13 @@ namespace OpenRA
|
|||||||
return (k & mod) == mod;
|
return (k & mod) == mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsValidInput(this KeyInput key)
|
||||||
|
{
|
||||||
|
return char.IsLetter(key.UnicodeChar) || char.IsDigit(key.UnicodeChar) ||
|
||||||
|
char.IsSymbol(key.UnicodeChar) || char.IsSeparator(key.UnicodeChar) ||
|
||||||
|
char.IsPunctuation(key.UnicodeChar);
|
||||||
|
}
|
||||||
|
|
||||||
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
|
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
|
||||||
where V : new()
|
where V : new()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace OpenRA
|
|||||||
public struct KeyInput
|
public struct KeyInput
|
||||||
{
|
{
|
||||||
public KeyInputEvent Event;
|
public KeyInputEvent Event;
|
||||||
public char KeyChar;
|
public char UnicodeChar;
|
||||||
public string KeyName;
|
public string KeyName;
|
||||||
public Modifiers Modifiers;
|
public Modifiers Modifiers;
|
||||||
public int VirtKey;
|
public int VirtKey;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
if (e.Event == KeyInputEvent.Up) return false;
|
if (e.Event == KeyInputEvent.Up) return false;
|
||||||
|
|
||||||
if (e.KeyChar == '\r')
|
if (e.KeyName == "return" || e.KeyName == "enter" )
|
||||||
{
|
{
|
||||||
if (composing)
|
if (composing)
|
||||||
{
|
{
|
||||||
@@ -94,15 +94,15 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
if (composing)
|
if (composing)
|
||||||
{
|
{
|
||||||
if (e.KeyChar == '\b' || e.KeyChar == 0x7f)
|
if (e.KeyName == "backspace")
|
||||||
{
|
{
|
||||||
if (content.Length > 0)
|
if (content.Length > 0)
|
||||||
content = content.Remove(content.Length - 1);
|
content = content.Remove(content.Length - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (!char.IsControl(e.KeyChar))
|
else if (e.IsValidInput())
|
||||||
{
|
{
|
||||||
content += e.KeyChar;
|
content += e.UnicodeChar.ToString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,10 +95,10 @@ namespace OpenRA.Widgets
|
|||||||
if (!Focused)
|
if (!Focused)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (e.KeyChar == '\r' && OnEnterKey())
|
if ((e.KeyName == "return" || e.KeyName == "enter") && OnEnterKey())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (e.KeyChar == '\t' && OnTabKey())
|
if (e.KeyName == "tab" && OnTabKey())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (e.KeyName == "left")
|
if (e.KeyName == "left")
|
||||||
@@ -126,31 +126,29 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeChar(e.KeyChar);
|
TypeChar(e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TypeChar(char c)
|
public void TypeChar(KeyInput key)
|
||||||
{
|
|
||||||
// backspace
|
|
||||||
if (c == '\b' || c == 0x7f)
|
|
||||||
{
|
|
||||||
if (Text.Length > 0 && CursorPosition > 0)
|
|
||||||
{
|
|
||||||
Text = Text.Remove(CursorPosition - 1, 1);
|
|
||||||
|
|
||||||
CursorPosition--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!char.IsControl(c))
|
|
||||||
{
|
{
|
||||||
if (Text == null)
|
if (Text == null)
|
||||||
Text = "";
|
Text = "";
|
||||||
|
|
||||||
|
if (key.KeyName == "backspace" && Text.Length > 0 && CursorPosition > 0)
|
||||||
|
{
|
||||||
|
Text = Text.Remove(CursorPosition - 1, 1);
|
||||||
|
CursorPosition--;
|
||||||
|
}
|
||||||
|
else if (key.KeyName == "delete" && Text.Length > 0 && CursorPosition < Text.Length - 1)
|
||||||
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
|
|
||||||
|
else if (key.IsValidInput())
|
||||||
|
{
|
||||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Text = Text.Insert(CursorPosition, c.ToString());
|
Text = Text.Insert(CursorPosition, key.UnicodeChar.ToString());
|
||||||
|
|
||||||
CursorPosition++;
|
CursorPosition++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
if (e.Event == KeyInputEvent.Down)
|
if (e.Event == KeyInputEvent.Down)
|
||||||
{
|
{
|
||||||
if (e.KeyChar == 27) // Escape
|
if (e.KeyName == "escape")
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DoBuildingHotkey(Char.ToLowerInvariant(e.KeyChar), world);
|
return DoBuildingHotkey(e.KeyName, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: BuildPaletteWidget doesn't support delegate methods for mouse input
|
// TODO: BuildPaletteWidget doesn't support delegate methods for mouse input
|
||||||
@@ -499,12 +499,12 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
p.ToInt2(), Color.White);
|
p.ToInt2(), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DoBuildingHotkey(char c, World world)
|
bool DoBuildingHotkey(string key, World world)
|
||||||
{
|
{
|
||||||
if (!paletteOpen) return false;
|
if (!paletteOpen) return false;
|
||||||
if (CurrentQueue == null) return false;
|
if (CurrentQueue == null) return false;
|
||||||
|
|
||||||
var toBuild = CurrentQueue.BuildableItems().FirstOrDefault(b => b.Traits.Get<BuildableInfo>().Hotkey == c.ToString());
|
var toBuild = CurrentQueue.BuildableItems().FirstOrDefault(b => b.Traits.Get<BuildableInfo>().Hotkey == key);
|
||||||
|
|
||||||
if ( toBuild != null )
|
if ( toBuild != null )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
public World World { get { return OrderManager.world; } }
|
public World World { get { return OrderManager.world; } }
|
||||||
|
|
||||||
public char AttackMoveKey = 'a';
|
public string AttackMoveKey = "a";
|
||||||
public char StopKey = 's';
|
public string StopKey = "s";
|
||||||
public char ScatterKey = 'x';
|
public string ScatterKey = "x";
|
||||||
public char DeployKey = 'f';
|
public string DeployKey = "f";
|
||||||
|
public string BaseCycleKey = "backspace";
|
||||||
public readonly OrderManager OrderManager;
|
public readonly OrderManager OrderManager;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -40,22 +41,22 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
if (e.Modifiers == Modifiers.None)
|
if (e.Modifiers == Modifiers.None)
|
||||||
{
|
{
|
||||||
if (e.KeyChar == '\b' || e.KeyChar == (char)127)
|
if (e.KeyName == BaseCycleKey)
|
||||||
return CycleBases();
|
return CycleBases();
|
||||||
|
|
||||||
if (!World.Selection.Actors.Any())
|
if (!World.Selection.Actors.Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (e.KeyChar == AttackMoveKey)
|
if (e.KeyName == AttackMoveKey)
|
||||||
return PerformAttackMove();
|
return PerformAttackMove();
|
||||||
|
|
||||||
if (e.KeyChar == StopKey)
|
if (e.KeyName == StopKey)
|
||||||
return PerformStop();
|
return PerformStop();
|
||||||
|
|
||||||
if (e.KeyChar == ScatterKey)
|
if (e.KeyName == ScatterKey)
|
||||||
return PerformScatter();
|
return PerformScatter();
|
||||||
|
|
||||||
if (e.KeyChar == DeployKey)
|
if (e.KeyName == DeployKey)
|
||||||
return PerformDeploy();
|
return PerformDeploy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ namespace OpenRA.Renderer.Cg
|
|||||||
{
|
{
|
||||||
Event = KeyInputEvent.Down,
|
Event = KeyInputEvent.Down,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
UnicodeChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
@@ -258,7 +258,7 @@ namespace OpenRA.Renderer.Cg
|
|||||||
{
|
{
|
||||||
Event = KeyInputEvent.Up,
|
Event = KeyInputEvent.Up,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
UnicodeChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
{
|
{
|
||||||
Event = KeyInputEvent.Down,
|
Event = KeyInputEvent.Down,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
UnicodeChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
@@ -253,7 +253,7 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
{
|
{
|
||||||
Event = KeyInputEvent.Up,
|
Event = KeyInputEvent.Up,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
UnicodeChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user