Skip to content

Commit

Permalink
Add Fog Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby222 committed Oct 18, 2020
1 parent 9fea92b commit 99c40ba
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 21 deletions.
6 changes: 6 additions & 0 deletions About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<version>1.1.0</version>
<manifestUri>https://raw.githubusercontent.com/Toby222/ClaimDoors/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/Toby222/ClaimDoors/releases/v1.1.0</downloadUri>
</Manifest>
Binary file modified Assemblies/ClaimDoors.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions Patches/DesignationCategories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>/Defs/DesignationCategoryDef[defName="Orders"]/specialDesignatorClasses</xpath>
<value>
<li>ClaimDoors.Designator_RemoveFog</li>
<li>ClaimDoors.Designator_AddFog</li>
</value>
</Operation>
</Patch>
10 changes: 9 additions & 1 deletion Source/ClaimDoors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@
<HintPath>..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patches.cs" />
<Compile Include="Designator_AddFog.cs" />
<Compile Include="Designator_Fog.cs" />
<Compile Include="Designator_RemoveFog.cs" />
<Compile Include="ClaimDoorsMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Patches.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.0.0.10">
Expand Down
39 changes: 39 additions & 0 deletions Source/ClaimDoorsMain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using HarmonyLib;
using Verse;

namespace ClaimDoors
{
internal class ClaimDoorsMod : Mod
{
public ClaimDoorsMod(ModContentPack content) : base(content)
{
GetSettings<ClaimDoorsSettings>();
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;

/// <summary>
/// The part that writes our settings to file. Note that saving is by ref.
/// </summary>
public override void ExposeData()
{
Scribe_Values.Look(ref enableFogTool, nameof(enableFogTool));
base.ExposeData();
}
}
}
16 changes: 16 additions & 0 deletions Source/Designator_AddFog.cs
Original file line number Diff line number Diff line change
@@ -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<Texture2D>.Get("UI/Designators/Hide");
}
}
}
62 changes: 62 additions & 0 deletions Source/Designator_Fog.cs
Original file line number Diff line number Diff line change
@@ -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<IntVec3> 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();
}
}
}
}
16 changes: 16 additions & 0 deletions Source/Designator_RemoveFog.cs
Original file line number Diff line number Diff line change
@@ -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<Texture2D>.Get("UI/Designators/Reveal");
}
}
}
25 changes: 8 additions & 17 deletions Source/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Building_Door>();
foreach (var door in doors)
door.SetFactionDirect(null);
}
}
}
}
5 changes: 2 additions & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")]
Binary file added Textures/UI/Designators/Hide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Textures/UI/Designators/Reveal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 99c40ba

Please sign in to comment.