diff --git a/About/Manifest.xml b/About/Manifest.xml new file mode 100644 index 0000000..f077152 --- /dev/null +++ b/About/Manifest.xml @@ -0,0 +1,6 @@ + + + 1.1.0 + https://raw.githubusercontent.com/Toby222/ClaimDoors/About/Manifest.xml + https://github.com/Toby222/ClaimDoors/releases/v1.1.0 + \ No newline at end of file diff --git a/Assemblies/ClaimDoors.dll b/Assemblies/ClaimDoors.dll index d5c2ff2..0e878ab 100644 Binary files a/Assemblies/ClaimDoors.dll and b/Assemblies/ClaimDoors.dll differ diff --git a/Patches/DesignationCategories.xml b/Patches/DesignationCategories.xml new file mode 100644 index 0000000..15f8e11 --- /dev/null +++ b/Patches/DesignationCategories.xml @@ -0,0 +1,10 @@ + + + + /Defs/DesignationCategoryDef[defName="Orders"]/specialDesignatorClasses + +
  • ClaimDoors.Designator_RemoveFog
  • +
  • ClaimDoors.Designator_AddFog
  • +
    +
    +
    \ No newline at end of file diff --git a/Source/ClaimDoors.csproj b/Source/ClaimDoors.csproj index 68bae83..f45a778 100644 --- a/Source/ClaimDoors.csproj +++ b/Source/ClaimDoors.csproj @@ -48,10 +48,18 @@ ..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll False + + ..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll + False + - + + + + + diff --git a/Source/ClaimDoorsMain.cs b/Source/ClaimDoorsMain.cs new file mode 100644 index 0000000..868b814 --- /dev/null +++ b/Source/ClaimDoorsMain.cs @@ -0,0 +1,39 @@ +using HarmonyLib; +using Verse; + +namespace ClaimDoors +{ + internal class ClaimDoorsMod : Mod + { + public ClaimDoorsMod(ModContentPack content) : base(content) + { + GetSettings(); + new Harmony("tobs.claimdoors.mod").PatchAll(); + } + + public override string SettingsCategory() => "Claim Doors"; + + public override void DoSettingsWindowContents(UnityEngine.Rect inRect) + { + Listing_Standard listingStandard = new Listing_Standard(); + listingStandard.Begin(inRect); + listingStandard.CheckboxLabeled("Enable Fog Tools", ref ClaimDoorsSettings.enableFogTool); + listingStandard.End(); + base.DoSettingsWindowContents(inRect); + } + } + + internal class ClaimDoorsSettings : ModSettings + { + public static bool enableFogTool = true; + + /// + /// The part that writes our settings to file. Note that saving is by ref. + /// + public override void ExposeData() + { + Scribe_Values.Look(ref enableFogTool, nameof(enableFogTool)); + base.ExposeData(); + } + } +} \ No newline at end of file diff --git a/Source/Designator_AddFog.cs b/Source/Designator_AddFog.cs new file mode 100644 index 0000000..f004267 --- /dev/null +++ b/Source/Designator_AddFog.cs @@ -0,0 +1,16 @@ +using RimWorld; +using UnityEngine; +using Verse; + +namespace ClaimDoors +{ + public class Designator_AddFog : Designator_Fog + { + public Designator_AddFog() : base(DesignateMode.Add) + { + defaultLabel = "Fog Map"; + defaultDesc = "Cover the map with fog of war."; + icon = ContentFinder.Get("UI/Designators/Hide"); + } + } +} \ No newline at end of file diff --git a/Source/Designator_Fog.cs b/Source/Designator_Fog.cs new file mode 100644 index 0000000..24b5cde --- /dev/null +++ b/Source/Designator_Fog.cs @@ -0,0 +1,62 @@ +using HarmonyLib; +using RimWorld; +using Verse; + +namespace ClaimDoors +{ + public class Designator_Fog : Designator + { + public override int DraggableDimensions => 2; + + public override AcceptanceReport CanDesignateCell(IntVec3 loc) => loc.InBounds(Map) && loc.Fogged(Map) == (mode == DesignateMode.Remove); + + private readonly DesignateMode mode; + public override bool DragDrawMeasurements => true; + public override bool Visible => ClaimDoorsSettings.enableFogTool; + + public Designator_Fog(DesignateMode mode) + { + this.mode = mode; + soundDragSustain = SoundDefOf.Designate_DragStandard; + soundDragChanged = SoundDefOf.Designate_DragStandard_Changed; + useMouseIcon = true; + soundSucceeded = SoundDefOf.Designate_Claim; + } + + public override void DesignateSingleCell(IntVec3 cell) + { + if (CanDesignateCell(cell).Accepted) + { + switch (mode) + { + case DesignateMode.Add: + FogWorker(cell); + break; + + case DesignateMode.Remove: + Traverse.Create(Map.fogGrid).Method("UnfogWorker", cell).GetValue(); + break; + } + } + } + + public override void SelectedUpdate() + { + GenUI.RenderMouseoverBracket(); + } + + public override void RenderHighlight(System.Collections.Generic.List dragCells) => DesignatorUtility.RenderHighlightOverSelectableCells(this, dragCells); + + private void FogWorker(IntVec3 c) + { + Log.Message($"{c} - {Map.cellIndices.CellToIndex(c)} - {Map.fogGrid.fogGrid[Map.cellIndices.CellToIndex(c)]}"); + int index = Map.cellIndices.CellToIndex(c); + Map.fogGrid.fogGrid[index] = true; + if (Current.ProgramState == ProgramState.Playing) + { + Map.mapDrawer.MapMeshDirty(c, MapMeshFlag.Things | MapMeshFlag.FogOfWar); + Map.roofGrid.Drawer.SetDirty(); + } + } + } +} \ No newline at end of file diff --git a/Source/Designator_RemoveFog.cs b/Source/Designator_RemoveFog.cs new file mode 100644 index 0000000..c0fb7c1 --- /dev/null +++ b/Source/Designator_RemoveFog.cs @@ -0,0 +1,16 @@ +using RimWorld; +using UnityEngine; +using Verse; + +namespace ClaimDoors +{ + public class Designator_RemoveFog : Designator_Fog + { + public Designator_RemoveFog() : base(DesignateMode.Remove) + { + defaultLabel = "Unfog Map"; + defaultDesc = "Remove fog of war from the map."; + icon = ContentFinder.Get("UI/Designators/Reveal"); + } + } +} \ No newline at end of file diff --git a/Source/Patches.cs b/Source/Patches.cs index 6209ee5..380edc0 100644 --- a/Source/Patches.cs +++ b/Source/Patches.cs @@ -3,25 +3,16 @@ using System.Linq; using Verse; -namespace ClaimDoors +namespace ClaimDoors.Patches { - [StaticConstructorOnStartup] - internal static class ClaimDoorsMain + [HarmonyPatch(typeof(MapGenerator), nameof(MapGenerator.GenerateMap))] + internal static class UnclaimAllDoorsOnGeneratedMap { - static ClaimDoorsMain() + private static void Postfix(Map __result) { - new Harmony("tobs.claimdoors.mod").PatchAll(); - } - - [HarmonyPatch(typeof(MapGenerator), nameof(MapGenerator.GenerateMap))] - internal static class MapParent_PostMapGenerate - { - private static void Postfix(Map __result) - { - var doors = __result.spawnedThings.Where(thing => thing is Building_Door && thing.Faction != Faction.OfPlayer); - foreach (var door in doors) - door.SetFactionDirect(null); - } + var doors = __result.spawnedThings.Where(thing => thing is Building_Door && thing.Faction != Faction.OfPlayer).Cast(); + foreach (var door in doors) + door.SetFactionDirect(null); } } -} +} \ No newline at end of file diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs index 7d56e6f..3ed8962 100644 --- a/Source/Properties/AssemblyInfo.cs +++ b/Source/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -32,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] \ No newline at end of file diff --git a/Textures/UI/Designators/Hide.png b/Textures/UI/Designators/Hide.png new file mode 100644 index 0000000..ccb6a42 Binary files /dev/null and b/Textures/UI/Designators/Hide.png differ diff --git a/Textures/UI/Designators/Reveal.png b/Textures/UI/Designators/Reveal.png new file mode 100644 index 0000000..238dae9 Binary files /dev/null and b/Textures/UI/Designators/Reveal.png differ