Fixed: don't use script control for non-script arg0str. That breaks things.

This commit is contained in:
ZZYZX 2017-02-25 11:04:00 +02:00
parent 6d1717336b
commit 2bb2c92aaa
3 changed files with 125 additions and 65 deletions

View file

@ -27,8 +27,9 @@
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.splitcontainer = new System.Windows.Forms.SplitContainer();
this.arg0str = new System.Windows.Forms.TextBox();
this.cbuseargstr = new System.Windows.Forms.CheckBox();
this.arg0str = new CodeImp.DoomBuilder.Controls.ColoredComboBox();
this.arg0named = new CodeImp.DoomBuilder.Controls.ColoredComboBox();
this.arg0int = new CodeImp.DoomBuilder.Controls.ColoredComboBox();
this.arg0label = new System.Windows.Forms.Label();
this.arg1label = new System.Windows.Forms.Label();
@ -55,8 +56,9 @@
//
// splitcontainer.Panel1
//
this.splitcontainer.Panel1.Controls.Add(this.cbuseargstr);
this.splitcontainer.Panel1.Controls.Add(this.arg0str);
this.splitcontainer.Panel1.Controls.Add(this.cbuseargstr);
this.splitcontainer.Panel1.Controls.Add(this.arg0named);
this.splitcontainer.Panel1.Controls.Add(this.arg0int);
this.splitcontainer.Panel1.Controls.Add(this.arg0label);
this.splitcontainer.Panel1.Controls.Add(this.arg1label);
@ -77,6 +79,14 @@
this.splitcontainer.TabIndex = 0;
this.splitcontainer.TabStop = false;
//
// arg0str
//
this.arg0str.Location = new System.Drawing.Point(237, 131);
this.arg0str.Name = "arg0str";
this.arg0str.Size = new System.Drawing.Size(110, 20);
this.arg0str.TabIndex = 45;
this.arg0str.Visible = false;
//
// cbuseargstr
//
this.cbuseargstr.Location = new System.Drawing.Point(3, -5);
@ -87,19 +97,19 @@
this.cbuseargstr.UseVisualStyleBackColor = true;
this.cbuseargstr.CheckedChanged += new System.EventHandler(this.cbuseargstr_CheckedChanged);
//
// arg0str
// arg0named
//
this.arg0str.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.arg0str.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.arg0str.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.arg0str.BackColor = System.Drawing.Color.Honeydew;
this.arg0str.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.arg0str.FormattingEnabled = true;
this.arg0str.Location = new System.Drawing.Point(237, 104);
this.arg0str.Name = "arg0str";
this.arg0str.Size = new System.Drawing.Size(110, 21);
this.arg0str.TabIndex = 41;
this.arg0str.TextChanged += new System.EventHandler(this.arg0str_TextChanged);
this.arg0named.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.arg0named.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.arg0named.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.arg0named.BackColor = System.Drawing.Color.Honeydew;
this.arg0named.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.arg0named.FormattingEnabled = true;
this.arg0named.Location = new System.Drawing.Point(237, 104);
this.arg0named.Name = "arg0named";
this.arg0named.Size = new System.Drawing.Size(110, 21);
this.arg0named.TabIndex = 41;
this.arg0named.TextChanged += new System.EventHandler(this.arg0str_TextChanged);
//
// arg0int
//
@ -218,6 +228,7 @@
this.Name = "ArgumentsControl";
this.Size = new System.Drawing.Size(700, 140);
this.splitcontainer.Panel1.ResumeLayout(false);
this.splitcontainer.Panel1.PerformLayout();
this.splitcontainer.Panel2.ResumeLayout(false);
this.splitcontainer.ResumeLayout(false);
this.ResumeLayout(false);
@ -233,7 +244,7 @@
private ColoredComboBox arg0int;
private System.Windows.Forms.Label arg2label;
private System.Windows.Forms.Label arg1label;
private ColoredComboBox arg0str;
private ColoredComboBox arg0named;
private System.Windows.Forms.Label arg3label;
private System.Windows.Forms.Label arg4label;
private ArgumentBox arg3;
@ -241,5 +252,6 @@
private System.Windows.Forms.CheckBox cbuseargstr;
private System.Windows.Forms.ToolTip tooltip;
private ArgumentBox arg2;
}
private System.Windows.Forms.TextBox arg0str;
}
}

View file

