TextPrompt.cs - Set Controls to private, added setter properties for them and added empty constructor

This commit is contained in:
miku-666
2023-06-17 16:07:24 +02:00
parent 91c5bcb4ef
commit fe7123418e
7 changed files with 116 additions and 103 deletions

View File

@@ -251,9 +251,9 @@ namespace PckStudio.Features
private void addCustomPckToolStripMenuItem_Click(object sender, EventArgs e)
{
TextPrompt prompt = new TextPrompt(string.Empty);
prompt.OKButton.Text = "OK";
prompt.TextLabel.Text = "Folder:";
TextPrompt prompt = new TextPrompt();
prompt.OKButtonText = "OK";
prompt.LabelText = "Folder:";
if (prompt.ShowDialog(this) != DialogResult.OK)
return;

View File

@@ -28,92 +28,92 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TextPrompt));
this.TextLabel = new System.Windows.Forms.Label();
this.OKButton = new System.Windows.Forms.Button();
this.InputTextBox = new MetroFramework.Controls.MetroTextBox();
this.contextLabel = new MetroFramework.Controls.MetroLabel();
this.SuspendLayout();
//
// TextLabel
//
resources.ApplyResources(this.TextLabel, "TextLabel");
this.TextLabel.ForeColor = System.Drawing.Color.White;
this.TextLabel.Name = "TextLabel";
//
// OKButton
//
resources.ApplyResources(this.OKButton, "OKButton");
this.OKButton.ForeColor = System.Drawing.Color.White;
this.OKButton.Name = "OKButton";
this.OKButton.UseVisualStyleBackColor = true;
this.OKButton.Click += new System.EventHandler(this.OKBtn_Click);
//
// InputTextBox
//
resources.ApplyResources(this.InputTextBox, "InputTextBox");
//
//
//
this.InputTextBox.CustomButton.Image = ((System.Drawing.Image)(resources.GetObject("resource.Image")));
this.InputTextBox.CustomButton.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("resource.ImeMode")));
this.InputTextBox.CustomButton.Location = ((System.Drawing.Point)(resources.GetObject("resource.Location")));
this.InputTextBox.CustomButton.Name = "";
this.InputTextBox.CustomButton.Size = ((System.Drawing.Size)(resources.GetObject("resource.Size")));
this.InputTextBox.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.InputTextBox.CustomButton.TabIndex = ((int)(resources.GetObject("resource.TabIndex")));
this.InputTextBox.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
this.InputTextBox.CustomButton.UseSelectable = true;
this.InputTextBox.CustomButton.Visible = ((bool)(resources.GetObject("resource.Visible")));
this.InputTextBox.Lines = new string[0];
this.InputTextBox.MaxLength = 255;
this.InputTextBox.Name = "InputTextBox";
this.InputTextBox.PasswordChar = '\0';
this.InputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.InputTextBox.SelectedText = "";
this.InputTextBox.SelectionLength = 0;
this.InputTextBox.SelectionStart = 0;
this.InputTextBox.ShortcutsEnabled = true;
this.InputTextBox.Style = MetroFramework.MetroColorStyle.White;
this.InputTextBox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.InputTextBox.UseSelectable = true;
this.InputTextBox.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.InputTextBox.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
//
// contextLabel
//
resources.ApplyResources(this.contextLabel, "contextLabel");
this.contextLabel.FontSize = MetroFramework.MetroLabelSize.Small;
this.contextLabel.Name = "contextLabel";
this.contextLabel.Theme = MetroFramework.MetroThemeStyle.Dark;
this.contextLabel.WrapToLine = true;
//
// TextPrompt
//
this.AcceptButton = this.OKButton;
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.contextLabel);
this.Controls.Add(this.InputTextBox);
this.Controls.Add(this.OKButton);
this.Controls.Add(this.TextLabel);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TextPrompt";
this.Resizable = false;
this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow;
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.Load += new System.EventHandler(this.RenamePrompt_Load);
this.ResumeLayout(false);
this.PerformLayout();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TextPrompt));
this.TextLabel = new System.Windows.Forms.Label();
this.OKButton = new System.Windows.Forms.Button();
this.InputTextBox = new MetroFramework.Controls.MetroTextBox();
this.contextLabel = new MetroFramework.Controls.MetroLabel();
this.SuspendLayout();
//
// TextLabel
//
resources.ApplyResources(this.TextLabel, "TextLabel");
this.TextLabel.ForeColor = System.Drawing.Color.White;
this.TextLabel.Name = "TextLabel";
//
// OKButton
//
resources.ApplyResources(this.OKButton, "OKButton");
this.OKButton.ForeColor = System.Drawing.Color.White;
this.OKButton.Name = "OKButton";
this.OKButton.UseVisualStyleBackColor = true;
this.OKButton.Click += new System.EventHandler(this.OKBtn_Click);
//
// InputTextBox
//
resources.ApplyResources(this.InputTextBox, "InputTextBox");
//
//
//
this.InputTextBox.CustomButton.Image = ((System.Drawing.Image)(resources.GetObject("resource.Image")));
this.InputTextBox.CustomButton.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("resource.ImeMode")));
this.InputTextBox.CustomButton.Location = ((System.Drawing.Point)(resources.GetObject("resource.Location")));
this.InputTextBox.CustomButton.Name = "";
this.InputTextBox.CustomButton.Size = ((System.Drawing.Size)(resources.GetObject("resource.Size")));
this.InputTextBox.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.InputTextBox.CustomButton.TabIndex = ((int)(resources.GetObject("resource.TabIndex")));
this.InputTextBox.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
this.InputTextBox.CustomButton.UseSelectable = true;
this.InputTextBox.CustomButton.Visible = ((bool)(resources.GetObject("resource.Visible")));
this.InputTextBox.Lines = new string[0];
this.InputTextBox.MaxLength = 255;
this.InputTextBox.Name = "InputTextBox";
this.InputTextBox.PasswordChar = '\0';
this.InputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.InputTextBox.SelectedText = "";
this.InputTextBox.SelectionLength = 0;
this.InputTextBox.SelectionStart = 0;
this.InputTextBox.ShortcutsEnabled = true;
this.InputTextBox.Style = MetroFramework.MetroColorStyle.White;
this.InputTextBox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.InputTextBox.UseSelectable = true;
this.InputTextBox.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.InputTextBox.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
//
// contextLabel
//
resources.ApplyResources(this.contextLabel, "contextLabel");
this.contextLabel.FontSize = MetroFramework.MetroLabelSize.Small;
this.contextLabel.Name = "contextLabel";
this.contextLabel.Theme = MetroFramework.MetroThemeStyle.Dark;
this.contextLabel.WrapToLine = true;
//
// TextPrompt
//
this.AcceptButton = this.OKButton;
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.contextLabel);
this.Controls.Add(this.InputTextBox);
this.Controls.Add(this.OKButton);
this.Controls.Add(this.TextLabel);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TextPrompt";
this.Resizable = false;
this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow;
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.Load += new System.EventHandler(this.RenamePrompt_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.Button OKButton;
public System.Windows.Forms.Label TextLabel;
private MetroFramework.Controls.MetroTextBox InputTextBox;
public MetroFramework.Controls.MetroLabel contextLabel;
}
private System.Windows.Forms.Button OKButton;
private System.Windows.Forms.Label TextLabel;
}
}

