Exemple #1
0
 private void ExportProfileSave(string filename)
 {
     profile.Export(filename);
 }
Exemple #2
0
        private void SetupSection(Panel p, Save.ProfileSave pfl)
        {
            while (p.Controls.Count > 0)
            {
                p.Controls.RemoveAt(0);
            }

            // MISCELLANEOUS

            int pad = 8, padMid = 4, h = 20, wT = 96, wI = 180, wI2 = 32, hIoff = -2, vIoff = -2, mgn = 2;

            string[] rows = new string[4] {
                "Name", "Truguts", "Pit Droids", "Selected Vehicle"
            };
            Label l1;

            for (int i = 0; i < rows.Length; i++)
            {
                l1          = new Label();
                l1.Text     = rows[i];
                l1.Location = new Point(pad, pad + (h + padMid) * i);
                l1.Size     = new Size(wT, h);
                l1.Padding  = new Padding(mgn);
                l1.Margin   = new Padding(0);
                l1.AutoSize = true;
                p.Controls.Add(l1);
            }

            TextBox tb1 = new TextBox();

            tb1              = new TextBox();
            tb1.MaxLength    = Save.MaxNameLength;
            tb1.Text         = pfl.Player;
            tb1.Location     = new Point(pad + wT + hIoff, pad + (h + padMid) * 0 + vIoff);
            tb1.Size         = new Size(wI, h);
            tb1.TextChanged += (o, e) => UpdateName(tb1.Text, pfl);
            p.Controls.Add(tb1);

            NumericUpDown numM = new NumericUpDown();

            numM.Maximum       = int.MaxValue;
            numM.Minimum       = int.MinValue;
            numM.Value         = pfl.Truguts;
            numM.Increment     = 1000;
            numM.Location      = new Point(pad + wT + hIoff, pad + (h + padMid) * 1 + vIoff);
            numM.Size          = new Size(wI / 2, h);
            numM.ValueChanged += (o, e) => pfl.Truguts = (int)numM.Value;
            p.Controls.Add(numM);
            Button btnMmin = new Button();

            btnMmin.Text     = "Min";
            btnMmin.Location = new Point(numM.Location.X + numM.Size.Width + padMid, numM.Location.Y);
            btnMmin.Size     = new Size((wI - numM.Size.Width - padMid * 2) / 2, h);
            btnMmin.Click   += (o, e) => numM.Value = numM.Minimum;
            p.Controls.Add(btnMmin);
            Button btnMmax = new Button();

            btnMmax.Text     = "Max";
            btnMmax.Location = new Point(btnMmin.Location.X + btnMmin.Size.Width + padMid, btnMmin.Location.Y);
            btnMmax.Size     = new Size((wI - numM.Size.Width - padMid * 2) / 2, h);
            btnMmax.Click   += (o, e) => numM.Value = numM.Maximum;
            p.Controls.Add(btnMmax);

            NumericUpDown numP = new NumericUpDown();

            numP.Maximum       = 7;
            numP.Minimum       = 1;
            numP.Value         = pfl.PitDroids;
            numP.Increment     = 1;
            numP.Location      = new Point(pad + wT + hIoff, pad + (h + padMid) * 2 + vIoff);
            numP.Size          = new Size(wI / 2, h);
            numP.ValueChanged += (o, e) => pfl.PitDroids = (byte)numP.Value;
            p.Controls.Add(numP);
            Button btnPmin = new Button();

            btnPmin.Text     = "Min";
            btnPmin.Location = new Point(numP.Location.X + numP.Size.Width + padMid, numP.Location.Y);
            btnPmin.Size     = new Size((wI - numP.Size.Width - padMid * 2) / 2, h);
            btnPmin.Click   += (o, e) => numP.Value = numP.Minimum;
            p.Controls.Add(btnPmin);
            Button btnPmax = new Button();

            btnPmax.Text     = "Max";
            btnPmax.Location = new Point(btnPmin.Location.X + btnPmin.Size.Width + padMid, btnPmin.Location.Y);
            btnPmax.Size     = new Size((wI - numP.Size.Width - padMid * 2) / 2, h);
            btnPmax.Click   += (o, e) => numP.Value = numP.Maximum;
            p.Controls.Add(btnPmax);

            ComboBox cbx = new ComboBox();

            cbx.Location              = new Point(pad + wT + hIoff, pad + (h + padMid) * 3 + vIoff);
            cbx.Size                  = new Size(wI, h);
            cbx.DropDownStyle         = ComboBoxStyle.DropDownList;
            cbx.BindingContext        = new BindingContext();
            cbx.DataSource            = new BindingSource(Value.Vehicle.Name, null);
            cbx.DisplayMember         = "VALUE";
            cbx.ValueMember           = "KEY";
            cbx.SelectedValue         = (byte)pfl.SelectedVehicle;
            cbx.SelectedIndexChanged += (o, e) => pfl.SelectedVehicle = (Save.Vehicle)cbx.SelectedValue;
            p.Controls.Add(cbx);


            int clbVclW = (basepanel.Width - pad * 3 - 32) / 5 * 2, pTrkW = (basepanel.Width - pad * 3 - 32) - clbVclW, clbH = 210, clbBtnW = 48, pBtnW = 48, vclY = cbx.Location.Y + cbx.Size.Height + pad * 2, trkY = vclY;

            // VEHICLES

            Label lVcl = new Label();

            lVcl          = new Label();
            lVcl.Text     = "Vehicles";
            lVcl.Location = new Point(pad, vclY);
            lVcl.Size     = new Size(wI2, h);
            lVcl.Padding  = new Padding(0);
            lVcl.Margin   = new Padding(0);
            lVcl.AutoSize = true;
            p.Controls.Add(lVcl);
            CheckedListBox clbVcl = new CheckedListBox();

            clbVcl.IntegralHeight = false;
            clbVcl.Location       = new Point(lVcl.Location.X, lVcl.Location.Y + lVcl.Size.Height + padMid);
            clbVcl.Size           = new Size(clbVclW, clbH);
            clbVcl.CheckOnClick   = true;
            Array vclFlagList = Enum.GetValues(typeof(Save.VehicleUnlockFlags));

            foreach (Save.VehicleUnlockFlags flag in vclFlagList)
            {
                if (pfl.AvailableVehicles.HasFlag(flag))
                {
                    clbVcl.Items.Add(flag, true);
                }
                else
                {
                    clbVcl.Items.Add(flag, false);
                }
            }
            clbVcl.ItemCheck += (o, e) => UpdateVehicles(o, pfl);
            p.Controls.Add(clbVcl);
            Button btnVnone = new Button();

            btnVnone.Text     = "None";
            btnVnone.Size     = new Size(clbBtnW, h);
            btnVnone.Location = new Point(clbVcl.Location.X, clbVcl.Location.Y + clbVcl.Size.Height + padMid);
            btnVnone.Click   += (o, e) => SelectAll(clbVcl, false);
            p.Controls.Add(btnVnone);
            Button btnVall = new Button();

            btnVall.Text     = "All";
            btnVall.Size     = new Size(clbBtnW, h);
            btnVall.Location = new Point(btnVnone.Location.X + btnVnone.Size.Width + padMid, clbVcl.Location.Y + clbVcl.Size.Height + padMid);
            btnVall.Click   += (o, e) => SelectAll(clbVcl, true);
            p.Controls.Add(btnVall);

            // TRACKS

            Label lTrk = new Label();

            lTrk          = new Label();
            lTrk.Text     = "Tracks";
            lTrk.Location = new Point(lVcl.Location.X + clbVclW + pad, trkY);
            lTrk.Size     = new Size(wI2, h);
            lTrk.Padding  = new Padding(0);
            lTrk.Margin   = new Padding(0);
            lTrk.AutoSize = true;
            p.Controls.Add(lTrk);
            Panel pTrk = new Panel();

            pTrk.Location    = new Point(lTrk.Location.X, lTrk.Location.Y + lTrk.Size.Height + padMid);
            pTrk.Size        = new Size(pTrkW, clbH);
            pTrk.AutoScroll  = true;
            pTrk.BorderStyle = BorderStyle.FixedSingle;
            pTrk.BackColor   = Color.White;
            p.Controls.Add(pTrk);
            Array trkFlagList = Enum.GetValues(typeof(Save.TrackUnlockFlags));

            CheckBox[] cbTrk  = new CheckBox[trkFlagList.Length];
            ComboBox[] cbxTrk = new ComboBox[trkFlagList.Length];
            int        trkPlW = 64;

            for (int i = 0; i < trkFlagList.Length; i++)
            {
                //eventually expand events to reconcile available/placing combinations to be realistic? or just keep it totally free control? option for both?

                Enum flag = (Enum)trkFlagList.GetValue(i);
                Save.TrackUnlockFlags flagReal = (Save.TrackUnlockFlags)trkFlagList.GetValue(i);
                bool isRace = !flag.ToString().EndsWith("Done");

                cbTrk[i] = new CheckBox();
                CheckBox check = cbTrk[i], checkPrev = cbTrk[Math.Max(0, i - 1)];
                check.Text     = trkFlagList.GetValue(i).ToString();
                check.Checked  = pfl.AvailableTracks.HasFlag(flag);
                check.Enabled  = isRace;
                check.AutoSize = true;
                check.Padding  = new Padding(4);
                check.Margin   = new Padding(0);
                check.Location = new Point(0, (h + padMid) * i);
                if (!isRace)
                {
                    checkPrev.CheckedChanged += (o, e) => check.Checked = checkPrev.Checked;
                }
                else
                {
                    check.CheckedChanged += (o, e) => UpdateTracks(pTrk, pfl);
                }
                pTrk.Controls.Add(check);

                if (isRace)
                {
                    cbxTrk[i] = new ComboBox();
                    ComboBox combo = cbxTrk[i], comboPrev = cbxTrk[Math.Max(0, i - 1)];
                    combo.Location              = new Point(pTrk.Size.Width - 20 - trkPlW, check.Location.Y + 1);
                    combo.Size                  = new Size(trkPlW, h);
                    combo.DropDownStyle         = ComboBoxStyle.DropDownList;
                    combo.BindingContext        = new BindingContext();
                    combo.DataSource            = new BindingSource(Save.TrackPlacingText, null);
                    combo.DisplayMember         = "VALUE";
                    combo.ValueMember           = "KEY";
                    combo.SelectedValue         = pfl.GetPlacement(flagReal);
                    combo.SelectedIndexChanged += (o, e) => pfl.SetPlacement(flagReal, (Save.TrackPlacing)combo.SelectedValue);
                    pTrk.Controls.Add(combo);
                }
            }
            List <Control> cbList   = pTrk.Controls.OfType <CheckBox>().Where(cb => cb.Enabled).Cast <Control>().ToList();
            Button         btnTnone = new Button();

            btnTnone.Text     = "None";
            btnTnone.Size     = new Size(pBtnW, h);
            btnTnone.Location = new Point(pTrk.Location.X, pTrk.Location.Y + pTrk.Size.Height + padMid);
            btnTnone.Click   += (o, e) => { foreach (CheckBox cb in cbList)
                                            {
                                                cb.Checked = false;
                                            }
            };
            p.Controls.Add(btnTnone);
            Button btnTall = new Button();

            btnTall.Text     = "All";
            btnTall.Size     = new Size(pBtnW, h);
            btnTall.Location = new Point(btnTnone.Location.X + btnTnone.Size.Width + padMid, pTrk.Location.Y + pTrk.Size.Height + padMid);
            btnTall.Click   += (o, e) => { foreach (CheckBox cb in cbList)
                                           {
                                               cb.Checked = true;
                                           }
            };
            p.Controls.Add(btnTall);


            int upBaseY = btnVnone.Location.Y + btnVnone.Size.Height + pad * 2;

            // UPGRADES

            string[] lUpColT = new string[2] {
                "Upgrade", "Health"
            };
            ComboBox[] cbxUp  = new ComboBox[pfl.Upgrades.Length];
            TrackBar[] tbUpHp = new TrackBar[pfl.Upgrades.Length];
            Label[]    lUp    = new Label[pfl.Upgrades.Length], lUpHp = new Label[pfl.Upgrades.Length], lUpCol = new Label[lUpColT.Length];
            int        wIup   = (basepanel.Width - wT - wI2 - pad * 6) / 2;

            for (int i = 0; i < lUpColT.Length; i++)
            {
                int x = pad + wT + (wIup + padMid) * i;
                int y = upBaseY;
                lUpCol[i]          = new Label();
                lUpCol[i].Text     = lUpColT[i];
                lUpCol[i].Location = new Point(x, y);
                lUpCol[i].Size     = new Size(wI, h);
                lUpCol[i].Padding  = new Padding(mgn);
                lUpCol[i].Margin   = new Padding(0);
                lUpCol[i].AutoSize = true;
                p.Controls.Add(lUpCol[i]);
            }
            for (int i = 0; i < pfl.Upgrades.Length; i++)
            {
                Save.ProfileSave.Upgrade u = pfl.Upgrades[i];
                int y = upBaseY + (h + padMid) * (i + 1);

                lUp[i] = new Label();
                Label thisLUp = lUp[i];
                lUp[i].Text     = Value.Upgrade.Title[(Value.Upgrade.Id)i];
                lUp[i].Location = new Point(pad, y);
                lUp[i].Size     = new Size(wT, h);
                lUp[i].Padding  = new Padding(mgn);
                lUp[i].Margin   = new Padding(0);
                lUp[i].AutoSize = true;
                p.Controls.Add(lUp[i]);

                cbxUp[i] = new ComboBox();
                ComboBox thisCbxUp = cbxUp[i];
                cbxUp[i].Location              = new Point(lUp[i].Location.X + wT, y + vIoff);
                cbxUp[i].Size                  = new Size(wIup, h);
                cbxUp[i].DropDownStyle         = ComboBoxStyle.DropDownList;
                cbxUp[i].BindingContext        = new BindingContext();
                cbxUp[i].DataSource            = new BindingSource(Value.Upgrade.Name[(Value.Upgrade.Id)i], null);
                cbxUp[i].DisplayMember         = "VALUE";
                cbxUp[i].ValueMember           = "KEY";
                cbxUp[i].SelectedValue         = u.Level;
                cbxUp[i].SelectedIndexChanged += (o, e) => u.Level = (byte)thisCbxUp.SelectedValue;
                p.Controls.Add(cbxUp[i]);

                lUpHp[i] = new Label();
                Label thisLUpHp = lUpHp[i];
                tbUpHp[i] = new TrackBar();
                TrackBar thisTbUpHp = tbUpHp[i];
                tbUpHp[i].Location      = new Point(cbxUp[i].Location.X + cbxUp[i].Size.Width, y);
                tbUpHp[i].Size          = new Size(wIup, h);
                tbUpHp[i].Maximum       = byte.MaxValue;
                tbUpHp[i].Minimum       = byte.MinValue;
                tbUpHp[i].Value         = u.Health;
                tbUpHp[i].TickStyle     = TickStyle.None;
                tbUpHp[i].AutoSize      = false;
                tbUpHp[i].ValueChanged += (o, e) => UpdateUpgradeHealth(o, thisLUpHp, u);
                p.Controls.Add(tbUpHp[i]);
                lUpHp[i].Location = new Point(tbUpHp[i].Location.X + tbUpHp[i].Size.Width, y);
                lUpHp[i].Size     = new Size(wI2, h);
                lUpHp[i].Text     = u.Health.ToString();
                lUpHp[i].Padding  = new Padding(0);
                lUpHp[i].Margin   = new Padding(0);
                lUpHp[i].AutoSize = true;
                p.Controls.Add(lUpHp[i]);
            }

            // IMPORT/EXPORT

            Button lImport = new Button();

            lImport.Text     = "Import";
            lImport.Location = new Point(lUp.Last().Location.X, cbxUp.Last().Location.Y + cbxUp.Last().Size.Height + pad * 2);
            lImport.Size     = new Size(64, h + mgn * 2);
            lImport.Padding  = new Padding(0);
            lImport.Margin   = new Padding(0);
            lImport.Click   += (o, e) =>
            {
                if (dlg_inProfile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        pfl.Import(dlg_inProfile.FileName);
                        SetupSection(p, pfl);
                        sections.Resize();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            };
            p.Controls.Add(lImport);

            Button lExport = new Button();

            lExport.Text     = "Export";
            lExport.Location = new Point(lImport.Location.X + lImport.Size.Width + pad, lImport.Location.Y);
            lExport.Size     = new Size(lImport.Size.Width, lImport.Size.Height);
            lExport.Padding  = new Padding(0);
            lExport.Margin   = new Padding(0);
            lExport.Click   += (o, e) =>
            {
                try
                {
                    dlg_outProfile.FileName = string.Format(@"{0}.{1}", pfl.Player, Save.ProfileSave.Extension);
                    if (dlg_outProfile.ShowDialog() == DialogResult.OK)
                    {
                        pfl.Export(dlg_outProfile.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            };
            p.Controls.Add(lExport);
        }