mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 22:41:46 +00:00
Texture and Flats browsers now have the current texture selected by default
This commit is contained in:
parent
67f4237bc0
commit
6ba030d64d
3 changed files with 195 additions and 50 deletions
|
@ -220,26 +220,47 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
#region ================== Methods
|
||||
|
||||
// This selects an item by name
|
||||
public void SelectItem(string name)
|
||||
public void SelectItem(string name, ListViewGroup preferredgroup)
|
||||
{
|
||||
ListViewItem lvi;
|
||||
ListViewItem lvi = null;
|
||||
|
||||
// Not when selecting is prevented
|
||||
if(preventselection) return;
|
||||
|
||||
// Find item with this text
|
||||
lvi = list.FindItemWithText(name);
|
||||
if(lvi != null)
|
||||
// Search in preferred group first
|
||||
if(preferredgroup != null)
|
||||
{
|
||||
// Does the text really match?
|
||||
if(lvi.Text == name)
|
||||
foreach(ListViewItem item in list.Items)
|
||||
{
|
||||
if((item.Group == preferredgroup) && (string.Compare(item.Text, name, true) == 0))
|
||||
{
|
||||
lvi = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing found yet, search all items
|
||||
if(lvi == null)
|
||||
{
|
||||
foreach(ListViewItem item in list.Items)
|
||||
{
|
||||
if(string.Compare(item.Text, name, true) == 0)
|
||||
{
|
||||
lvi = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Select the item
|
||||
if(lvi != null)
|
||||
{
|
||||
// Select this item
|
||||
list.SelectedItems.Clear();
|
||||
lvi.Selected = true;
|
||||
lvi.EnsureVisible();
|
||||
}
|
||||
}
|
||||
|
||||
UpdateTextureSizeLabel();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using CodeImp.DoomBuilder.Actions;
|
||||
|
@ -42,6 +43,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
private Size lastsize;
|
||||
private ListViewGroup usedgroup;
|
||||
private ListViewGroup availgroup;
|
||||
private ListViewItem selectedset;
|
||||
|
||||
// Properties
|
||||
public string SelectedName { get { return selectedname; } }
|
||||
|
@ -77,11 +79,10 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
|
||||
// Select the last one that was selected
|
||||
string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");
|
||||
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) i.Selected = true;
|
||||
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
|
||||
|
||||
// None selected? Then select the first
|
||||
if(texturesets.SelectedItems.Count == 0)
|
||||
texturesets.Items[0].Selected = true;
|
||||
if(selectedset == null) selectedset = texturesets.Items[0];
|
||||
|
||||
// Make groups
|
||||
usedgroup = browser.AddGroup("Used Textures");
|
||||
|
@ -104,6 +105,51 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
this.ResumeLayout(true);
|
||||
}
|
||||
|
||||
// This fills the lists and selects the given texture
|
||||
public void Setup(string selectflat)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(selectflat))
|
||||
{
|
||||
// We prefer selecting the texture using the Texture Set that was previously selected
|
||||
if(texturesets.SelectedItems.Count > 0)
|
||||
{
|
||||
if(SelectFlatInSet(texturesets.SelectedItems[0], selectflat)) return;
|
||||
}
|
||||
|
||||
// Otherwise, go from top to bottom to find the texture
|
||||
foreach(ListViewItem i in texturesets.Items)
|
||||
{
|
||||
if(SelectFlatInSet(i, selectflat)) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Select texture set and fill list
|
||||
selectedset.Selected = true;
|
||||
selectedset.EnsureVisible();
|
||||
FillImagesList(selectflat);
|
||||
}
|
||||
|
||||
// This selects a Texture Set and the texture if it can be found
|
||||
private bool SelectFlatInSet(ListViewItem setitem, string selectflat)
|
||||
{
|
||||
long longname = Lump.MakeLongName(selectflat);
|
||||
IFilledTextureSet set = (setitem.Tag as IFilledTextureSet);
|
||||
foreach(ImageData img in set.Textures)
|
||||
{
|
||||
if(img.LongName == longname)
|
||||
{
|
||||
// Texture found in this set! Select it now.
|
||||
selectedset = setitem;
|
||||
selectedset.Selected = true;
|
||||
selectedset.EnsureVisible();
|
||||
FillImagesList(selectflat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Selection changed
|
||||
private void browser_SelectedItemChanged()
|
||||
{
|
||||
|
@ -203,6 +249,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
public static string Browse(IWin32Window parent, string select)
|
||||
{
|
||||
FlatBrowserForm browser = new FlatBrowserForm();
|
||||
browser.Setup(select);
|
||||
if(browser.ShowDialog(parent) == DialogResult.OK)
|
||||
{
|
||||
// Return result
|
||||
|
@ -220,9 +267,27 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
{
|
||||
// Anything slected?
|
||||
if(texturesets.SelectedItems.Count > 0)
|
||||
{
|
||||
// Not the same?
|
||||
if(texturesets.SelectedItems[0] != selectedset)
|
||||
{
|
||||
selectedset = texturesets.SelectedItems[0];
|
||||
FillImagesList(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Item double clicked
|
||||
private void browser_SelectedItemDoubleClicked()
|
||||
{
|
||||
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// This fills the list of textures, depending on the selected texture set
|
||||
private void FillImagesList(string selectflat)
|
||||
{
|
||||
// Get the selected texture set
|
||||
IFilledTextureSet set = (texturesets.SelectedItems[0].Tag as IFilledTextureSet);
|
||||
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
|
||||
|
||||
// Start adding
|
||||
browser.BeginAdding(false);
|
||||
|
@ -237,13 +302,10 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
|
||||
// Done adding
|
||||
browser.EndAdding();
|
||||
}
|
||||
}
|
||||
|
||||
// Item double clicked
|
||||
private void browser_SelectedItemDoubleClicked()
|
||||
{
|
||||
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
|
||||
// Select texture
|
||||
if(!string.IsNullOrEmpty(selectflat))
|
||||
browser.SelectItem(selectflat, usedgroup);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using CodeImp.DoomBuilder.Actions;
|
||||
|
@ -42,6 +43,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
private Size lastsize;
|
||||
private ListViewGroup usedgroup;
|
||||
private ListViewGroup availgroup;
|
||||
private ListViewItem selectedset;
|
||||
|
||||
// Properties
|
||||
public string SelectedName { get { return selectedname; } }
|
||||
|
@ -77,11 +79,10 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
|
||||
// Select the last one that was selected
|
||||
string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");
|
||||
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) i.Selected = true;
|
||||
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
|
||||
|
||||
// None selected? Then select the first
|
||||
if(texturesets.SelectedItems.Count == 0)
|
||||
texturesets.Items[0].Selected = true;
|
||||
if(selectedset == null) selectedset = texturesets.Items[0];
|
||||
|
||||
// Make groups
|
||||
usedgroup = browser.AddGroup("Used Textures");
|
||||
|
@ -104,6 +105,51 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
this.ResumeLayout(true);
|
||||
}
|
||||
|
||||
// This fills the lists and selects the given texture
|
||||
public void Setup(string selecttexture)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(selecttexture))
|
||||
{
|
||||
// We prefer selecting the texture using the Texture Set that was previously selected
|
||||
if(texturesets.SelectedItems.Count > 0)
|
||||
{
|
||||
if(SelectTextureInSet(texturesets.SelectedItems[0], selecttexture)) return;
|
||||
}
|
||||
|
||||
// Otherwise, go from top to bottom to find the texture
|
||||
foreach(ListViewItem i in texturesets.Items)
|
||||
{
|
||||
if(SelectTextureInSet(i, selecttexture)) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Select texture set and fill list
|
||||
selectedset.Selected = true;
|
||||
selectedset.EnsureVisible();
|
||||
FillImagesList(selecttexture);
|
||||
}
|
||||
|
||||
// This selects a Texture Set and the texture if it can be found
|
||||
private bool SelectTextureInSet(ListViewItem setitem, string selecttexture)
|
||||
{
|
||||
long longname = Lump.MakeLongName(selecttexture);
|
||||
IFilledTextureSet set = (setitem.Tag as IFilledTextureSet);
|
||||
foreach(ImageData img in set.Textures)
|
||||
{
|
||||
if(img.LongName == longname)
|
||||
{
|
||||
// Texture found in this set! Select it now.
|
||||
selectedset = setitem;
|
||||
selectedset.Selected = true;
|
||||
selectedset.EnsureVisible();
|
||||
FillImagesList(selecttexture);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Selection changed
|
||||
private void browser_SelectedItemChanged()
|
||||
{
|
||||
|
@ -203,6 +249,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
public static string Browse(IWin32Window parent, string select)
|
||||
{
|
||||
TextureBrowserForm browser = new TextureBrowserForm();
|
||||
browser.Setup(select);
|
||||
if(browser.ShowDialog(parent) == DialogResult.OK)
|
||||
{
|
||||
// Return result
|
||||
|
@ -220,9 +267,27 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
{
|
||||
// Anything slected?
|
||||
if(texturesets.SelectedItems.Count > 0)
|
||||
{
|
||||
// Not the same?
|
||||
if(texturesets.SelectedItems[0] != selectedset)
|
||||
{
|
||||
selectedset = texturesets.SelectedItems[0];
|
||||
FillImagesList(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Item double clicked
|
||||
private void browser_SelectedItemDoubleClicked()
|
||||
{
|
||||
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// This fills the list of textures, depending on the selected texture set
|
||||
private void FillImagesList(string selecttexture)
|
||||
{
|
||||
// Get the selected texture set
|
||||
IFilledTextureSet set = (texturesets.SelectedItems[0].Tag as IFilledTextureSet);
|
||||
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
|
||||
|
||||
// Start adding
|
||||
browser.BeginAdding(false);
|
||||
|
@ -237,13 +302,10 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
|
||||
// Done adding
|
||||
browser.EndAdding();
|
||||
}
|
||||
}
|
||||
|
||||
// Item double clicked
|
||||
private void browser_SelectedItemDoubleClicked()
|
||||
{
|
||||
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
|
||||
// Select texture
|
||||
if(!string.IsNullOrEmpty(selecttexture))
|
||||
browser.SelectItem(selecttexture, usedgroup);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue