-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.16, Quick Tweak tool, UI Tweak tool
- Loading branch information
Showing
9 changed files
with
1,140 additions
and
59 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
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,42 @@ | ||
using System; | ||
using System.Reflection; | ||
using Terraria.ModLoader; | ||
|
||
namespace ModdersToolkit.Tools.QuickTweak | ||
{ | ||
class QuickTweakCommand : ModCommand | ||
{ | ||
public override string Command => "tweak"; | ||
|
||
public override string Description => "Adds a static field to the Quick Tweak menu"; | ||
|
||
public override string Usage => "/tweak className fieldName"; | ||
|
||
public override CommandType Type => CommandType.Chat; | ||
|
||
public override void Action(CommandCaller caller, string input, string[] args) { | ||
try { | ||
string className = args[0]; | ||
string fieldName = args[1]; | ||
|
||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { | ||
foreach (var type in assembly.GetTypes()) { | ||
if(type.Name == className) { | ||
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic)) { | ||
if(field.Name == fieldName) { | ||
QuickTweakTool.AddTweak(field, $"{className}.{fieldName}"); | ||
caller.Reply($"Quick tweak found and added for {className}.{fieldName}"); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
caller.Reply($"Static field {className}.{fieldName} not found"); | ||
} | ||
catch (Exception) { | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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,108 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Terraria; | ||
using Terraria.UI; | ||
|
||
namespace ModdersToolkit.Tools.QuickTweak | ||
{ | ||
class TweakEntry | ||
{ | ||
public object item; | ||
public string label; | ||
//public Func<string> label; | ||
|
||
public TweakEntry(object item, string label) { | ||
this.item = item; | ||
this.label = label; | ||
} | ||
} | ||
|
||
public class QuickTweakTool : Tool | ||
{ | ||
internal static QuickTweakUI QuickTweakUI; | ||
internal static List<TweakEntry> tweaks = new List<TweakEntry>(); | ||
|
||
internal static bool showPrivateFields = false; | ||
|
||
public override void Initialize() { | ||
ToggleTooltip = "Click to toggle Quick Tweak Tool"; | ||
} | ||
|
||
public override void ClientInitialize() { | ||
Interface = new UserInterface(); | ||
|
||
QuickTweakUI = new QuickTweakUI(Interface); | ||
QuickTweakUI.Activate(); | ||
|
||
Interface.SetState(QuickTweakUI); | ||
} | ||
|
||
public override void ClientTerminate() { | ||
Interface = null; | ||
|
||
QuickTweakUI?.Deactivate(); | ||
QuickTweakUI = null; | ||
} | ||
|
||
public override void UIDraw() { | ||
if (Visible) { | ||
QuickTweakUI.Draw(Main.spriteBatch); | ||
} | ||
} | ||
|
||
internal static void Call(object[] args) { | ||
// Pass in object instance -> all fields shown | ||
// Pass in just fieldinfo -> static field | ||
// pass in static class somehow? Pass in Type? | ||
// Pass in ()=> annonomous functions. | ||
// --> View only usage? () => Main.LocalPlayer.Center.X, ModPLayer bool, etc. | ||
// check RangeAttribute automatically somehow? pass in range? | ||
// Pass in object "stringFieldName" | ||
|
||
string label = ""; | ||
if (args.Length >= 3 && args[2] is string _label) | ||
label = _label; | ||
|
||
//Type inputType = args[1].GetType(); | ||
//if (inputType.IsGenericType) { | ||
// var openType = inputType.GetGenericTypeDefinition(); | ||
// if (openType == typeof(ValueTuple<,>)) { | ||
|
||
// //object myTuple = ((object)instance, new object()); | ||
|
||
// if (typeof(object).IsAssignableFrom(inputType.GenericTypeArguments[0]) && typeof(FieldInfo).IsAssignableFrom(inputType.GenericTypeArguments[1])){ | ||
// var tuple = (ValueTuple <object, string>)args[1]; | ||
// var result = new ValueTuple<object, string>(); | ||
// tweaks.Add(new TweakEntry(args[1], label)); | ||
// } | ||
// } | ||
//} | ||
|
||
tweaks.Add(new TweakEntry(args[1], label)); | ||
} | ||
|
||
internal static void AddTweak(FieldInfo field, string label) { | ||
tweaks.Add(new TweakEntry(field, label)); | ||
QuickTweakUI.updateNeeded = true; | ||
} | ||
|
||
public static void AddTweak(object field, string label) { | ||
tweaks.Add(new TweakEntry(field, label)); | ||
QuickTweakUI.updateNeeded = true; | ||
} | ||
|
||
internal static void AddTweak(ValueTuple<object, FieldInfo> tuple) { | ||
tweaks.Add(new TweakEntry(tuple, "")); | ||
QuickTweakUI.updateNeeded = true; | ||
} | ||
|
||
internal static void AddTweakUIElement(UIElement uIElement) { | ||
tweaks.Add(new TweakEntry(uIElement, "")); | ||
QuickTweakUI.updateNeeded = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.