Mercurial > repos > WarFoundryForge
view FrmSystem.cs @ 17:0ea6ce3c6434 default tip
Updated System Form on General Tab
Added System Information text box. Currently only a mock up.
author | Tsudico |
---|---|
date | Thu, 06 Jan 2011 21:44:05 -0600 |
parents | 489d36b167a6 |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry.Forge.WinForms { public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm { private IBBoard.WarFoundry.API.Objects.GameSystem system; private IBBoard.WarFoundry.API.Objects.Category currentCategory; private IBBoard.WarFoundry.API.Objects.SystemStats currentStats; private bool UpdateCategory { get { if(currentCategory == null) { return false; } if (currentCategory.Name == (string)this.listCategories.SelectedItem) { if (currentCategory.Name != this.txtCategoryName.Text) { return true; } if (currentCategory.ID != this.txtCategoryID.Text) { return true; } if (currentCategory.MinimumPoints > 0 && !this.cbPointMin.Checked) { return true; } else if (currentCategory.MinimumPoints != this.numPointMin.Value) { return true; } if (currentCategory.MaximumPoints < this.numPointMax.Maximum && !this.cbPointMax.Checked) { return true; } else if (currentCategory.MaximumPoints != this.numPointMax.Value) { return true; } if (currentCategory.MinimumPercentage > 0 && !this.cbPercentMin.Checked) { return true; } else if (currentCategory.MinimumPercentage != this.numPercentMin.Value) { return true; } if (currentCategory.MaximumPercentage < this.numPercentMax.Maximum && !this.cbPercentMax.Checked) { return true; } else if (currentCategory.MaximumPercentage != this.numPercentMax.Value) { return true; } } return false; } } private bool UpdateSystemStats { get { if(currentStats == null) { return false; } if(currentStats.ID != this.txtStatLineID.Text) { return true; } if(currentStats.SlotCount != this.listCategories.Items.Count) { return true; } if(system.GetSystemStatsForID(currentStats.ID).SlotCount != currentStats.SlotCount) { return true; } for(int i = 0; i < currentStats.SlotCount; i++) { if(system.GetSystemStatsForID(currentStats.ID).StatSlots[i].Name == currentStats.StatSlots[i].Name) { return true; } } return false; } } public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem) { InitializeComponent(); system = loadSystem; this.txtSystemName.Text = system.Name; this.txtSystemId.Text = system.ID; this.numDefaultSize.Value = system.SystemArmyDefaultSize; this.numPointMax.Value = this.numDefaultSize.Value; if(system.AllowAllies) { this.radSystemAlliesYes.Checked = true; } else { this.radSystemAlliesNo.Checked = true; } if (system.WarnOnError) { this.radSystemWarnYes.Checked = true; } else { this.radSystemWarnNo.Checked = true; } updateCategoryList(); updateSystemStatsList(); } private string generateID(string name) { string newId = String.Empty; MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]"); foreach (Match part in id_parts) { newId += part.ToString(); } if (newId.Length < 3) { newId = name.ToLower().Replace(" ", ""); } return newId.ToLower(); } private void clearCategory() { this.txtCategoryName.Text = string.Empty; this.txtCategoryID.Text = string.Empty; this.cbPointMin.Checked = false; this.cbPointMax.Checked = false; this.cbPercentMin.Checked = false; this.cbPercentMax.Checked = false; this.numPointMin.Value = 0; this.numPointMin.Enabled = false; this.numPointMax.Value = this.numDefaultSize.Value; this.numPointMax.Enabled = false; this.numPercentMin.Value = 0; this.numPercentMin.Enabled = false; this.numPercentMax.Value = 100; this.numPercentMax.Enabled = false; currentCategory = null; } private void clearStatLine() { this.txtStatName.Clear(); this.txtStatLineID.Clear(); this.listStatNames.Items.Clear(); this.lviewStatPreview.Columns.Clear(); this.lviewStatPreview.Items.Clear(); currentStats = null; } private void updateCategoryList() { this.listCategories.Items.Clear(); if (system.Categories.Length > 0) { for (int i = 0; i < system.Categories.Length; i++) { this.listCategories.Items.Add(system.Categories[i].Name); } } else { this.btnCategoryRemove.Enabled = false; } } private void updateSystemStatsList() { this.lviewStats.Items.Clear(); if (system.SystemStats.Length > 0) { for(int i = 0; i < system.SystemStats.Length; i++) { ListViewItem item = new ListViewItem(); item.Text = system.SystemStats[i].ID; if(system.SystemStats[i].Equals(system.StandardSystemStats)) { item.SubItems.Add('\u2713'+""); } this.lviewStats.Items.Add(item); } } this.lviewStats.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent); this.lviewStats.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize); } private void updateStatLinePreview(IBBoard.WarFoundry.API.Objects.SystemStats stats) { this.lviewStatPreview.Items.Clear(); this.lviewStatPreview.Columns.Clear(); if(stats.SlotCount > 0) { for(int i = 0; i < stats.SlotCount; i++) { System.Windows.Forms.ColumnHeader column = new ColumnHeader(); column.Name = generateID(stats.StatSlots[i].Name); column.Text = stats.StatSlots[i].Name; column.TextAlign = HorizontalAlignment.Center; this.lviewStatPreview.Columns.Add(column); } this.lviewStatPreview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.lviewStatPreview.Items.Add(" "); } this.btnStatLineApply.Enabled = this.UpdateSystemStats; } private void updateStatNames(IBBoard.WarFoundry.API.Objects.SystemStats stats) { this.listStatNames.Items.Clear(); if (stats.SlotCount > 0) { for (int i = 0; i < stats.SlotCount; i++) { this.listStatNames.Items.Add(stats.StatSlots[i].Name); } } } private void btnSystemClose_Click(object sender, EventArgs e) { this.Close(); } private void btnGenerateSysId_Click(object sender, EventArgs e) { this.txtSystemId.Text = generateID(this.txtSystemName.Text); } private void listCategories_SelectedIndexChanged(object sender, EventArgs e) { currentCategory = null; foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) { if (cat.Name == (string)this.listCategories.SelectedItem) { currentCategory = cat; this.txtCategoryName.Text = currentCategory.Name; this.txtCategoryID.Text = currentCategory.ID; if (currentCategory.MinimumPoints > 0) { this.numPointMin.Value = currentCategory.MinimumPoints; this.cbPointMin.Checked = true; this.numPointMin.Enabled = true; } else { this.cbPointMin.Checked = false; this.numPointMin.Enabled = false; } if (currentCategory.MaximumPoints > 0 && currentCategory.MaximumPoints < this.numPointMax.Maximum) { this.numPointMax.Value = currentCategory.MaximumPoints; this.cbPointMax.Checked = true; this.numPointMax.Enabled = true; } else { this.numPointMax.Value = this.numDefaultSize.Value; this.cbPointMax.Checked = false; this.numPointMax.Enabled = false; } if (currentCategory.MinimumPercentage > 0) { this.numPercentMin.Value = currentCategory.MinimumPercentage; this.cbPercentMin.Checked = true; this.numPercentMin.Enabled = true; } else { this.cbPercentMin.Checked = false; this.numPercentMin.Enabled = false; } if (currentCategory.MaximumPercentage < 100) { this.numPercentMax.Value = currentCategory.MaximumPercentage; this.cbPercentMax.Checked = true; this.numPercentMax.Enabled = true; } else { this.cbPercentMax.Checked = false; this.numPercentMax.Enabled = false; } this.btnCategoryRemove.Enabled = true; this.btnCategoryApply.Enabled = false; break; } } if(this.listCategories.SelectedIndex == 0) { this.btnCategoryUp.Enabled = false; } else { this.btnCategoryUp.Enabled = true; } if (this.listCategories.SelectedIndex == this.listCategories.Items.Count - 1) { this.btnCategoryDown.Enabled = false; } else { this.btnCategoryDown.Enabled = true; } } private void btnCategoryAdd_Click(object sender, EventArgs e) { if(this.txtCategoryName.Text == string.Empty) { MessageBox.Show("Category must have a name", "Category Error"); return; } if (this.txtCategoryID.Text == string.Empty) { MessageBox.Show("Category must have an ID", "Category Error"); return; } IBBoard.WarFoundry.API.Objects.Category cat = new IBBoard.WarFoundry.API.Objects.Category( this.txtCategoryID.Text, this.txtCategoryName.Text ); cat.MinimumPoints = (int)this.numPointMin.Value; cat.MaximumPoints = (int)this.numPointMax.Value; cat.MinimumPercentage = (int)this.numPercentMin.Value; cat.MaximumPercentage = (int)this.numPercentMax.Value; system.AddCategory(cat); updateCategoryList(); clearCategory(); } private void btnCategoryRemove_Click(object sender, EventArgs e) { foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) { if(cat.Name == (string)this.listCategories.SelectedItem) { system.RemoveCategory(cat.ID); this.listCategories.ClearSelected(); this.btnCategoryRemove.Enabled = false; break; } } updateCategoryList(); } private void btnCategoryUp_Click(object sender, EventArgs e) { int index = this.listCategories.SelectedIndex; IBBoard.WarFoundry.API.Objects.Category[] catList = new IBBoard.WarFoundry.API.Objects.Category[this.listCategories.Items.Count]; for(int i = 0; i < system.Categories.Length; i++) { catList[i] = system.Categories[i]; } foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) { system.RemoveCategory(cat.ID); } IBBoard.WarFoundry.API.Objects.Category temp = catList[index]; catList[index] = catList[index - 1]; catList[index - 1] = temp; for(int i = catList.Length - 1; i >= 0; i--) { system.AddCategory(catList[i]); } updateCategoryList(); this.listCategories.SelectedIndex = index - 1; } private void btnCategoryDown_Click(object sender, EventArgs e) { int index = this.listCategories.SelectedIndex; IBBoard.WarFoundry.API.Objects.Category[] catList = new IBBoard.WarFoundry.API.Objects.Category[this.listCategories.Items.Count]; for (int i = 0; i < system.Categories.Length; i++) { catList[i] = system.Categories[i]; } foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) { system.RemoveCategory(cat.ID); } IBBoard.WarFoundry.API.Objects.Category temp = catList[index]; catList[index] = catList[index + 1]; catList[index + 1] = temp; for (int i = catList.Length - 1; i >= 0; i--) { system.AddCategory(catList[i]); } updateCategoryList(); this.listCategories.SelectedIndex = index + 1; } private void txtCategoryName_TextChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; if(this.txtCategoryName.Text != string.Empty && this.txtCategoryID.Text != string.Empty) { this.btnCategoryAdd.Enabled = true; } else { this.btnCategoryAdd.Enabled = false; } } private void txtCategoryID_TextChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; } private void btnGenerateCatID_Click(object sender, EventArgs e) { this.txtCategoryID.Text = generateID(this.txtCategoryName.Text); } private void cbPointMin_CheckedChanged(object sender, EventArgs e) { if(this.cbPointMin.Checked) { this.numPointMin.Enabled = true; } else { this.numPointMin.Enabled = false; } this.btnCategoryApply.Enabled = this.UpdateCategory; } private void cbPointMax_CheckedChanged(object sender, EventArgs e) { if (this.cbPointMax.Checked) { this.numPointMax.Enabled = true; } else { this.numPointMax.Enabled = false; } this.btnCategoryApply.Enabled = this.UpdateCategory; } private void cbPercentMin_CheckedChanged(object sender, EventArgs e) { if (this.cbPercentMin.Checked) { this.numPercentMin.Enabled = true; } else { this.numPercentMin.Enabled = false; } this.btnCategoryApply.Enabled = this.UpdateCategory; } private void cbPercentMax_CheckedChanged(object sender, EventArgs e) { if (this.cbPercentMax.Checked) { this.numPercentMax.Enabled = true; } else { this.numPercentMax.Enabled = false; } this.btnCategoryApply.Enabled = this.UpdateCategory; } private void numPointMin_ValueChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; } private void numPointMax_ValueChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; } private void numPercentMin_ValueChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; } private void numPercentMax_ValueChanged(object sender, EventArgs e) { this.btnCategoryApply.Enabled = this.UpdateCategory; } private void btnCategoryApply_Click(object sender, EventArgs e) { currentCategory.Name = this.txtCategoryName.Text; currentCategory.ID = this.txtCategoryID.Text; if(this.cbPointMin.Checked) { currentCategory.MinimumPoints = (int)this.numPointMin.Value; } else { currentCategory.MinimumPoints = 0; } if (this.cbPointMax.Checked) { currentCategory.MaximumPoints = (int)this.numPointMax.Value; } else { currentCategory.MaximumPoints = IBBoard.WarFoundry.API.WarFoundryCore.INFINITY; } if (this.cbPercentMin.Checked) { currentCategory.MinimumPercentage = (int)this.numPercentMin.Value; } else { currentCategory.MinimumPercentage = 0; } if (this.cbPercentMax.Checked) { currentCategory.MinimumPercentage = (int)this.numPercentMax.Value; } else { currentCategory.MaximumPercentage = 100; } system.SetCategory(currentCategory); updateCategoryList(); this.listCategories.ClearSelected(); } void lviewStats_SelectedIndexChanged(object sender, System.EventArgs e) { currentStats = null; foreach(IBBoard.WarFoundry.API.Objects.SystemStats stat in system.SystemStats) { foreach(ListViewItem item in this.lviewStats.SelectedItems) { if(stat.ID == item.Text) { if(this.lviewStats.Items.Count > 0) { this.btnStatsRemove.Enabled = true; } currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(stat.ID); foreach(IBBoard.WarFoundry.API.Objects.StatSlot slot in stat.StatSlots) { currentStats.AddStatSlot(slot.Name); } if(currentStats.ID.Equals(system.StandardSystemStatsID)) { this.btnStatsDefault.Enabled = false; } else { this.btnStatsDefault.Enabled = true; } if (item.Index == 0) { this.btnStatsUp.Enabled = false; } else { this.btnStatsUp.Enabled = true; } if (item.Index == this.lviewStats.Items.Count - 1) { this.btnStatsDown.Enabled = false; } else { this.btnStatsDown.Enabled = true; } this.txtStatLineID.Text = currentStats.ID; this.txtStatName.Enabled = true; updateStatNames(currentStats); updateStatLinePreview(currentStats); } } } if(this.txtStatLineID.Text == string.Empty) { this.txtStatName.Enabled = false; } } private void btnStatsAdd_Click(object sender, EventArgs e) { if(this.txtStatLineID.Text == string.Empty) { MessageBox.Show("You must enter an ID!", "Create Stat Line Error"); return; } if (currentStats == null) { currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text); } system.AddSystemStats(currentStats); clearStatLine(); updateSystemStatsList(); } private void btnStatsRemove_Click(object sender, EventArgs e) { system.RemoveSystemStats(currentStats.ID); this.btnStatsRemove.Enabled = false; updateSystemStatsList(); } private void btnStatsDefault_Click(object sender, EventArgs e) { system.StandardSystemStatsID = this.lviewStats.SelectedItems[0].Text; updateSystemStatsList(); } private void btnStatsUp_Click(object sender, EventArgs e) { int index = this.lviewStats.SelectedIndices[0]; IBBoard.WarFoundry.API.Objects.SystemStats[] statsList = new IBBoard.WarFoundry.API.Objects.SystemStats[this.lviewStats.Items.Count]; for (int i = 0; i < system.SystemStats.Length; i++) { statsList[i] = system.SystemStats[i]; } foreach (IBBoard.WarFoundry.API.Objects.SystemStats stat in system.SystemStats) { system.RemoveSystemStats(stat.ID); } IBBoard.WarFoundry.API.Objects.SystemStats temp = statsList[index]; statsList[index] = statsList[index - 1]; statsList[index - 1] = temp; for (int i = statsList.Length - 1; i >= 0; i--) { system.AddSystemStats(statsList[i]); } updateSystemStatsList(); this.lviewStats.Items[index - 1].Selected = true; } private void btnStatsDown_Click(object sender, EventArgs e) { int index = this.lviewStats.SelectedIndices[0]; IBBoard.WarFoundry.API.Objects.SystemStats[] statsList = new IBBoard.WarFoundry.API.Objects.SystemStats[this.lviewStats.Items.Count]; for (int i = 0; i < system.SystemStats.Length; i++) { statsList[i] = system.SystemStats[i]; } foreach (IBBoard.WarFoundry.API.Objects.SystemStats stat in system.SystemStats) { system.RemoveSystemStats(stat.ID); } IBBoard.WarFoundry.API.Objects.SystemStats temp = statsList[index]; statsList[index] = statsList[index + 1]; statsList[index + 1] = temp; for (int i = statsList.Length - 1; i >= 0; i--) { system.AddSystemStats(statsList[i]); } updateSystemStatsList(); this.lviewStats.Items[index + 1].Selected = true; } private void txtStatLineID_TextChanged(object sender, EventArgs e) { if(this.txtStatLineID.Text != string.Empty) { this.btnStatsAdd.Enabled = true; this.txtStatName.Enabled = true; } else { this.btnStatsAdd.Enabled = false; this.txtStatName.Enabled = false; this.btnStatListAdd.Enabled = false; } } private void txtStatName_TextChanged(object sender, EventArgs e) { if(this.txtStatName.Text != string.Empty) { this.btnStatListAdd.Enabled = true; } else { this.btnStatListAdd.Enabled = false; } } private void btnStatListAdd_Click(object sender, EventArgs e) { if(currentStats == null) { if(this.txtStatLineID.Text != string.Empty) { currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text); } else { MessageBox.Show("You must first define an ID for the stat line.", "No ID Error"); return; } } if(this.txtStatName.Text != string.Empty) { currentStats.AddStatSlot(this.txtStatName.Text); } this.txtStatName.Clear(); updateStatNames(currentStats); updateStatLinePreview(currentStats); } private void listStatNames_SelectedIndexChanged(object sender, EventArgs e) { if(this.listStatNames.SelectedIndex >= 0) { this.btnStatListRemove.Enabled = true; if(this.listStatNames.SelectedIndex == 0) { this.btnStatListUp.Enabled = false; } else { this.btnStatListUp.Enabled = true; } if(this.listStatNames.SelectedIndex == this.listStatNames.Items.Count - 1) { this.btnStatListDown.Enabled = false; } else { this.btnStatListDown.Enabled = true; } } else { this.btnStatListRemove.Enabled = false; this.btnStatListUp.Enabled = false; this.btnStatListDown.Enabled = false; } } private void btnStatListRemove_Click(object sender, EventArgs e) { currentStats.RemoveStatSlot((string)this.listStatNames.SelectedItem); updateStatNames(currentStats); updateStatLinePreview(currentStats); } private void btnStatListUp_Click(object sender, EventArgs e) { int index = this.listStatNames.SelectedIndex; string[] slotList = new string[this.listStatNames.Items.Count]; for (int i = 0; i < currentStats.SlotCount; i++) { slotList[i] = currentStats.StatSlots[i].Name; } for (int i = 0; i < slotList.Length; i++) { currentStats.RemoveStatSlot(slotList[i]); } string temp = slotList[index]; slotList[index] = slotList[index - 1]; slotList[index - 1] = temp; for (int i = 0; i < slotList.Length; i++) { currentStats.AddStatSlot(slotList[i]); } updateStatNames(currentStats); updateStatLinePreview(currentStats); this.listStatNames.SelectedIndex = index - 1; } private void btnStatListDown_Click(object sender, EventArgs e) { int index = this.listStatNames.SelectedIndex; string[] slotList = new string[this.listStatNames.Items.Count]; for (int i = 0; i < currentStats.SlotCount; i++) { slotList[i] = currentStats.StatSlots[i].Name; } for (int i = 0; i < slotList.Length; i++) { currentStats.RemoveStatSlot(slotList[i]); } string temp = slotList[index]; slotList[index] = slotList[index + 1]; slotList[index + 1] = temp; for (int i = 0; i < slotList.Length; i++) { currentStats.AddStatSlot(slotList[i]); } updateStatNames(currentStats); updateStatLinePreview(currentStats); this.listStatNames.SelectedIndex = index + 1; } private void btnStatLineApply_Click(object sender, EventArgs e) { system.SetSystemStats(currentStats); clearStatLine(); } } }