2007-10-31 20:34:09 +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;
|
2009-03-01 16:47:43 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
2007-10-31 20:34:09 +00:00
|
|
|
using Microsoft.Win32;
|
|
|
|
using System.Diagnostics;
|
2008-05-29 11:34:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
2007-10-31 20:34:09 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
2007-11-04 22:19:30 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-05-29 11:54:45 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
2007-10-31 20:34:09 +00:00
|
|
|
{
|
2009-01-23 14:41:01 +00:00
|
|
|
internal partial class TextureBrowserForm : Form
|
2007-10-31 20:34:09 +00:00
|
|
|
{
|
2009-03-17 12:40:10 +00:00
|
|
|
// Constants
|
|
|
|
private const int COLUMN_WIDTH_COUNT = 52;
|
|
|
|
|
2007-11-04 23:09:21 +00:00
|
|
|
// Variables
|
|
|
|
private string selectedname;
|
|
|
|
private Point lastposition;
|
|
|
|
private Size lastsize;
|
2008-10-01 14:17:52 +00:00
|
|
|
private ListViewGroup usedgroup;
|
|
|
|
private ListViewGroup availgroup;
|
2009-03-01 16:47:43 +00:00
|
|
|
private ListViewItem selectedset;
|
2009-04-13 11:12:42 +00:00
|
|
|
private string selecttextureonfill;
|
2007-11-04 23:09:21 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
public string SelectedName { get { return selectedname; } }
|
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Constructor
|
2009-04-13 11:12:42 +00:00
|
|
|
public TextureBrowserForm(string selecttexture)
|
2007-10-31 20:34:09 +00:00
|
|
|
{
|
2008-09-28 21:20:56 +00:00
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
2008-10-01 14:17:52 +00:00
|
|
|
ListViewItem item;
|
2009-04-13 11:12:42 +00:00
|
|
|
bool foundselecttexture = false;
|
|
|
|
long longname = Lump.MakeLongName(selecttexture);
|
2007-11-04 22:19:30 +00:00
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
2009-02-01 22:33:01 +00:00
|
|
|
browser.ApplySettings();
|
2007-11-07 21:14:27 +00:00
|
|
|
|
2008-09-28 21:20:56 +00:00
|
|
|
// Update the used textures
|
|
|
|
General.Map.Data.UpdateUsedTextures();
|
2008-05-05 14:22:36 +00:00
|
|
|
|
2009-03-17 12:40:10 +00:00
|
|
|
// Resize columns to maximize available width
|
|
|
|
countcolumn.Width = COLUMN_WIDTH_COUNT;
|
|
|
|
namecolumn.Width = texturesets.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - countcolumn.Width - 2;
|
|
|
|
|
2008-10-01 14:17:52 +00:00
|
|
|
// Fill texture sets list with normal texture sets
|
|
|
|
foreach(IFilledTextureSet ts in General.Map.Data.TextureSets)
|
2008-05-05 14:22:36 +00:00
|
|
|
{
|
2008-10-01 14:17:52 +00:00
|
|
|
item = texturesets.Items.Add(ts.Name);
|
|
|
|
item.Tag = ts;
|
2008-10-01 20:04:50 +00:00
|
|
|
item.ImageIndex = 0;
|
2009-03-17 12:40:10 +00:00
|
|
|
item.UseItemStyleForSubItems = false;
|
|
|
|
item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor,
|
|
|
|
item.BackColor, new Font(item.Font, FontStyle.Regular));
|
2008-05-05 14:22:36 +00:00
|
|
|
}
|
2008-09-28 21:20:56 +00:00
|
|
|
|
2009-01-09 23:05:41 +00:00
|
|
|
// Add special textures sets
|
|
|
|
item = texturesets.Items.Add(General.Map.Data.AllTextureSet.Name);
|
|
|
|
item.Tag = General.Map.Data.AllTextureSet;
|
2009-03-01 18:34:37 +00:00
|
|
|
item.ImageIndex = 1;
|
2009-03-17 12:40:10 +00:00
|
|
|
item.UseItemStyleForSubItems = false;
|
|
|
|
item.SubItems.Add(General.Map.Data.AllTextureSet.Textures.Count.ToString(),
|
|
|
|
item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular));
|
2009-03-01 18:34:37 +00:00
|
|
|
|
|
|
|
// Add container-specific texture sets
|
|
|
|
foreach(ResourceTextureSet ts in General.Map.Data.ResourceTextureSets)
|
|
|
|
{
|
|
|
|
item = texturesets.Items.Add(ts.Name);
|
|
|
|
item.Tag = ts;
|
|
|
|
item.ImageIndex = 2 + ts.LocationType;
|
2009-03-17 12:40:10 +00:00
|
|
|
item.UseItemStyleForSubItems = false;
|
|
|
|
item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor,
|
|
|
|
item.BackColor, new Font(item.Font, FontStyle.Regular));
|
2009-03-01 18:34:37 +00:00
|
|
|
}
|
2007-11-04 23:09:21 +00:00
|
|
|
|
2008-10-01 15:06:46 +00:00
|
|
|
// Select the last one that was selected
|
2009-01-12 14:43:35 +00:00
|
|
|
string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");
|
2009-04-13 11:12:42 +00:00
|
|
|
foreach(ListViewItem i in texturesets.Items)
|
|
|
|
{
|
|
|
|
if(i.Text == selectname)
|
|
|
|
{
|
|
|
|
i.Selected = true;
|
|
|
|
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
|
|
|
|
foreach(ImageData img in set.Textures)
|
|
|
|
{
|
|
|
|
if(img.LongName == longname)
|
|
|
|
{
|
|
|
|
i.Selected = true;
|
|
|
|
foundselecttexture = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the selected texture was not found in the last-selected set, try finding it in the other sets
|
|
|
|
if(!foundselecttexture)
|
|
|
|
{
|
|
|
|
foreach(ListViewItem i in texturesets.Items)
|
|
|
|
{
|
|
|
|
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
|
|
|
|
foreach(ImageData img in set.Textures)
|
|
|
|
{
|
|
|
|
if(img.LongName == longname)
|
|
|
|
{
|
|
|
|
i.Selected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-01 15:06:46 +00:00
|
|
|
|
|
|
|
// None selected? Then select the first
|
2009-04-13 11:12:42 +00:00
|
|
|
if(texturesets.SelectedItems.Count == 0)
|
|
|
|
texturesets.Items[0].Selected = true;
|
2008-10-01 14:17:52 +00:00
|
|
|
|
2009-04-13 11:12:42 +00:00
|
|
|
selecttextureonfill = selecttexture;
|
|
|
|
|
2008-10-01 14:17:52 +00:00
|
|
|
// Make groups
|
|
|
|
usedgroup = browser.AddGroup("Used Textures");
|
|
|
|
availgroup = browser.AddGroup("Available Textures");
|
2009-01-23 14:41:01 +00:00
|
|
|
|
2007-11-04 23:09:21 +00:00
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
2009-01-23 14:41:01 +00:00
|
|
|
|
|
|
|
// Position window from configuration settings
|
|
|
|
this.SuspendLayout();
|
|
|
|
/*
|
|
|
|
this.Location = new Point(General.Settings.ReadSetting("browserwindow.positionx", this.Location.X),
|
|
|
|
General.Settings.ReadSetting("browserwindow.positiony", this.Location.Y));
|
|
|
|
*/
|
|
|
|
this.Size = new Size(General.Settings.ReadSetting("browserwindow.sizewidth", this.Size.Width),
|
|
|
|
General.Settings.ReadSetting("browserwindow.sizeheight", this.Size.Height));
|
|
|
|
this.WindowState = (FormWindowState)General.Settings.ReadSetting("browserwindow.windowstate", (int)FormWindowState.Normal);
|
|
|
|
if(this.WindowState == FormWindowState.Normal) this.StartPosition = FormStartPosition.CenterParent;
|
|
|
|
this.ResumeLayout(true);
|
2007-11-04 22:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Selection changed
|
|
|
|
private void browser_SelectedItemChanged()
|
|
|
|
{
|
|
|
|
apply.Enabled = (browser.SelectedItem != null);
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
2007-11-04 23:09:21 +00:00
|
|
|
|
|
|
|
// OK clicked
|
|
|
|
private void apply_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Set selected name and close
|
2009-04-09 14:30:22 +00:00
|
|
|
if(browser.SelectedItem != null)
|
|
|
|
{
|
|
|
|
selectedname = browser.SelectedItem.Text;
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectedname = "";
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
}
|
2007-11-04 23:09:21 +00:00
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel clicked
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// No selection, close
|
|
|
|
selectedname = "";
|
2007-11-10 19:24:52 +00:00
|
|
|
DialogResult = DialogResult.Cancel;
|
2007-11-04 23:09:21 +00:00
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activated
|
|
|
|
private void TextureBrowserForm_Activated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Focus the textbox
|
|
|
|
browser.FocusTextbox();
|
2008-09-28 21:20:56 +00:00
|
|
|
Cursor.Current = Cursors.Default;
|
2007-11-04 23:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Loading
|
|
|
|
private void TextureBrowserForm_Load(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resized
|
|
|
|
private void TextureBrowserForm_ResizeEnd(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Moved
|
|
|
|
private void TextureBrowserForm_Move(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Closing
|
|
|
|
private void TextureBrowserForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
int windowstate;
|
|
|
|
|
|
|
|
// Determine window state to save
|
|
|
|
if(this.WindowState != FormWindowState.Minimized)
|
|
|
|
windowstate = (int)this.WindowState;
|
|
|
|
else
|
|
|
|
windowstate = (int)FormWindowState.Normal;
|
|
|
|
|
|
|
|
// Save window settings
|
|
|
|
General.Settings.WriteSetting("browserwindow.positionx", lastposition.X);
|
|
|
|
General.Settings.WriteSetting("browserwindow.positiony", lastposition.Y);
|
|
|
|
General.Settings.WriteSetting("browserwindow.sizewidth", lastsize.Width);
|
|
|
|
General.Settings.WriteSetting("browserwindow.sizeheight", lastsize.Height);
|
|
|
|
General.Settings.WriteSetting("browserwindow.windowstate", windowstate);
|
2008-05-05 14:22:36 +00:00
|
|
|
|
2008-10-01 15:06:46 +00:00
|
|
|
// Save last selected texture set
|
2009-01-12 14:43:35 +00:00
|
|
|
if(texturesets.SelectedItems.Count > 0)
|
|
|
|
General.Settings.WriteSetting("browserwindow.textureset", texturesets.SelectedItems[0].Text);
|
2008-10-01 15:06:46 +00:00
|
|
|
|
2008-05-05 14:22:36 +00:00
|
|
|
// Clean up
|
|
|
|
browser.CleanUp();
|
2007-11-04 23:09:21 +00:00
|
|
|
}
|
2007-11-10 19:24:52 +00:00
|
|
|
|
|
|
|
// Static method to browse for texture
|
|
|
|
// Returns null when cancelled.
|
|
|
|
public static string Browse(IWin32Window parent, string select)
|
|
|
|
{
|
2009-04-13 11:12:42 +00:00
|
|
|
TextureBrowserForm browser = new TextureBrowserForm(select);
|
2007-11-10 19:24:52 +00:00
|
|
|
if(browser.ShowDialog(parent) == DialogResult.OK)
|
|
|
|
{
|
|
|
|
// Return result
|
|
|
|
return browser.SelectedName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Cancelled
|
2008-10-17 09:39:07 +00:00
|
|
|
return select;
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 14:17:52 +00:00
|
|
|
|
|
|
|
// Texture set selected
|
|
|
|
private void texturesets_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Anything slected?
|
|
|
|
if(texturesets.SelectedItems.Count > 0)
|
|
|
|
{
|
2009-04-13 11:12:42 +00:00
|
|
|
selectedset = texturesets.SelectedItems[0];
|
|
|
|
FillImagesList();
|
2008-10-01 14:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-14 23:30:42 +00:00
|
|
|
|
|
|
|
// Item double clicked
|
|
|
|
private void browser_SelectedItemDoubleClicked()
|
|
|
|
{
|
|
|
|
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
|
|
|
|
}
|
2009-03-01 16:47:43 +00:00
|
|
|
|
|
|
|
// This fills the list of textures, depending on the selected texture set
|
2009-04-13 11:12:42 +00:00
|
|
|
private void FillImagesList()
|
2009-03-01 16:47:43 +00:00
|
|
|
{
|
|
|
|
// Get the selected texture set
|
|
|
|
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
|
|
|
|
|
|
|
|
// Start adding
|
|
|
|
browser.BeginAdding(false);
|
|
|
|
|
|
|
|
// Add all available textures and mark the images for temporary loading
|
|
|
|
foreach(ImageData img in set.Textures)
|
|
|
|
browser.Add(img.Name, img, img, availgroup);
|
|
|
|
|
|
|
|
// Add all used textures and mark the images for permanent loading
|
|
|
|
foreach(ImageData img in set.Textures)
|
|
|
|
if(img.UsedInMap) browser.Add(img.Name, img, img, usedgroup);
|
|
|
|
|
|
|
|
// Done adding
|
|
|
|
browser.EndAdding();
|
|
|
|
}
|
2009-04-05 19:29:27 +00:00
|
|
|
|
|
|
|
// Help
|
|
|
|
private void TextureBrowserForm_HelpRequested(object sender, HelpEventArgs hlpevent)
|
|
|
|
{
|
|
|
|
General.ShowHelp("w_imagesbrowser.html");
|
|
|
|
hlpevent.Handled = true;
|
|
|
|
}
|
2009-04-13 11:12:42 +00:00
|
|
|
|
|
|
|
private void TextureBrowserForm_Shown(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Select texture
|
|
|
|
if(!string.IsNullOrEmpty(selecttextureonfill))
|
|
|
|
{
|
|
|
|
browser.SelectItem(selecttextureonfill, usedgroup);
|
|
|
|
selecttextureonfill = null;
|
|
|
|
}
|
|
|
|
}
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
|
|
|
}
|