Exemple #1
0
        // This fills the list of textures, depending on the selected texture set
        private void FillImagesList(string selectflat)
        {
            // Get the selected texture set
            IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);

            // Start adding
            browser.BeginAdding(false);

            // Add all used flats
            foreach (ImageData img in set.Flats)
            {
                if (img.UsedInMap)
                {
                    browser.Add(img.Name, img, img, usedgroup);
                }
            }

            // Add all available flats
            foreach (ImageData img in set.Flats)
            {
                browser.Add(img.Name, img, img, availgroup);
            }

            // Done adding
            browser.EndAdding();
        }
        //mxd
        private TreeNode FindTextureByLongName(TreeNode node, long longname)
        {
            //first search in child nodes

            foreach (TreeNode n in node.Nodes)
            {
                TreeNode match = FindTextureByLongName(n, longname);
                if (match != null)
                {
                    return(match);
                }
            }

            //then - in current node
            IFilledTextureSet set = (node.Tag as IFilledTextureSet);

            foreach (ImageData img in (browseflats ? set.Flats : set.Textures))
            {
                if (img.LongName == longname)
                {
                    return(node);
                }
            }

            return(null);
        }
Exemple #3
0
        // This fills the list of textures, depending on the selected texture set
        private void FillImagesList()
        {
            // 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();
        }
        // This fills the list of textures, depending on the selected texture set
        private void FillImagesList()
        {
            //mxd. Show root items
            if (selectedset == null)
            {
                FillCategoriesList();
                return;
            }

            // Get the selected texture set
            IFilledTextureSet set = ((TreeNodeData)selectedset.Tag).Set;

            // Start adding
            browser.BeginAdding(false);

            //mxd. Add "Browse up" item
            if (selectedset.Parent != null)
            {
                TreeNodeData data = (TreeNodeData)selectedset.Parent.Tag;
                browser.AddFolder(ImageBrowserItemType.FOLDER_UP, data.FolderName);
            }
            else
            {
                browser.AddFolder(ImageBrowserItemType.FOLDER_UP, "All Texture Sets");
            }

            //mxd. Add folders
            foreach (TreeNode child in selectedset.Nodes)
            {
                TreeNodeData data = (TreeNodeData)child.Tag;
                browser.AddFolder(ImageBrowserItemType.FOLDER, data.FolderName);
            }

            // Add textures
            if (browseflats)
            {
                // Add all available flats
                foreach (ImageData img in set.Flats)
                {
                    browser.AddItem(img);
                }
            }
            else
            {
                // Add all available textures
                foreach (ImageData img in set.Textures)
                {
                    browser.AddItem(img);
                }
            }

            browser.MakeTexturesUnique();             // biwa

            // Done adding
            browser.EndAdding();
        }
Exemple #5
0
        // Constructor
        public FlatBrowserForm(string selecttexture)
        {
            Cursor.Current = Cursors.WaitCursor;
            ListViewItem item;
            bool         foundselecttexture = false;
            long         longname           = Lump.MakeLongName(selecttexture ?? "");

            // Initialize
            InitializeComponent();
            browser.ApplySettings();

            // Update the used textures
            General.Map.Data.UpdateUsedTextures();

            // Resize columns to maximize available width
            countcolumn.Width = COLUMN_WIDTH_COUNT;
            namecolumn.Width  = texturesets.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - countcolumn.Width - 2;

            // Fill texture sets list with normal texture sets
            foreach (IFilledTextureSet ts in General.Map.Data.TextureSets)
            {
                item            = texturesets.Items.Add(ts.Name);
                item.Tag        = ts;
                item.ImageIndex = 0;
                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor,
                                  item.BackColor, new Font(item.Font, FontStyle.Regular));
            }

            // 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.Location.type;
                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor,
                                  item.BackColor, new Font(item.Font, FontStyle.Regular));
            }

            // Add All textures set
            item            = texturesets.Items.Add(General.Map.Data.AllTextureSet.Name);
            item.Tag        = General.Map.Data.AllTextureSet;
            item.ImageIndex = 1;
            item.UseItemStyleForSubItems = false;
            item.SubItems.Add(General.Map.Data.AllTextureSet.Textures.Count.ToString(),
                              item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular));

            // Select the last one that was selected
            string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");

            foreach (ListViewItem i in texturesets.Items)
            {
                if (i.Text == selectname)
                {
                    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;
                            foundselecttexture = true;
                            break;
                        }
                    }
                }
            }

            // Texture still now found? Then just select the last used set
            if (!foundselecttexture)
            {
                foreach (ListViewItem i in texturesets.Items)
                {
                    if (i.Text == selectname)
                    {
                        i.Selected         = true;
                        foundselecttexture = true;
                        break;
                    }
                }
            }

            // WARNING: Some strange behavior of the listview here!
            // When you leave this line out, the list becomes very slow.
            // Also, this does not change the item selected previously.
            texturesets.Items[0].Selected = true;

            // Texture to select when list is filled
            selecttextureonfill = selecttexture;

            // Make groups
            usedgroup  = browser.AddGroup("Used Textures");
            availgroup = browser.AddGroup("Available Textures");

            // Keep last position and size
            lastposition = this.Location;
            lastsize     = this.Size;

            // 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);
        }
