This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from joseasoler/RenameDrones
Allow renaming drones
- Loading branch information
Showing
5 changed files
with
72 additions
and
1 deletion.
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
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,26 @@ | ||
using RimWorld; | ||
using Verse; | ||
using VFEMech; | ||
|
||
namespace VFECore | ||
{ | ||
// Dialog_NamePawn only supports persons or animals. Drones need a separate (but simpler) implementation. | ||
public class Dialog_NameDrone : Dialog_Rename | ||
{ | ||
private readonly Machine drone; | ||
|
||
public Dialog_NameDrone(Machine pawn) | ||
{ | ||
drone = pawn; | ||
curName = drone.Name.ToStringShort; | ||
} | ||
|
||
protected override void SetName(string name) | ||
{ | ||
drone.Name = new NameSingle(name); | ||
|
||
Messages.Message("VFEM.DroneGainsName".Translate((NamedArgument)name), (Thing)drone, | ||
MessageTypeDefOf.PositiveEvent, false); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Source/VFECore/VFECore/HarmonyPatches/Mechanoids/MainTabWindow_Patches.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,37 @@ | ||
using HarmonyLib; | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
using VFECore; | ||
using VFEMech; | ||
|
||
namespace VFE.Mechanoids.HarmonyPatches | ||
{ | ||
[HarmonyPatch(typeof(MainTabWindow_Inspect), nameof(MainTabWindow_Inspect.DoInspectPaneButtons))] | ||
public static class MainTabWindow_Inspect_Renaming | ||
{ | ||
/// Show a rename button in the inspect pane when a single drone is selected. | ||
public static void Postfix(Rect rect, ref float lineEndWidth) | ||
{ | ||
// Only functioning drones belonging to the player faction can be renamed. | ||
if (Find.Selector.NumSelected != 1 || !(Find.Selector.SingleSelectedThing is Machine drone) || | ||
drone.health.Dead || drone.Faction != Faction.OfPlayer) | ||
{ | ||
return; | ||
} | ||
|
||
const float renameSize = 30f; | ||
// See MainTabWindow_Inspect.DoInspectPaneButtons for the initial value of x. | ||
float x = rect.width - 48f - renameSize; | ||
|
||
Rect renameArea = new Rect(x, 0.0f, renameSize, renameSize); | ||
TooltipHandler.TipRegionByKey(renameArea, "Rename"); | ||
if (Widgets.ButtonImage(renameArea, TexButton.Rename)) | ||
{ | ||
Find.WindowStack.Add(new Dialog_NameDrone(drone)); | ||
} | ||
|
||
lineEndWidth += renameSize; | ||
} | ||
} | ||
} |
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