Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assemblies/0Harmony.dll
Binary file not shown.
Binary file removed Assemblies/ClassLibrary.dll
Binary file not shown.
Binary file added Assemblies/ColoredMoodBar.dll
Binary file not shown.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# ColorCodedMoodBar
A RimWorld mod to color code each pawn's mood bar within the colonist bar based on their current mood.
A red mood bar indicates the pawn is at or under their extreme mental break threshold, orange indicates the major mental break threshold, yellow indicates the minor mental break threshold, and blue indicates the pawn is not under any mental break threshold.
The bar will turn green if the pawn is particularly happy.

## Known Bugs/Limitations/Requirements:
- None
- Mod incompatibilities:
- "Advanced biomes" and "Rimstory" should be loaded after this mod. Otherwise there might be some conflicts (Thx 2 Xerberus86)

## Updates
- Sep 16 2017: Initial release on GitHub and closed release on Steam
- Sep 17 2017: Open release on Steam
- Nov 18 2017: Updated for RimWord version 0.18.1722, and added content and happy colors.
- Sep 03 2018: Update for Rimworld version 0.19.* and doing some bugfixes.

## Author/Mod Team
- PorqueNoLosDos
- fyarn
- semTex (Update B19)
- PorqueNoLosDos (Update B18)
- fyarn (Original Author)

## Download
- Github (with Source): https://github.com/bcooper94/ColorCodedMoodBar
- Direct: https://github.com/bcooper94/ColorCodedMoodBar/archive/master.zip
- Steam: https://steamcommunity.com/sharedfiles/filedetails/?id=1136819681
- Github (with Source): https://github.com/resTive2k12/ColorCodedMoodBar
- Direct: https://github.com/resTive2k12/ColorCodedMoodBar/archive/master.zip
- Steam: https://steamcommunity.com/sharedfiles/filedetails/?id=1501832876

## How to install (non-Steam users):
- Unzip the contents and place them in your RimWorld/Mods folder.
Expand Down
10 changes: 6 additions & 4 deletions Source/ColoredMoodBar/ColoredMoodBar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ProjectGuid>{2EABFAFA-B6E5-43EB-948F-62FCECCBCCC0}</ProjectGuid>
<OutputType>Library</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>ClassLibrary</AssemblyName>
<AssemblyName>ColoredMoodBar</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -35,7 +35,7 @@
<HintPath>D:\dev\RimWorld Libs\Release\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>G:\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -45,12 +45,13 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\RimWorldWin_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>G:\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="HarmonyPatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include=".vs\MoodBarPatch\v15\.suo" />
Expand All @@ -65,6 +66,7 @@
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
<PropertyGroup>
<PostBuildEvent>..\..\..\RimWorldWin -quicktest</PostBuildEvent>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "E:\Steam Bibliothek\steamapps\common\RimWorld\Mods\ColorCodedMoodBar\Assemblies\$(TargetName).dll"
"E:\Steam Bibliothek\steamapps\common\RimWorld\RimworldWin64.exe" -quicktest</PostBuildEvent>
</PropertyGroup>
</Project>
80 changes: 44 additions & 36 deletions Source/ColoredMoodBar/HarmonyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ public class Main {
public static Texture2D happyTex;

static Main() {
var harmony = HarmonyInstance.Create("com.github.bc.rimworld.mod.moodbar");
var harmony = HarmonyInstance.Create("com.github.restive2k12.rimworld.mod.moodbar");
harmony.PatchAll(Assembly.GetExecutingAssembly());

drawSelectionOverlayOnGUIMethod = typeof(ColonistBarColonistDrawer).GetMethod("DrawSelectionOverlayOnGUI",
BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Pawn), typeof(Rect) }, null);
drawCaravanSelectionOverlayOnGUIMethod = typeof(ColonistBarColonistDrawer).GetMethod("DrawCaravanSelectionOverlayOnGUI",
BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Caravan), typeof(Rect) }, null);
getPawnTextureRectMethod = typeof(ColonistBarColonistDrawer).GetMethod("GetPawnTextureRect", BindingFlags.Instance | BindingFlags.NonPublic,
null, new Type[] { typeof(float), typeof(float) }, null);

