Skip to content

Commit

Permalink
Comments and a rename
Browse files Browse the repository at this point in the history
  • Loading branch information
JTJutajoh committed Aug 24, 2021
1 parent aa82f2c commit 94e3999
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 45 deletions.
Binary file modified 1.3/Assemblies/Signs.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions Source/Signs/Building_Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Dark.Signs
{
// Special comment class with graphic-swapping capability more or less copied from power switches/air vents
// Allows comments to be hidden altogether by swapping to an invisible graphic
public class Building_Comment : Building
{
private Comp_Sign signComp;
Expand Down
2 changes: 2 additions & 0 deletions Source/Signs/CommentContentClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Dark.Signs
{
// TODO make a clipboard class/struct instead of a bunch of fields
public static class CommentContentClipboard
{
private static string copiedString = "";
Expand Down Expand Up @@ -42,6 +43,7 @@ public static void PasteInto(ref Comp_Sign sign)
sign.labelColor = CommentContentClipboard.copiedColor;

}
// Used by Comp_Sign to add copy/paste gizmos for sign settings
public static IEnumerable<Gizmo> CopyPasteGizmosFor(Comp_Sign sign)
{
yield return new Command_Action
Expand Down
55 changes: 32 additions & 23 deletions Source/Signs/Comp_Sign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public Graphic CurrentGraphic
{
get
{
if (Settings.commentToggleHidesComments && ShowCommentToggle.drawComments == false && this.parent.def.defName == "Comment")
// Swap out the graphic if comment graphics are set to be hidden currently
if (Settings.commentToggleHidesComments && DoPlaySettingsGlobalControls_ShowCommentToggle.drawComments == false && this.parent.def.defName == "Comment")
{
if (this.HiddenGraphic == null)
{
// Load the alternate graphic
this.HiddenGraphic = GraphicDatabase.Get(this.parent.def.graphicData.graphicClass, this.parent.def.graphicData.texPath + "_Hidden",
this.parent.def.graphicData.shaderType.Shader, this.parent.def.graphicData.drawSize, this.parent.DrawColor, this.parent.DrawColorTwo, null);
}
Expand All @@ -38,6 +40,7 @@ public Graphic CurrentGraphic

public void NotifyVisibilityChange()
{
// Notified usually by the toggle comment button, possibly by the Settings window
this.parent.DirtyMapMesh(this.parent.Map);
}

Expand Down Expand Up @@ -68,7 +71,6 @@ public GameFont fontSize
}
}

// This property is ignored for now, in favor of getting the global setting at draw time
private Color _labelColor = Settings.globalLabelColor;
public Color labelColor
{
Expand Down Expand Up @@ -125,10 +127,11 @@ public override void PostSpawnSetup(bool respawningAfterLoad)

if (this.parent.def.defName == "Comment")
{
ShowCommentToggle.RegisterForNotify(this);
DoPlaySettingsGlobalControls_ShowCommentToggle.RegisterForNotify(this);
}
}

// Content utilities
private void RemoveExtraLineEndings()
{
if (signContent == null)
Expand All @@ -140,6 +143,18 @@ private void RemoveExtraLineEndings()
signContent = orig.Replace("\r", "");
}

public static string UnescapeContents(string raw)
{
string result = raw;
result = result.Replace("&apos;", "'");
result = result.Replace("&quot;", "\"");
result = result.Replace("&gt;", ">");
result = result.Replace("&lt;", "<");
result = result.Replace("&amp;", "&");
return result;
}

// Room sign methods
public void SetContentsFromRoom()
{
Room room = this.parent.GetRoom();
Expand All @@ -154,6 +169,7 @@ public void SetContentsFromRoom()
public override void CompTickRare()
{
base.CompTickRare();
// Only use the tick if we're a room sign for performance reasons. Most other signs shouldn't be set to tick at all anyway
if (Props.isRoomSign)
{
// On rare ticks, force an update to check if the room has changed and wasn't caught by a notify.
Expand All @@ -162,6 +178,7 @@ public override void CompTickRare()
}
}


private bool ShouldDrawLabel()
{
if (Find.Selector.IsSelected(this.parent))
Expand All @@ -172,7 +189,7 @@ private bool ShouldDrawLabel()
return false;

// Check if the button in the bottom right is toggled on
if (ShowCommentToggle.drawComments == false)
if (DoPlaySettingsGlobalControls_ShowCommentToggle.drawComments == false)
return false;

// Check if we should ignore zoom level
Expand Down Expand Up @@ -243,17 +260,6 @@ protected static string GetRoomRoleLabel(Room room)
return taggedString;
}

public static string UnescapeContents(string raw)
{
string result = raw;
result = result.Replace("&apos;", "'");
result = result.Replace("&quot;", "\"");
result = result.Replace("&gt;", ">");
result = result.Replace("&lt;", "<");
result = result.Replace("&amp;", "&");
return result;
}

private IEnumerable<string> DoSignContents()
{
if (this._signContent == null)
Expand Down Expand Up @@ -419,16 +425,12 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
}

// Don't even show the sign gizmos if the sign doesn't belong to the player faction
if (this.parent.Faction == null)
{
yield break;
}

if (!this.parent.Faction.IsPlayer)
if (this.parent.Faction == null || !this.parent.Faction.IsPlayer)
{
yield break;
}

// show/hide
yield return new Command_Toggle
{
defaultLabel = "Signs_ShowGizmo".Translate(),
Expand All @@ -441,7 +443,7 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
this.hideLabelOverride = !this.hideLabelOverride;
}
};

// font size
yield return new Command_Action
{
icon = ContentFinder<Texture2D>.Get("UI/SignSize", true),
Expand Down Expand Up @@ -470,13 +472,15 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
hotKey = KeyBindingDefOf.Misc1
};

// copy/paste
foreach (Gizmo gizmo in CommentContentClipboard.CopyPasteGizmosFor(this))
{
yield return gizmo;
}
}
yield break;
}
// Returns front-facing font names instead of the internal ones which are confusing
private static string GetSizeName(GameFont f)
{
switch (f)
Expand All @@ -493,6 +497,7 @@ public override string CompInspectStringExtra()
{
StringBuilder stringBuilder = new StringBuilder();

// Debug stuff
/*stringBuilder.Append(hideLabelOverride ? "Hidden. " : "Visible. ");
stringBuilder.Append("Size: ");
stringBuilder.Append(Building_Sign.GetSizeName(fontSize));
Expand All @@ -503,7 +508,10 @@ public override string CompInspectStringExtra()
return "";
}

string trimmedContent = Comp_Sign.UnescapeContents(this._signContent.Trim());
string trimmedContent = this.signContent;
// Remove ending whitespace
trimmedContent = trimmedContent.Trim();
trimmedContent = Comp_Sign.UnescapeContents(trimmedContent);
if (trimmedContent.Length <= 0)
{
// Don't add anything if there's no sign content
Expand Down Expand Up @@ -531,6 +539,7 @@ public override string CompInspectStringExtra()

public static bool BuildableCanGoOverFog(BuildableDef def)
{
//TODO make this a DefModExtension
if (def.defName == "Comment")
{
return true;
Expand Down
14 changes: 5 additions & 9 deletions Source/Signs/Dialog_RenameSign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Dialog_RenameSign(Comp_Sign signComp)
protected override AcceptanceReport NameIsValid(string name)
{
AcceptanceReport result = new AcceptanceReport();
result = true;
//AcceptanceReport result = base.NameIsValid(name); // makes sure it's longer than 0
result = true; // Doesn't work in 1.2 i think
if (!this.signComp.Props.canBeEmpty)
{
result = base.NameIsValid(name); // only checks 0 length
Expand Down Expand Up @@ -75,7 +74,7 @@ private AcceptanceReport CheckLength(string name)

// Sanitize the user's input so that no one comes to me complaining about corrupted saves
// because they thought it would be a bright idea to put xml tags in their sign
private string SanitizeInput(string raw)
static private string SanitizeInput(string raw)
{
string sanitized = raw;
sanitized = System.Security.SecurityElement.Escape(raw);
Expand All @@ -85,11 +84,6 @@ private string SanitizeInput(string raw)

protected override void SetName(string name)
{
/*if (this.sign != null)
{
this.sign.signContent = name.Trim();
}*/

name = SanitizeInput(name);

if (this.signComp != null)
Expand All @@ -112,6 +106,7 @@ protected void SetColor(Color color)
}
}

// Expand the dialog window
public override Vector2 InitialSize
{
get
Expand Down Expand Up @@ -185,7 +180,8 @@ public override void DoWindowContents(Rect inRect)
//int charsLeft = this.MaxNameLength - 2 - text.Length;
//Widgets.Label(new Rect(0f, 112f, inRect.width, 30f), charsLeft.ToString() + " characters remaining");

if (Widgets.ButtonText(new Rect(0f, inRect.height - 45f, inRect.width, 36f), "OK", true, true, true) || enterPressed)
// OK Button
if (Widgets.ButtonText(new Rect(0f, inRect.height - 45f, inRect.width, 36f), "OK".Translate(), true, true, true) || enterPressed)
{
AcceptanceReport acceptanceReport = this.NameIsValid(this.curName);
if (!acceptanceReport.Accepted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Dark.Signs
{
[HarmonyPatch(typeof(PlaySettings), nameof(PlaySettings.DoPlaySettingsGlobalControls))]
public class ShowCommentToggle
public class DoPlaySettingsGlobalControls_ShowCommentToggle
{
public static bool drawComments = true;
private static bool lastVal = drawComments;
Expand Down
10 changes: 0 additions & 10 deletions Source/Signs/Patches/ThingOverlays_ThingOverlaysOnGUI_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}
}

// return the rest of the original instructions
//if (lastIndex > -1) // did we find our anchor and successfully inject code?
//{
// yield return codes.GetRange(lastIndex, codes.Count-lastIndex);
//}
//else
//{
// Log.Error("(Signs) Error patching ThingOverlaysOnGUI. did not find the target instruction. Did RimWorld update?");
//}

//return codes.AsEnumerable();
//yield break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Signs/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void DoWindowContents(Rect inRect)
listingStandard.CheckboxLabeled("Signs_SettingsToggleToolTipHidesComments".Translate(), ref commentToggleHidesComments, "Signs_SettingsToggleToolTipHidesComments_desc".Translate());
if (commentToggleHidesComments != lastVal_commentToggleHidesComments && Find.CurrentMap != null)
{
ShowCommentToggle.RefreshAllSigns();
DoPlaySettingsGlobalControls_ShowCommentToggle.RefreshAllSigns();
lastVal_commentToggleHidesComments = commentToggleHidesComments;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Signs/Signs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<Compile Include="Patches\ThingOverlays_ThingOverlaysOnGUI_Patch.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShowCommentToggle.cs" />
<Compile Include="Patches\DoPlaySettingsGlobalControls_ShowCommentToggle.cs" />
<Compile Include="SignUtils.cs" />
<Compile Include="Patches\ThingSelectionUtility_SelectableByMapClick_Patch.cs" />
</ItemGroup>
Expand Down

0 comments on commit 94e3999

Please sign in to comment.