Exemple #1
0
        private void DeleteEntriesRow(int entry, int index)
        {
            FormationDataMgr.RemoveEntry(entry);

            int newIndex = -1;

            if (index > 0)
            {
                newIndex = index - 1;
            }
            else
            {
                if (FormationDataMgr.Count() < 1)
                {
                    // check if have at least one entry
                    FormationDataEntry dataEntry = FormationDataMgr.AddEntry(1);

                    // Fill the DataGridView
                    DataGridViewRow newRow = (DataGridViewRow)EntriesDGV.Rows[0].Clone();
                    newRow.Cells[0].Value = dataEntry.Entry.ToString();
                    newRow.Cells[1].Value = dataEntry.MasterX.ToString();
                    newRow.Cells[2].Value = dataEntry.MasterY.ToString();
                    newRow.Cells[3].Value = dataEntry.MasterO.ToString();
                    newRow.Tag            = dataEntry.Entry;
                    EntriesDGV.Rows.Add(newRow);
                }
                newIndex = 1;
            }

            ShowEntry((int)EntriesDGV.Rows[newIndex].Tag);
        }
 public SlaveRotationForm(Form1 mainForm, FormationDataEntry dataEntry)
 {
     MainForm = mainForm;
     CurrentFormationEntry = dataEntry;
     InitializeComponent();
     trackBar1.Value = 180;
 }
Exemple #3
0
        public bool SetEntry(int oldEntry, int newEntry)
        {
            if (newEntry <= 0)
            {
                return(false);
            }
            FormationDataEntry currEntry = null;

            foreach (FormationDataEntry dataEntry in dataList)
            {
                if (dataEntry.Entry == newEntry)
                {
                    return(false);
                }

                if (dataEntry.Entry == oldEntry)
                {
                    currEntry = dataEntry;
                }
            }

            if (currEntry == null)
            {
                return(false);
            }

            currEntry.Entry = newEntry;
            if (AvailableEntryID >= newEntry)
            {
                AvailableEntryID = newEntry + 1;
            }

            return(true);
        }
Exemple #4
0
        public void RotateEntry(FormationDataEntry dataEntry, int degrees)
        {
            for (int i = 0; i < CurrentSelectedEntry.slaveEntries.Count; ++i)
            {
                SlaveDataEntry currSlaveEntry = CurrentSelectedEntry.slaveEntries[i];
                SlaveDataEntry tempSlaveEntry = dataEntry.slaveEntries[i];

                tempSlaveEntry.Angle = currSlaveEntry.Angle + degrees;
            }
        }
Exemple #5
0
 public void EditEntry(FormationDataEntry dataEntry)
 {
     for (int i = 0; i < dataList.Count; ++i)
     {
         if (dataList[i].Entry == dataEntry.Entry)
         {
             dataList[i] = dataEntry;
             return;
         }
     }
 }
Exemple #6
0
        public void ShowEntry(int entry)
        {
            FormationDataEntry currEntry = FormationDataMgr.GetEntry(entry);

            if (currEntry == null)
            {
                return;
            }

            CurrentSelectedEntry = currEntry;
            ShowEntry(currEntry);
        }
Exemple #7
0
        private void rotateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormationDataEntry dataEntry = new FormationDataEntry(CurrentSelectedEntry);
            SlaveRotationForm  sRF       = new SlaveRotationForm(this, dataEntry);

            if (sRF.ShowDialog() == DialogResult.OK)
            {
                CurrentSelectedEntry = dataEntry;
                FormationDataMgr.EditEntry(dataEntry);
            }

            ShowEntry(dataEntry.Entry);
        }
Exemple #8
0
        public FormationDataEntry(FormationDataEntry dataEntry)
        {
            Entry        = dataEntry.Entry;
            MasterX      = dataEntry.MasterX;
            MasterY      = dataEntry.MasterY;
            MasterO      = dataEntry.MasterO;
            slaveEntries = new List <SlaveDataEntry>();

            foreach (SlaveDataEntry sEntry in dataEntry.slaveEntries)
            {
                slaveEntries.Add(new SlaveDataEntry(sEntry));
            }

            GeneratedIDs = dataEntry.GeneratedIDs;
        }
Exemple #9
0
        public void AddSlave(int entry, float angle, float distance, int id = 0)
        {
            foreach (FormationDataEntry row in dataList)
            {
                if (row.Entry == entry)
                {
                    row.AddSlave(angle, distance, id);
                    return;
                }
            }

            // no entry found create new one
            FormationDataEntry slaveEntry = AddEntry(entry);

            slaveEntry.AddSlave(angle, distance);
        }