drawIconsMethod = typeof(ColonistBarColonistDrawer).GetMethod("DrawIcons", BindingFlags.Instance | BindingFlags.NonPublic,
null, new Type[] { typeof(Rect), typeof(Pawn) }, null);
pawnTextureCameraOffsetField = typeof(ColonistBarColonistDrawer).GetField("PawnTextureCameraOffset",
Expand All @@ -42,11 +44,11 @@ static Main() {
BindingFlags.Static | BindingFlags.NonPublic);
pawnLabelsCacheField = typeof(ColonistBarColonistDrawer).GetField("pawnLabelsCache",
BindingFlags.Instance | BindingFlags.NonPublic);
float colorAlpha = 0.44f;
float colorAlpha = 0.6f;
Color red = Color.red;
Color orange = new Color(1f, 0.5f, 0.31f, colorAlpha);
Color yellow = Color.yellow;
Color neutralColor = new Color(0.87f, 0.96f, 0.79f, colorAlpha);
Color neutralColor = new Color(0.77f, 0.96f, 0.69f, colorAlpha);
Color cyan = Color.cyan;
Color happyColor = new Color(0.1f, 0.75f, 0.2f, colorAlpha);
red.a = orange.a = yellow.a = cyan.a = colorAlpha;
Expand All @@ -57,47 +59,57 @@ static Main() {
neutralTex = SolidColorMaterials.NewSolidColorTexture(neutralColor);
contentTex = SolidColorMaterials.NewSolidColorTexture(cyan);
happyTex = SolidColorMaterials.NewSolidColorTexture(happyColor);
LogMessage("ColorCodedMoodBar initialized");
LogMessage("initialized");
}

public static void LogMessage(string text) {
Log.Message("[ColorCodedMoodBar] " + text);
}
}

