Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #46 from joseasoler/RenameDrones
Browse files Browse the repository at this point in the history
Allow renaming drones
  • Loading branch information
Taranchuk authored Jun 3, 2022
2 parents 4184009 + 2399c03 commit e51c8fa
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Languages/English/Keyed/Machines.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
<VFEMechSetAreaDesc>Set the allowed area for all of this platform's associated machines.</VFEMechSetAreaDesc>
<VFEMRideableMachineTip>This droid is rideable. People in a caravan will ride the fastest available animals/droids, improving the speed of the caravan as a whole.</VFEMRideableMachineTip>
<VFEM.CaravanMachineRanOutPower>{MACHINE_nameDef} ran out of power, and was left behind.</VFEM.CaravanMachineRanOutPower>

<VFEM.DroneGainsName>The drone's name is now {0}.</VFEM.DroneGainsName>
</LanguageData>
2 changes: 2 additions & 0 deletions Source/VFECore/VFECore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@
<Compile Include="VFECore\HarmonyPatches\Def_SpecialDisplayStats_Patch.cs" />
<Compile Include="Memes\PlaceWorkers\PlaceWorker_DisabledByMeme.cs" />
<Compile Include="VFECore\Comps\HediffComps\HediffComp_Targeting.cs" />
<Compile Include="VFECore\Dialogs\Dialog_NameDrone.cs" />
<Compile Include="VFECore\HarmonyPatches\Mechanoids\MainTabWindow_Patches.cs" />
<Compile Include="VFECore\HarmonyPatches\Stat_Patches.cs" />
<Compile Include="VFECore\HarmonyPatches\MapGenerator_GenerateContentsIntoMap_Patch.cs" />
<Compile Include="VFECore\HarmonyPatches\GenStep_Terrain_TerrainFrom_Patch.cs" />
Expand Down
26 changes: 26 additions & 0 deletions Source/VFECore/VFECore/Dialogs/Dialog_NameDrone.cs
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);
}
}
}
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;
}
}
}
6 changes: 6 additions & 0 deletions Source/VFECore/VFECore/Pawns/Machine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public override void SpawnSetup(Map map, bool respawningAfterLoad)
this.drafter = new Pawn_DraftController(this);
}
}

if (this.Faction == Faction.OfPlayer && this.Name == null)
{
this.Name = PawnBioAndNameGenerator.GeneratePawnName(this, NameStyle.Numeric);
}
}

public override void PostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
{
base.PostApplyDamage(dinfo, totalDamageDealt);
Expand Down

0 comments on commit e51c8fa

Please sign in to comment.