-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDialogCustomInput.cs
More file actions
65 lines (56 loc) · 2.35 KB
/
DialogCustomInput.cs
File metadata and controls
65 lines (56 loc) · 2.35 KB
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
// Created by Ron 'Maxwolf' McDowell ([email protected])
// Timestamp 01/16/2016@5:33 PM
using System;
using System.Text;
using WolfCurses.Window;
using WolfCurses.Window.Form;
namespace WolfCurses.Example.CustomInput
{
/// <summary>
/// Asks for user name and then accepts the input from the input buffer.
/// </summary>
[ParentWindow(typeof (ExampleWindow))]
public sealed class DialogCustomInput : Form<ExampleWindowInfo>
{
/// <summary>
/// Makes it easy to print and manage multiple lines of text.
/// </summary>
private readonly StringBuilder _inputNamesHelp;
/// <summary>
/// Initializes a new instance of the <see cref="Form{TData}" /> class.
/// This constructor will be used by the other one
/// </summary>
/// <param name="window">The window.</param>
// ReSharper disable once UnusedMember.Global
public DialogCustomInput(IWindow window) : base(window)
{
_inputNamesHelp = new StringBuilder();
}
/// <summary>
/// Returns a text only representation of the current game Windows state. Could be a statement, information, question
/// waiting input, etc.
/// </summary>
/// <returns>
/// The text user interface.<see cref="string" />.
/// </returns>
public override string OnRenderForm()
{
ParentWindow.PromptText = string.Empty;
_inputNamesHelp.Clear();
_inputNamesHelp.AppendLine($"{Environment.NewLine}Dialog Custom Input{Environment.NewLine}");
_inputNamesHelp.Append("What is your name?");
return _inputNamesHelp.ToString();
}
/// <summary>Fired when the game Windows current state is not null and input buffer does not match any known command.</summary>
/// <param name="input">Contents of the input buffer which didn't match any known command in parent game Windows.</param>
public override void OnInputBufferReturned(string input)
{
// Do not allow empty names.
if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
return;
// Copy name into user name and show form.
UserData.PlayerName = input;
SetForm(typeof (ShowName));
}
}
}