Skip to content

Commit

Permalink
Merge pull request #12 from Mehni/fluffy-relations-tab
Browse files Browse the repository at this point in the history
Compatibility fix for Fluffy relations tab
  • Loading branch information
Mehni authored Sep 16, 2018
2 parents 26079cd + fa94d81 commit d9b750c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 35 deletions.
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModSyncNinjaData>
<ID>1e80a892-6217-4b34-9430-85d6ac00e66f</ID>
<ModName>More Faction Interaction</ModName>
<Version>0.1.0.6</Version>
<Version>0.1.0.7</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>Mehni</Owner>
Expand Down
Binary file modified Assemblies/MoreFactionInteraction.dll
Binary file not shown.
23 changes: 23 additions & 0 deletions MoreFactionInteraction/General/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Harmony;
using UnityEngine;
using RimWorld.Planet;
using MoreFactionInteraction.MoreFactionWar;
using System.Reflection;
using System.Reflection.Emit;

Expand Down Expand Up @@ -51,6 +52,28 @@ static HarmonyPatches()
//harmony.Patch(original: AccessTools.Method(type: typeof(ThoughtWorker_PsychicEmanatorSoothe), name: "CurrentStateInternal"), prefix: null, postfix: null,
// transpiler: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(PsychicEmanatorSoothe_Transpiler)));

if (ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Relations Tab"))
{
try
{
((Action)(() =>
{
harmony.Patch(AccessTools.Method(typeof(Fluffy_Relations.MainTabWindow_Relations), nameof(Fluffy_Relations.MainTabWindow_Relations.DrawFactionInformation)), null,
new HarmonyMethod(typeof(HarmonyPatches), nameof(WonderfullyFluffyRelations)));
}))();
}
catch (TypeLoadException) { }
}
}

private static void WonderfullyFluffyRelations(ref float __result, Faction faction, Vector2 pos, float width)
{
if (Find.World.GetComponent<WorldComponent_MFI_FactionWar>().StuffIsGoingDown)
{
Rect canvas = new Rect(pos.x, pos.y + 5, width, 125f);
MainTabWindow_FactionWar.DrawFactionWarBar(canvas);
__result += 125f;
}
}

//private static IEnumerable<CodeInstruction> PsychicEmanatorSoothe_Transpiler(IEnumerable<CodeInstruction> instructions)
Expand Down
4 changes: 4 additions & 0 deletions MoreFactionInteraction/MoreFactionInteraction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Fluffy_Relations">
<HintPath>C:\Program Files (x86)\Steam\steamapps\workshop\content\294100\709317151\Assemblies\Fluffy_Relations.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
48 changes: 28 additions & 20 deletions MoreFactionInteraction/MoreFactionWar/MainTabWindow_FactionWar.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using RimWorld;
using Verse;
using UnityEngine;
using System.Linq;
using System;

namespace MoreFactionInteraction.MoreFactionWar
{
Expand All @@ -9,37 +11,37 @@ public class MainTabWindow_FactionWar : MainTabWindow_Factions
private const float TitleHeight = 70f;
private const float InfoHeight = 60f;

private Texture2D factionOneColorTexture;
private Texture2D factionTwoColorTexture;
private static Texture2D factionOneColorTexture;
private static Texture2D factionTwoColorTexture;

public Texture2D FactionOneColorTexture
public static Texture2D FactionOneColorTexture
{
get
{
if (this.factionOneColorTexture == null)
Faction factionOne = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionOne;

if (factionOneColorTexture == null && factionOne != null)
{
this.factionOneColorTexture = SolidColorMaterials.NewSolidColorTexture(factionOne.Color);
factionOneColorTexture = SolidColorMaterials.NewSolidColorTexture(factionOne.Color);
}
return this.factionOneColorTexture;
return factionOneColorTexture;
}
}

public Texture2D FactionTwoColorTexture
public static Texture2D FactionTwoColorTexture
{
get
{
if (this.factionTwoColorTexture == null)
Faction factionInstigator = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionTwo;

if (factionTwoColorTexture == null && factionInstigator != null)
{
this.factionTwoColorTexture = SolidColorMaterials.NewSolidColorTexture(factionInstigator.Color);
factionTwoColorTexture = SolidColorMaterials.NewSolidColorTexture(factionInstigator.Color);
}
return this.factionTwoColorTexture;
return factionTwoColorTexture;
}
}

readonly Faction factionOne = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionOne;
readonly Faction factionInstigator = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionTwo;



//[TweakValue("MainTabWindow_FactionWar", -100f, 150f)]
private static float yMaxOffset = 0;
Expand All @@ -60,7 +62,7 @@ public override void DoWindowContents(Rect fillRect)
}
else
{
this.DrawFactionWarBar(fillRect);
DrawFactionWarBar(fillRect);

// scooch down original. amount of offset depends on devmode or not (because of devmode "show all" button)
Rect baseRect = fillRect;
Expand All @@ -73,9 +75,15 @@ public override void DoWindowContents(Rect fillRect)
}
}

