forked from RonenNess/GeonBit.UI
/
GamePadSetup.cs
128 lines (114 loc) · 5.86 KB
/
GamePadSetup.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
123
124
125
126
127
128
using GeonBit.UI.Entities;
using Microsoft.Xna.Framework;
namespace GeonBit.UI.Source.Input
{
/// <summary>
/// Use the GamePadSetup class to define some basic rules for your GamePad supported GeonBit.UI GUI.
/// </summary>
public static class GamePadSetup
{
/// <summary>
/// Default function we use to generate tooltip text entities.
/// </summary>
/// <param name="source">Source entity.</param>
/// <returns>Entity to use for tooltip text.</returns>
public static Entity GenerateGamePadTooltipFunc(Entity source)
{
// no tooltip text? return null
if (source.ToolTipText == null) return null;
// create tooltip paragraph
var tooltip = new Paragraph(source.ToolTipText, size: new Vector2(500, -1));
tooltip.BackgroundColor = Color.Black;
// add callback to update tooltip position
tooltip.BeforeDraw += (Entity ent) =>
{
// get dest rect and calculate tooltip position based on size and mouse position
var destRect = tooltip.GetActualDestRect();
var sourceVec = new Vector2(
source.GetActualDestRect().X + source.GetActualDestRect().Width / 2f,
source.GetActualDestRect().Y + source.GetActualDestRect().Height / UserInterface.Active.GlobalScale);
var position = sourceVec + source.Padding + new Vector2(-destRect.Width / 2, -destRect.Height - 20);
// make sure tooltip is not out of screen boundaries
var screenBounds = UserInterface.Active.Root.GetActualDestRect();
if (position.Y < screenBounds.Top) position.Y = screenBounds.Top;
if (position.Y > screenBounds.Bottom - destRect.Height) position.Y = screenBounds.Bottom - destRect.Height;
if (position.X < screenBounds.Left) position.X = screenBounds.Left;
if (position.X > screenBounds.Right - destRect.Width) position.X = screenBounds.Right - destRect.Width;
// update tooltip position
tooltip.SetAnchorAndOffset(Anchor.TopLeft, position / UserInterface.Active.GlobalScale);
};
tooltip.CalcTextActualRectWithWrap();
tooltip.BeforeDraw(tooltip);
// return tooltip object
return tooltip;
}
/// <summary>
/// The default Color of an entity.
/// </summary>
public static Color DefaultColor { get; set; } = Color.White;
/// <summary>
/// The selected Color of an entity.
/// </summary>
public static Color SelectedColor { get; set; } = Color.LightPink;
/// <summary>
/// LIST_TITLE color.
/// </summary>
public static Color ListTitle { get; set; } = new Color(155, 74, 240);
/// <summary>
/// The deadzone of the left thumbstick.
/// </summary>
public static Vector2 ThumbstickLeftDeadzone { get; set; } = new Vector2(0.25f);
/// <summary>
/// The deadzone of the right thumbstick.
/// </summary>
public static Vector2 ThumbstickRightDeadzone { get; set; } = new Vector2(0.25f);
/// <summary>
/// Xbox Button_A color.
/// </summary>
public static Color ButtonA { get; set; } = new Color(60, 219, 78);
/// <summary>
/// Xbox Button_X color.
/// </summary>
public static Color ButtonX { get; set; } = new Color(64, 204, 208);
/// <summary>
/// Xbox Button_Y color.
/// </summary>
public static Color ButtonY { get; set; } = new Color(236, 219, 51);
/// <summary>
/// Xbox Button_B color.
/// </summary>
public static Color ButtonB { get; set; } = new Color(208, 66, 66);
/// <summary>
/// The default Skin of an entity.
/// </summary>
public static PanelSkin DefaultSkin { get; set; } = PanelSkin.Simple;
/// <summary>
/// The selected Skin of an entity.
/// </summary>
public static PanelSkin SelectedSkin { get; set; } = PanelSkin.Fancy;
/// <summary>
/// How long does it take before a MessageBox should be confirmable?
/// Don't make it to short to avoid that the MessageBox would close immediately.
/// </summary>
public static double MessageBoxTimeOut { get; set; } = 500;
/// <summary>
/// How long does it take before a clicked panel content should call the OnClick(); event?
/// Don't make it to short to avoid that the clicked panel content triggers right after a panel was selected.
/// </summary>
public static double PanelContentClickedTimeOut { get; set; } = 100;
/// <summary>
/// Initialize the GamePadSetup class.
/// </summary>
public static void Initialize()
{
UserInterface.Active.MouseInputProvider.UpdateMousePosition(Vector2.Zero);
UserInterface.Active.GenerateTooltipFunc = GenerateGamePadTooltipFunc;
RichParagraphStyleInstruction.AddInstruction("LIST_TITLE", new RichParagraphStyleInstruction(ListTitle, FontStyle.Bold, 2));
RichParagraphStyleInstruction.AddInstruction("BUTTON_A", new RichParagraphStyleInstruction(ButtonA, FontStyle.Bold, 2));
RichParagraphStyleInstruction.AddInstruction("BUTTON_X", new RichParagraphStyleInstruction(ButtonX, FontStyle.Bold, 2));
RichParagraphStyleInstruction.AddInstruction("BUTTON_Y", new RichParagraphStyleInstruction(ButtonY, FontStyle.Bold, 2));
RichParagraphStyleInstruction.AddInstruction("BUTTON_B", new RichParagraphStyleInstruction(ButtonB, FontStyle.Bold, 2));
RichParagraphStyleInstruction.AddInstruction("MONO", new RichParagraphStyleInstruction(Color.Black, FontStyle.Bold, 1, Color.WhiteSmoke));
}
}
}