From 99c40bad532d7f71160361415f0a6bf708993d48 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 18 Oct 2020 13:09:03 +0200 Subject: [PATCH] Add Fog Tools --- About/Manifest.xml | 6 +++ Assemblies/ClaimDoors.dll | Bin 5632 -> 8704 bytes Patches/DesignationCategories.xml | 10 +++++ Source/ClaimDoors.csproj | 10 ++++- Source/ClaimDoorsMain.cs | 39 ++++++++++++++++++ Source/Designator_AddFog.cs | 16 ++++++++ Source/Designator_Fog.cs | 62 +++++++++++++++++++++++++++++ Source/Designator_RemoveFog.cs | 16 ++++++++ Source/Patches.cs | 25 ++++-------- Source/Properties/AssemblyInfo.cs | 5 +-- Textures/UI/Designators/Hide.png | Bin 0 -> 1211 bytes Textures/UI/Designators/Reveal.png | Bin 0 -> 450 bytes 12 files changed, 168 insertions(+), 21 deletions(-) create mode 100644 About/Manifest.xml create mode 100644 Patches/DesignationCategories.xml create mode 100644 Source/ClaimDoorsMain.cs create mode 100644 Source/Designator_AddFog.cs create mode 100644 Source/Designator_Fog.cs create mode 100644 Source/Designator_RemoveFog.cs create mode 100644 Textures/UI/Designators/Hide.png create mode 100644 Textures/UI/Designators/Reveal.png 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 d5c2ff26059edf2c0efbb3711843ccbf64650612..0e878ab1357b42363dadfacdd2ca0cf3dba54311 100644 GIT binary patch literal 8704 zcmeHMYj7M@c0RXfre`!3vNX0O8-!{30fQc6Jq*}jjAcD+84KBxZ0{0nlsF0%gL5gHeAXGV<6yZl| zLsDh(o!c{`L3TFDk7WPkN`3mg?z!ild+)io?~FeD1citwjOUY2h+e>(%MJy9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f<-PlK%gt4*@VQf-1SR9PDyRu@}J9=+n z8)2Oe$xsuWH>iI!!XHEpF^&i%_yg1*CTd*#NQ?x~_yZFY0tsJ67vFO>kdxf!ywCH# z=RNQFxc5#5Cw*^BmwhyU_nL+CVbwqm3AP2X*EjQFZ;r(Wba7z=FfGq`^0M~; z*~Hr`fd5WMSjOYqrugD|tQdDuZj1cwY$(0V}lR6;*mQ_{DS5J^;nYUS~O1*#_t0uXpg49ZF zIdOYswoNM}BVQ{bv}rEFs=uzxuUjbLB+uI=$w3>l5iMGEhDNoTolW-iWdt1yW`fFXwMo1E*L$r~*)G?x&qw=&2Co z0%^WIpt(i=Fo>@TrWAB0Es89yjkYq>trgV`K{VSiMVejG;Nxkw#xp&9U*MR)7YS`R zLFmFIVb2MD4zJTbpT?Z*rPnVi*QN0rPNE6Miy3$R!WJb>3S4#v*XRvr^6 zF5q)%0=M9ir{KpDoFUA^Il^N6OjwRv)D?J^X5~*P|88)=!o&Z`?iRhlE(6qi0 zO`Y0cDz2_KQ%h@0x5b8cXvz2>7Na9^6&=BtKBDR2NZh=iv&PvO9_bDz)r2w7t?34_ zHZ`FpXE!f9!p!@Q)s5}pkb>yAqZ@a$I%iG$A*KNmel=&L_=e`p$wadqZbPA`3&al_R=eyQ+>;QMu@j?)8ovdo>! zSEf61GBa3#(#MotvP~JzC{R>M*(F)s5-TZmI+#?Tq*y5)qAHa_ve+rw#wBG}rki|y zEDywa5{sMerq#`uGA6qz)D2~f&RiMGJU8CoTU2}f7)|5Iq-ZgZgRT>^(sfsQXb{b8 zHWgJ$63kdpgjJj06m7R!_}9>MyK1rn{`%U$T7ONTE>LFLtIQER@!e~8fBLfZz<|+^0(-YFJkv zll>!u5%?DWems4v&+IOCNewe*jb?4{0Z aURh5#wsJblz3|)J*)*H$zR6~)GyVg{41st6 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 0000000000000000000000000000000000000000..ccb6a429171475b1a4d8c325ca5e17642c1fe16c GIT binary patch literal 1211 zcmV;s1VsCZP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1W-vtK~#8N-J3mc z)G!=}9gwObIu!LqNL;u32ryhFRPhPQ((VW`Ffgzof;lWS^PB_;-n&g>MI&vKp092(K&v1WFK7ajxtxcG!)nX<1|J(djXJ z-9MGJpd5p#K(QDBPYE%@o3Q1|?0YyTSe5z1gJu3QoK)qf=f=@ecUxAmQ?(39)6`l{ zSJyJ(FF$_BUj6N8CgA-;1Zhf4X@)ML#z;O2uMW2yC**~WAy&aEbDK*khOBEh6gl+ z#s&72DS(Gg`H&bE)XU&wKC{i=H}B;q{+Rk@D3!=HsN*AH#Nkzj?_U(vF!V-^r`*)a zO_uii?CkSbQO7IlcwZ&PX-^o&zy8J+FHZ)G=QezxZA5Xwb|#GR$mf6=b)~XPXRg7) zKHd29^dg19S~7WLH#q_7KV^>GF-wFMG{Q=MOh*wObj5<+*NZYK&65}vR~ zhz_otYQrH{(p<;%2OXb>9J;z=d$gmlFQ?t2q6(;b8xig3;q@soet_lDIYkdMTh`L{$mS0_qr^FiGHjUFXjb!~X|Sgp+_ehbIgY4tbw@WfDpS zG$A|@BEc%4N#O}!355ch7@qKvU=+~g@Pw;`oPaijC%A+)-v5uX3UU%M0@@Uw;1YT~ zhx+w7BVj0@jo}HK1R-c)}hOdvLH%)bzwO}xANTm4Aipdz Z_8(YeU8=L)kbD3D002ovPDHLkV1jZzB|QKD literal 0 HcmV?d00001 diff --git a/Textures/UI/Designators/Reveal.png b/Textures/UI/Designators/Reveal.png new file mode 100644 index 0000000000000000000000000000000000000000..238dae9ceaddaeabc77e159db6f086835be2c924 GIT binary patch literal 450 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc4dI?Hjv*CsZ!bskH5>4-1ibkB-X~Q=S>0m7 zQL~V_-e}$;G6@f1r~xdCAfV hCn{lK#PHy~&S~+LU1dVLjS?q8qMojPF6*2Ung9fIv%>%Y literal 0 HcmV?d00001