[HarmonyPatch(typeof(ColonistBarColonistDrawer), "DrawColonist")]
[HarmonyPatch(typeof(ColonistBarColonistDrawer))]
[HarmonyPatch("DrawColonist")]
[HarmonyPatch(new Type[ ] { typeof(Rect) , typeof(Pawn) , typeof(Map) , typeof(bool) , typeof(bool) } )]
public class MoodPatch {
private static float ApplyEntryInAnotherMapAlphaFactor(Map map, float alpha) {

if (map == null) {
if (!WorldRendererUtility.WorldRenderedNow) {
alpha = Mathf.Min(alpha, 0.4f);
}
}
else if (map != Find.VisibleMap || WorldRendererUtility.WorldRenderedNow) {

else if (map != Find.CurrentMap || WorldRendererUtility.WorldRenderedNow) {
alpha = Mathf.Min(alpha, 0.4f);
}

return alpha;
}

public static bool Prefix(ColonistBarColonistDrawer __instance, ref Rect rect, ref Pawn colonist, ref Map pawnMap) {
public static bool Prefix(ColonistBarColonistDrawer __instance, ref Rect rect, ref Pawn colonist, ref Map pawnMap, ref bool highlight, ref bool reordering) {
ColonistBar colonistBar = Find.ColonistBar;
float entryRectAlpha = colonistBar.GetEntryRectAlpha(rect);
entryRectAlpha = ApplyEntryInAnotherMapAlphaFactor(pawnMap, entryRectAlpha);
bool flag = (!colonist.Dead) ? Find.Selector.SelectedObjects.Contains(colonist) : Find.Selector.SelectedObjects.Contains(colonist.Corpse);
Color color = new Color(1f, 1f, 1f, entryRectAlpha);
float alpha = ApplyEntryInAnotherMapAlphaFactor(pawnMap, colonistBar.GetEntryRectAlpha(rect));

Rect pawnBackgroundSize = rect.ExpandedBy(2.5f);

if (reordering) {
alpha *= 0.5f;
}
Color color = new Color(1f, 1f, 1f, alpha);
GUI.color = color;
GUI.DrawTexture(rect, ColonistBar.BGTex);

if (colonist.needs != null && colonist.needs.mood != null) {
Rect position = rect.ContractedBy(2f);
float num = position.height * colonist.needs.mood.CurLevelPercentage;
position.yMin = position.yMax - num;
position.height = num;
Rect position = pawnBackgroundSize.ContractedBy(2f);
float value = position.height * colonist.needs.mood.CurLevelPercentage;
position.yMin = position.yMax - value;
position.height = value;


float statValue = colonist.GetStatValue(StatDefOf.MentalBreakThreshold, true);

float currentMoodLevel = colonist.needs.mood.CurLevel;


// Extreme break threshold
if (currentMoodLevel <= statValue) {
GUI.DrawTexture(position, Main.extremeBreakTex);
Expand All @@ -123,36 +135,32 @@ public static bool Prefix(ColonistBarColonistDrawer __instance, ref Rect rect, r
else {
GUI.DrawTexture(position, Main.happyTex);
}
}

}
if (highlight) {
int thickness = (rect.width > 22f) ? 3 : 2;
GUI.color = Color.white;
Widgets.DrawBox(rect, thickness);
GUI.color = color;
}
Rect rect2 = rect.ContractedBy(-2f * colonistBar.Scale);

if (flag && !WorldRendererUtility.WorldRenderedNow) {
bool notdeadandselected = (!colonist.Dead) ? Find.Selector.SelectedObjects.Contains(colonist) : Find.Selector.SelectedObjects.Contains(colonist.Corpse);
if (notdeadandselected && !WorldRendererUtility.WorldRenderedNow) {
Main.drawSelectionOverlayOnGUIMethod.Invoke(__instance, new object[] { colonist, rect2 });
}
else if (WorldRendererUtility.WorldRenderedNow && colonist.IsCaravanMember() && Find.WorldSelector.IsSelected(colonist.GetCaravan())) {
} else if (WorldRendererUtility.WorldRenderedNow && colonist.IsCaravanMember() && Find.WorldSelector.IsSelected(colonist.GetCaravan())) {
Main.drawCaravanSelectionOverlayOnGUIMethod.Invoke(__instance, new object[] { colonist.GetCaravan(), rect2 });
}
GUI.DrawTexture(__instance.GetPawnTextureRect(rect.position), PortraitsCache.Get(colonist, ColonistBarColonistDrawer.PawnTextureSize, ColonistBarColonistDrawer.PawnTextureCameraOffset, 1.28205f));

Rect pawnTexturePosition = (Rect) Main.getPawnTextureRectMethod.Invoke(__instance, new object[] { rect.x, rect.y });

GUI.DrawTexture(pawnTexturePosition, PortraitsCache.Get(colonist, ColonistBarColonistDrawer.PawnTextureSize,
(Vector3) Main.pawnTextureCameraOffsetField.GetValue(null),
1.28205f));
GUI.color = new Color(1f, 1f, 1f, entryRectAlpha * 0.8f);
GUI.color = new Color(1f, 1f, 1f, alpha * 0.8f);
Main.drawIconsMethod.Invoke(__instance, new object[] { rect, colonist });
GUI.color = color;

if (colonist.Dead) {
GUI.DrawTexture(rect, (Texture) Main.deadColonistTexField.GetValue(null));
GUI.DrawTexture(rect, (Texture)Main.deadColonistTexField.GetValue(__instance));
}

float num2 = 4f * colonistBar.Scale;
Vector2 pos = new Vector2(rect.center.x, rect.yMax - num2);
GenMapUI.DrawPawnLabel(colonist, pos, entryRectAlpha,
rect.width + colonistBar.SpaceBetweenColonistsHorizontal - 2f,
(Dictionary<string, string>)Main.pawnLabelsCacheField.GetValue(__instance),
GameFont.Tiny, true, true);
float num3 = 4f * colonistBar.Scale;
Vector2 pos = new Vector2(rect.center.x, rect.yMax - num3);
GenMapUI.DrawPawnLabel(colonist, pos, alpha, rect.width + colonistBar.SpaceBetweenColonistsHorizontal - 2f, (Dictionary<string, string>)Main.pawnLabelsCacheField.GetValue(__instance), GameFont.Tiny, true, true);
Text.Font = GameFont.Small;
GUI.color = Color.white;

Expand Down
33 changes: 33 additions & 0 deletions Source/ColoredMoodBar/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("ColoredMoodBar")]
[assembly: AssemblyDescription("Color code each pawn's mood bar within the colonist bar based on their current mood.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColoredMoodBar.Properties")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("d7feaa9a-a2c4-46d7-81de-fccf6944661e")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]