Esempio n. 1
0
 public TowerBaseButton(Screen screen, string text)
 {
     if (screen is TowerScreen)
     {
         TowerScreen ts = screen as TowerScreen;
         this.Text = new TowerText(ts.AddText(text));
     }
     else
     {
         // fail.
         throw new InvalidOperationException(TowerUtils.USE_TOWER_FRAMEWORK_MESSAGE);
     }
 }
Esempio n. 2
0
        public Tower3SliceButton(Screen screen, string text, string imagePrefix, int fontSize = 12, int textOffset = 0, string mouseOverPrefix = null, string imageExtension="png")
            : base(screen, text)
        {
            if (string.IsNullOrEmpty(imagePrefix))
            {
                throw new ArgumentOutOfRangeException("Image prefix must be specified. eg. if it's bubble, we look for bubble-left.png, bubble-center.png, and bubble-right.png");
            }

            if (screen is TowerScreen)
            {
                TowerScreen ts = screen as TowerScreen;
                this.Text.BaseText.Scale = fontSize;

                this._centerSprite = ts.AddSprite("Content/Button/" + imagePrefix + "-center." + imageExtension);
                this._leftSprite = ts.AddSprite("Content/Button/" + imagePrefix + "-left." + imageExtension);
                this._rightSprite = ts.AddSprite("Content/Button/" + imagePrefix + "-right." + imageExtension);

                #region button images
                // Length = number of characters, scale = font-size (approximation of pixel size?)
                // Everything is relative to this guy, so set him first.
                this._centerSprite.ScaleX = this.Text.BaseText.DisplayText.Length  * (this.Text.BaseText.Scale / 2.5f);
                this._centerSprite.ScaleY = this.Text.BaseText.Scale + SCALE_PADDING;
                this._centerSprite.Y = textOffset;
                this._centerSprite.AttachTo(this.Text.BaseText, true);

                this._leftSprite.ScaleX = this.Text.BaseText.Scale;
                this._leftSprite.ScaleY = this.Text.BaseText.Scale + SCALE_PADDING;
                this._leftSprite.X -= this._centerSprite.ScaleX + (this._leftSprite.ScaleX / 2);
                this._leftSprite.Y = textOffset;
                this._leftSprite.AttachTo(this.Text.BaseText, true);

                this._rightSprite.ScaleX = this.Text.BaseText.Scale;
                this._rightSprite.ScaleY = this.Text.BaseText.Scale + SCALE_PADDING;
                this._rightSprite.X += this._centerSprite.ScaleX + (this._rightSprite.ScaleX / 2);
                this._rightSprite.Y = textOffset;
                this._rightSprite.AttachTo(this.Text.BaseText, true);
                #endregion

                #region on-click event handlers
                this._centerSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._leftSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._rightSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                #endregion
            }
            else
            {
                // fail.
                throw new InvalidOperationException(TowerUtils.USE_TOWER_FRAMEWORK_MESSAGE);
            }
        }
Esempio n. 3
0
 public TowerSprite(Screen screen, string texture)
 {
     if (screen is TowerScreen)
     {
         // Automatically managed and removed
         TowerScreen t = screen as TowerScreen;
         this._sprite = t.AddSprite(texture);
         this._sprite.PixelSize = 0.5f;
         //this._sprite.AttachTo(this, true);
         this._sprite.CustomBehavior += new SpriteCustomBehavior(_sprite_CustomBehavior);
     }
     else
     {
         // User must manage them since we can't touch mTexts and mSprites.
         throw new ArgumentException(TowerUtils.USE_TOWER_FRAMEWORK_MESSAGE);
     }
 }
Esempio n. 4
0
        public TowerMessagePanel(Screen screen, string backgroundSprite, string text)
        {
            if (screen is TowerScreen) {
                // Automatically managed and removed
                TowerScreen t = screen as TowerScreen;
                this._background = t.AddSprite(backgroundSprite);
                this._text = t.AddText(string.Empty);
            } else {
                // User must manage them since we can't touch mTexts and mSprites.
                throw new ArgumentException(TowerUtils.USE_TOWER_FRAMEWORK_MESSAGE);
            }

            this._background.PixelSize = 0.5f;
            // +4 to offset so we don't TOUCH the border

            this._text.Scale = 18;
            this.DisplayText = text;

            this._background.CustomBehavior += new SpriteCustomBehavior(_background_CustomBehavior);

            // We need to be really high up.
            this._background.Z = 1;
            this._text.Z = this._background.Z + 1;
        }
