Skip to content

Commit 9035804

Browse files
committed
Handle GamepadControl API differences
1 parent 6b2006c commit 9035804

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/kc-accessibility/ScreenReaderAccessibilityBehaviour.Helpers.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
public partial class ScreenReaderAccessibilityBehaviour
1111
{
1212
private static readonly FieldInfo GameUiCursorModeField = typeof(GameUI).GetField("currCursorMode", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
13+
private static readonly FieldInfo GamepadControlIsControllerActiveField = typeof(GamepadControl).GetField("isControllerActive", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
14+
private static readonly FieldInfo GamepadControlControllerUpdateField = typeof(GamepadControl).GetField("controllerUpdate", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
1315
private const int SettingsSaveIndex = -2;
1416

1517
private sealed class GameplayTileElement
@@ -262,6 +264,31 @@ private bool HasActiveAccessibleGameplayPanel()
262264
return IsIslandInfoPanelVisible(GameUI.inst);
263265
}
264266

267+
private void PrimeGamepadControlForKeyboardNavigation()
268+
{
269+
GamepadControl control = GamepadControl.inst;
270+
if (control == null)
271+
{
272+
return;
273+
}
274+
275+
if (GamepadControlIsControllerActiveField != null)
276+
{
277+
GamepadControlIsControllerActiveField.SetValue(
278+
GamepadControlIsControllerActiveField.IsStatic ? null : (object)control,
279+
true);
280+
}
281+
282+
if (GamepadControlControllerUpdateField != null)
283+
{
284+
Delegate controllerUpdate = GamepadControlControllerUpdateField.GetValue(
285+
GamepadControlControllerUpdateField.IsStatic ? null : (object)control) as Delegate;
286+
controllerUpdate?.DynamicInvoke(true);
287+
}
288+
289+
control.PrepForGamepad();
290+
}
291+
265292
private static bool IsIslandInfoPanelVisible(GameUI gameUi)
266293
{
267294
return gameUi != null

src/kc-accessibility/ScreenReaderAccessibilityBehaviour.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,7 @@ private void EnsureKeyboardNavigationEnabled()
340340
try
341341
{
342342
suppressedHoverAnnouncements++;
343-
GamepadControl.inst.isControllerActive = true;
344-
if (GamepadControl.inst.controllerUpdate != null)
345-
{
346-
GamepadControl.inst.controllerUpdate(true);
347-
}
348-
GamepadControl.inst.PrepForGamepad();
343+
PrimeGamepadControlForKeyboardNavigation();
349344
log("Enabled keyboard-driven accessibility navigation.");
350345
}
351346
catch (Exception ex)

src/kc-accessibility/ScreenReaderLoadMod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class ScreenReaderLoadMod
66
{
77
private const string InitialAnnouncement = "Kingdoms and Castles loaded.";
8-
private const string BuildStamp = "0.2.4";
8+
private const string BuildStamp = "0.2.5";
99

1010
private static KCModHelper helper;
1111

src/kc-accessibility/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"Name": "kc-accessibility",
33
"Author": "chris",
44
"Description": "Adds screen-reader accessibility support for menus and gameplay.",
5-
"ModVersion": "0.2.4"
5+
"ModVersion": "0.2.5"
66
}

0 commit comments

Comments
 (0)