2009-04-19 18:07:22 +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.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
2014-11-06 12:56:47 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2014-10-29 11:35:27 +00:00
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Controls;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
|
|
|
public partial class ThingBrowserControl : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
public delegate void TypeChangedDeletegate(ThingTypeInfo value);
|
|
|
|
public delegate void TypeDoubleClickDeletegate();
|
|
|
|
|
|
|
|
public event TypeChangedDeletegate OnTypeChanged;
|
|
|
|
public event TypeDoubleClickDeletegate OnTypeDoubleClicked;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
private List<TreeNode> nodes;
|
2014-11-10 11:27:37 +00:00
|
|
|
private List<TreeNode> validnodes; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
private ThingTypeInfo thinginfo;
|
|
|
|
private bool doupdatenode;
|
|
|
|
private bool doupdatetextbox;
|
2014-10-29 11:35:27 +00:00
|
|
|
private TreeNode doubleclickednode; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public string TypeStringValue { get { return typeid.Text; } }
|
2014-10-29 11:35:27 +00:00
|
|
|
public bool UseMultiSelection { get { return typelist.SelectionMode == TreeViewSelectionMode.MultiSelectSameLevel; } set { typelist.SelectionMode = (value ? TreeViewSelectionMode.MultiSelectSameLevel : TreeViewSelectionMode.SingleSelect); } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ThingBrowserControl()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets up the control
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
// Go for all predefined categories
|
|
|
|
typelist.Nodes.Clear();
|
|
|
|
nodes = new List<TreeNode>();
|
2014-11-10 11:27:37 +00:00
|
|
|
validnodes = new List<TreeNode>(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
foreach(ThingCategory tc in General.Map.Data.ThingCategories)
|
|
|
|
{
|
|
|
|
// Create category
|
|
|
|
TreeNode cn = typelist.Nodes.Add(tc.Name, tc.Title);
|
|
|
|
if((tc.Color >= 0) && (tc.Color < thingimages.Images.Count)) cn.ImageIndex = tc.Color;
|
|
|
|
cn.SelectedImageIndex = cn.ImageIndex;
|
|
|
|
foreach(ThingTypeInfo ti in tc.Things)
|
|
|
|
{
|
|
|
|
// Create thing
|
|
|
|
TreeNode n = cn.Nodes.Add(ti.Title);
|
|
|
|
if((ti.Color >= 0) && (ti.Color < thingimages.Images.Count)) n.ImageIndex = ti.Color;
|
|
|
|
n.SelectedImageIndex = n.ImageIndex;
|
|
|
|
n.Tag = ti;
|
|
|
|
nodes.Add(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doupdatenode = true;
|
|
|
|
doupdatetextbox = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// Select a type
|
|
|
|
public void SelectType(int type)
|
|
|
|
{
|
|
|
|
// Set type index
|
|
|
|
typeid.Text = type.ToString();
|
|
|
|
typeid_TextChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return selected type info
|
|
|
|
public ThingTypeInfo GetSelectedInfo()
|
|
|
|
{
|
|
|
|
return thinginfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This clears the type
|
|
|
|
public void ClearSelectedType()
|
|
|
|
{
|
|
|
|
doupdatenode = false;
|
|
|
|
|
|
|
|
// Clear selection
|
2014-10-29 11:35:27 +00:00
|
|
|
typelist.SelectedNodes.Clear(); //mxd
|
2014-11-10 11:27:37 +00:00
|
|
|
validnodes.Clear(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
typeid.Text = "";
|
|
|
|
|
|
|
|
// Collapse nodes
|
|
|
|
foreach(TreeNode n in nodes)
|
|
|
|
if(n.Parent.IsExpanded) n.Parent.Collapse();
|
|
|
|
|
|
|
|
doupdatenode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result
|
|
|
|
public int GetResult(int original)
|
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
//mxd. Get a random ThingTypeInfo from valid nodes?
|
|
|
|
if(typelist.SelectionMode == TreeViewSelectionMode.MultiSelectSameLevel && validnodes.Count > 0)
|
2014-10-29 11:35:27 +00:00
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
return (validnodes[General.Random(0, validnodes.Count - 1)].Tag as ThingTypeInfo).Index;
|
2013-07-11 11:43:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
return typeid.GetResult(original);
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:43:49 +00:00
|
|
|
//mxd
|
2014-10-29 11:35:27 +00:00
|
|
|
private List<TreeNode> GetValidNodes()
|
2014-05-20 09:09:28 +00:00
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
Dictionary<string, TreeNode> vn = new Dictionary<string, TreeNode>(StringComparer.Ordinal);
|
|
|
|
foreach(TreeNode n in typelist.SelectedNodes) GetValidNodes(n, ref vn);
|
|
|
|
return new List<TreeNode>(vn.Values);
|
|
|
|
}
|
2013-07-11 11:43:49 +00:00
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
private static void GetValidNodes(TreeNode root, ref Dictionary<string, TreeNode> vn)
|
2014-11-10 11:27:37 +00:00
|
|
|
{
|
|
|
|
if (root.Nodes.Count == 0)
|
2014-10-29 11:35:27 +00:00
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
if(root.Tag is ThingTypeInfo && !vn.ContainsKey(root.Text)) vn.Add(root.Text, root);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach(TreeNode n in root.Nodes) GetValidNodes(n, ref vn);
|
2013-07-11 11:43:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 12:56:47 +00:00
|
|
|
// Update preview image (mxd)
|
|
|
|
private void UpdateThingSprite()
|
|
|
|
{
|
|
|
|
if(General.Map == null) return;
|
2014-11-10 11:27:37 +00:00
|
|
|
|
2014-11-06 12:56:47 +00:00
|
|
|
if(thinginfo != null)
|
|
|
|
{
|
|
|
|
if(thinginfo.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX) &&
|
|
|
|
(thinginfo.Sprite.Length > DataManager.INTERNAL_PREFIX.Length))
|
|
|
|
{
|
2014-12-05 14:33:31 +00:00
|
|
|
spritetex.Image = General.Map.Data.GetSpriteImage(thinginfo.Sprite).GetBitmap();
|
2014-11-10 11:27:37 +00:00
|
|
|
return;
|
2014-11-06 12:56:47 +00:00
|
|
|
}
|
2014-11-10 11:27:37 +00:00
|
|
|
|
|
|
|
if((thinginfo.Sprite.Length < 9) && (thinginfo.Sprite.Length > 0))
|
2014-11-06 12:56:47 +00:00
|
|
|
{
|
|
|
|
ImageData sprite = General.Map.Data.GetSpriteImage(thinginfo.Sprite);
|
2014-12-05 14:33:31 +00:00
|
|
|
spritetex.Image = sprite.GetPreview();
|
2014-11-06 12:56:47 +00:00
|
|
|
if(!sprite.IsPreviewLoaded) updatetimer.Start();
|
2014-11-10 11:27:37 +00:00
|
|
|
return;
|
2014-11-06 12:56:47 +00:00
|
|
|
}
|
2014-11-10 11:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Show Mixed Things icon?
|
|
|
|
if(validnodes.Count > 1)
|
2014-11-06 12:56:47 +00:00
|
|
|
{
|
2015-01-23 12:02:35 +00:00
|
|
|
spritetex.Image = Properties.Resources.MixedThings;
|
2014-11-10 11:27:37 +00:00
|
|
|
return;
|
2014-11-06 12:56:47 +00:00
|
|
|
}
|
2014-11-10 11:27:37 +00:00
|
|
|
|
2015-01-23 12:02:35 +00:00
|
|
|
spritetex.Image = null;
|
2014-11-06 12:56:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
2014-10-29 11:35:27 +00:00
|
|
|
// List double-clicked. e.Node and typelist.SelectedNodes[0] may contain incorrect node,
|
|
|
|
// so we set the correct one in typelist_AfterSelect handler (mxd)
|
2014-08-26 11:08:34 +00:00
|
|
|
private void typelist_MouseDoubleClick(object sender, MouseEventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-10-29 11:35:27 +00:00
|
|
|
if (typelist.SelectedNodes.Count == 1
|
|
|
|
&& doubleclickednode != null
|
|
|
|
&& doubleclickednode.Nodes.Count == 0
|
|
|
|
&& doubleclickednode.Tag is ThingTypeInfo
|
|
|
|
&& OnTypeDoubleClicked != null
|
|
|
|
&& typeid.Text.Length > 0)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-10-29 11:35:27 +00:00
|
|
|
OnTypeDoubleClicked();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Thing type selection changed
|
2014-11-10 11:27:37 +00:00
|
|
|
private void typelist_SelectionsChanged(object sender, EventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-10-29 11:35:27 +00:00
|
|
|
doubleclickednode = null; //mxd
|
|
|
|
if (!doupdatetextbox) return;
|
|
|
|
|
2014-11-10 11:27:37 +00:00
|
|
|
//mxd
|
|
|
|
validnodes = GetValidNodes();
|
|
|
|
|
2014-10-29 11:35:27 +00:00
|
|
|
//mxd. Got a valid multiselection? Well, can't show any useful info about that...
|
2014-11-10 11:27:37 +00:00
|
|
|
if(typelist.SelectionMode == TreeViewSelectionMode.MultiSelectSameLevel && validnodes.Count > 1)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-10-29 11:35:27 +00:00
|
|
|
doupdatenode = false;
|
2014-11-06 12:56:47 +00:00
|
|
|
if (!string.IsNullOrEmpty(typeid.Text))
|
|
|
|
{
|
|
|
|
// Event will be raised in typeid_OnTextChanged
|
2014-10-29 11:35:27 +00:00
|
|
|
typeid.Text = "";
|
2014-11-06 12:56:47 +00:00
|
|
|
}
|
|
|
|
else if (OnTypeChanged != null)
|
|
|
|
{
|
|
|
|
// Or raise event here
|
|
|
|
UpdateThingSprite();
|
|
|
|
OnTypeChanged(thinginfo);
|
|
|
|
}
|
2014-10-29 11:35:27 +00:00
|
|
|
doupdatenode = true;
|
|
|
|
}
|
2014-11-10 11:27:37 +00:00
|
|
|
else if(validnodes.Count == 1) //Anything selected?
|
2014-10-29 11:35:27 +00:00
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
// Show info
|
|
|
|
doupdatenode = false;
|
|
|
|
typeid.Text = (validnodes[0].Tag as ThingTypeInfo).Index.ToString();
|
|
|
|
doupdatenode = true;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2014-11-10 11:27:37 +00:00
|
|
|
// Set as double-clicked only if a single child node is selected
|
|
|
|
if (typelist.SelectedNodes.Count == 1 && typelist.SelectedNodes[0].Nodes.Count == 0)
|
2014-10-29 11:35:27 +00:00
|
|
|
{
|
2014-11-10 11:27:37 +00:00
|
|
|
doubleclickednode = validnodes[0]; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-10 11:27:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
UpdateThingSprite(); //mxd
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Thing type index changed
|
|
|
|
private void typeid_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
bool knownthing = false;
|
|
|
|
|
|
|
|
// Any text?
|
|
|
|
if(typeid.Text.Length > 0)
|
|
|
|
{
|
|
|
|
// Get the info
|
2013-07-11 11:43:49 +00:00
|
|
|
int typeindex = typeid.GetResult(0);
|
|
|
|
thinginfo = General.Map.Data.GetThingInfoEx(typeindex);
|
2009-04-19 18:07:22 +00:00
|
|
|
if(thinginfo != null)
|
|
|
|
{
|
|
|
|
knownthing = true;
|
|
|
|
|
|
|
|
// Size
|
|
|
|
sizelabel.Text = (thinginfo.Radius * 2) + " x " + thinginfo.Height;
|
|
|
|
|
|
|
|
// Hangs from ceiling
|
|
|
|
if(thinginfo.Hangs) positionlabel.Text = "Ceiling"; else positionlabel.Text = "Floor";
|
|
|
|
|
|
|
|
// Blocking
|
|
|
|
switch(thinginfo.Blocking)
|
|
|
|
{
|
|
|
|
case ThingTypeInfo.THING_BLOCKING_NONE: blockinglabel.Text = "No"; break;
|
|
|
|
case ThingTypeInfo.THING_BLOCKING_FULL: blockinglabel.Text = "Completely"; break;
|
|
|
|
case ThingTypeInfo.THING_BLOCKING_HEIGHT: blockinglabel.Text = "True-Height"; break;
|
|
|
|
default: blockinglabel.Text = "Unknown"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doupdatenode)
|
|
|
|
{
|
|
|
|
doupdatetextbox = false;
|
2014-10-29 11:35:27 +00:00
|
|
|
typelist.SelectedNodes.Clear();
|
2014-11-10 11:27:37 +00:00
|
|
|
validnodes.Clear(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
foreach(TreeNode n in nodes)
|
|
|
|
{
|
|
|
|
// Matching node?
|
|
|
|
if((n.Tag as ThingTypeInfo).Index == typeindex)
|
|
|
|
{
|
|
|
|
// Select this
|
2014-10-29 11:35:27 +00:00
|
|
|
if(typelist.Nodes.Contains(n.Parent)) //mxd. Tree node may've been removed during filtering
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
n.Parent.Expand();
|
2014-10-29 11:35:27 +00:00
|
|
|
typelist.SelectedNodes.Add(n);
|
2013-04-04 12:04:52 +00:00
|
|
|
n.EnsureVisible();
|
2014-10-29 11:35:27 +00:00
|
|
|
break;
|
2013-04-04 12:04:52 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
doupdatetextbox = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
thinginfo = null;
|
2014-11-10 11:27:37 +00:00
|
|
|
if (doupdatenode)
|
|
|
|
{
|
|
|
|
typelist.SelectedNodes.Clear();
|
|
|
|
validnodes.Clear(); //mxd
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No known thing?
|
|
|
|
if(!knownthing)
|
|
|
|
{
|
|
|
|
sizelabel.Text = "-";
|
|
|
|
positionlabel.Text = "-";
|
|
|
|
blockinglabel.Text = "-";
|
|
|
|
}
|
|
|
|
|
2014-11-06 12:56:47 +00:00
|
|
|
// Update icon (mxd)
|
|
|
|
UpdateThingSprite();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Raise event
|
|
|
|
if(OnTypeChanged != null) OnTypeChanged(thinginfo);
|
|
|
|
}
|
2009-07-09 22:43:39 +00:00
|
|
|
|
2014-11-06 12:56:47 +00:00
|
|
|
private void updatetimer_Tick(object sender, EventArgs e)
|
2009-07-09 22:43:39 +00:00
|
|
|
{
|
2014-11-06 12:56:47 +00:00
|
|
|
updatetimer.Stop();
|
|
|
|
UpdateThingSprite();
|
2009-07-09 22:43:39 +00:00
|
|
|
}
|
2013-04-04 12:04:52 +00:00
|
|
|
|
2013-11-21 10:53:11 +00:00
|
|
|
//mxd
|
2014-10-29 11:35:27 +00:00
|
|
|
private void typelist_MouseEnter(object sender, EventArgs e)
|
|
|
|
{
|
2013-11-21 10:53:11 +00:00
|
|
|
typelist.Focus();
|
|
|
|
}
|
|
|
|
|
2013-04-04 12:04:52 +00:00
|
|
|
//mxd
|
2014-10-29 11:35:27 +00:00
|
|
|
private void bClear_Click(object sender, EventArgs e)
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
tbFilter.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-10-29 11:35:27 +00:00
|
|
|
private void tbFilter_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
typelist.SuspendLayout();
|
|
|
|
|
2014-10-29 11:35:27 +00:00
|
|
|
if(string.IsNullOrEmpty(tbFilter.Text))
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
Setup();
|
|
|
|
typeid_TextChanged(this, EventArgs.Empty);
|
2014-10-29 11:35:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
// Go for all predefined categories
|
2014-10-29 11:35:27 +00:00
|
|
|
typelist.SelectedNodes.Clear();
|
2013-04-04 12:04:52 +00:00
|
|
|
typelist.Nodes.Clear();
|
2014-11-10 11:27:37 +00:00
|
|
|
validnodes.Clear();
|
2013-04-04 12:04:52 +00:00
|
|
|
|
|
|
|
string match = tbFilter.Text.ToUpperInvariant();
|
2014-10-29 11:35:27 +00:00
|
|
|
foreach(TreeNode node in nodes)
|
|
|
|
{
|
|
|
|
if(node.Text.ToUpperInvariant().Contains(match))
|
|
|
|
{
|
2013-04-04 12:04:52 +00:00
|
|
|
typelist.Nodes.Add(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doupdatenode = true;
|
|
|
|
doupdatetextbox = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
typelist.ResumeLayout();
|
|
|
|
}
|
2015-01-05 14:56:44 +00:00
|
|
|
|
|
|
|
//mxd. Because anchor-based alignment fails when using high-Dpi settings...
|
|
|
|
private void ThingBrowserControl_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
infopanel.Top = this.Height - infopanel.Height;
|
|
|
|
infopanel.Width = this.Width;
|
|
|
|
spritepanel.Left = infopanel.Width - spritepanel.Width;
|
|
|
|
typelist.Height = infopanel.Top - typelist.Top;
|
|
|
|
typelist.Width = this.Width;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|