UltimateZoneBuilder/Source/Core/Controls/CommentEditor.cs
MaxED 5cd998b1fc Changed, Linedef/Thing Edit windows: when using ACS specials and choosing a script with arguments, appropriate action argument names are replaced with script argument names.
Changed, Linedef/Thing Info panel: when displaying a linedef/thing with an ACS special, which uses a script with arguments, appropriate action argument names are replaced with script argument names.
Changed, Sector/Linedef/Thing Edit windows, Comments tab: window is no longer closed when pressing Enter while editing a comment. Newline is inserted instead.
Changed: Script Editor window is now toggled to normal state when pressing "Show Script Editor" button if said window was already open, but minimized.
Fixed: in some cases action arguments were not cleared during setup when displaying multiple map elements with mixed argument values.
Internal: added ArgumentsControl.
2015-07-27 09:02:28 +00:00

141 lines
3.3 KiB
C#

#region ================== Copyright
/*
* Made by MaxED, mkay?
*/
#endregion
#region ================== Namespaces
using System;
using System.Drawing;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.GZBuilder.Tools;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
public partial class CommentEditor : UserControl
{
#region ================== Variables
private const string DEFAULT_TEXT = "Click to enter a comment...";
private bool mixedvalues;
private int commenttype;
#endregion
#region ================== Constructor / Disposer
public CommentEditor()
{
InitializeComponent();
}
#endregion
#region ================== Methods
public void SetValues(UniFields fields, bool first)
{
if(mixedvalues) return;
string c = fields.GetValue("comment", string.Empty);
if(first)
{
textbox.Text = c;
}
else if(textbox.Text != c)
{
textbox.Clear();
mixedvalues = true;
}
}
public void FinishSetup()
{
if(mixedvalues) return;
if(string.IsNullOrEmpty(textbox.Text))
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
radioButton1.Checked = true;
}
else if(textbox.Text.Length > 2)
{
string type = textbox.Text.Substring(0, 3);
int index = Array.IndexOf(CommentType.Types, type);
commenttype = (index > 0 ? index : 0);
if(commenttype > 0) textbox.Text = textbox.Text.TrimStart(type.ToCharArray());
// Isn't there a better way to do this?..
switch(commenttype)
{
case 0: radioButton1.Checked = true; break;
case 1: radioButton2.Checked = true; break;
case 2: radioButton3.Checked = true; break;
case 3: radioButton4.Checked = true; break;
case 4: radioButton5.Checked = true; break;
}
}
}
public void Apply(UniFields fields)
{
if(mixedvalues) return;
string text = (!string.IsNullOrEmpty(textbox.Text) && textbox.Text != DEFAULT_TEXT ? CommentType.Types[commenttype] + textbox.Text : String.Empty);
UDMFTools.SetString(fields, "comment", text, string.Empty);
}
#endregion
#region ================== Events
private void clear_Click(object sender, EventArgs e)
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
mixedvalues = false;
}
private void textbox_Enter(object sender, EventArgs e)
{
if(textbox.Text == DEFAULT_TEXT)
{
textbox.Clear();
textbox.ForeColor = SystemColors.WindowText;
}
}
private void textbox_Leave(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(textbox.Text) && !mixedvalues)
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
}
}
private void textbox_TextChanged(object sender, EventArgs e)
{
mixedvalues = false;
}
private void radiobutton_CheckedChanged(object sender, EventArgs e)
{
commenttype = (int)((Control)sender).Tag;
}
// We don't want to close the parent form when user presses Enter while typing the text
private void textbox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if(e.KeyCode == Keys.Enter) e.IsInputKey = true;
}
#endregion
}
}