@ -140,8 +140,16 @@ namespace CodeImp.DoomBuilder.Controls
{
// Apply arg0str
case ArgZeroMode.STRING:
if(!string.IsNullOrEmpty(arg0str.Text))
l.Fields["arg0str"] = new UniValue(UniversalType.String, arg0str.Text);
if (isacs)
{
if (!string.IsNullOrEmpty(arg0named.Text))
l.Fields["arg0str"] = new UniValue(UniversalType.String, arg0named.Text);
}
else
{
if (!string.IsNullOrEmpty(arg0str.Text))
l.Fields["arg0str"] = new UniValue(UniversalType.String, arg0str.Text);
}
break;
// Apply script number
@ -178,41 +186,53 @@ namespace CodeImp.DoomBuilder.Controls
public void Apply(Thing t, int step)
{
//mxd. Script name/number handling
// We can't rely on control visibility here, because all controlls will be invisible if ArgumentsControl is invisible
// (for example, when a different tab is selected)
switch(Arg0Mode)
{
// Apply arg0str
case ArgZeroMode.STRING:
if(!string.IsNullOrEmpty(arg0str.Text))
t.Fields["arg0str"] = new UniValue(UniversalType.String, arg0str.Text);
break;
//mxd. Script name/number handling
// We can't rely on control visibility here, because all controlls will be invisible if ArgumentsControl is invisible
// (for example, when a different tab is selected)
bool isacs = (Array.IndexOf(GZGeneral.ACS_SPECIALS, action) != -1);
switch (Arg0Mode)
{
// Apply arg0str
case ArgZeroMode.STRING:
if (isacs)
{
if (!string.IsNullOrEmpty(arg0named.Text))
t.Fields["arg0str"] = new UniValue(UniversalType.String, arg0named.Text);
}
else
{
if (!string.IsNullOrEmpty(arg0str.Text))
t.Fields["arg0str"] = new UniValue(UniversalType.String, arg0str.Text);
}
break;
// Apply script number
case ArgZeroMode.INT:
if(!string.IsNullOrEmpty(arg0int.Text))
{
if(arg0int.SelectedItem != null)
t.Args[0] = ((ScriptItem)((ColoredComboBoxItem)arg0int.SelectedItem).Value).Index;
else if(!int.TryParse(arg0int.Text.Trim(), out t.Args[0]))
t.Args[0] = 0;
// Apply script number
case ArgZeroMode.INT:
if (!isacs)
goto case ArgZeroMode.DEFAULT;
//
if (!string.IsNullOrEmpty(arg0int.Text))
{
if (arg0int.SelectedItem != null)
t.Args[0] = ((ScriptItem)((ColoredComboBoxItem)arg0int.SelectedItem).Value).Index;
else if (!int.TryParse(arg0int.Text.Trim(), out t.Args[0]))
t.Args[0] = 0;
if(t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
}
break;
if (t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
}
break;
// Apply classic arg
case ArgZeroMode.DEFAULT:
t.Args[0] = arg0.GetResult(t.Args[0], step);
if(t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
break;
// Apply classic arg
case ArgZeroMode.DEFAULT:
t.Args[0] = arg0.GetResult(t.Args[0], step);
if (t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
break;
default: throw new NotImplementedException("Unknown ArgZeroMode");
}
default: throw new NotImplementedException("Unknown ArgZeroMode");
}
// Apply the rest of args
t.Args[1] = arg1.GetResult(t.Args[1], step);
// Apply the rest of args
t.Args[1] = arg1.GetResult(t.Args[1], step);
t.Args[2] = arg2.GetResult(t.Args[2], step);
t.Args[3] = arg3.GetResult(t.Args[3], step);
t.Args[4] = arg4.GetResult(t.Args[4], step);
@ -275,6 +295,7 @@ namespace CodeImp.DoomBuilder.Controls
arg4.SetValue(0);
}
// arg0str currently can't have any default
arg0named.Text = arg0strval = " ";
arg0str.Text = arg0strval = " ";
}
@ -305,29 +326,35 @@ namespace CodeImp.DoomBuilder.Controls
//mxd. Setup script names
if (General.Map.UDMF)
{
arg0str.Items.Clear();
arg0str.Location = arg0int.Location;
// [ZZ] note: only do this if our action is acs.
if (isacs)
{
arg0named.Items.Clear();
arg0named.Location = arg0int.Location;
foreach (ScriptItem nsi in General.Map.NamedScripts.Values)
arg0str.Items.Add(new ColoredComboBoxItem(nsi, nsi.IsInclude ? SystemColors.HotTrack : SystemColors.WindowText));
arg0str.DropDownWidth = Tools.GetDropDownWidth(arg0str);
arg0named.Items.Add(new ColoredComboBoxItem(nsi, nsi.IsInclude ? SystemColors.HotTrack : SystemColors.WindowText));
arg0named.DropDownWidth = Tools.GetDropDownWidth(arg0named);
}
else
{
arg0str.Clear();
arg0str.Location = arg0int.Location;
}
}
else
{
arg0named.Visible = false;
arg0str.Visible = false;
cbuseargstr.Visible = false;
}
//
arg0str.DropDownStyle = isacs ? ComboBoxStyle.DropDown : ComboBoxStyle.Simple;
// Update script controls visibility
bool showarg0str = (General.Map.UDMF && havearg0str);
cbuseargstr.Visible = General.Map.UDMF;
cbuseargstr.Checked = showarg0str;
arg0str.Visible = showarg0str;
arg0named.Visible = showarg0str && isacs;
arg0str.Visible = showarg0str && !isacs;
arg0int.Visible = (!showarg0str && isacs);
arg0.Visible = (!showarg0str && !isacs);
@ -335,7 +362,7 @@ namespace CodeImp.DoomBuilder.Controls
if(showarg0str)
{
Arg0Mode = ArgZeroMode.STRING;
arg0str.Text = arg0strval;
arg0str.Text = arg0named.Text = arg0strval;
if (isacs && General.Map.NamedScripts.ContainsKey(arg0strval))
UpdateScriptArguments(General.Map.NamedScripts[arg0strval]);
@ -371,7 +398,8 @@ namespace CodeImp.DoomBuilder.Controls
{
arg0.Visible = true;
cbuseargstr.Visible = false;
arg0str.Visible = false;
arg0named.Visible = false;
arg0str.Visible = false;
arg0int.Visible = false;
cbuseargstr.Checked = false;
Arg0Mode = ArgZeroMode.DEFAULT;
@ -486,7 +514,8 @@ namespace CodeImp.DoomBuilder.Controls
{
if(!cbuseargstr.Visible) return;
bool isacs = (Array.IndexOf(GZGeneral.ACS_SPECIALS, action) != -1);
arg0str.Visible = cbuseargstr.Checked;
arg0named.Visible = (cbuseargstr.Checked && isacs);
arg0str.Visible = (cbuseargstr.Checked && !isacs);
arg0int.Visible = (!cbuseargstr.Checked && isacs);
arg0.Visible = (!cbuseargstr.Checked && !isacs);
Arg0Mode = (cbuseargstr.Checked ? ArgZeroMode.STRING : ArgZeroMode.INT);
@ -512,15 +541,15 @@ namespace CodeImp.DoomBuilder.Controls
private void arg0str_TextChanged(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(arg0str.Text)) return;
if(string.IsNullOrEmpty(arg0named.Text)) return;
ScriptItem item = null;
if(arg0str.SelectedIndex != -1)
if(arg0named.SelectedIndex != -1)
{
item = ((ScriptItem)((ColoredComboBoxItem)arg0str.SelectedItem).Value);
item = ((ScriptItem)((ColoredComboBoxItem)arg0named.SelectedItem).Value);
}
else
{
string scriptname = arg0str.Text.Trim().ToLowerInvariant();
string scriptname = arg0named.Text.Trim().ToLowerInvariant();
if(General.Map.NamedScripts.ContainsKey(scriptname))
item = General.Map.NamedScripts[scriptname];
}
@ -528,6 +557,16 @@ namespace CodeImp.DoomBuilder.Controls
UpdateScriptArguments(item);
}
#endregion
}
#endregion
private void scriptnames_TextChanged(object sender, EventArgs e)
{
}
private void scriptnumbers_TextChanged(object sender, EventArgs e)
{
}
}
}

View file

@ -7,10 +7,19 @@ namespace CodeImp.DoomBuilder.Controls
{
public ColoredComboBox()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DrawMode = DrawMode.OwnerDrawFixed;
this.KeyPress += ColoredComboBox_KeyPress;
}
protected override void OnDrawItem(DrawItemEventArgs e)
private void ColoredComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
e.Handled = true;
}
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.DrawBackground();