UltimateZoneBuilder/Source/Windows/FlatBrowserForm.cs

239 lines
6.7 KiB
C#
Raw Normal View History

2007-11-10 19:24:52 +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 Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Actions;
2007-11-10 19:24:52 +00:00
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Controls;
2007-11-10 19:24:52 +00:00
#endregion
namespace CodeImp.DoomBuilder.Windows
2007-11-10 19:24:52 +00:00
{
2008-01-02 21:49:43 +00:00
internal partial class FlatBrowserForm : DelayedForm
2007-11-10 19:24:52 +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;
2007-11-10 19:24:52 +00:00
// Properties
public string SelectedName { get { return selectedname; } }
// Constructor
public FlatBrowserForm()
{
Cursor.Current = Cursors.WaitCursor;
2008-10-01 14:17:52 +00:00
ListViewItem item;
2007-11-10 19:24:52 +00:00
// Initialize
InitializeComponent();
browser.ApplyColorSettings();
// Update the used textures
General.Map.Data.UpdateUsedTextures();
2007-11-10 19:24:52 +00:00
2008-10-01 14:17:52 +00:00
// 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;
2008-10-01 14:17:52 +00:00
}
// Add other textures set
2008-10-01 14:17:52 +00:00
item = texturesets.Items.Add(General.Map.Data.OthersTextureSet.Name);
item.Tag = General.Map.Data.OthersTextureSet;
item.ImageIndex = 1;
2008-10-01 15:06:46 +00:00
// Select the last one that was selected
string selectname = General.Settings.ReadSetting("browserwindow.flatstextureset", "");
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) i.Selected = true;
2008-10-01 14:17:52 +00:00
2008-10-01 15:06:46 +00:00
// None selected? Then select the first
if(texturesets.SelectedItems.Count == 0)
texturesets.Items[0].Selected = true;
2008-10-01 14:17:52 +00:00
// Make groups
usedgroup = browser.AddGroup("Used Textures");
availgroup = browser.AddGroup("Available Textures");
2007-11-10 19:24:52 +00:00
// Keep last position and size
lastposition = this.Location;
lastsize = this.Size;
}
// Selection changed
private void browser_SelectedItemChanged()
{
apply.Enabled = (browser.SelectedItem != null);
}
// OK clicked
private void apply_Click(object sender, EventArgs e)
{
// Set selected name and close
selectedname = browser.SelectedItem.Text;
DialogResult = DialogResult.OK;
this.Close();
}
// Cancel clicked
private void cancel_Click(object sender, EventArgs e)
{
// No selection, close
selectedname = "";
DialogResult = DialogResult.Cancel;
this.Close();
}
// Activated
private void FlatBrowserForm_Activated(object sender, EventArgs e)
{
// Focus the textbox
browser.FocusTextbox();
Cursor.Current = Cursors.Default;
2007-11-10 19:24:52 +00:00
}
// Loading
private void FlatBrowserForm_Load(object sender, EventArgs e)
{
2008-10-01 14:17:52 +00:00
/*
2007-11-10 19:24:52 +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);
this.ResumeLayout(true);
2008-10-01 14:17:52 +00:00
*/
2007-11-10 19:24:52 +00:00
// Normal windowstate?
if(this.WindowState == FormWindowState.Normal)
{
// Keep last position and size
lastposition = this.Location;
lastsize = this.Size;
}
}
// Resized
private void FlatBrowserForm_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 FlatBrowserForm_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 FlatBrowserForm_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-10-01 15:06:46 +00:00
// Save last selected texture set
if((texturesets.SelectedItems.Count > 0) && (texturesets.SelectedItems[0].Tag is MatchingTextureSet))
General.Settings.WriteSetting("browserwindow.flatstextureset", texturesets.SelectedItems[0].Text);
// Clean up
browser.CleanUp();
2007-11-10 19:24:52 +00:00
}
// Static method to browse for flats
// Returns null when cancelled.
public static string Browse(IWin32Window parent, string select)
{
FlatBrowserForm browser = new FlatBrowserForm();
if(browser.ShowDialog(parent) == DialogResult.OK)
{
// Return result
return browser.SelectedName;
}
else
{
// Cancelled
return null;
}
}
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)
{
// Get the selected texture set
IFilledTextureSet set = (texturesets.SelectedItems[0].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();
}
}
2007-11-10 19:24:52 +00:00
}
}