-
Notifications
You must be signed in to change notification settings - Fork 1
/
UI.cs
122 lines (89 loc) · 2.78 KB
/
UI.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using HamstarHelpers.Helpers.Debug;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.UI;
namespace Intrinsics.UI {
partial class IntrinsicsControlsUI : UIState {
internal Texture2D ButtonPageAddTex;
private UIText Label;
private UIImageButton ButtonOpenDialog;
////////////////
public IntrinsicsControlsUI() : base() {
var mymod = IntrinsicsMod.Instance;
this.ButtonPageAddTex = mymod.GetTexture( "UI/Button" );
}
////////////////
public override void OnInitialize() {
this.Label = new UIText( "Show active intrinsics" );
this.ButtonOpenDialog = new UIImageButton( this.ButtonPageAddTex );
bool isLabelHover = false;
bool isButtonHover = false;
////
this.Label.OnMouseOver += ( _, __ ) => {
if( isLabelHover ) { return; }
isLabelHover = true;
this.Label.TextColor = Color.White;
this.ButtonOpenDialog?.MouseOver(_);
isLabelHover = false;
};
this.Label.OnMouseOut += ( _, __ ) => {
if( isLabelHover ) { return; }
isLabelHover = true;
this.ButtonOpenDialog?.MouseOut( _ );
isLabelHover = false;
};
this.ButtonOpenDialog.OnMouseOver += ( _, __ ) => {
if( isButtonHover ) { return; }
isButtonHover = true;
this.Label.TextColor = Color.White;
this.Label?.MouseOver( _ );
isButtonHover = false;
};
this.ButtonOpenDialog.OnMouseOut += ( _, __ ) => {
if( isButtonHover ) { return; }
isButtonHover = true;
this.Label?.MouseOut( _ );
isButtonHover = false;
};
////
this.Label.OnClick += ( evt, elem ) => {
IntrinsicsMod.Instance.ControlPanelDialog.Open();
};
this.ButtonOpenDialog.OnClick += ( evt, elem ) => {
IntrinsicsMod.Instance.ControlPanelDialog.Open();
};
////
this.UpdateLayout();
////
base.Append( this.Label );
base.Append( this.ButtonOpenDialog );
}
////////////////
public override void Update( GameTime gameTime ) {
this.UpdateLayout();
if( !this.Label.IsMouseHovering ) {
this.Label.TextColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor) * 0.85f;
}
base.Update( gameTime );
}
////////////////
public void UpdateLayout() {
var mymod = IntrinsicsMod.Instance;
int x = mymod.Config.ControlsPositionX >= 0
? mymod.Config.ControlsPositionX
: Main.screenWidth + mymod.Config.ControlsPositionX;
int y = mymod.Config.ControlsPositionY >= 0
? mymod.Config.ControlsPositionY
: Main.screenHeight + mymod.Config.ControlsPositionY;
this.Recalculate();
this.ButtonOpenDialog.Left.Set( x, 0f );
this.ButtonOpenDialog.Top.Set( y - 8f, 0f );
this.Label.Left.Set( x + 24f, 0f );
this.Label.Top.Set( y - 6f, 0f );
this.Recalculate();
}
}
}