예제 #1
0
 public PresetForm(Form1 mainform, VillageForm vf)
 {
     mform = mainform;
     vform = vf;
     InitializeComponent();
     preset = new BuildPreset();
     preset.buildSettings = new BuildSettings();
     preset.Queue         = new List <string>(); // move it to classs itself when initialize it
     mform = mainform;
     for (int i = 0; i < Buildingslist.Items.Count; i++)
     {
         Buildingslist.Items[i].SubItems.Add(new ListViewItem.ListViewSubItem(Buildingslist.Items[i], "0"));
     }
     //Load queue
     UpdateView(preset.Queue);
 }
예제 #2
0
 private void PresetChooser_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (PresetChooser.Text == "Add preset")
     {
         PresetForm pf = new PresetForm(mform, this);
         pf.Show();
         PresetChooser.Text = "";
     }
     else
     {
         BuildPreset bp = mform.BuildPresets.Find(x => x.Name == PresetChooser.Text);
         //get building levels
         List <string[]> blevels    = new List <string[]>();
         var             model      = village.buildings.GetType();
         var             properties = model.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
         for (int i = 0; i < Buildingslist.Items.Count; i++)
         {
             blevels.Add(new string[] { properties[i].Name, properties[i].GetValue(village.buildings, null).ToString() });
         }
         bp.Queue.Reverse();
         for (int i = bp.Queue.Count - 1; i > -1; i--)
         {
             for (int l = 0; l < blevels.Count; l++)
             {
                 if (blevels[l][0].ToLower() ==
                     bp.Queue[i].ToLower())
                 {
                     if (int.Parse(blevels[l][1]) > 0)
                     {
                         bp.Queue.RemoveAt(i);
                         blevels[l][1] = (int.Parse(blevels[l][1]) - 1).ToString();
                     }
                     break;
                 }
             }
         }
         bp.Queue.Reverse();
         village.BuildQueue    = bp.Queue;
         village.buildSettings = bp.buildSettings;
         UpdateBools(bp.buildSettings);
         UpdateQueueView(village.BuildQueue);
     }
 }