예제 #1
0
        void AddNewElement(int width, int height)
        {
            SignComponent c = new SignComponent() { Width = width, Height = height };
            EditElement e = new EditElement(this, c);

            // Find a new grid-aligned location that doesn't overlap with any other element
            for (int y = 0; y < MaxY; y += height)
            {
                for (int x = 0; x < MaxX; x += width)
                {
                    e.Location.X = x;
                    e.Location.Y = y;
                    if (!e.Collides()) break;
                }
                if (!e.Collides()) break;
            }

            if(e.Collides())
            {
                // Silently fail.
                return;
            }

            e.SyncLocation();
            AddElement(e);
            ConfigurationChange();
        }
        /// <summary>
        /// Called whenever the tile entity is created. Setup time!
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="entityUniverseFacade"></param>
        public override void Construct(Blob arguments, EntityUniverseFacade entityUniverseFacade)
        {
            this._configuration = GameContext.TileDatabase.GetTileConfiguration(arguments.GetString("tile"));
            this._signComponent = _configuration.Components.GetOrDefault <SignComponent>();
            this.Location       = arguments.FetchBlob("location").GetVector3I();
            this._variant       = (uint)arguments.GetLong("variant");

            this.Entity.Physics.Construct(arguments.FetchBlob("position").GetVector3D(), Vector3D.Zero);
            this.Entity.Physics.MakePhysicsless();
        }
예제 #3
0
        public SignPreview()
        {
            lockObj = new object();
            SignName = "Sign Preview";
            if (PreviewIndex > 1)
                SignName += " " + PreviewIndex;
            PreviewIndex++;

            InitializeComponent();

            Text = SignName;

            SignComponent[] c  = new SignComponent[2];
            c[0] = new SignComponent() { X = 0, Y = 0, Width = 32, Height = 32 };
            c[1] = new SignComponent() { X = 32, Y = 0, Width = 32, Height = 32 };
            CurrentConfig = new SignConfiguration(c);
            ResizeForConfiguration();
        }
예제 #4
0
        //You must have an Update.
        //Always read in deltaTime, and only deltaTime (it's the time that's passed since the last frame)
        //Use deltaTime for things like changing velocity or changing position from velocity
        //This is where you do anything that you want to happen every frame.
        //There is a chance that your system won't need to do anything in update. Still have it.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                SignComponent signComp = (SignComponent)e.getComponent(GlobalVars.SIGN_COMPONENT_NAME);

                if (!signComp.isActive)
                {
                    continue;
                }
                else //checks to see if player is still colliding with the sign
                {
                    PositionComponent posComp = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

                    System.Drawing.PointF position = posComp.getLocAsPoint();
                    float xPos = position.X;
                    float yPos = position.Y;
                    System.Drawing.PointF startPoint = new System.Drawing.PointF(xPos - posComp.width / 2, yPos);
                    System.Drawing.PointF endPoint   = new System.Drawing.PointF(xPos + posComp.width / 2, yPos);

                    List <Entity> list = level.getCollisionSystem().findObjectsBetweenPoints(startPoint, endPoint); //find all the objects between (hopefully) the ends of the sign

                    bool playerExists = false;
                    foreach (Entity ent in list)
                    {
                        if (ent is Entities.Player)
                        {
                            playerExists = true;
                            break;
                        }
                    }
                    if (playerExists)
                    {
                        signComp.isActive = true;
                        level.sysManager.drawSystem.beginConstText(signComp.text, level.sysManager.signSystem.signCol);
                    }
                    else
                    {
                        signComp.isActive = false;
                        level.sysManager.drawSystem.endConstText(signComp.text, signCol, 0.5f);
                    }
                }
            }
        }
        /// <summary>
        /// Restore entity from temp save data
        /// </summary>
        public override void Restore()
        {
            base.Restore();

            this.Location       = base._blob.FetchBlob("location").GetVector3I();
            this._variant       = (uint)base._blob.GetLong("variant");
            this._configuration = GameContext.TileDatabase.GetTileConfiguration(base._blob.GetString("tile"));

            this._centerPos = base._blob.GetBlob("centerPos").GetVector3D();
            this._isRemoved = base._blob.GetBool("isRemoved");

            this._message = base._blob.GetString("message");
            this._color   = new Color()
            {
                PackedValue = (uint)base._blob.GetLong("color")
            };
            this._scale = (float)base._blob.GetDouble("scale");
            this._align = (BmFontAlign)base._blob.GetLong("align");

            this._signComponent = _configuration.Components.GetOrDefault <SignComponent>();
        }
