Skip to content

Commit ad9a8bc

Browse files
committedDec 21, 2016
Documented OverlayManager, ShopMenu, TitleMenu, KeyboardSubscriberProxy. Added global settings.StyleCop
1 parent e7e7563 commit ad9a8bc

File tree

5 files changed

+779
-227
lines changed

5 files changed

+779
-227
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,106 @@
1-
using Farmhand.UI.Interfaces;
2-
3-
namespace Farmhand.UI
1+
namespace Farmhand.UI
42
{
5-
public class KeyboardSubscriberProxy : StardewValley.IKeyboardSubscriber
3+
using Farmhand.UI.Interfaces;
4+
5+
using Microsoft.Xna.Framework.Input;
6+
7+
using StardewValley;
8+
9+
/// <summary>
10+
/// A keyboard subscriber proxy.
11+
/// </summary>
12+
public class KeyboardSubscriberProxy : IKeyboardSubscriber
613
{
7-
protected IKeyboardComponent Component;
14+
/// <summary>
15+
/// Gets or sets the component to pass events to.
16+
/// </summary>
17+
protected IKeyboardComponent Component { get; set; }
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="KeyboardSubscriberProxy"/> class.
21+
/// </summary>
22+
/// <param name="component">
23+
/// The component to pass events to.
24+
/// </param>
825
public KeyboardSubscriberProxy(IKeyboardComponent component)
926
{
10-
Component = component;
27+
this.Component = component;
1128
}
29+
30+
#region IKeyboardSubscriber Members
31+
32+
/// <summary>
33+
/// Gets or sets a value indicating whether the component is selected.
34+
/// </summary>
1235
public bool Selected
1336
{
1437
get
1538
{
16-
return Component.Selected;
39+
return this.Component.Selected;
1740
}
41+
1842
set
1943
{
20-
Component.Selected = value;
44+
this.Component.Selected = value;
2145
}
2246
}
47+
48+
/// <summary>
49+
/// Called on receiving character input.
50+
/// </summary>
51+
/// <param name="chr">
52+
/// The received character.
53+
/// </param>
2354
public void RecieveTextInput(char chr)
2455
{
25-
if (Component.Selected)
26-
Component.TextReceived(chr);
56+
if (this.Component.Selected)
57+
{
58+
this.Component.TextReceived(chr);
59+
}
2760
}
61+
62+
/// <summary>
63+
/// Called on receiving text input.
64+
/// </summary>
65+
/// <param name="str">
66+
/// The received text.
67+
/// </param>
2868
public void RecieveTextInput(string str)
2969
{
30-
if (Component.Selected)
31-
Component.TextReceived(str);
70+
if (this.Component.Selected)
71+
{
72+
this.Component.TextReceived(str);
73+
}
3274
}
75+
76+
/// <summary>
77+
/// Called on receiving a command.
78+
/// </summary>
79+
/// <param name="cmd">
80+
/// The received command.
81+
/// </param>
3382
public void RecieveCommandInput(char cmd)
3483
{
35-
if (Component.Selected)
36-
Component.CommandReceived(cmd);
84+
if (this.Component.Selected)
85+
{
86+
this.Component.CommandReceived(cmd);
87+
}
3788
}
38-
public void RecieveSpecialInput(Microsoft.Xna.Framework.Input.Keys key)
89+
90+
/// <summary>
91+
/// Called on receiving a special key.
92+
/// </summary>
93+
/// <param name="key">
94+
/// The received key.
95+
/// </param>
96+
public void RecieveSpecialInput(Keys key)
3997
{
40-
if (Component.Selected)
41-
Component.SpecialReceived(key);
98+
if (this.Component.Selected)
99+
{
100+
this.Component.SpecialReceived(key);
101+
}
42102
}
103+
104+
#endregion
43105
}
44-
}
106+
}
+92-38
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,182 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using Farmhand.Events;
5-
using Farmhand.Events.Arguments.ControlEvents;
6-
using Microsoft.Xna.Framework.Input;
1+
namespace Farmhand.UI
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
76

8-
using StardewValley;
9-
using StardewValley.Menus;
7+
using Farmhand.Events;
8+
using Farmhand.Events.Arguments.ControlEvents;
9+
10+
using Microsoft.Xna.Framework.Input;
11+
12+
using StardewValley;
13+
using StardewValley.Menus;
1014

