/
API.cs
105 lines (74 loc) · 2.29 KB
/
API.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace HUDElementsLib {
public static class HUDElementsLibAPI {
private static void MessageAboutHUD_If() {
Mod msgMod = ModLoader.GetMod( "Messages" );
if( msgMod == null ) {
return;
}
//
void AddUsageMessage() {
msgMod = ModLoader.GetMod( "Messages" );
if( msgMod.Version < new Version(1, 4, 0, 3) ) {
return;
}
//
string id = "HUDElementsLibUsage";
try {
bool isUnread = (bool)msgMod.Call( "IsUnread", id );
object rawParentMsg = msgMod.Call( "GetMessage", "Messages - Mod Info" ); //MessagesAPI.ModInfoCategoryMsg
//
msgMod.Call(
"AddMessageNoColor",
"Reposition HUD elements via. hotkey", //title:
"Bind a key to activate Edit Mode to reposition custom HUD elements freely to your liking.", //description:
(Mod)HUDElementsLibMod.Instance, //modOfOrigin:
(bool)isUnread, //alertPlayer:
false, //isImportant:
rawParentMsg, //parentMessage:
(string)id, //id:
0 //weight:
);
} catch( Exception e ) {
HUDElementsLibMod.Instance.Logger.Error( "", e );
}
}
Action usageMessageAdder = AddUsageMessage;
//
msgMod.Call( "AddMessagesCategoriesInitializeEvent", usageMessageAdder );
}
////////////////
public static bool IsEditModeActive() {
return HUDElementsLibMod.Instance
.HUDEditMode?
.Current
?? false;
}
////////////////
public static HUDElement GetDraggingElement() {
var mymod = ModContent.GetInstance<HUDElementsLibMod>();
foreach( HUDElement elem in mymod.HUDManager.Elements.Values ) {
if( elem.IsDraggingSinceLastTick ) {
return elem;
}
}
return null;
}
////////////////
public static void AddWidget( HUDElement element ) { //string layerName = "Vanilla: Mouse Text"
var mymod = ModContent.GetInstance<HUDElementsLibMod>();
mymod.HUDManager?.LoadHUDElement( element );
mymod.MyUI?.Append( element );
mymod.MyUI?.Recalculate();
HUDElementsLibAPI.MessageAboutHUD_If();
}
////////////////
public static void AddWidgetVisibilityHook( Func<string, bool> hook ) {
var mymod = ModContent.GetInstance<HUDElementsLibMod>();
mymod.VisibilityHooks.Add( hook );
}
}
}