Example #1
0
        public PlaneForm(ISharedManager sm, IPlaneFormManager pfm, string title, AddressPlane sourcePlane = null)
        {
            sharedManager    = sm;
            planeFormManager = pfm;

            InitializeComponent();
            Text = title;

            if (sourcePlane != null)
            {
                XMinUpDown.Value         = sourcePlane.XMin;
                XMaxUpDown.Value         = sourcePlane.XMax;
                YMinUpDown.Value         = sourcePlane.YMin;
                YMaxUpDown.Value         = sourcePlane.YMax;
                DefaultValueUpDown.Value = sourcePlane.DefaultValue;
                DescriptionTextBox.Text  = sourcePlane.Description;
            }

            StructuresGridView.AutoGenerateColumns = false;
            XAddressesGridView.AutoGenerateColumns = false;
            YAddressesGridView.AutoGenerateColumns = false;


            StructuresGridView.DataSource = planeFormManager.GetStructureSource();
            XAddressesGridView.DataSource = planeFormManager.GetXAddressSource();
            YAddressesGridView.DataSource = planeFormManager.GetYAddressSource();
        }
        private static void WriteAddressPlane(AddressPlane ap, StringBuilder builder)
        {
            builder.Append((int)ap.Type + d + ap.Description + d + ap.XMin + d + ap.XMax + d
                           + ap.YMin + d + ap.YMax + d + ap.DefaultValue + d + ap.GetMax() + d
                           + ap.Structures.Count + d + ap.XCenterAddress.Count + d + ap.YCenterAddress.Count + n);

            foreach (var s in ap.Structures)
            {
                switch (s.Type)
                {
                case MemStructObject.ObjectType.OBJECT:
                    WriteObjectBlock((ObjectBlock)s, builder);
                    break;

                case MemStructObject.ObjectType.REGION:
                    WriteAddressRegion((AddressRegion)s, builder);
                    break;

                case MemStructObject.ObjectType.XYREGION:
                    WriteXYRegion((XYRegion)s, builder);
                    break;
                }
            }

            foreach (var x in ap.XCenterAddress)
            {
                WriteIntegerAddress(x, builder);
            }

            foreach (var y in ap.YCenterAddress)
            {
                WriteIntegerAddress(y, builder);
            }
        }
        public AddressPlane(AddressPlane copy)
            : base(copy)
        {
            structures     = new List <MemStructObject>();
            xCenterAddress = new List <IntegerAddress>();
            yCenterAddress = new List <IntegerAddress>();

            CopyValues(copy);
        }
        public bool Confirm(decimal xMinDec, decimal xMaxDec, decimal yMinDec, decimal yMaxDec, decimal defaultValueDec, string description)
        {
            if (description == "")
            {
                return(false);
            }

            int xMin         = (int)Math.Round(xMinDec);
            int xMax         = (int)Math.Round(xMaxDec);
            int yMin         = (int)Math.Round(yMinDec);
            int yMax         = (int)Math.Round(yMaxDec);
            int defaultValue = (int)Math.Round(defaultValueDec);

            newPlane = new AddressPlane(structures, description, xMin, xMax, yMin, yMax, defaultValue, xAddresses, yAddresses);
            Notify();

            return(true);
        }
        public PlaneFormManager(ISharedManager sm, AddressPlane op = null)
        {
            sharedManager = sm;
            observers     = new List <IStructureObserver <AddressPlane> >();
            oldPlane      = op;

            if (op != null)
            {
                structures = new BindingList <MemStructObject>(op.Structures.Select(o => (MemStructObject)(o.Clone())).ToList());
                xAddresses = new BindingList <IntegerAddress>(op.XCenterAddress.Select(o => (IntegerAddress)o.Clone()).ToList());
                yAddresses = new BindingList <IntegerAddress>(op.YCenterAddress.Select(o => (IntegerAddress)o.Clone()).ToList());
            }
            else
            {
                structures = new BindingList <MemStructObject>();
                xAddresses = new BindingList <IntegerAddress>();
                yAddresses = new BindingList <IntegerAddress>();
            }

            xPending = false;
        }
        public static void TestSaveFunction()
        {
            List <IntegerAddress> xCursors = new List <IntegerAddress>();
            List <IntegerAddress> yCursors = new List <IntegerAddress>();

            xCursors.Add(new IntegerAddress(0x326, "Cursor X", -96, (decimal)1 / 8));
            yCursors.Add(new IntegerAddress(0x327, "Cursor Y", -48, (decimal)1 / 8));

            Dictionary <int, int> orientationValues = new Dictionary <int, int>();

            orientationValues[0]  = 1;
            orientationValues[2]  = 2;
            orientationValues[4]  = 3;
            orientationValues[6]  = 4;
            orientationValues[8]  = 5;
            orientationValues[10] = 6;
            orientationValues[12] = 7;
            orientationValues[14] = 8;
            orientationValues[16] = 9;
            orientationValues[18] = 10;
            orientationValues[20] = 9;
            orientationValues[22] = 10;
            orientationValues[24] = 11;
            orientationValues[26] = 11;
            orientationValues[28] = 11;
            orientationValues[30] = 11;
            orientationValues[32] = 12;
            orientationValues[34] = 13;
            orientationValues[36] = 12;
            orientationValues[38] = 13;
            orientationValues[40] = 14;
            orientationValues[42] = 15;
            orientationValues[44] = 16;
            orientationValues[46] = 17;
            orientationValues[48] = 18;
            orientationValues[50] = 19;
            orientationValues[52] = 18;
            orientationValues[54] = 19;

            InformationAddress shapeAndOrientation = new InformationAddress(0x317, "Block shape and orientation", 0, orientationValues);

            Dictionary <int, int> cv1 = new Dictionary <int, int>();

            cv1[0] = 0;

            XYRegion placedBlockLocations = new XYRegion("Placed block locations", 0x100, 12, -1, 0x17, -2, 0x10, 1, cv1);

            List <IntegerAddress> scoreAddresses = new List <IntegerAddress>();

            scoreAddresses.Add(new IntegerAddress(0x270, "Score 1", 0, 1));
            scoreAddresses.Add(new IntegerAddress(0x271, "Score 2", 0, 256));
            scoreAddresses.Add(new IntegerAddress(0x272, "Score 3", 0, 256 * 256));
            scoreAddresses.Add(new IntegerAddress(0x273, "Score 4", 0, 256 * 256 * 256));

            List <MemStructObject> planeObjects = new List <MemStructObject>();

            planeObjects.Add(placedBlockLocations);

            AddressPlane mainPlane = new AddressPlane(planeObjects, "Main plane", -6, 6, -1, 10, 1, xCursors, yCursors);

            List <MemStructObject> structures = new List <MemStructObject>();

            structures.Add(mainPlane);
            structures.Add(shapeAndOrientation);

            List <CategoryColor> cc = new List <CategoryColor>();

            cc.Add(new CategoryColor(Color.Black, 0));
            cc.Add(new CategoryColor(Color.White, 1));

            List <string> buttons = new List <string>();

            buttons.Add("P1 A");
            buttons.Add("P1 B");
            buttons.Add("P1 Down");
            buttons.Add("P1 Left");
            buttons.Add("P1 Right");

            DatabaseSettings settings = new DatabaseSettings(cc, buttons, 300, 30, 0x1912, 80, 600, 20);

            Stream fs = File.Create("Tetris & Dr. Mario - Tetris.plcf");

            WriteFile(structures, scoreAddresses, settings, fs);
        }
        private static AddressPlane ReadAddressPlane(string[] planeLine, StreamReader reader, ref int lineCount)
        {
            string exceptionString = "Invalid address plane line at line " + lineCount;

            if (planeLine.Count() != 11)
            {
                throw new FormatException(exceptionString);
            }

            AddressPlane ap;
            int          sCount;
            int          xCount;
            int          yCount;

            try
            {
                string desc = planeLine[1];
                int    xMin = Convert.ToInt32(planeLine[2]);
                int    xMax = Convert.ToInt32(planeLine[3]);
                int    yMin = Convert.ToInt32(planeLine[4]);
                int    yMax = Convert.ToInt32(planeLine[5]);
                int    dVal = Convert.ToInt32(planeLine[6]);
                sCount = Convert.ToInt32(planeLine[8]);
                xCount = Convert.ToInt32(planeLine[9]);
                yCount = Convert.ToInt32(planeLine[10]);

                ap = new AddressPlane(new List <MemStructObject>(),
                                      desc, xMin, xMax, yMin, yMax, dVal,
                                      new List <IntegerAddress>(), new List <IntegerAddress>());
            }
            catch
            {
                throw new FormatException(exceptionString);
            }

            for (int i = 0; i < sCount; ++i)
            {
                string[] nextLine = reader.ReadLine().Split(',');
                ++lineCount;


                int t = 0;
                if (!int.TryParse(nextLine[0], out t))
                {
                    throw new FormatException("First argument must be an int at line " + lineCount);
                }

                switch (t)
                {
                case (int)MemStructObject.ObjectType.OBJECT:
                    ap.Structures.Add(ReadObjectBlock(nextLine, reader, ref lineCount));
                    break;

                case (int)MemStructObject.ObjectType.REGION:
                    ap.Structures.Add(ReadAddressRegion(nextLine, reader, ref lineCount));
                    break;

                case (int)MemStructObject.ObjectType.XYREGION:
                    ap.Structures.Add(ReadXYRegion(nextLine, reader, ref lineCount));
                    break;

                default:
                    throw new FormatException("Invalid type for a region at line " + lineCount);
                }
            }

            for (int i = 0; i < xCount; ++i)
            {
                ap.XCenterAddress.Add(ReadIntegerAddress(reader, ref lineCount));
            }

            for (int i = 0; i < yCount; ++i)
            {
                ap.YCenterAddress.Add(ReadIntegerAddress(reader, ref lineCount));
            }

            return(ap);
        }