Exemple #10
0
        public void Load(string fileName = "Datas.json")
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            string json = File.ReadAllText(fileName);
            List <FormationDataEntry> newList = JSONSerializer.Deserialize <List <FormationDataEntry> >(json);

            // Check the values and add them to data list
            List <int> usedEntries = new List <int>();

            for (int i = 0; i < newList.Count; ++i)
            {
                FormationDataEntry formationEntry = newList[i];

                if (usedEntries.BinarySearch(formationEntry.Entry) > 0)
                {
                    continue;
                }

                usedEntries.Add(formationEntry.Entry);
                FormationDataEntry newEntry = new FormationDataEntry(formationEntry.Entry, formationEntry.MasterX, formationEntry.MasterY, formationEntry.MasterO);
                dataList.Add(newEntry);

                if (formationEntry.Entry >= AvailableEntryID)
                {
                    AvailableEntryID = formationEntry.Entry + 1;
                }

                List <int> usedIds = new List <int>();
                for (int j = 0; j < formationEntry.slaveEntries.Count; ++j)
                {
                    SlaveDataEntry slaveEntry = formationEntry.slaveEntries[j];

                    if (usedIds.BinarySearch(slaveEntry.ID) > 0)
                    {
                        continue;
                    }

                    usedIds.Add(slaveEntry.ID);

                    newEntry.AddSlave(slaveEntry.Angle, slaveEntry.Distance, slaveEntry.ID);
                }
            }
        }
Exemple #11
0
        public void ShowEntry(FormationDataEntry dataEntry)
        {
            ClearObjects();

            List <SlaveDataEntry> slaves = dataEntry.slaveEntries;

            if (slaves != null)
            {
                foreach (SlaveDataEntry slave in slaves)
                {
                    int             rowIndex = MainDataDGV.Rows.Add(slave.ID.ToString(), slave.Angle.ToString(), slave.Distance.ToString());
                    DataGridViewRow currRow  = MainDataDGV.Rows[rowIndex];
                    currRow.Tag = slave.ID;
                    AddObject(currRow, slave);

                    foreach (DataGridViewCell cell in currRow.Cells)
                    {
                        cell.Style.BackColor = Color.Green;
                    }
                }
            }
            MainDataDGV.Rows[MainDataDGV.Rows.Count - 1].Cells[0].Value           = slaves.Count + 1;
            MainDataDGV.Rows[MainDataDGV.Rows.Count - 1].Cells[0].Style.BackColor = Color.LawnGreen;
        }
Exemple #12
0
        private void EntriesDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            float value          = 0;
            int   intValue       = 0;
            int   newWantedEntry = 0;

            DataGridViewRow  currRow  = EntriesDGV.Rows[e.RowIndex];
            DataGridViewCell currCell = currRow.Cells[e.ColumnIndex];

            switch (e.ColumnIndex)
            {
            case 0:
                if (currCell.Value != null && ValidateInt(currCell.Value.ToString(), out intValue))
                {
                    newWantedEntry = intValue;
                }
                else
                {
                    if (currRow.Tag == null)
                    {
                        currCell.Value = null;
                        return;
                    }

                    MessageBox.Show("Invalid entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    currCell.Value = currRow.Tag.ToString();
                    return;
                }

                break;

            case 1:
                if (currCell.Value != null && ValidateFloat(currCell.Value.ToString(), out value))
                {
                    CurrentSelectedEntry.MasterX = value;
                }
                else
                {
                    if (currRow.Tag == null)
                    {
                        currCell.Value = null;
                        return;
                    }
                }

                currCell.Value = CurrentSelectedEntry.MasterX.ToString();
                break;

            case 2:
                if (currCell.Value != null && ValidateFloat(currCell.Value.ToString(), out value))
                {
                    CurrentSelectedEntry.MasterY = value;
                }
                else
                {
                    if (currRow.Tag == null)
                    {
                        currCell.Value = null;
                        return;
                    }
                }

                currCell.Value = CurrentSelectedEntry.MasterY.ToString();
                break;

            case 3:
                if (currCell.Value != null && ValidateFloat(currCell.Value.ToString(), out value))
                {
                    CurrentSelectedEntry.MasterO = value;
                }
                else
                {
                    if (currRow.Tag == null)
                    {
                        currCell.Value = null;
                        return;
                    }
                }

                currCell.Value = CurrentSelectedEntry.MasterO.ToString();
                break;

            default:
                break;
            }

            if (currRow.Tag == null)
            {
                // New line!
                if (newWantedEntry == 0 || !FormationDataMgr.IsNewEntryIDValid(newWantedEntry))
                {
                    newWantedEntry = FormationDataMgr.GetAvailableEntryID();
                }
                FormationDataMgr.CreateEntryIfNeed(newWantedEntry);
                currRow.Tag            = newWantedEntry;
                currRow.Cells[0].Value = newWantedEntry.ToString();

                for (int i = 1; i < currRow.Cells.Count; ++i)
                {
                    float tempVal = 0;
                    if (currRow.Cells[i].Value == null || !ValidateFloat(currRow.Cells[i].Value.ToString(), out tempVal))
                    {
                        currRow.Cells[i].Value = 0;
                    }
                }
            }
            else
            {
                // Existing row
                int realEntry = (int)currRow.Tag;
                FormationDataEntry dataEntry = FormationDataMgr.GetEntry(realEntry);
                if (newWantedEntry != 0 && newWantedEntry != realEntry)
                {
                    if (!FormationDataMgr.SetEntry(realEntry, newWantedEntry))
                    {
                        MessageBox.Show("Entry already exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        currCell.Value = currRow.Tag.ToString();
                    }
                    return;
                }
            }

            if (newWantedEntry == CurrentSelectedEntry.Entry)
            {
                foreach (var item in ObjectsList)
                {
                    item.Value.SetBaseGamePos(CurrentSelectedEntry.MasterX, CurrentSelectedEntry.MasterY, CurrentSelectedEntry.MasterO);
                }
            }
        }