From aa29971bf97e56a503601db5536373143ea6c3c5 Mon Sep 17 00:00:00 2001 From: chrisf Date: Sat, 7 Jul 2007 06:09:18 +0000 Subject: [PATCH] git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1132 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.FileFormats/IniFile.cs | 5 +- OpenRa.TechTreeTest/Building.cs | 5 + OpenRa.TechTreeTest/Form1.Designer.cs | 26 ++++ OpenRa.TechTreeTest/Form1.cs | 30 ++++- OpenRa.TechTreeTest/Form1.resx | 123 ++++++++++++++++++ .../OpenRa.TechTreeTest.csproj | 4 + OpenRa.TechTreeTest/TechTree.cs | 7 +- 7 files changed, 195 insertions(+), 5 deletions(-) create mode 100644 OpenRa.TechTreeTest/Form1.resx diff --git a/OpenRa.FileFormats/IniFile.cs b/OpenRa.FileFormats/IniFile.cs index 589c3a161d..689547cd34 100644 --- a/OpenRa.FileFormats/IniFile.cs +++ b/OpenRa.FileFormats/IniFile.cs @@ -23,7 +23,7 @@ namespace OpenRa.FileFormats } Regex sectionPattern = new Regex( @"\[([^]]*)\]" ); - Regex entryPattern = new Regex( @"([^=]+)=([^;]*)" ); + Regex entryPattern = new Regex( @"([^=;]+)=([^;]*)" ); bool ProcessSection( string line ) { @@ -75,7 +75,8 @@ namespace OpenRa.FileFormats public void Add( string key, string value ) { - values.Add( key, value ); + values[key] = value; + //values.Add( key, value ); } public string GetValue( string key, string defaultValue ) diff --git a/OpenRa.TechTreeTest/Building.cs b/OpenRa.TechTreeTest/Building.cs index 819f492f66..d11b8882d5 100644 --- a/OpenRa.TechTreeTest/Building.cs +++ b/OpenRa.TechTreeTest/Building.cs @@ -17,6 +17,11 @@ namespace OpenRa.TechTreeTest get { return friendlyName; } } + public string Tag + { + get { return tag; } + } + string[] prerequisites; public string[] Prerequisites diff --git a/OpenRa.TechTreeTest/Form1.Designer.cs b/OpenRa.TechTreeTest/Form1.Designer.cs index f820b7a20c..61e4d5e8d4 100644 --- a/OpenRa.TechTreeTest/Form1.Designer.cs +++ b/OpenRa.TechTreeTest/Form1.Designer.cs @@ -29,11 +29,37 @@ namespace OpenRa.TechTreeTest private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + this.buildableItems = new System.Windows.Forms.FlowLayoutPanel(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.SuspendLayout(); + // + // buildableItems + // + this.buildableItems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.buildableItems.AutoScroll = true; + this.buildableItems.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.buildableItems.Location = new System.Drawing.Point(13, 13); + this.buildableItems.Name = "buildableItems"; + this.buildableItems.Size = new System.Drawing.Size(336, 591); + this.buildableItems.TabIndex = 0; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(365, 616); + this.Controls.Add(this.buildableItems); + this.Name = "Form1"; this.Text = "Form1"; + this.ResumeLayout(false); + } #endregion + + private System.Windows.Forms.FlowLayoutPanel buildableItems; + private System.Windows.Forms.ToolTip toolTip1; } } diff --git a/OpenRa.TechTreeTest/Form1.cs b/OpenRa.TechTreeTest/Form1.cs index 6a5d019eca..0523acd53f 100644 --- a/OpenRa.TechTreeTest/Form1.cs +++ b/OpenRa.TechTreeTest/Form1.cs @@ -10,10 +10,38 @@ namespace OpenRa.TechTreeTest { public partial class Form1 : Form { - TechTree techTree; + TechTree techTree = new TechTree(); + public Form1() { InitializeComponent(); + RefreshList(); + } + + void RefreshList() + { + buildableItems.Controls.Clear(); + + foreach (Building b in techTree.BuildableItems) + { + PictureBox box = new PictureBox(); + box.SizeMode = PictureBoxSizeMode.AutoSize; + box.Image = b.Icon; + + toolTip1.SetToolTip(box, b.Tag); + + buildableItems.Controls.Add(box); + + Building k = b; + + box.Click += delegate { Build(k); }; + } + } + + void Build(Building b) + { + techTree.Build(b.Tag); + RefreshList(); } } } \ No newline at end of file diff --git a/OpenRa.TechTreeTest/Form1.resx b/OpenRa.TechTreeTest/Form1.resx new file mode 100644 index 0000000000..7ce03af83e --- /dev/null +++ b/OpenRa.TechTreeTest/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/OpenRa.TechTreeTest/OpenRa.TechTreeTest.csproj b/OpenRa.TechTreeTest/OpenRa.TechTreeTest.csproj index 260fc5a70c..61bf9dbf72 100644 --- a/OpenRa.TechTreeTest/OpenRa.TechTreeTest.csproj +++ b/OpenRa.TechTreeTest/OpenRa.TechTreeTest.csproj @@ -45,6 +45,10 @@ + + Designer + Form1.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/OpenRa.TechTreeTest/TechTree.cs b/OpenRa.TechTreeTest/TechTree.cs index 9df05a44f2..92c9c0100e 100644 --- a/OpenRa.TechTreeTest/TechTree.cs +++ b/OpenRa.TechTreeTest/TechTree.cs @@ -15,12 +15,15 @@ namespace OpenRa.TechTreeTest { LoadBuildings(); LoadRules(); + + built.Add("FACT"); + CheckAll(); } void LoadRules() { IniFile rulesFile; - rulesFile = new IniFile(File.OpenRead("rules.ini")); + rulesFile = new IniFile(File.OpenRead("../../../rules.ini")); foreach (string key in buildings.Keys) { IniSection section = rulesFile.GetSection(key); @@ -33,7 +36,7 @@ namespace OpenRa.TechTreeTest void LoadBuildings() { - foreach (string line in File.ReadAllLines("buildings.txt")) + foreach (string line in File.ReadAllLines("../../../buildings.txt")) { Regex pattern = new Regex(@"^(\w+),([\w ]+)$"); Match m = pattern.Match(line);