예제 #6
0
        public TargetTestBoard()
        {
            TestBoard = null;
            foreach(var dev in SignTest.Enumerate())
            {
                try
                {
                    TestBoard = new SignTest(dev);
                    break;
                }
                catch { }
            }
            if (TestBoard == null)
                throw new Exception("Unable to attach to a Sign Test board.");

            SignComponent[] c = new SignComponent[1];
            c[0] = new SignComponent() { X = 0, Y = 0, Width = 32, Height = 32 };
            CurrentConfig = new SignConfiguration(c);

            // Initialize test board.

            TestBoard.SetMode(SignTest.DeviceMode.On);
            TestBoard.SetMode(SignTest.DeviceMode.FpgaActive);
        }
예제 #7
0
        void ImageTile_MouseMove(object sender, MouseEventArgs e)
        {
            int scale = SignTargetConfigure.ScaleFactor;
            int maxx = SignTargetConfigure.MaxX;
            int maxy = SignTargetConfigure.MaxY;
            int grid = 8;
            int minMove = grid * scale * 3 / 4;
            if (Dragging)
            {
                int dx = e.X - MouseX;
                int dy = e.Y - MouseY;

                int movex = 0;
                int movey = 0;

                if (Math.Abs(dx) > minMove)
                {
                    movex = (int)Math.Round((float)dx / (grid * scale)) * grid;
                }
                if (Math.Abs(dy) > minMove)
                {
                    movey = (int)Math.Round((float)dy / (grid * scale)) * grid;
                }

                // Clip to edges
                if (Location.X + movex < 0)
                {
                    movex = -Location.X;
                }
                if (Location.Y + movey < 0)
                {
                    movey = -Location.Y;
                }

                if (Location.X + movex + Location.Width > maxx)
                {
                    movex = maxx - Location.X - Location.Width;
                }
                if (Location.Y + movey + Location.Height > maxy)
                {
                    movey = maxy - Location.Y - Location.Height;
                }

                SignComponent fallback = Location;
                // Perform move
                Location.X += movex;
                Location.Y += movey;

                if(Collides())
                {
                    // Don't allow overlapping tiles
                    Location = fallback;
                }
                else
                {
                    ImageTile.Location = new Point(Location.X * scale, Location.Y * scale);
                    Parent.ConfigurationChange();
                }

            }
        }
예제 #8
0
        public EditElement(SignTargetConfigure container, SignComponent c)
        {
            Parent = container;
            Location = c;
            ImageTile = new PictureBox();
            ImageSection = new Bitmap(Location.Width, Location.Height);
            ImageTile.Image = ImageSection;

            int scale = SignTargetConfigure.ScaleFactor;

            ImageTile.Width = Location.Width * scale;
            ImageTile.Height = Location.Height * scale;
            ImageTile.Location = new Point(Location.X * scale, Location.Y * scale);

            ImageTile.SizeMode = PictureBoxSizeMode.StretchImage;
            ImageTile.Cursor = Cursors.SizeAll;

            ImageTile.MouseDown += ImageTile_MouseDown;
            ImageTile.MouseMove += ImageTile_MouseMove;
            ImageTile.MouseUp += ImageTile_MouseUp;
        }