Exemple #6
0
        private readonly bool browseflats; //mxd

        // Constructor
        public TextureBrowserForm(string selecttexture, bool nbrowseflats)
        {
            bStillLoading = true;

            browseflats = nbrowseflats;

            Cursor.Current = Cursors.WaitCursor;
            bool foundselecttexture = false;
            long longname = Lump.MakeLongName(selecttexture ?? "");

            // Initialize
            InitializeComponent();
            browser.ApplySettings();

            // Update the used textures
            General.Map.Data.UpdateUsedTextures();

            // Resize columns to maximize available width
            countcolumn.Width = COLUMN_WIDTH_COUNT;
            namecolumn.Width = texturesets.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - countcolumn.Width - 2;

            if (General.Settings.ReverseTextureCategories)
            {
                AddAllSets();
                AddContainerSets();
                AddCategorySets();
            }
            else
            {
                AddCategorySets();
                AddContainerSets();
                AddAllSets();
            }

            // Select the last one that was selected
            // ano - renamed this from "selectname" because there's also a "selectedname"
            // in scope and it's confusing
            string cfgTextureSet = General.Settings.ReadSetting("browserwindow.textureset", "");
            bool bAllSelected = false;

            if (cfgTextureSet == "All" || cfgTextureSet == "Flats" || cfgTextureSet == "Textures")
            {
                bAllSelected = true;

                // ano - swap flats / textures box selection as appropriate
                if (General.Map.Config.MixTexturesFlats && cfgTextureSet != "All")
                {
                    cfgTextureSet = browseflats ? "Flats" : "Textures";
                }

                // 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;
                                foundselecttexture = true;
                                break;
                            }
                        }
                        if (foundselecttexture) break;
                    }
                }

                if (!foundselecttexture)
                {
                    cfgTextureSet = "All";
                }
            }

            // ano - look in the last selected set for our texture
            foreach (ListViewItem i in texturesets.Items)
            {
                if (i.Text == cfgTextureSet)
                {
                    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 && !bAllSelected)
            {
                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;
                            foundselecttexture = true;
                            break;
                        }
                    }
                    if (foundselecttexture) break;
                }
            }

            // Texture still now found? Then just select the last used set
            if (!foundselecttexture)
            {
                foreach (ListViewItem i in texturesets.Items)
                {
                    if (i.Text == cfgTextureSet)
                    {
                        i.Selected = true;
                        foundselecttexture = true;
                        break;
                    }
                }
            }

            // ano - otherwise definitely select All
            if (!foundselecttexture)
            {
                foreach (ListViewItem i in texturesets.Items)
                {
                    if (i.Text == "All")
                    {
                        i.Selected = true;
                        foundselecttexture = true;
                        break;
                    }
                }
            }

            // WARNING: Some strange behavior of the listview here!
            // When you leave this line out, the list becomes very slow.
            // Also, this does not change the item selected previously.
            texturesets.Items[0].Selected = true;

            // Texture to select when list is filled
            selecttextureonfill = selecttexture;

            // Make groups
            usedgroup = browser.AddGroup(browseflats ? "Used Flats" : "Used Textures");
            availgroup = browser.AddGroup(browseflats ? "Available Flats" : "Available Textures");

            // Keep last position and size
            lastposition = this.Location;
            lastsize = this.Size;

            // ano - rename labels if we're browsing flats
            if (browseflats)
            {
                Text = "Browse Flats";
                browser.LabelText = "Select or enter a flat name:";
            }

            // 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);
            bStillLoading = false;
        }
        // Constructor
        public TextureBrowserForm(string selecttexture, bool browseflats)
        {
            Cursor.Current = Cursors.WaitCursor;
            General.Interface.DisableProcessing(); //mxd

            TreeNode item;                         //mxd
            long     longname = Lump.MakeLongName(selecttexture ?? "");

            longname = (browseflats ? General.Map.Data.GetFullLongFlatName(longname) : General.Map.Data.GetFullLongTextureName(longname)); //mxd
            int count;                                                                                                                     //mxd

            selectedset      = null;                                                                                                       //mxd
            this.browseflats = browseflats;                                                                                                //mxd

            // Initialize
            InitializeComponent();

            //mxd. Set title
            string imagetype = (browseflats ? "flats" : "textures");

            this.Text = "Browse " + imagetype;

            // Setup texture browser
            ImageBrowserControl.ShowTexturesFromSubDirectories = General.Settings.ReadSetting("browserwindow.showtexturesfromsubdirs", true);
            ImageBrowserControl.UseLongTextureNames            = General.Map.Options.UseLongTextureNames;
            browser.BrowseFlats = browseflats;
            browser.ApplySettings();

            // Update the used textures
            General.Map.Data.UpdateUsedTextures();

            tvTextureSets.BeginUpdate();             //mxd

            //mxd. Texture longname to select when list is filled
            selecttextureonfill = longname;

            // Make groups
            usedgroup  = browser.AddGroup("Used " + imagetype + ":");
            availgroup = browser.AddGroup("Available " + imagetype + ":");

            //mxd. Make "Used" group collapsible
            usedgroupcollapsed = General.Settings.ReadSetting("browserwindow.usedgroupcollapsed", false);
            browser.SetGroupCollapsed(usedgroup, usedgroupcollapsed);

            //mxd. Fill texture sets list with normal texture sets
            foreach (IFilledTextureSet ts in General.Map.Data.TextureSets)
            {
                count = (browseflats ? ts.Flats.Count : ts.Textures.Count);
                if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0))
                {
                    continue;
                }

                item            = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]");
                item.Name       = ts.Name;
                item.Tag        = ts;
                item.ImageIndex = 0;
            }

            //mxd. Add container-specific texture sets
            foreach (ResourceTextureSet ts in General.Map.Data.ResourceTextureSets)
            {
                count = (browseflats ? ts.Flats.Count : ts.Textures.Count);
                if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0))
                {
                    continue;
                }

                item                    = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]");
                item.Name               = ts.Name;
                item.Tag                = ts;
                item.ImageIndex         = 2 + ts.Location.type;
                item.SelectedImageIndex = item.ImageIndex;

                CreateNodes(item);
                item.Expand();
            }

            //mxd. Add "All" texture set
            count                   = (browseflats ? General.Map.Data.AllTextureSet.Flats.Count : General.Map.Data.AllTextureSet.Textures.Count);
            item                    = tvTextureSets.Nodes.Add(General.Map.Data.AllTextureSet.Name + " [" + count + "]");
            item.Name               = General.Map.Data.AllTextureSet.Name;
            item.Tag                = General.Map.Data.AllTextureSet;
            item.ImageIndex         = 1;
            item.SelectedImageIndex = item.ImageIndex;

            //mxd. Should we bother finding the correct texture set?
            if (General.Settings.LocateTextureGroup)
            {
                //mxd. Get the previously selected texture set
                string   prevtextureset = General.Settings.ReadSetting("browserwindow.textureset", "");
                TreeNode match;

                // When texture set name is empty, select "All" texture set
                if (string.IsNullOrEmpty(prevtextureset))
                {
                    match = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1];
                }
                else
                {
                    match = FindNodeByName(tvTextureSets.Nodes, prevtextureset);
                }

                if (match != null)
                {
                    IFilledTextureSet set = (match.Tag as IFilledTextureSet);
                    foreach (ImageData img in (browseflats ? set.Flats : set.Textures))
                    {
                        if (img.LongName == longname)
                        {
                            selectedset = match;
                            break;
                        }
                    }
                }

                //mxd. If the selected texture was not found in the last-selected set, try finding it in the other sets
                if (selectedset == null && selecttexture != "-")
                {
                    foreach (TreeNode n in tvTextureSets.Nodes)
                    {
                        selectedset = FindTextureByLongName(n, longname);
                        if (selectedset != null)
                        {
                            break;
                        }
                    }
                }

                //mxd. Texture still not found? Then just select the last used set
                if (selectedset == null && match != null)
                {
                    selectedset = match;
                }
            }

            //mxd. Select the found set or "All", if none were found
            if (tvTextureSets.Nodes.Count > 0)
            {
                if (selectedset == null)
                {
                    selectedset = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1];
                }
                tvTextureSets.SelectedNodes.Clear();
                tvTextureSets.SelectedNodes.Add(selectedset);
                selectedset.EnsureVisible();
            }

            tvTextureSets.EndUpdate();            //mxd

            // Keep last position and size
            lastposition = this.Location;
            lastsize     = this.Size;

            this.SuspendLayout();

            // Position window from configuration settings
            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);

            //mxd
            if (this.WindowState == FormWindowState.Normal)
            {
                Point location = new Point(General.Settings.ReadSetting("browserwindow.positionx", int.MaxValue), General.Settings.ReadSetting("browserwindow.positiony", int.MaxValue));
                if (location.X < int.MaxValue && location.Y < int.MaxValue)
                {
                    this.Location = location;
                }
                else
                {
                    this.StartPosition = FormStartPosition.CenterParent;
                }
            }

            this.ResumeLayout(true);

            //mxd. Set splitter position and state (doesn't work when layout is suspended)
            if (General.Settings.ReadSetting("browserwindow.splittercollapsed", false))
            {
                splitter.IsCollapsed = true;
            }

            //mxd. Looks like SplitterDistance is unaffected by DPI scaling. Let's fix that...
            int splitterdistance = General.Settings.ReadSetting("browserwindow.splitterdistance", int.MinValue);

            if (splitterdistance == int.MinValue)
            {
                splitterdistance = 210;
                if (MainForm.DPIScaler.Width != 1.0f)
                {
                    splitterdistance = (int)Math.Round(splitterdistance * MainForm.DPIScaler.Width);
                }
            }

            splitter.SplitPosition = splitterdistance;
        }
