Skip to content

Commit

Permalink
base
Browse files Browse the repository at this point in the history
  • Loading branch information
Killface1980 committed Nov 18, 2017
1 parent 316e43f commit e31df8c
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 113 deletions.
Binary file modified Assemblies/Outfitter.dll
Binary file not shown.
9 changes: 3 additions & 6 deletions Source/Outfitter/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Harmony;

using Outfitter;
using Outfitter.TabPatch;

using RimWorld;

Expand Down Expand Up @@ -46,14 +47,10 @@ static HarmonyPatches()
new HarmonyMethod(typeof(HarmonyPatches), nameof(UpdatePriorities)));

harmony.Patch(
AccessTools.Method(typeof(ITab_Bills), "FillTab"),
new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.FillTab_Prefix)),
AccessTools.Method(typeof(BillStack), nameof(BillStack.DoListing)),
new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.DoListing)),
null);

harmony.Patch(
AccessTools.Method(typeof(ITab_Bills), "TabUpdate"),
new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.TabUpdate_Prefix)),
null);

// harmony.Patch(
// AccessTools.Method(typeof(ThinkNode_JobGiver), nameof(ThinkNode_JobGiver.TryIssueJobPackage)),
Expand Down
106 changes: 0 additions & 106 deletions Source/Outfitter/ITab_Bills_Patch.cs

This file was deleted.

5 changes: 4 additions & 1 deletion Source/Outfitter/Outfitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
<Compile Include="ApparelEntry.cs" />
<Compile Include="ApparelStatCache.cs" />
<Compile Include="Cache.cs" />
<Compile Include="ITab_Bills_Patch.cs" />
<Compile Include="TabPatch\Tools.cs" />
<Compile Include="TabPatch\FloatMenuColonists.cs" />
<Compile Include="TabPatch\FloatMenuLabels.cs" />
<Compile Include="TabPatch\ITab_Bills_Patch.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GameComponent_Outfitter.cs" />
<Compile Include="MainJob.cs" />
Expand Down
43 changes: 43 additions & 0 deletions Source/Outfitter/TabPatch/FloatMenuColonists.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Outfitter.TabPatch
{
using System.Collections.Generic;

using Harmony;

using JetBrains.Annotations;

using UnityEngine;

using Verse;

public class FloatMenuColonists : FloatMenu
{
public FloatMenuColonists([NotNull] List<FloatMenuOption> options, [CanBeNull] string label)
: base(options, label)
{
this.givesColonistOrders = true;
this.vanishIfMouseDistant = true;
this.closeOnClickedOutside = true;
}

public override void DoWindowContents(Rect rect)
{
this.options.Do(
o =>
{
// FloatMenuOptionSorting option = o as FloatMenuOptionSorting;
// option.Label = PathInfo.GetJobReport(option.sortBy);
o.SetSizeMode(FloatMenuSizeMode.Normal);
});
this.windowRect = new Rect(this.windowRect.x, this.windowRect.y, this.InitialSize.x, this.InitialSize.y);
base.DoWindowContents(this.windowRect);
}

public override void PostClose()
{
base.PostClose();

Tools.CloseLabelMenu(false);
}
}
}
34 changes: 34 additions & 0 deletions Source/Outfitter/TabPatch/FloatMenuLabels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Outfitter.TabPatch
{
using System;
using System.Collections.Generic;

using UnityEngine;

using Verse;

public class FloatMenuLabels : FloatMenu
{
public FloatMenuLabels(List<FloatMenuOption> options)
: base(options, null)
{
this.givesColonistOrders = false;
this.vanishIfMouseDistant = true;
this.closeOnClickedOutside = false;
}
}

public class FloatMenuOptionNoClose : FloatMenuOption
{
public FloatMenuOptionNoClose(string label, Action action)
: base(label, action)
{
}

public override bool DoGUI(Rect rect, bool colonistOrdering)
{
base.DoGUI(rect, colonistOrdering);
return false; // don't close after an item is selected
}
}
}
67 changes: 67 additions & 0 deletions Source/Outfitter/TabPatch/ITab_Bills_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace Outfitter.TabPatch
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using RimWorld;

