Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rework bindings to be dynamic and independent (#1391)
* fix: rework bindings to be dynamic and independent * fix: enum getname type * fix: modifier key label
- Loading branch information
Showing
9 changed files
with
210 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,40 @@ | ||
using Intersect.Client.Framework.GenericClasses; | ||
using Intersect.Client.Framework.Input; | ||
using Intersect.Client.General; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Intersect.Client.Core.Controls | ||
{ | ||
|
||
public partial class ControlMap | ||
{ | ||
public ControlValue Key1; | ||
|
||
public ControlValue Key2; | ||
public List<ControlValue> Bindings { get; } | ||
|
||
public ControlMap(Control control, ControlValue key1, ControlValue key2) | ||
public ControlMap(ControlValue binding, params ControlValue[] alternateBindings) | ||
{ | ||
this.Key1 = key1; | ||
this.Key2 = key2; | ||
} | ||
Bindings = new List<ControlValue>(1 + (alternateBindings?.Length ?? 0)) { binding }; | ||
Bindings.AddRange(alternateBindings ?? Array.Empty<ControlValue>()); | ||
|
||
public bool KeyDown() | ||
{ | ||
if (Key1.IsMouseKey || Key2.IsMouseKey) | ||
if (Bindings.Count < 2) | ||
{ | ||
if (Interface.Interface.MouseHitGui()) | ||
{ | ||
return false; | ||
} | ||
Bindings.Add(ControlValue.Default); | ||
} | ||
} | ||
|
||
if (Key1.IsDown()) | ||
public ControlMap(ControlMap controlMap) | ||
{ | ||
if (controlMap == default) | ||
{ | ||
return true; | ||
throw new ArgumentNullException(nameof(controlMap)); | ||
} | ||
|
||
if (Key2.IsDown()) | ||
var bindings = controlMap.Bindings.ToList(); | ||
if (bindings.Count < 1) | ||
{ | ||
return true; | ||
throw new ArgumentException("The control map does not have at least one binding.", nameof(controlMap)); | ||
} | ||
|
||
return false; | ||
Bindings = new List<ControlValue>(bindings); | ||
} | ||
|
||
public bool KeyDown() => Bindings.Any(button => button.IsDown() && (!button.IsMouseKey || !Interface.Interface.MouseHitGui())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.