Exemple #8
0
        private readonly bool browseflats; //mxd

        // Constructor
        public TextureBrowserForm(string selecttexture, bool nbrowseflats)
        {
            bStillLoading = true;

            browseflats = nbrowseflats;

            Cursor.Current = Cursors.WaitCursor;
            ListViewItem item;
            bool foundselecttexture = false;
            long longname = Lump.MakeLongName(selecttexture ?? "");

            // Initialize
            InitializeComponent();
            browser.ApplySettings();

            // Update the used textures
            General.Map.Data.UpdateUsedTextures();

            // Resize columns to maximize available width
            countcolumn.Width = COLUMN_WIDTH_COUNT;
            namecolumn.Width = texturesets.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - countcolumn.Width - 2;

            // Fill texture sets list with normal texture sets
            foreach (IFilledTextureSet ts in General.Map.Data.TextureSets)
            {
                int textureCount;
                if (General.Map.Config.MixTexturesFlats)
                {
                    textureCount = ts.Flats.Count + ts.Textures.Count;
                }
                else if (browseflats)
                {
                    textureCount = ts.Flats.Count;
                }
                else
                {
                    textureCount = ts.Textures.Count;
                }

                // ano - hide empty texturesets
                if (textureCount > 0)
                {
                    item = texturesets.Items.Add(ts.Name);
                    item.Tag = ts;
                    item.ImageIndex = 0;
                    item.UseItemStyleForSubItems = false;
                    item.SubItems.Add(textureCount.ToString(), item.ForeColor,
                            item.BackColor, new Font(item.Font, FontStyle.Regular));
                }
            }

            // Add container-specific texture sets
            foreach (ResourceTextureSet ts in General.Map.Data.ResourceTextureSets)
            {
                int textureCount;
                if (General.Map.Config.MixTexturesFlats)
                {
                    textureCount = ts.Flats.Count + ts.Textures.Count;
                }
                else if (browseflats)
                {
                    textureCount = ts.Flats.Count;
                }
                else
                {
                    textureCount = ts.Textures.Count;
                }

                item = texturesets.Items.Add(ts.Name);
                item.Tag = ts;
                item.ImageIndex = 2 + ts.Location.type;
                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(textureCount.ToString(), item.ForeColor,
                        item.BackColor, new Font(item.Font, FontStyle.Regular));
            }

            // Add All textures set
            {
                int textureCount;
                if (General.Map.Config.MixTexturesFlats)
                {
                    textureCount = General.Map.Data.AllTextureSet.Flats.Count + General.Map.Data.AllTextureSet.Textures.Count;
                }
                else if (browseflats)
                {
                    textureCount = General.Map.Data.AllTextureSet.Flats.Count;
                }
                else
                {
                    textureCount = General.Map.Data.AllTextureSet.Textures.Count;
                }

                item = texturesets.Items.Add(General.Map.Data.AllTextureSet.Name);
                item.Tag = General.Map.Data.AllTextureSet;
                item.ImageIndex = 1;
                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(textureCount.ToString(),
                    item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular));
            }

            if (General.Map.Config.MixTexturesFlats)
            {
                if (General.Map.Data.WallsTextureSet != null)
                {
                    // Add all Textures-only set
                    int textureCount;
                    textureCount = General.Map.Data.WallsTextureSet.Textures.Count;

                    item = texturesets.Items.Add(General.Map.Data.WallsTextureSet.Name);
                    item.Tag = General.Map.Data.WallsTextureSet;
                    item.ImageIndex = 1;
                    item.UseItemStyleForSubItems = false;
                    item.SubItems.Add(textureCount.ToString(),
                        item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular));
                }
                else if (browseflats && General.Map.Data.FlatsTextureSet != null)
                {
                    // Add All flats-only set
                    int textureCount;
                    textureCount = General.Map.Data.FlatsTextureSet.Textures.Count;

                    item = texturesets.Items.Add(General.Map.Data.FlatsTextureSet.Name);
                    item.Tag = General.Map.Data.FlatsTextureSet;
                    item.ImageIndex = 1;
                    item.UseItemStyleForSubItems = false;
                    item.SubItems.Add(textureCount.ToString(),
                        item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular));
                }
            }

            // Select the last one that was selected
            // ano - renamed this from "selectname" because there's also a "selectedname"
            // in scope and it's confusing
            string cfgTextureSet = General.Settings.ReadSetting("browserwindow.textureset", "");

            // ano - select flats box if we're on a mixflats/textures cfg and we're looking in "All"
            if (!foundselecttexture && General.Map.Config.MixTexturesFlats && cfgTextureSet == "All")
            {
                cfgTextureSet = browseflats ? "Textures" : "Flats";
            }

            foreach (ListViewItem i in texturesets.Items)
			{
				if(i.Text == cfgTextureSet)
				{
					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;
							foundselecttexture = true;
							break;
						}
					}
					if(foundselecttexture) break;
				}
			}
			
			// Texture still now found? Then just select the last used set
			if(!foundselecttexture)
			{
				foreach(ListViewItem i in texturesets.Items)
				{
					if(i.Text == cfgTextureSet)
					{
						i.Selected = true;
						foundselecttexture = true;
						break;
					}
				}
			}

			// WARNING: Some strange behavior of the listview here!
			// When you leave this line out, the list becomes very slow.
			// Also, this does not change the item selected previously.
			texturesets.Items[0].Selected = true;

			// Texture to select when list is filled
			selecttextureonfill = selecttexture;
			
			// Make groups
			usedgroup = browser.AddGroup(browseflats ? "Used Flats" : "Used Textures");
			availgroup = browser.AddGroup(browseflats ? "Available Flats" : "Available Textures");
			
			// Keep last position and size
			lastposition = this.Location;
			lastsize = this.Size;

            // ano - rename labels if we're browsing flats
            if (browseflats)
            {
                Text = "Browse Flats";
                browser.LabelText = "Select or enter a flat name:";
            }

            // 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);
            bStillLoading = false;
        }
        // Constructor
        public TextureBrowserForm(string selecttexture, bool browseflats)
        {
            Cursor.Current = Cursors.WaitCursor;
            General.Interface.DisableProcessing(); //mxd

            TreeNode item;                         //mxd
            long     longname = Lump.MakeLongName(selecttexture ?? "");

            // [ZZ] check if this name is even ok.
            if (browseflats && General.Map.Data.GetFlatImage(longname) == General.Map.Data.UnknownImage)
            {
                longname = Lump.MakeLongName("");
            }
            longname = (browseflats ? General.Map.Data.GetFullLongFlatName(longname) : General.Map.Data.GetFullLongTextureName(longname)); //mxd
            int count;                                                                                                                     //mxd

            selectedset      = null;                                                                                                       //mxd
            this.browseflats = browseflats;                                                                                                //mxd

            // Initialize
            InitializeComponent();

            //mxd. Set titles
            string imagetype = (browseflats ? "flats" : "textures");

            this.Text           = "Browse " + imagetype;
            browser.ElementName = imagetype;

            // Setup texture browser
            browser.ApplySettings("windows." + configname, browseflats);

            // Update the used textures
            General.Map.Data.UpdateUsedTextures();

            tvTextureSets.BeginUpdate();             //mxd

            //mxd. Texture longname to select when list is filled
            selecttextureonfill = longname;

            //mxd. Fill texture sets list with normal texture sets
            foreach (IFilledTextureSet ts in General.Map.Data.TextureSets)
            {
                count = (browseflats ? ts.Flats.Count : ts.Textures.Count);
                if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0))
                {
                    continue;
                }

                item      = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]");
                item.Name = ts.Name;
                item.Tag  = new TreeNodeData {
                    Set = ts, FolderName = ts.Name
                };
                item.ImageIndex = 0;
            }

            //mxd. Add container-specific texture sets
            foreach (ResourceTextureSet ts in General.Map.Data.ResourceTextureSets)
            {
                count = (browseflats ? ts.Flats.Count : ts.Textures.Count);
                if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0))
                {
                    continue;
                }

                item      = tvTextureSets.Nodes.Add(ts.Name);
                item.Name = ts.Name;
                item.Tag  = new TreeNodeData {
                    Set = ts, FolderName = ts.Name
                };
                item.ImageIndex         = 2 + ts.Location.type;
                item.SelectedImageIndex = item.ImageIndex;

                CreateNodes(item);
                item.Expand();
            }

            //mxd. Add "All" texture set
            count     = (browseflats ? General.Map.Data.AllTextureSet.Flats.Count : General.Map.Data.AllTextureSet.Textures.Count);
            item      = tvTextureSets.Nodes.Add(General.Map.Data.AllTextureSet.Name + " [" + count + "]");
            item.Name = General.Map.Data.AllTextureSet.Name;
            item.Tag  = new TreeNodeData {
                Set = General.Map.Data.AllTextureSet, FolderName = General.Map.Data.AllTextureSet.Name
            };
            item.ImageIndex         = 1;
            item.SelectedImageIndex = item.ImageIndex;

            //mxd. Should we bother finding the correct texture set?
            if (General.Settings.LocateTextureGroup)
            {
                //mxd. Get the previously selected texture set
                string   prevtextureset = General.Settings.ReadSetting("windows." + configname + ".textureset", "");
                TreeNode match;

                // When texture set name is empty, select "All" texture set
                if (string.IsNullOrEmpty(prevtextureset))
                {
                    match = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1];
                }
                else
                {
                    match = FindNodeByName(tvTextureSets.Nodes, prevtextureset);
                }

                if (match != null)
                {
                    IFilledTextureSet set = ((TreeNodeData)match.Tag).Set;
                    foreach (ImageData img in (browseflats ? set.Flats : set.Textures))
                    {
                        if (img.LongName == longname)
                        {
                            selectedset = match;
                            break;
                        }
                    }
                }

                //mxd. If the selected texture was not found in the last-selected set, try finding it in the other sets
                if (selectedset == null && selecttexture != "-")
                {
                    foreach (TreeNode n in tvTextureSets.Nodes)
                    {
                        selectedset = FindTextureByLongName(n, longname);
                        if (selectedset != null)
                        {
                            break;
                        }
                    }
                }

                //mxd. Texture still not found? Then just select the last used set
                if (selectedset == null && match != null)
                {
                    selectedset = match;
                }
            }

            //mxd. Select the found set or "All", if none were found
            if (tvTextureSets.Nodes.Count > 0)
            {
                if (selectedset == null)
                {
                    selectedset = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1];
                }
                tvTextureSets.SelectedNodes.Clear();
                tvTextureSets.SelectedNodes.Add(selectedset);
                selectedset.EnsureVisible();
            }

            tvTextureSets.EndUpdate();             //mxd

            //mxd. Set splitter position and state (doesn't work when layout is suspended)
            if (General.Settings.ReadSetting("windows." + configname + ".splittercollapsed", false))
            {
                splitter.IsCollapsed = true;
            }

            //mxd. Looks like SplitterDistance is unaffected by DPI scaling. Let's fix that...
            int splitterdistance = General.Settings.ReadSetting("windows." + configname + ".splitterdistance", int.MinValue);

            if (splitterdistance == int.MinValue)
            {
                splitterdistance = 210;
                if (MainForm.DPIScaler.Width != 1.0f)
                {
                    splitterdistance = (int)Math.Round(splitterdistance * MainForm.DPIScaler.Width);
                }
            }

            splitter.SplitPosition = splitterdistance;
        }