View File

@@ -11,19 +11,32 @@ namespace PckStudio
/// </summary>
public string NewText => InputTextBox.Text;
public TextPrompt(string InitialText) : this(InitialText, -1)
public string OKButtonText
{
set => OKButton.Text = value;
}
public string LabelText
{
set => TextLabel.Text = value;
}
public TextPrompt() : this(string.Empty, -1)
{ }
public TextPrompt(string InitialText, int maxChar)
public TextPrompt(string initialText) : this(initialText, -1)
{ }
public TextPrompt(string initialText, int maxTextLength)
{
InitializeComponent();
InputTextBox.Text = InitialText;
InputTextBox.MaxLength = maxChar < 0 ? short.MaxValue : maxChar;
InputTextBox.Text = initialText;
InputTextBox.MaxLength = maxTextLength < 0 ? short.MaxValue : maxTextLength;
}
private void OKBtn_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(InputTextBox.Text))
if (string.IsNullOrEmpty(InputTextBox.Text))
{
MessageBox.Show(this, "Please insert a value in the text box.", "Empty string");
}
@@ -32,7 +45,7 @@ namespace PckStudio
private void RenamePrompt_Load(object sender, EventArgs e)
{
if(String.IsNullOrEmpty(contextLabel.Text))
if(string.IsNullOrEmpty(contextLabel.Text))
{
contextLabel.Visible = false;
Size = new System.Drawing.Size(264, 85);

View File

@@ -247,8 +247,8 @@ namespace PckStudio.Forms.Editor
{
if (!string.IsNullOrWhiteSpace(value)) MessageBox.Show($"The following value \"{value}\" is not valid. Please try again.");
TextPrompt diag = new TextPrompt(value);
diag.TextLabel.Text = "ANIM";
diag.OKButton.Text = "Ok";
diag.LabelText = "ANIM";
diag.OKButtonText = "Ok";
if (diag.ShowDialog() == DialogResult.OK)
{
value = diag.NewText;

View File

@@ -205,9 +205,9 @@ namespace PckStudio.Forms.Editor
? GrfTreeView.SelectedNode.Nodes
: GrfTreeView.Nodes;
using (TextPrompt prompt = new TextPrompt(""))
using (TextPrompt prompt = new TextPrompt())
{
prompt.OKButton.Text = "Add";
prompt.OKButtonText = "Add";
if (MessageBox.Show($"Add Game Rule to {parentRule.Name}", "Attention",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes &&
prompt.ShowDialog() == DialogResult.OK &&

View File

@@ -61,9 +61,9 @@ namespace PckStudio.Forms.Editor
private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e)
{
if (treeViewLocKeys.SelectedNode is TreeNode)
using (TextPrompt prompt = new TextPrompt(""))
using (TextPrompt prompt = new TextPrompt())
{
prompt.OKButton.Text = "Add";
prompt.OKButtonText = "Add";
if (prompt.ShowDialog() == DialogResult.OK &&
!currentLoc.LocKeys.ContainsKey(prompt.NewText) &&
currentLoc.AddLocKey(prompt.NewText, ""))

View File

@@ -1064,7 +1064,7 @@ namespace PckStudio
using TextPrompt diag = new TextPrompt(node.Tag is null ? Path.GetFileName(node.FullPath) : node.FullPath);
diag.contextLabel.Text = $"Creating a clone of \"{path}\". Ensure that the path isn't yet.";
diag.OKButton.Text = "Clone";
diag.OKButtonText = "Clone";
if (diag.ShowDialog(this) == DialogResult.OK)
{
@@ -1296,8 +1296,8 @@ namespace PckStudio
private void skinPackToolStripMenuItem_Click(object sender, EventArgs e)
{
checkSaveState();
TextPrompt namePrompt = new TextPrompt("");
namePrompt.OKButton.Text = "Ok";
TextPrompt namePrompt = new TextPrompt();
namePrompt.OKButtonText = "Ok";
if (namePrompt.ShowDialog() == DialogResult.OK)
{
currentPCK = InitializePack(new Random().Next(8000, int.MaxValue), 0, namePrompt.NewText, true);
@@ -1647,9 +1647,9 @@ namespace PckStudio
private void folderToolStripMenuItem_Click(object sender, EventArgs e)
{
TextPrompt folderNamePrompt = new TextPrompt("");
TextPrompt folderNamePrompt = new TextPrompt();
if(treeViewMain.SelectedNode is not null) folderNamePrompt.contextLabel.Text = $"New folder at the location of \"{treeViewMain.SelectedNode.FullPath}\"";
folderNamePrompt.OKButton.Text = "Add";
folderNamePrompt.OKButtonText = "Add";
if (folderNamePrompt.ShowDialog() == DialogResult.OK)
{
TreeNode folerNode = CreateNode(folderNamePrompt.NewText);
@@ -1921,7 +1921,7 @@ namespace PckStudio
if (fileDialog.ShowDialog() == DialogResult.OK)
{
using TextPrompt renamePrompt = new TextPrompt(Path.GetFileName(fileDialog.FileName));
renamePrompt.TextLabel.Text = "Path";
renamePrompt.LabelText = "Path";
if (renamePrompt.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(renamePrompt.NewText))
{
var file = currentPCK.CreateNewFile(renamePrompt.NewText, PckFile.FileData.FileType.TextureFile);