2008-10-01 08:21:10 +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.Controls;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
|
|
|
{
|
|
|
|
internal partial class TextureSetForm : DelayedForm
|
|
|
|
{
|
|
|
|
// Variables
|
|
|
|
private DefinedTextureSet textureset;
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public TextureSetForm()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2008-10-01 12:42:30 +00:00
|
|
|
|
|
|
|
// Show/hide components
|
|
|
|
matchesbutton.Visible = (General.Map != null);
|
|
|
|
nomatchesbutton.Visible = (General.Map != null);
|
|
|
|
matcheslist.Visible = (General.Map != null);
|
|
|
|
noresultlabel.Visible = (General.Map == null);
|
2008-10-01 08:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This initializes the set
|
|
|
|
public void Setup(DefinedTextureSet set)
|
|
|
|
{
|
|
|
|
// Keep reference
|
|
|
|
textureset = set;
|
2008-10-01 12:42:30 +00:00
|
|
|
|
2008-10-01 08:21:10 +00:00
|
|
|
// Set name
|
|
|
|
name.Text = set.Name;
|
2008-10-01 12:42:30 +00:00
|
|
|
|
2008-10-01 08:21:10 +00:00
|
|
|
// Fill filters list
|
|
|
|
foreach(string s in set.Filters)
|
|
|
|
filters.Items.Add(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK clicked
|
|
|
|
private void apply_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Apply name
|
|
|
|
textureset.Name = name.Text;
|
2008-10-01 12:42:30 +00:00
|
|
|
|
2008-10-01 08:21:10 +00:00
|
|
|
// Apply filters
|
|
|
|
textureset.Filters.Clear();
|
|
|
|
foreach(ListViewItem i in filters.Items) textureset.Filters.Add(i.Text);
|
2008-10-01 12:42:30 +00:00
|
|
|
|
2008-10-01 08:21:10 +00:00
|
|
|
// Done
|
2008-10-01 12:42:30 +00:00
|
|
|
matcheslist.CleanUp();
|
2008-10-01 08:21:10 +00:00
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel clicked
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Be gone.
|
2008-10-01 12:42:30 +00:00
|
|
|
matcheslist.CleanUp();
|
2008-10-01 08:21:10 +00:00
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
|
|
this.Close();
|
|
|
|
}
|
2008-10-01 12:42:30 +00:00
|
|
|
|
|
|
|
// Add texture
|
|
|
|
private void addfilter_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
ListViewItem i = new ListViewItem("");
|
|
|
|
filters.Items.Add(i);
|
|
|
|
i.BeginEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove selected items
|
|
|
|
private void removefilter_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
foreach(ListViewItem i in filters.SelectedItems) i.Remove();
|
|
|
|
|
|
|
|
// Run the timer
|
|
|
|
filterstimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Items selected/deselected
|
|
|
|
private void filters_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
removefilter.Enabled = (filters.SelectedItems.Count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double clicking an item
|
|
|
|
private void filters_DoubleClick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Edit item
|
|
|
|
if(filters.SelectedItems.Count == 1)
|
|
|
|
filters.SelectedItems[0].BeginEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This removes empty items and makes others uppercase
|
|
|
|
private void filterstimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Stop timer
|
|
|
|
filterstimer.Stop();
|
|
|
|
|
|
|
|
// Update labels
|
|
|
|
for(int i = filters.Items.Count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
// Empty label?
|
|
|
|
if((filters.Items[i].Text == null) ||
|
|
|
|
(filters.Items[i].Text.Trim().Length == 0))
|
|
|
|
{
|
|
|
|
// Remove it
|
|
|
|
filters.Items.RemoveAt(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Make uppercase
|
|
|
|
filters.Items[i].Text = filters.Items[i].Text.ToUpperInvariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show example results if when we can
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
Cursor.Current = Cursors.AppStarting;
|
|
|
|
|
|
|
|
// Make a set for comparing
|
2008-10-01 14:17:52 +00:00
|
|
|
List<string> filterslist = new List<string>(filters.Items.Count);
|
|
|
|
foreach(ListViewItem i in filters.Items) filterslist.Add(i.Text);
|
|
|
|
MatchingTextureSet set = new MatchingTextureSet(filterslist);
|
2008-10-01 12:42:30 +00:00
|
|
|
|
|
|
|
// Determine tooltip text
|
|
|
|
string tooltiptext = null;
|
|
|
|
if(nomatchesbutton.Checked) tooltiptext = "Doubleclick to include this texture";
|
|
|
|
|
|
|
|
// Start adding
|
|
|
|
matcheslist.PreventSelection = matchesbutton.Checked;
|
|
|
|
matcheslist.BeginAdding(true);
|
|
|
|
|
|
|
|
// Go for all textures
|
|
|
|
foreach(ImageData img in General.Map.Data.Textures)
|
|
|
|
{
|
|
|
|
bool ismatch = set.IsMatch(img);
|
|
|
|
if((ismatch && matchesbutton.Checked) || (!ismatch && nomatchesbutton.Checked))
|
|
|
|
matcheslist.Add(img.Name, img, img, null, tooltiptext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not already mixed, add flats as well
|
|
|
|
if(!General.Map.Config.MixTexturesFlats)
|
|
|
|
{
|
|
|
|
// Go for all flats
|
|
|
|
foreach(ImageData img in General.Map.Data.Flats)
|
|
|
|
{
|
|
|
|
bool ismatch = set.IsMatch(img);
|
|
|
|
if((ismatch && matchesbutton.Checked) || (!ismatch && nomatchesbutton.Checked))
|
|
|
|
matcheslist.Add(img.Name, img, img, null, tooltiptext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done adding
|
|
|
|
matcheslist.EndAdding();
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done editing a filter
|
|
|
|
private void filters_AfterLabelEdit(object sender, LabelEditEventArgs e)
|
|
|
|
{
|
|
|
|
// Run the timer
|
|
|
|
filterstimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// When first shown
|
|
|
|
private void TextureSetForm_Shown(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Run the timer
|
|
|
|
filterstimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show (not) matches clicked
|
|
|
|
private void matchesbutton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Run the timer
|
|
|
|
filterstimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Texture doubleclicked
|
|
|
|
private void matcheslist_SelectedItemDoubleClicked()
|
|
|
|
{
|
|
|
|
// Add texture name to the list
|
|
|
|
if(matcheslist.SelectedItem != null)
|
|
|
|
filters.Items.Add(matcheslist.SelectedItem.Text);
|
|
|
|
|
|
|
|
// Run the timer
|
|
|
|
filterstimer.Start();
|
|
|
|
}
|
2008-10-01 08:21:10 +00:00
|
|
|
}
|
2008-10-01 12:42:30 +00:00
|
|
|
}
|
|
|
|
|