using UnityEngine;

using Verse;

public static class ITab_Bills_Patch
{
private static float viewHeight = 1000f;

private static Vector2 scrollPosition = default(Vector2);

private static readonly Vector2 WinSize = new Vector2(420f, 480f);

private static Bill mouseoverBill;

// RimWorld.ITab_Bills

public static bool DoListing(BillStack __instance, ref Bill __result, Rect rect, Func<List<FloatMenuOption>> recipeOptionsMaker, ref Vector2 scrollPosition, ref float viewHeight)
{
Bill result = null;
GUI.BeginGroup(rect);
Text.Font = GameFont.Small;
if (__instance.Count < 15)
{
Rect rect2 = new Rect(0f, 0f, 150f, 29f);
if (Widgets.ButtonText(rect2, "AddBill".Translate(), true, false, true))
{
Find.WindowStack.Add(new FloatMenu(recipeOptionsMaker()));
}
UIHighlighter.HighlightOpportunity(rect2, "AddBill");
}
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.white;
Rect outRect = new Rect(0f, 35f, rect.width, (float)(rect.height - 35.0));
Rect viewRect = new Rect(0f, 0f, (float)(outRect.width - 16.0), viewHeight);
Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect, true);
float num = 0f;
for (int i = 0; i < __instance.Count; i++)
{
Bill bill = __instance.Bills[i];

Rect rect3 = bill.DoInterface(0f, num, viewRect.width, i);
if (!bill.DeletedOrDereferenced && Mouse.IsOver(rect3))
{
result = bill;
}
num = (float)(num + (rect3.height + 6.0));
}
if (Event.current.type == EventType.Layout)
{
viewHeight = (float)(num + 60.0);
}
Widgets.EndScrollView();
GUI.EndGroup();
__result= result;
return false;
}
}
}
81 changes: 81 additions & 0 deletions Source/Outfitter/TabPatch/Tools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace Outfitter.TabPatch
{
using System;
using System.Collections.Generic;
using System.Linq;

using Harmony;

using JetBrains.Annotations;

using Verse;

public static class Tools
{
public static FloatMenuLabels LabelMenu;

private static FloatMenuColonists actionMenu;

public static void CloseLabelMenu(bool sound)
{
if (LabelMenu != null)
{
Find.WindowStack.TryRemove(LabelMenu, sound);
LabelMenu = null;
}
}

public static FloatMenuOption MakeMenuItemForLabel([NotNull] string label, [NotNull] List<FloatMenuOption> fmo)
{
// List<SortByWhat> sortByWhats = fmo.Keys.ToList();
List<FloatMenuOption> options = fmo.ToList();
string labelFixed = label;
FloatMenuOptionNoClose option = new FloatMenuOptionNoClose(
labelFixed,
() =>
{
if (options.Count() == 1 && options[0].Disabled == false)
{
Action action = options[0].action;
if (action != null)
{
CloseLabelMenu(true);
action();
}
}
else
{
int i = 0;
List<FloatMenuOption> actions = new List<FloatMenuOption>();
fmo.Do(
menuOption =>
{
FloatMenuOption floatMenuOption =
new FloatMenuOption(
menuOption.Label,
() =>
{
FloatMenuOption pawnOption =
menuOption;
actionMenu.Close();
CloseLabelMenu(true);
pawnOption.action();
},
(MenuOptionPriority)i++,
() =>
{
// PathInfo.current = pawn;
});
actions.Add(floatMenuOption);
});
actionMenu = new FloatMenuColonists(actions, null);
Find.WindowStack.Add(actionMenu);
}
})
{
Disabled = options.All(o => o.Disabled)
};
return option;
}
}
}

0 comments on commit e31df8c

Please sign in to comment.