Esempio n. 5
0
        public Tower9SliceButton(Screen screen, string text)
            : base(screen, text)
        {
            //Screen screen = ScreenManager.CurrentScreen;
            if (screen is TowerScreen)
            {
                TowerScreen ts = screen as TowerScreen;
                this._bottomCenterSprite = ts.AddSprite("Content/Button/bottom-center.png");
                this._bottomLeftSprite = ts.AddSprite("Content/Button/bottom-left.png");
                this._bottomRightSprite = ts.AddSprite("Content/Button/bottom-right.png");
                this._middleCenterSprite = ts.AddSprite("Content/Button/middle-center.png");
                this._middleLeftSprite = ts.AddSprite("Content/Button/middle-left.png");
                this._middleRightSprite = ts.AddSprite("Content/Button/middle-right.png");
                this._topCenterSprite = ts.AddSprite("Content/Button/top-center.png");
                this._topLeftSprite = ts.AddSprite("Content/Button/top-left.png");
                this._topRightSprite = ts.AddSprite("Content/Button/top-right.png");

                // Validate LHS sprites are the same width
                if (this._topLeftSprite.Texture.Width != this._middleLeftSprite.Texture.Width ||
                    this._middleLeftSprite.Texture.Width != this._bottomLeftSprite.Texture.Width)
                {
                    throw new ArgumentException(string.Format("Top-left, middle-left, and bottom-left images need to be the same width; currently, they're {0}px, {1}px, and {2}px respectively.", this._topLeftSprite.Texture.Width, this._middleLeftSprite.Texture.Width, this._bottomLeftSprite.Texture.Width));
                }

                // Validate RHS sprites are the same width
                if (this._topRightSprite.Texture.Width != this._middleRightSprite.Texture.Width ||
                    this._middleRightSprite.Texture.Width != this._bottomRightSprite.Texture.Width)
                {
                    throw new ArgumentException(string.Format("Top-right, middle-right, and bottom-right images need to be the same width; currently, they're {0}px, {1}px, and {2}px respectively.", this._topRightSprite.Texture.Width, this._middleRightSprite.Texture.Width, this._bottomRightSprite.Texture.Width));
                }

                #region button images
                // Length = number of characters, scale = font-size (approximation of pixel size?)
                // Everything is relative to this guy, so set him first.
                this._middleCenterSprite.ScaleX = this.Text.BaseText.DisplayText.Length * (this.Text.BaseText.Scale / 2);
                this._middleCenterSprite.ScaleY = this.Text.BaseText.Scale;
                this._middleCenterSprite.AttachTo(this.Text.BaseText, true);

                #region top images
                this._topLeftSprite.X -= this._middleCenterSprite.ScaleX + (this._topLeftSprite.Texture.Width / 2);
                this._topLeftSprite.Y += this._middleCenterSprite.Texture.Height + (this._topLeftSprite.Texture.Height * 1.5f);
                this._topLeftSprite.AttachTo(this.Text.BaseText, true);

                this._topCenterSprite.ScaleX = this._middleCenterSprite.ScaleX;
                this._topCenterSprite.X = this._topLeftSprite.X + (this._topLeftSprite.Texture.Width / 2) + this._topCenterSprite.ScaleX;
                this._topCenterSprite.Y = this._topLeftSprite.Y;
                this._topCenterSprite.AttachTo(this._topLeftSprite, true);

                this._topRightSprite.X += this._middleCenterSprite.ScaleX + (this._topRightSprite.Texture.Width / 2);
                this._topRightSprite.Y += this._middleCenterSprite.Texture.Height + (this._topRightSprite.Texture.Height * 1.5f);
                this._topRightSprite.AttachTo(this.Text.BaseText, true);
                #endregion

                #region bottom images
                this._bottomLeftSprite.X -= this._middleCenterSprite.ScaleX + (this._bottomLeftSprite.Texture.Width / 2);
                this._bottomLeftSprite.Y -= this._middleCenterSprite.Texture.Height + (this._bottomLeftSprite.Texture.Height * 1.5f);
                this._bottomLeftSprite.AttachTo(this.Text.BaseText, true);

                this._bottomCenterSprite.ScaleX = this._middleCenterSprite.ScaleX;
                this._bottomCenterSprite.X = this._bottomLeftSprite.X + (this._bottomLeftSprite.Texture.Width / 2) + this._bottomCenterSprite.ScaleX;
                this._bottomCenterSprite.Y = this._bottomLeftSprite.Y;
                this._bottomCenterSprite.AttachTo(this._bottomLeftSprite, true);

                this._bottomRightSprite.X += this._middleCenterSprite.ScaleX + (this._bottomRightSprite.Texture.Width / 2);
                this._bottomRightSprite.Y -= this._middleCenterSprite.Texture.Height + (this._bottomRightSprite.Texture.Height * 1.5f);
                this._bottomRightSprite.AttachTo(this.Text.BaseText, true);
                #endregion

                #region middle images
                this._middleLeftSprite.X = this._topLeftSprite.X;
                this._middleLeftSprite.ScaleY = this._middleCenterSprite.ScaleY;
                this._middleLeftSprite.AttachTo(this._topLeftSprite, true);

                this._middleRightSprite.X = this._topRightSprite.X;
                this._middleRightSprite.ScaleY = this._middleCenterSprite.ScaleY;
                this._middleRightSprite.AttachTo(this._topRightSprite, true);
                #endregion

                #region on-click event handlers
                this._bottomCenterSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._bottomLeftSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._bottomRightSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._middleCenterSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._middleLeftSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._middleRightSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._topCenterSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._topLeftSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                this._topRightSprite.CustomBehavior += new SpriteCustomBehavior(imageClicked_CustomBehavior);
                #endregion

                #endregion
            }
            else
            {
                // fail.
                throw new InvalidOperationException(TowerUtils.USE_TOWER_FRAMEWORK_MESSAGE);
            }
        }
Esempio n. 6
0
 public TowerMessagePanel(Screen screen, string backgroundSprite, string[] texts)
     : this(screen, backgroundSprite, texts[0])
 {
     this._messages = texts;
     this._messageIndex = 0;
 }