2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-05-29 11:54:45 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
2008-05-17 17:43:57 +00:00
|
|
|
{
|
|
|
|
public partial class ThingEditForm : DelayedForm
|
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
private ICollection<Thing> things;
|
|
|
|
private List<TreeNode> nodes;
|
2009-02-27 12:29:57 +00:00
|
|
|
private ThingTypeInfo thinginfo;
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ThingEditForm()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
// Fill flags list
|
2008-05-31 19:31:45 +00:00
|
|
|
foreach(KeyValuePair<string, string> tf in General.Map.Config.ThingFlags)
|
|
|
|
flags.Add(tf.Value, tf.Key);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Fill actions list
|
|
|
|
action.GeneralizedCategories = General.Map.Config.GenActionCategories;
|
|
|
|
action.AddInfo(General.Map.Config.SortedLinedefActions.ToArray());
|
2008-05-30 22:14:12 +00:00
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// Fill universal fields list
|
|
|
|
fieldslist.ListFixedFields(General.Map.Config.ThingFields);
|
|
|
|
|
2008-05-30 22:14:12 +00:00
|
|
|
// Initialize custom fields editor
|
2008-06-02 04:55:51 +00:00
|
|
|
fieldslist.Setup("thing");
|
2008-06-03 19:02:06 +00:00
|
|
|
|
2009-03-05 14:46:11 +00:00
|
|
|
// UDMF map?
|
|
|
|
if(General.Map.IsType(typeof(UniversalMapSetIO)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// Hexen map?
|
|
|
|
else if(General.Map.IsType(typeof(HexenMapSetIO)))
|
|
|
|
{
|
|
|
|
tabs.TabPages.Remove(tabcustom);
|
|
|
|
}
|
|
|
|
// Doom map?
|
|
|
|
else
|
2008-06-03 19:02:06 +00:00
|
|
|
{
|
|
|
|
tabs.TabPages.Remove(tabcustom);
|
2009-03-05 14:46:11 +00:00
|
|
|
tabs.TabPages.Remove(tabeffects);
|
|
|
|
height.Visible = false;
|
|
|
|
heightlabel.Visible = false;
|
2008-06-03 19:02:06 +00:00
|
|
|
}
|
2008-05-17 17:43:57 +00:00
|
|
|
|
2009-03-12 23:03:57 +00:00
|
|
|
// Setup types list
|
|
|
|
thingtype.Setup();
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This sets up the form to edit the given things
|
|
|
|
public void Setup(ICollection<Thing> things)
|
|
|
|
{
|
|
|
|
Thing ft;
|
|
|
|
|
|
|
|
// Keep this list
|
|
|
|
this.things = things;
|
|
|
|
if(things.Count > 1) this.Text = "Edit Things (" + things.Count + ")";
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set all options to the first thing properties
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-04 09:54:15 +00:00
|
|
|
ft = General.GetByIndex(things, 0);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
2009-03-12 23:03:57 +00:00
|
|
|
// Set type
|
|
|
|
thingtype.SelectType(ft.Type);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Flags
|
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
2008-06-01 20:25:46 +00:00
|
|
|
if(ft.Flags.ContainsKey(c.Tag.ToString())) c.Checked = ft.Flags[c.Tag.ToString()];
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Coordination
|
2009-01-12 19:21:01 +00:00
|
|
|
angle.Text = Angle2D.RealToDoom(ft.Angle).ToString();
|
2008-06-01 20:25:46 +00:00
|
|
|
height.Text = ((int)ft.Position.z).ToString();
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Action/tags
|
|
|
|
action.Value = ft.Action;
|
|
|
|
tag.Text = ft.Tag.ToString();
|
2008-05-29 21:09:43 +00:00
|
|
|
arg0.SetValue(ft.Args[0]);
|
|
|
|
arg1.SetValue(ft.Args[1]);
|
|
|
|
arg2.SetValue(ft.Args[2]);
|
|
|
|
arg3.SetValue(ft.Args[3]);
|
|
|
|
arg4.SetValue(ft.Args[4]);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// Custom fields
|
|
|
|
fieldslist.SetValues(ft.Fields, true);
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Now go for all lines and change the options when a setting is different
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Go for all things
|
|
|
|
foreach(Thing t in things)
|
|
|
|
{
|
2009-03-12 23:03:57 +00:00
|
|
|
// Type does not match?
|
|
|
|
if((thingtype.GetSelectedInfo() != null) &&
|
|
|
|
(thingtype.GetSelectedInfo().Index != t.Type))
|
|
|
|
thingtype.ClearSelectedType();
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Flags
|
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
|
|
|
{
|
2008-06-01 20:25:46 +00:00
|
|
|
if(t.Flags.ContainsKey(c.Tag.ToString()))
|
2008-05-17 17:43:57 +00:00
|
|
|
{
|
2008-06-01 20:25:46 +00:00
|
|
|
if(t.Flags[c.Tag.ToString()] != c.Checked)
|
|
|
|
{
|
|
|
|
c.ThreeState = true;
|
|
|
|
c.CheckState = CheckState.Indeterminate;
|
|
|
|
}
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Coordination
|
2009-01-12 19:21:01 +00:00
|
|
|
int angledeg = Angle2D.RealToDoom(t.Angle);
|
2008-05-17 17:43:57 +00:00
|
|
|
if(angledeg.ToString() != angle.Text) angle.Text = "";
|
2008-06-01 20:25:46 +00:00
|
|
|
if(((int)t.Position.z).ToString() != height.Text) height.Text = "";
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Action/tags
|
|
|
|
if(t.Action != action.Value) action.Empty = true;
|
|
|
|
if(t.Tag.ToString() != tag.Text) tag.Text = "";
|
2008-05-29 21:09:43 +00:00
|
|
|
if(t.Args[0] != arg0.GetResult(-1)) arg0.ClearValue();
|
|
|
|
if(t.Args[1] != arg1.GetResult(-1)) arg1.ClearValue();
|
|
|
|
if(t.Args[2] != arg2.GetResult(-1)) arg2.ClearValue();
|
|
|
|
if(t.Args[3] != arg3.GetResult(-1)) arg3.ClearValue();
|
|
|
|
if(t.Args[4] != arg4.GetResult(-1)) arg4.ClearValue();
|
2008-06-01 20:25:46 +00:00
|
|
|
|
|
|
|
// Custom fields
|
|
|
|
fieldslist.SetValues(t.Fields, false);
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Interface
|
|
|
|
|
|
|
|
// This finds a new (unused) tag
|
|
|
|
private void newtag_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
tag.Text = General.Map.Map.GetNewTag().ToString();
|
|
|
|
}
|
|
|
|
|
2009-03-12 23:03:57 +00:00
|
|
|
// Selected type changes
|
|
|
|
private void thingtype_OnTypeChanged(ThingTypeInfo value)
|
|
|
|
{
|
2009-03-17 10:49:50 +00:00
|
|
|
// Update preview image
|
|
|
|
thinginfo = value;
|
2009-03-12 23:03:57 +00:00
|
|
|
if(value != null)
|
|
|
|
General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(value.Sprite).GetPreview());
|
|
|
|
else
|
|
|
|
General.DisplayZoomedImage(spritetex, null);
|
2009-03-17 10:49:50 +00:00
|
|
|
|
|
|
|
// Update arguments
|
|
|
|
action_ValueChanges(this, EventArgs.Empty);
|
2009-03-12 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Action changes
|
|
|
|
private void action_ValueChanges(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int showaction = 0;
|
2009-02-27 12:29:57 +00:00
|
|
|
ArgumentInfo[] arginfo;
|
2008-05-17 17:43:57 +00:00
|
|
|
|
2009-02-27 12:29:57 +00:00
|
|
|
// Only when line type is known, otherwise use the thing arguments
|
2008-05-17 17:43:57 +00:00
|
|
|
if(General.Map.Config.LinedefActions.ContainsKey(action.Value)) showaction = action.Value;
|
2009-02-27 12:29:57 +00:00
|
|
|
if((showaction == 0) && (thinginfo != null)) arginfo = thinginfo.Args; else arginfo = General.Map.Config.LinedefActions[showaction].Args;
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Change the argument descriptions
|
2009-02-27 12:29:57 +00:00
|
|
|
arg0label.Text = arginfo[0].Title + ":";
|
|
|
|
arg1label.Text = arginfo[1].Title + ":";
|
|
|
|
arg2label.Text = arginfo[2].Title + ":";
|
|
|
|
arg3label.Text = arginfo[3].Title + ":";
|
|
|
|
arg4label.Text = arginfo[4].Title + ":";
|
|
|
|
arg0label.Enabled = arginfo[0].Used;
|
|
|
|
arg1label.Enabled = arginfo[1].Used;
|
|
|
|
arg2label.Enabled = arginfo[2].Used;
|
|
|
|
arg3label.Enabled = arginfo[3].Used;
|
|
|
|
arg4label.Enabled = arginfo[4].Used;
|
2008-05-17 17:43:57 +00:00
|
|
|
if(arg0label.Enabled) arg0.ForeColor = SystemColors.WindowText; else arg0.ForeColor = SystemColors.GrayText;
|
|
|
|
if(arg1label.Enabled) arg1.ForeColor = SystemColors.WindowText; else arg1.ForeColor = SystemColors.GrayText;
|
|
|
|
if(arg2label.Enabled) arg2.ForeColor = SystemColors.WindowText; else arg2.ForeColor = SystemColors.GrayText;
|
|
|
|
if(arg3label.Enabled) arg3.ForeColor = SystemColors.WindowText; else arg3.ForeColor = SystemColors.GrayText;
|
|
|
|
if(arg4label.Enabled) arg4.ForeColor = SystemColors.WindowText; else arg4.ForeColor = SystemColors.GrayText;
|
2009-02-27 12:29:57 +00:00
|
|
|
arg0.Setup(arginfo[0]);
|
|
|
|
arg1.Setup(arginfo[1]);
|
|
|
|
arg2.Setup(arginfo[2]);
|
|
|
|
arg3.Setup(arginfo[3]);
|
|
|
|
arg4.Setup(arginfo[4]);
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Browse Action clicked
|
|
|
|
private void browseaction_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
action.Value = ActionBrowserForm.BrowseAction(this, action.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Angle text changes
|
|
|
|
private void angle_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
anglecontrol.Value = angle.GetResult(int.MinValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Angle control clicked
|
|
|
|
private void anglecontrol_ButtonClicked(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
angle.Text = anglecontrol.Value.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply clicked
|
|
|
|
private void apply_Click(object sender, EventArgs e)
|
|
|
|
{
|
2009-03-01 19:19:43 +00:00
|
|
|
List<string> defaultflags = new List<string>();
|
2008-05-17 17:43:57 +00:00
|
|
|
string undodesc = "thing";
|
|
|
|
|
|
|
|
// Make undo
|
|
|
|
if(things.Count > 1) undodesc = things.Count + " things";
|
2008-12-24 18:27:13 +00:00
|
|
|
General.Map.UndoRedo.CreateUndo("Edit " + undodesc);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Go for all the things
|
|
|
|
foreach(Thing t in things)
|
|
|
|
{
|
|
|
|
// Thing type index
|
2009-03-12 23:03:57 +00:00
|
|
|
t.Type = thingtype.GetResult(t.Type);
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Coordination
|
2009-01-12 19:21:01 +00:00
|
|
|
t.Rotate(Angle2D.DoomToReal(angle.GetResult(Angle2D.RealToDoom(t.Angle))));
|
2008-06-01 20:25:46 +00:00
|
|
|
t.Move(t.Position.x, t.Position.y, (float)height.GetResult((int)t.Position.z));
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
// Apply all flags
|
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
|
|
|
{
|
2008-05-31 19:31:45 +00:00
|
|
|
if(c.CheckState == CheckState.Checked) t.Flags[c.Tag.ToString()] = true;
|
|
|
|
else if(c.CheckState == CheckState.Unchecked) t.Flags[c.Tag.ToString()] = false;
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Action/tags
|
|
|
|
t.Tag = tag.GetResult(t.Tag);
|
2009-02-25 14:52:36 +00:00
|
|
|
if(!action.Empty) t.Action = action.Value;
|
2009-02-27 08:51:38 +00:00
|
|
|
t.Args[0] = arg0.GetResult(t.Args[0]);
|
|
|
|
t.Args[1] = arg1.GetResult(t.Args[1]);
|
|
|
|
t.Args[2] = arg2.GetResult(t.Args[2]);
|
|
|
|
t.Args[3] = arg3.GetResult(t.Args[3]);
|
|
|
|
t.Args[4] = arg4.GetResult(t.Args[4]);
|
2009-02-25 14:52:36 +00:00
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// Custom fields
|
|
|
|
fieldslist.Apply(t.Fields);
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Update settings
|
|
|
|
t.UpdateConfiguration();
|
|
|
|
}
|
|
|
|
|
2008-06-10 11:32:06 +00:00
|
|
|
// Set as defaults
|
2009-03-01 19:19:43 +00:00
|
|
|
foreach(CheckBox c in flags.Checkboxes)
|
|
|
|
if(c.CheckState == CheckState.Checked) defaultflags.Add(c.Tag.ToString());
|
2009-03-12 23:03:57 +00:00
|
|
|
General.Settings.DefaultThingType = thingtype.GetResult(General.Settings.DefaultThingType);
|
2008-06-10 11:32:06 +00:00
|
|
|
General.Settings.DefaultThingAngle = Angle2D.DegToRad((float)angle.GetResult((int)Angle2D.RadToDeg(General.Settings.DefaultThingAngle) - 90) + 90);
|
2009-03-01 19:19:43 +00:00
|
|
|
General.Settings.SetDefaultThingFlags(defaultflags);
|
2008-06-10 11:32:06 +00:00
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Done
|
2008-05-18 11:56:45 +00:00
|
|
|
General.Map.IsChanged = true;
|
2008-05-17 17:43:57 +00:00
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel clicked
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Be gone
|
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
|
|
this.Close();
|
|
|
|
}
|
2009-04-05 19:29:27 +00:00
|
|
|
|
|
|
|
// Help
|
|
|
|
private void ThingEditForm_HelpRequested(object sender, HelpEventArgs hlpevent)
|
|
|
|
{
|
|
|
|
General.ShowHelp("w_thingeditor.html");
|
|
|
|
hlpevent.Handled = true;
|
|
|
|
}
|
2008-05-17 17:43:57 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|