예제 #1
0
        public SlaveDataEntry AddSlave(float angle, float distance, int id = -1)
        {
            if (id >= 0)
            {
                for (int i = 0; i < slaveEntries.Count; ++i)
                {
                    SlaveDataEntry row = slaveEntries[i];
                    if (row.ID == id)
                    {
                        row.Angle    = angle;
                        row.Distance = distance;
                        return(row);
                    }
                }

                if (GeneratedIDs <= id)
                {
                    GeneratedIDs = id + 1;
                }
            }
            else
            {
                id = GeneratedIDs++;
            }

            SlaveDataEntry newSlave = new SlaveDataEntry(id, angle, distance);

            slaveEntries.Add(newSlave);
            return(newSlave);
        }
예제 #2
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;
            }
        }
예제 #3
0
 public void EditSlave(int id, float angle, float distance)
 {
     for (int i = 0; i < slaveEntries.Count; ++i)
     {
         SlaveDataEntry row = slaveEntries[i];
         if (row.ID == id)
         {
             row.Angle    = angle;
             row.Distance = distance;
             return;
         }
     }
 }
예제 #4
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);
                }
            }
        }
예제 #5
0
        private void AddSlaveToObjectList(float angle, float distance)
        {
            SlaveDataEntry slaveEntry = CurrentSelectedEntry.AddSlave(angle, distance);

            int             rowIndex = MainDataDGV.Rows.Add(slaveEntry.ID.ToString(), angleResultTBX.Text, distResultTBX.Text);
            DataGridViewRow currRow  = MainDataDGV.Rows[rowIndex];

            currRow.Tag = slaveEntry.ID;
            AddObject(currRow, slaveEntry);
            MainDataDGV.Rows[MainDataDGV.Rows.Count - 1].Cells[0].Value = MainDataDGV.Rows.Count;
            currRow.Cells[1].Value = angle.ToString();
            currRow.Cells[2].Value = distance.ToString();

            foreach (DataGridViewCell cell in currRow.Cells)
            {
                cell.Style.BackColor = Color.Green;
            }
        }
예제 #6
0
        private void AddObject(DataGridViewRow currRow, SlaveDataEntry slaveEntry)
        {
            Slave  slave = null;
            Object obj   = null;

            currRow.Tag = slaveEntry.ID;
            if (!ObjectsList.TryGetValue(slaveEntry.ID, out obj))
            {
                slave = new Slave(VirtualClientSize);
            }
            else
            {
                slave = obj as Slave;
            }

            Vector2 orig       = new Vector2(0, slaveEntry.Distance * ClientRatio);
            Vector2 rotPos     = Rotate(orig, slaveEntry.Angle);
            Vector2 finalPoint = rotPos;

            int x, y;

            x = Convert.ToInt32(finalPoint.X);
            y = Convert.ToInt32(finalPoint.Y);

            slave.SetBaseGamePos(CurrentSelectedEntry.MasterX, CurrentSelectedEntry.MasterY, CurrentSelectedEntry.MasterO);
            slave.SetScreenPosition(new Point(x, y));


            slave.SetLinkedRow(currRow);
            if (obj == null)
            {
                ObjectsList.Add(slaveEntry.ID, slave);
            }

            MainDrawPB.Invalidate();
        }
예제 #7
0
        private void MainDataDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int   id        = -1;
            float angle     = -1;
            float dist      = -1;
            int   validCell = 0;

            DataGridViewRow currRow = MainDataDGV.CurrentRow;

            foreach (DataGridViewCell cell in currRow.Cells)
            {
                switch (cell.ColumnIndex)
                {
                case 0:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateInt(cell.Value.ToString(), out id))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                case 1:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateFloat(cell.Value.ToString(), out angle))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                case 2:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateFloat(cell.Value.ToString(), out dist))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                default:
                    break;
                }
            }

            if (validCell == 3)
            {
                foreach (DataGridViewCell cell in currRow.Cells)
                {
                    cell.Style.BackColor = Color.Green;
                }

                int currentid = -1;
                if (currRow.Tag != null)
                {
                    currentid = (int)currRow.Tag;
                }

                SlaveDataEntry slaveEntry = CurrentSelectedEntry.AddSlave(angle, dist, currentid);
                AddObject(currRow, slaveEntry);
            }
            else
            {
                if (currRow.Tag != null)
                {
                    RemoveObject((int)currRow.Tag);
                }
            }
        }
예제 #8
0
 public SlaveDataEntry(SlaveDataEntry sEntry)
 {
     ID       = sEntry.ID;
     Angle    = sEntry.Angle;
     Distance = sEntry.Distance;
 }