-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom citizen information into info panels (closes #83)
- Loading branch information
Showing
17 changed files
with
548 additions
and
0 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
55 changes: 55 additions & 0 deletions
55
src/RealTime/GameConnection/Patches/WorldInfoPanelPatches.cs
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// <copyright file="WorldInfoPanelPatches.cs" company="dymanoid"> | ||
// Copyright (c) dymanoid. All rights reserved. | ||
// </copyright> | ||
|
||
namespace RealTime.GameConnection.Patches | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using RealTime.UI; | ||
using SkyTools.Patching; | ||
|
||
/// <summary> | ||
/// A static class that provides the patch objects for the world info panel game methods. | ||
/// </summary> | ||
internal static class WorldInfoPanelPatches | ||
{ | ||
/// <summary>Gets or sets the customized citizen information panel.</summary> | ||
public static CustomCitizenInfoPanel CitizenInfoPanel { get; set; } | ||
|
||
/// <summary>Gets or sets the customized vehicle information panel.</summary> | ||
public static CustomVehicleInfoPanel VehicleInfoPanel { get; set; } | ||
|
||
/// <summary>Gets the patch for the update bindings method.</summary> | ||
public static IPatch UpdateBindings { get; } = new WorldInfoPanel_UpdateBindings(); | ||
|
||
private sealed class WorldInfoPanel_UpdateBindings : PatchBase | ||
{ | ||
protected override MethodInfo GetMethod() | ||
{ | ||
return typeof(WorldInfoPanel).GetMethod( | ||
"UpdateBindings", | ||
BindingFlags.Instance | BindingFlags.NonPublic, | ||
null, | ||
new Type[0], | ||
new ParameterModifier[0]); | ||
} | ||
|
||
#pragma warning disable SA1313 // Parameter names must begin with lower-case letter | ||
private static void Postfix(WorldInfoPanel __instance, ref InstanceID ___m_InstanceID) | ||
{ | ||
switch (__instance) | ||
{ | ||
case CitizenWorldInfoPanel _: | ||
CitizenInfoPanel?.UpdateCustomInfo(ref ___m_InstanceID); | ||
break; | ||
|
||
case VehicleWorldInfoPanel _: | ||
VehicleInfoPanel?.UpdateCustomInfo(ref ___m_InstanceID); | ||
break; | ||
} | ||
} | ||
#pragma warning restore SA1313 // Parameter names must begin with lower-case letter | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// <copyright file="CustomCitizenInfoPanel.cs" company="dymanoid"> | ||
// Copyright (c) dymanoid. All rights reserved. | ||
// </copyright> | ||
|
||
namespace RealTime.UI | ||
{ | ||
using RealTime.CustomAI; | ||
using SkyTools.Localization; | ||
|
||
/// <summary> | ||
/// A customized citizen info panel that additionally shows the origin building of the citizen. | ||
/// </summary> | ||
internal sealed class CustomCitizenInfoPanel : RealTimeInfoPanelBase<HumanWorldInfoPanel> | ||
{ | ||
private const string GameInfoPanelName = "(Library) CitizenWorldInfoPanel"; | ||
|
||
private CustomCitizenInfoPanel(string panelName, RealTimeResidentAI<ResidentAI, Citizen> residentAI, ILocalizationProvider localizationProvider) | ||
: base(panelName, residentAI, localizationProvider) | ||
{ | ||
} | ||
|
||
/// <summary>Enables the citizen info panel customization. Can return null on failure.</summary> | ||
/// <param name="residentAI">The custom resident AI.</param> | ||
/// <param name="localizationProvider">The localization provider to use for text translation.</param> | ||
/// <returns>An instance of the <see cref="CustomCitizenInfoPanel"/> object that can be used for disabling | ||
/// the customization, or null when the customization fails.</returns> | ||
public static CustomCitizenInfoPanel Enable(RealTimeResidentAI<ResidentAI, Citizen> residentAI, ILocalizationProvider localizationProvider) | ||
{ | ||
var result = new CustomCitizenInfoPanel(GameInfoPanelName, residentAI, localizationProvider); | ||
return result.Initialize() ? result : null; | ||
} | ||
|
||
/// <summary>Updates the origin building display.</summary> | ||
/// <param name="instance">The game object instance to get the information from.</param> | ||
public override void UpdateCustomInfo(ref InstanceID instance) | ||
{ | ||
if (instance.Type != InstanceType.Citizen) | ||
{ | ||
UpdateCitizenInfo(0); | ||
} | ||
else | ||
{ | ||
UpdateCitizenInfo(instance.Citizen); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.