private void DrawFactionWarBar(Rect fillRect)
public static void DrawFactionWarBar(Rect fillRect)
{
Rect position = new Rect(0f, 0f, fillRect.width, fillRect.height);
if (!Find.World.GetComponent<WorldComponent_MFI_FactionWar>().StuffIsGoingDown)
return;

Faction factionOne = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionOne;
Faction factionInstigator = Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionTwo;

Rect position = new Rect(fillRect.x, fillRect.y, fillRect.width, fillRect.height);
GUI.BeginGroup(position);
Text.Font = GameFont.Small;
GUI.color = Color.white;
Expand All @@ -100,9 +108,9 @@ private void DrawFactionWarBar(Rect fillRect)

//"score card" bar
Rect leftFactionOneScoreBox = new Rect(0f, yPositionBar, position.width * Find.World.GetComponent<WorldComponent_MFI_FactionWar>().ScoreForFaction(factionOne), barHeight);
GUI.DrawTexture(leftFactionOneScoreBox, this.FactionOneColorTexture);
Rect rightFactionTwoScoreBox = new Rect(position.width * Find.World.GetComponent<WorldComponent_MFI_FactionWar>().ScoreForFaction(factionOne), yPositionBar, position.width * Find.World.GetComponent<WorldComponent_MFI_FactionWar>().ScoreForFaction(this.factionInstigator), barHeight);
GUI.DrawTexture(rightFactionTwoScoreBox, this.FactionTwoColorTexture);
GUI.DrawTexture(leftFactionOneScoreBox, FactionOneColorTexture);
Rect rightFactionTwoScoreBox = new Rect(position.width * Find.World.GetComponent<WorldComponent_MFI_FactionWar>().ScoreForFaction(factionOne), yPositionBar, position.width * Find.World.GetComponent<WorldComponent_MFI_FactionWar>().ScoreForFaction(factionInstigator), barHeight);
GUI.DrawTexture(rightFactionTwoScoreBox, FactionTwoColorTexture);

//stuff that fills up and does the faction name and call label boxes.
Text.Font = GameFont.Medium;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public Faction WarringFactionTwo

public bool WarIsOngoing => this.warIsOngoing;
public bool UnrestIsBrewing => this.unrestIsBrewing;
public bool StuffIsGoingDown => this.unrestIsBrewing || this.warIsOngoing;

private void SetFirstWarringFaction(Faction faction)
{
Expand Down
4 changes: 2 additions & 2 deletions MoreFactionInteraction/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,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("0.1.0.6")]
[assembly: AssemblyFileVersion("0.1.0.6")]
[assembly: AssemblyVersion("0.1.0.7")]
[assembly: AssemblyFileVersion("0.1.0.7")]
30 changes: 18 additions & 12 deletions Patches/MoreFactionInteraction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@

<Operation Class="PatchOperationAdd">
<xpath>/Defs/WorldObjectDef[defName="Settlement"]/comps</xpath>
<value>
<li Class="MoreFactionInteraction.World_Incidents.WorldObjectCompProperties_BumperCrop" />
</value>
<value>
<li Class="MoreFactionInteraction.World_Incidents.WorldObjectCompProperties_BumperCrop" />
</value>
</Operation>

<Operation Class="PatchOperationAdd">
<xpath>/Defs/WorldObjectDef[defName="Caravan"]</xpath>
<value>
<comps>
<li>
<compClass>MoreFactionInteraction.World_Incidents.WorldObjectComp_CaravanComp</compClass>
</li>
</comps>
</value>
<value>
<comps>
<li>
<compClass>MoreFactionInteraction.World_Incidents.WorldObjectComp_CaravanComp</compClass>
</li>
</comps>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/Defs/MainButtonDef[defName="Factions"]/tabWindowClass</xpath>
<Operation Class="PatchOperationFindMod">
<mods>
<li>Relations Tab</li>
</mods>
<nomatch Class="PatchOperationReplace">
<xpath>/Defs/MainButtonDef[defName="Factions"]/tabWindowClass</xpath>
<value>
<tabWindowClass>MoreFactionInteraction.MoreFactionWar.MainTabWindow_FactionWar</tabWindowClass>
</value>
</nomatch>

</Operation>

</Patch>

0 comments on commit d9b750c

Please sign in to comment.