11-
namespace Farmhand.UI
12-
{
1315
/// <summary>
14-
/// Enables overlaying any <see cref="IClickableMenu"/> over the Gui, both in and outside of menus
16+
/// Enables overlaying any <see cref="IClickableMenu" /> over the GUI, both in and outside of menus
1517
/// </summary>
1618
public static class OverlayManager
1719
{
20+
private static readonly List<IClickableMenu> Overlays = new List<IClickableMenu>();
21+
1822
/// <summary>
19-
/// Adds the given overlay to the list of <see cref="IClickableMenu"/>'s that should receive emulated events
23+
/// Count of how many <see cref="IClickableMenu" />'s are currently in the list
2024
/// </summary>
21-
/// <param name="overlay">The <see cref="IClickableMenu"/> to add</param>
25+
public static int Count => Overlays.Count;
26+
27+
/// <summary>
28+
/// Adds the given overlay to the list of <see cref="IClickableMenu" />'s that should receive emulated events
29+
/// </summary>
30+
/// <param name="overlay">The <see cref="IClickableMenu" /> to add</param>
2231
public static void Add(IClickableMenu overlay)
2332
{
2433
Overlays.Add(overlay);
2534
if (Overlays.Count == 1)
35+
{
2636
Init();
37+
}
2738
}
39+
2840
/// <summary>
29-
/// Removes the given overlay from the list of <see cref="IClickableMenu"/>'s that should receive emulated events
41+
/// Removes the given overlay from the list of <see cref="IClickableMenu" />'s that should receive emulated events
3042
/// </summary>
31-
/// <param name="overlay">The <see cref="IClickableMenu"/> to remove</param>
43+
/// <param name="overlay">The <see cref="IClickableMenu" /> to remove</param>
3244
public static void Remove(IClickableMenu overlay)
3345
{
3446
Overlays.Remove(overlay);
3547
if (Overlays.Count == 0)
48+
{
3649
Uninit();
50+
}
3751
}
52+
3853
/// <summary>
39-
/// Empties the list of <see cref="IClickableMenu"/>'s that should receive emulated events
54+
/// Empties the list of <see cref="IClickableMenu" />'s that should receive emulated events
4055
/// </summary>
4156
public static void Clear()
4257
{
4358
Overlays.Clear();
4459
Uninit();
4560
}
61+
4662
/// <summary>
47-
/// Checks if a given <see cref="IClickableMenu"/> is in the list of emulated <see cref="IClickableMenu"/>'s
63+
/// Checks if a given <see cref="IClickableMenu" /> is in the list of emulated <see cref="IClickableMenu" />'s
4864
/// </summary>
49-
/// <param name="overlay">The <see cref="IClickableMenu"/> to check for</param>
50-
/// <returns></returns>
65+
/// <param name="overlay">The <see cref="IClickableMenu" /> to check for</param>
66+
/// <returns>
67+
/// Whether the manager contains the specified overlay
68+
/// </returns>
5169
public static bool Contains(IClickableMenu overlay)
5270
{
5371
return Overlays.Contains(overlay);
5472
}
55-
/// <summary>
56-
/// Count of how many <see cref="IClickableMenu"/>'s are currently in the list
57-
/// </summary>
58-
public static int Count => Overlays.Count;
5973

6074
/// <summary>
61-
/// Tries to remove the given <see cref="IClickableMenu"/> from the list and returns a <see cref="bool"/> with the result of this attempt
75+
/// Tries to remove the given <see cref="IClickableMenu" /> from the list and returns a <see cref="bool" /> with the
76+
/// result of this attempt
6277
/// </summary>
63-
/// <param name="overlay">The <see cref="IClickableMenu"/> to remove</param>
78+
/// <param name="overlay">The <see cref="IClickableMenu" /> to remove</param>
6479
/// <returns>Returns true if the given overlay was removed successfully, or false otherwise</returns>
6580
public static bool TryRemove(IClickableMenu overlay)
6681
{
67-
bool a = Contains(overlay);
82+
var a = Contains(overlay);
6883
if (a)
84+
{
6985
Remove(overlay);
86+
}
87+
7088
return a;
7189
}
72-
// Internal functional code, not related to API level code.
73-
private static readonly List<IClickableMenu> Overlays = new List<IClickableMenu>();
90+
7491
private static void Init()
7592
{
7693
GameEvents.OnAfterUpdateTick += GameEvents_UpdateTick;
7794
GraphicsEvents.OnPostRenderGuiEvent += GraphicsEvents_OnPostRenderGuiEvent;
7895
ControlEvents.OnMouseChanged += ControlEvents_MouseChanged;
7996
ControlEvents.OnKeyboardChanged += ControlEvents_KeyboardChanged;
8097
}
98+
8199
private static void Uninit()
82100
{
83101
GameEvents.OnAfterUpdateTick -= GameEvents_UpdateTick;
84102
GraphicsEvents.OnPostRenderGuiEvent -= GraphicsEvents_OnPostRenderGuiEvent;
85103
ControlEvents.OnMouseChanged -= ControlEvents_MouseChanged;
86104
ControlEvents.OnKeyboardChanged -= ControlEvents_KeyboardChanged;
87105
}
106+
88107
internal static void GameEvents_UpdateTick(object s, EventArgs e)
89108
{
90-
foreach (IClickableMenu overlay in Overlays)
109+
foreach (var overlay in Overlays)
91110
{
92111
overlay.update(Game1.currentGameTime);
93112
overlay.performHoverAction(Game1.getMouseX(), Game1.getMouseY());
94113
}
95114
}
115+
96116
internal static void GraphicsEvents_OnPostRenderGuiEvent(object s, EventArgs e)
97117
{
98-
foreach (IClickableMenu overlay in Overlays)
118+
foreach (var overlay in Overlays)
119+
{
99120
overlay.draw(Game1.spriteBatch);
121+
}
100122
}
123+
101124
internal static void ControlEvents_MouseChanged(object s, EventArgsMouseStateChanged e)
102125
{
103126
if (e.NewState.LeftButton == ButtonState.Pressed && e.PriorState.LeftButton == ButtonState.Released)
104-
foreach (IClickableMenu overlay in Overlays)
127+
{
128+
foreach (var overlay in Overlays)
129+
{
105130
overlay.receiveLeftClick(Game1.getMouseX(), Game1.getMouseY());
131+
}
132+
}
133+
106134
if (e.NewState.RightButton == ButtonState.Pressed && e.PriorState.RightButton == ButtonState.Released)
107-
foreach (IClickableMenu overlay in Overlays)
135+
{
136+
foreach (var overlay in Overlays)
137+
{
108138
overlay.receiveRightClick(Game1.getMouseX(), Game1.getMouseY());
139+
}
140+
}
141+
109142
if (e.NewState.ScrollWheelValue != e.PriorState.ScrollWheelValue)
110-
foreach (IClickableMenu overlay in Overlays)
143+
{
144+
foreach (var overlay in Overlays)
145+
{
111146
overlay.receiveScrollWheelAction(e.NewState.ScrollWheelValue - e.PriorState.ScrollWheelValue);
147+
}
148+
}
149+
112150
if (e.NewState.RightButton == ButtonState.Released && e.PriorState.RightButton == ButtonState.Pressed)
113-
foreach (IClickableMenu overlay in Overlays)
151+
{
152+
foreach (var overlay in Overlays)
153+
{
114154
overlay.releaseLeftClick(Game1.getMouseX(), Game1.getMouseY());
155+
}
156+
}
157+
115158
if (e.NewState.RightButton == ButtonState.Pressed && e.PriorState.RightButton == ButtonState.Pressed)
116-
foreach (IClickableMenu overlay in Overlays)
159+
{
160+
foreach (var overlay in Overlays)
161+
{
117162
overlay.leftClickHeld(Game1.getMouseX(), Game1.getMouseY());
163+
}
164+
}
118165
}
166+
119167
internal static void ControlEvents_KeyboardChanged(object s, EventArgsKeyboardStateChanged e)
120168
{
121169
IEnumerable<Keys> old = e.PriorState.GetPressedKeys();
122-
foreach (Keys key in e.NewState.GetPressedKeys())
170+
foreach (var key in e.NewState.GetPressedKeys())
171+
{
123172
if (!old.Contains(key))
124-
foreach (IClickableMenu overlay in Overlays)
173+
{
174+
foreach (var overlay in Overlays)
175+
{
125176
overlay.receiveKeyPress(key);
177+
}
178+
}
179+
}
126180
}
127181
}
128-
}
182+
}

0 commit comments

Comments
 (0)