2012-08-14 20:10:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
|
|
|
|
{
|
|
|
|
|
public partial class FlagsForm : DelayedForm
|
|
|
|
|
{
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
private string value;
|
|
|
|
|
private IDictionary<string, string> flagdefs;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
public string Value { get { return value; } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
|
|
public FlagsForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Setup from EnumList
|
|
|
|
|
public void Setup(string value, IDictionary<string, string> inflags)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
//setup = true;
|
2012-08-14 20:10:59 +00:00
|
|
|
|
this.value = value;
|
|
|
|
|
flagdefs = inflags;
|
|
|
|
|
|
2016-06-08 00:06:20 +00:00
|
|
|
|
//mxd. Store current size...
|
|
|
|
|
int flagswidth = flags.Width;
|
|
|
|
|
int flagsheight = flags.Height;
|
|
|
|
|
|
|
|
|
|
//mxd. How many columns will be required?
|
|
|
|
|
flags.Columns = Math.Max(1, flagdefs.Count / 8);
|
|
|
|
|
|
2012-08-14 20:10:59 +00:00
|
|
|
|
// Fill flags list
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(KeyValuePair<string, string> tf in flagdefs)
|
2016-06-08 00:06:20 +00:00
|
|
|
|
{
|
|
|
|
|
CheckBox cb = flags.Add(tf.Value, tf.Key);
|
|
|
|
|
cb.ThreeState = true; //mxd
|
|
|
|
|
cb.CheckState = CheckState.Indeterminate; //mxd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mxd. Resize window?
|
|
|
|
|
int newflagswidth = flags.GetWidth();
|
|
|
|
|
int newflagsheight = flags.GetHeight();
|
|
|
|
|
|
|
|
|
|
if(flagswidth != newflagswidth) this.Width += (newflagswidth - flagswidth);
|
|
|
|
|
if(flagsheight != newflagsheight) this.Height += (newflagsheight - flagsheight);
|
2012-08-14 20:10:59 +00:00
|
|
|
|
|
|
|
|
|
// Parse the value string and check the boxes if necessary
|
2016-02-01 22:04:00 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(value.Trim()))
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(string s in value.Split(','))
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
|
|
|
|
string str = s.Trim();
|
|
|
|
|
|
2016-06-08 00:06:20 +00:00
|
|
|
|
//mxd. Negative flag?
|
2016-07-02 22:27:20 +00:00
|
|
|
|
CheckState setflag = CheckState.Checked;
|
2016-06-08 00:06:20 +00:00
|
|
|
|
if(str.StartsWith("!"))
|
|
|
|
|
{
|
2016-07-02 22:27:20 +00:00
|
|
|
|
setflag = CheckState.Unchecked;
|
2016-06-08 00:06:20 +00:00
|
|
|
|
str = str.Substring(1, str.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 20:10:59 +00:00
|
|
|
|
// Make sure the given flag actually exists
|
2016-06-08 00:06:20 +00:00
|
|
|
|
if(!flagdefs.ContainsKey(str)) continue;
|
2012-08-14 20:10:59 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
2016-07-02 22:27:20 +00:00
|
|
|
|
if(c.Text == flagdefs[str]) c.CheckState = setflag;
|
2012-08-14 20:10:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This shows the dialog
|
|
|
|
|
// Returns the flags or the same flags when cancelled
|
|
|
|
|
public static string ShowDialog(IWin32Window owner, string value, IDictionary<string, string> inflags)
|
|
|
|
|
{
|
|
|
|
|
string result = value;
|
|
|
|
|
FlagsForm f = new FlagsForm();
|
|
|
|
|
f.Setup(value, inflags);
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(f.ShowDialog(owner) == DialogResult.OK) result = f.Value;
|
2012-08-14 20:10:59 +00:00
|
|
|
|
f.Dispose();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void apply_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
value = "";
|
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
2016-06-08 00:06:20 +00:00
|
|
|
|
if(c.CheckState == CheckState.Indeterminate) continue;
|
2012-08-14 20:10:59 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(KeyValuePair<string, string> lf in flagdefs)
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(lf.Value == c.Text)
|
2012-08-14 20:10:59 +00:00
|
|
|
|
{
|
2016-02-01 22:04:00 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(value)) value += ",";
|
2016-06-08 00:06:20 +00:00
|
|
|
|
value += (c.CheckState == CheckState.Unchecked ? "!" + lf.Key : lf.Key);
|
2012-08-14 20:10:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Close
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|