-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Most of the mod was rewritten for a cleaner codebase and better performance - Added Forbid selection tool - Added Unforbid everything tool - Added Mass selection tool - Added hotkeys for quick tool selection - Tools have received custom textures
- Loading branch information
UnlimitedHugs
committed
Sep 14, 2016
1 parent
add3da5
commit 2ce2b6d
Showing
36 changed files
with
660 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
Mods/AllowTool/Defs/KeyBindingCategoryDefs/KeyBindingCategories.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<KeyBindingCategoryDefs> | ||
|
||
<KeyBindingCategoryDef> | ||
<defName>AllowTool</defName> | ||
<label>Allow Tool</label> | ||
<description>Shortcuts for designators provided by the Allow Tool mod.</description> | ||
<checkForConflicts></checkForConflicts> | ||
</KeyBindingCategoryDef> | ||
|
||
</KeyBindingCategoryDefs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<KeyBindingDefs> | ||
|
||
<KeyBindingDef> | ||
<category>AllowTool</category> | ||
<defName>DesignatorAllow</defName> | ||
<label>Designator: Allow</label> | ||
<defaultKeyCodeA>U</defaultKeyCodeA> | ||
</KeyBindingDef> | ||
|
||
<KeyBindingDef> | ||
<category>AllowTool</category> | ||
<defName>DesignatorForbid</defName> | ||
<label>Designator: Forbid</label> | ||
<defaultKeyCodeA>I</defaultKeyCodeA> | ||
</KeyBindingDef> | ||
|
||
<KeyBindingDef> | ||
<category>AllowTool</category> | ||
<defName>DesignatorAllowAll</defName> | ||
<label>Designator: Allow all</label> | ||
</KeyBindingDef> | ||
|
||
<KeyBindingDef> | ||
<category>AllowTool</category> | ||
<defName>DesignatorMassSelect</defName> | ||
<label>Designator: Mass select</label> | ||
<defaultKeyCodeA>O</defaultKeyCodeA> | ||
</KeyBindingDef> | ||
|
||
</KeyBindingDefs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Defs> | ||
|
||
<AllowTool.ThingDesignatorDef> | ||
<defName>AllowDesignator</defName> | ||
<!-- the class that handles the behaviour of this designator. Must extend AllowTool.Designator_SelectableThing --> | ||
<designatorClass>AllowTool.Designator_Allow</designatorClass> | ||
<!-- hides the designator --> | ||
<hidden>false</hidden> | ||
<!-- the category def name to add this designator to --> | ||
<category>Orders</category> | ||
<!-- the designator type to insert this designator after --> | ||
<insertAfter>Designator_Claim</insertAfter> | ||
<!-- the label on the button, optional --> | ||
<label>Unforbid selection</label> | ||
<!-- button tooltip, optional --> | ||
<description>Unforbid all items in the selected area. | ||
Click and drag over an area to use.</description> | ||
<!-- the icon texture for the button --> | ||
<iconTex>allow</iconTex> | ||
<!-- the texture to appear over a tile with items this designator is dragged over --> | ||
<dragHighlightTex>allowHighlight</dragHighlightTex> | ||
<!-- sound def played after a successful designation --> | ||
<soundSucceded>TickHigh</soundSucceded> | ||
<!-- key binding def used to activate the designator --> | ||
<hotkeyDef>DesignatorAllow</hotkeyDef> | ||
<!-- a string id to be displayed as a message on designation success. Optional. --> | ||
<messageSuccess>Allow_area_success</messageSuccess> | ||
<!-- a string id to be displayed as a message on designation failure. Optional. --> | ||
<messageFailure>Allow_area_failure</messageFailure> | ||
</AllowTool.ThingDesignatorDef> | ||
|
||
<AllowTool.ThingDesignatorDef> | ||
<defName>ForbidDesignator</defName> | ||
<designatorClass>AllowTool.Designator_Forbid</designatorClass> | ||
<hidden>false</hidden> | ||
<category>Orders</category> | ||
<insertAfter>AllowTool.Designator_Allow</insertAfter> | ||
<label>Forbid selection</label> | ||
<description>Forbid all items in the selected area. | ||
Click and drag over an area to use.</description> | ||
<iconTex>forbid</iconTex> | ||
<dragHighlightTex>forbidHighlight</dragHighlightTex> | ||
<soundSucceded>TickLow</soundSucceded> | ||
<hotkeyDef>DesignatorForbid</hotkeyDef> | ||
<messageSuccess>Forbid_area_success</messageSuccess> | ||
<messageFailure>Forbid_area_failure</messageFailure> | ||
</AllowTool.ThingDesignatorDef> | ||
|
||
<AllowTool.ThingDesignatorDef> | ||
<defName>AllowAllDesignator</defName> | ||
<designatorClass>AllowTool.Designator_AllowAll</designatorClass> | ||
<hidden>false</hidden> | ||
<category>Orders</category> | ||
<insertAfter>AllowTool.Designator_Forbid</insertAfter> | ||
<label>Unforbid everything</label> | ||
<description>Unforbids all forbidden items on the map. | ||
Click to activate.</description> | ||
<iconTex>allowAll</iconTex> | ||
<dragHighlightTex>allowHighlight</dragHighlightTex> | ||
<soundSucceded>TickHigh</soundSucceded> | ||
<hotkeyDef>DesignatorAllowAll</hotkeyDef> | ||
<messageSuccess>Allow_all_success</messageSuccess> | ||
<messageFailure>Allow_all_failure</messageFailure> | ||
</AllowTool.ThingDesignatorDef> | ||
|
||
<AllowTool.ThingDesignatorDef> | ||
<defName>MassSelectDesignator</defName> | ||
<designatorClass>AllowTool.Designator_MassSelect</designatorClass> | ||
<hidden>false</hidden> | ||
<category>Orders</category> | ||
<insertAfter>AllowTool.Designator_AllowAll</insertAfter> | ||
<label>Mass select</label> | ||
<description>Selects everything in an area, ignoring common sense and selection limits. Selecting too much stuff at once can slow down the game- use with care. | ||
Hold Shift to add to your current selection. | ||
Hold Ctrl/Option to invert selection.</description> | ||
<iconTex>massSelect</iconTex> | ||
<dragHighlightTex>massSelectHighlight</dragHighlightTex> | ||
<soundSucceded>ThingSelected</soundSucceded> | ||
<hotkeyDef>DesignatorMassSelect</hotkeyDef> | ||
</AllowTool.ThingDesignatorDef> | ||
|
||
</Defs> |
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
Mods/AllowTool/Languages/English/Keyed/AllowToolStrings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<LanguageData> | ||
|
||
<Allow_area_success>Allowed {0} items.</Allow_area_success> | ||
<Allow_area_failure>No forbidden items found.</Allow_area_failure> | ||
|
||
<Forbid_area_success>Forbidden {0} items.</Forbid_area_success> | ||
<Forbid_area_failure>No forbiddable items found.</Forbid_area_failure> | ||
|
||
<Allow_all_success>Allowed {0} things across the map.</Allow_all_success> | ||
<Allow_all_failure>No forbidden things found.</Allow_all_failure> | ||
|
||
</LanguageData> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace AllowTool { | ||
/** | ||
* The hub of the mod. | ||
* Injects the custom designators and handles hotkey presses. | ||
*/ | ||
public class AllowToolController { | ||
private const int MapSceneIndex = 1; | ||
|
||
private static FieldInfo resolvedDesignatorsField; | ||
private static AllowToolController instance; | ||
public static AllowToolController Instance { | ||
get { return instance ?? (instance = new AllowToolController()); } | ||
} | ||
|
||
private readonly List<HotkeyEntry> activeHotkeys = new List<HotkeyEntry>(); | ||
|
||
public UnlimitedDesignationDragger Dragger { get; private set; } | ||
|
||
private AllowToolController() { | ||
Dragger = new UnlimitedDesignationDragger(); | ||
InitReflectionFields(); | ||
} | ||
|
||
public void Update() { | ||
Dragger.Update(); | ||
} | ||
|
||
public void OnGUI() { | ||
if(Event.current.type != EventType.KeyDown) return; | ||
CheckForHotkeyPresses(); | ||
} | ||
|
||
public void OnLevelLoaded(int level) { | ||
if(level != MapSceneIndex) return; | ||
if (DefDatabase<ThingDesignatorDef>.DefCount == 0) { | ||
activeHotkeys.Clear(); // mod was unloaded | ||
} | ||
TryInjectDesignators(); | ||
} | ||
|
||
private void TryInjectDesignators() { | ||
var numDesignatorsInjected = 0; | ||
foreach (var designatorDef in DefDatabase<ThingDesignatorDef>.AllDefs) { | ||
if (designatorDef.hidden || designatorDef.Injected) continue; | ||
var resolvedDesignators = (List<Designator>)resolvedDesignatorsField.GetValue(designatorDef.Category); | ||
var insertIndex = -1; | ||
for (var i = 0; i < resolvedDesignators.Count; i++) { | ||
if(resolvedDesignators[i].GetType() != designatorDef.insertAfter) continue; | ||
insertIndex = i; | ||
break; | ||
} | ||
if (insertIndex >= 0) { | ||
var designator = (Designator) Activator.CreateInstance(designatorDef.designatorClass, designatorDef); | ||
resolvedDesignators.Insert(insertIndex + 1, designator); | ||
if (designatorDef.hotkeyDef != null) { | ||
activeHotkeys.Add(new HotkeyEntry(designatorDef.hotkeyDef, designator)); | ||
} | ||
numDesignatorsInjected++; | ||
} else { | ||
AllowToolUtility.Error(string.Format("Failed to inject {0} after {1}", designatorDef.defName, designatorDef.insertAfter.Name)); | ||
} | ||
designatorDef.Injected = true; | ||
} | ||
if (numDesignatorsInjected > 0) { | ||
AllowToolUtility.Log("Injected " + numDesignatorsInjected + " designators"); | ||
} | ||
} | ||
|
||
private void InitReflectionFields() { | ||
resolvedDesignatorsField = typeof (DesignationCategoryDef).GetField("resolvedDesignators", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (resolvedDesignatorsField == null) AllowToolUtility.Error("failed to reflect DesignationCategoryDef.resolvedDesignators"); | ||
} | ||
|
||
private void CheckForHotkeyPresses() { | ||
for (int i = 0; i < activeHotkeys.Count; i++) { | ||
if(!activeHotkeys[i].key.JustPressed) continue; | ||
activeHotkeys[i].designator.ProcessInput(Event.current); | ||
break; | ||
} | ||
} | ||
|
||
private class HotkeyEntry { | ||
public readonly KeyBindingDef key; | ||
public readonly Designator designator; | ||
public HotkeyEntry(KeyBindingDef key, Designator designator) { | ||
this.key = key; | ||
this.designator = designator; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace AllowTool { | ||
public class AllowToolUtility { | ||
private const string logPrefix = "[AllowTool] "; | ||
|
||
public static void Log(object message) { | ||
Verse.Log.Message(logPrefix + message); | ||
} | ||
|
||
public static void Error(object message) { | ||
Verse.Log.Error(logPrefix + message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using RimWorld; | ||
using Verse; | ||
|
||
namespace AllowTool { | ||
public class Designator_Allow : Designator_SelectableThings { | ||
public Designator_Allow(ThingDesignatorDef def) : base(def) { | ||
} | ||
|
||
protected override bool ThingIsRelevant(Thing item) { | ||
var comp = item is ThingWithComps ? (item as ThingWithComps).GetComp<CompForbiddable>() : null; | ||
return comp != null && comp.Forbidden; | ||
} | ||
|
||
override protected int ProcessCell(IntVec3 c) { | ||
var hitCount = 0; | ||
var cellThings = Find.ThingGrid.ThingsListAtFast(c); | ||
for (var i = 0; i < cellThings.Count; i++) { | ||
var thing = cellThings[i]; | ||
if (thing.def.selectable && thing.IsForbidden(Faction.OfPlayer)) { | ||
thing.SetForbidden(false); | ||
hitCount++; | ||
} | ||
} | ||
return hitCount; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
using Verse.Sound; | ||
|
||
namespace AllowTool { | ||
public class Designator_AllowAll : Designator_SelectableThings { | ||
public Designator_AllowAll(ThingDesignatorDef def) : base(def) { | ||
} | ||
|
||
public override void ProcessInput(Event ev) { | ||
if (!CheckCanInteract()) return; | ||
AllowAllTheThings(); | ||
} | ||
|
||
protected override bool ThingIsRelevant(Thing item) { | ||
return false; | ||
} | ||
|
||
protected override int ProcessCell(IntVec3 cell) { | ||
return 0; | ||
} | ||
|
||
private void AllowAllTheThings() { | ||
var things = Find.ListerThings.AllThings; | ||
var tallyCount = 0; | ||
for (var i = 0; i < things.Count; i++) { | ||
var thing = things[i]; | ||
var comp = thing is ThingWithComps ? (thing as ThingWithComps).GetComp<CompForbiddable>() : null; | ||
if (comp != null && comp.Forbidden) { | ||
comp.Forbidden = false; | ||
tallyCount++; | ||
} | ||
} | ||
if (tallyCount > 0) { | ||
if (def.messageSuccess != null) Messages.Message(def.messageSuccess.Translate(tallyCount.ToString()), MessageSound.Silent); | ||
def.soundSucceded.PlayOneShotOnCamera(); | ||
} else { | ||
if (def.messageFailure != null) Messages.Message(def.messageFailure.Translate(), MessageSound.RejectInput); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.