Example #1
0
 public IseText(IRenderSprite sprite, float fontCorrection = 1f) : base(sprite)
 {
     AspectCorrection    = ResizeMode.TouchFromInside;
     RenderText          = new RenderText(sprite);
     RenderText.FontSize = 16f;
     FontCorrection      = fontCorrection;
 }
Example #2
0
        public UIText AddText(IRenderText renderText, byte displayLayer = 1)
        {
            renderText.DisplayLayer = (byte)Util.Min(255, this.DisplayLayer + displayLayer);
            renderText.Visible      = true;
            var uiText = new UIText(renderText);

            texts.Add(uiText);
            return(uiText);
        }
Example #3
0
 void SetTextHovered(IRenderText text, bool hovered, bool enabled, string textEntry)
 {
     text.Shadow    = !enabled || !hovered;
     text.TextColor = !enabled ? TextColor.Disabled : hovered ? TextColor.Dark
         : colorProvider?.Invoke(textEntry) ?? TextColor.Bright;
 }
        public CharacterCreator(IRenderView renderView, Game game, Action <string, bool, int> selectHandler)
        {
            this.renderView = renderView;
            textureAtlas    = TextureAtlasManager.Instance.GetOrCreate(Layer.UI);
            var fontTextureAtlas = TextureAtlasManager.Instance.GetOrCreate(Layer.Text);
            var spriteFactory    = renderView.SpriteFactory;
            var layer            = renderView.GetLayer(Layer.UI);

            #region Window
            var windowSize = new Size(16, 6);
            var windowArea = new Rect
                             (
                (Global.VirtualScreenWidth - windowSize.Width * 16) / 2,
                (Global.VirtualScreenHeight - windowSize.Height * 16) / 2 - 8,
                windowSize.Width * 16,
                windowSize.Height * 16
                             );
            void AddBorder(PopupFrame frame, int column, int row)
            {
                var sprite = spriteFactory.Create(16, 16, true) as ILayerSprite;

                sprite.Layer = layer;
                sprite.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.GetPopupFrameGraphicIndex(frame));
                sprite.PaletteIndex       = 0;
                sprite.X       = windowArea.X + column * 16;
                sprite.Y       = windowArea.Y + row * 16;
                sprite.Visible = true;
                borders.Add(sprite);
            }

            // 4 corners
            AddBorder(PopupFrame.FrameUpperLeft, 0, 0);
            AddBorder(PopupFrame.FrameUpperRight, windowSize.Width - 1, 0);
            AddBorder(PopupFrame.FrameLowerLeft, 0, windowSize.Height - 1);
            AddBorder(PopupFrame.FrameLowerRight, windowSize.Width - 1, windowSize.Height - 1);
            // top and bottom border
            for (int i = 0; i < windowSize.Width - 2; ++i)
            {
                AddBorder(PopupFrame.FrameTop, i + 1, 0);
                AddBorder(PopupFrame.FrameBottom, i + 1, windowSize.Height - 1);
            }
            // left and right border
            for (int i = 0; i < windowSize.Height - 2; ++i)
            {
                AddBorder(PopupFrame.FrameLeft, 0, i + 1);
                AddBorder(PopupFrame.FrameRight, windowSize.Width - 1, i + 1);
            }
            backgroundFill = FillArea(new Rect(windowArea.X + 16, windowArea.Y + 16,
                                               windowSize.Width * 16 - 32, windowSize.Height * 16 - 32), game.GetUIColor(28), 0);
            #endregion

            #region Buttons
            var offset = windowArea.Position;
            maleButton                   = CreateButton(game, offset + new Position(16, 26));
            maleButton.ButtonType        = ButtonType.Male;
            maleButton.Visible           = true;
            maleButton.LeftClickAction   = () => ChangeMale(false);
            femaleButton                 = CreateButton(game, offset + new Position(16, 45));
            femaleButton.ButtonType      = ButtonType.Female;
            femaleButton.Visible         = true;
            femaleButton.LeftClickAction = () => ChangeMale(true);
            leftButton                   = CreateButton(game, offset + new Position(64, 35));
            leftButton.ButtonType        = ButtonType.MoveLeft;
            leftButton.Visible           = true;
            leftButton.LeftClickAction   = () => SwapPortrait(-1);
            rightButton                  = CreateButton(game, offset + new Position(160, 35));
            rightButton.ButtonType       = ButtonType.MoveRight;
            rightButton.Visible          = true;
            rightButton.LeftClickAction  = () => SwapPortrait(1);
            okButton                 = CreateButton(game, new Position(windowArea.Right - 16 - 32, windowArea.Bottom - 16 - 17));
            okButton.ButtonType      = ButtonType.Ok;
            okButton.Visible         = true;
            okButton.LeftClickAction = () =>
            {
                nameInput.Submit();
                afterFadeOutAction = () => selectHandler?.Invoke(nameInput.Text, isFemale, portraitIndex);
                DestroyAndFadeOut();
            };
            #endregion

            portraitBackground       = spriteFactory.Create(32, 34, true, 1) as ILayerSprite;
            portraitBackground.Layer = layer;
            portraitBackground.X     = offset.X + 112;
            portraitBackground.Y     = offset.Y + 32;
            portraitBackground.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.UICustomGraphicOffset + (uint)UICustomGraphic.PortraitBackground);
            portraitBackground.PaletteIndex       = 52;
            portraitBackground.Visible            = true;

            portrait       = spriteFactory.Create(32, 34, true, 2) as ILayerSprite;
            portrait.Layer = layer;
            portrait.X     = portraitBackground.X;
            portrait.Y     = portraitBackground.Y;
            portrait.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.PortraitOffset + (uint)portraitIndex - 1);
            portrait.PaletteIndex       = (byte)(renderView.GraphicProvider.PrimaryUIPaletteIndex - 1);
            portrait.Visible            = true;

            // draw border around portrait
            var area = new Rect(portraitBackground.X - 1, portraitBackground.Y - 1, 34, 36);
            // TODO: use named palette colors
            var darkBorderColor   = game.GetUIColor(26);
            var brightBorderColor = game.GetUIColor(31);
            // upper dark border
            portraitBorders.Add(FillArea(new Rect(area.X, area.Y, area.Width - 1, 1), darkBorderColor, 1));
            // left dark border
            portraitBorders.Add(FillArea(new Rect(area.X, area.Y + 1, 1, area.Height - 2), darkBorderColor, 1));
            // right bright border
            portraitBorders.Add(FillArea(new Rect(area.Right - 1, area.Y + 1, 1, area.Height - 2), brightBorderColor, 1));
            // lower bright border
            portraitBorders.Add(FillArea(new Rect(area.X + 1, area.Bottom - 1, area.Width - 1, 1), brightBorderColor, 1));

            const int inputWidth = 16 * Global.GlyphWidth - 2;
            nameInput = new TextInput(null, renderView, new Position(windowArea.Center.X - inputWidth / 2, offset.Y + 32 + 40),
                                      15, 2, TextInput.ClickAction.FocusOrSubmit, TextInput.ClickAction.Abort, TextAlign.Left);
            nameInput.AllowEmpty = true;
            nameInput.AutoSubmit = true;
            nameInput.SetText("Thalion");
            nameInput.InputChanged += text => { okButton.Disabled = string.IsNullOrWhiteSpace(text); };
            AddSunkenBox(game, new Rect(windowArea.Center.X - inputWidth / 2 - 2, offset.Y + 32 + 38, inputWidth + 6, Global.GlyphLineHeight + 3));

            string headerText = game.DataNameProvider.ChooseCharacter.Trim();
            int    textWidth  = headerText.Length * Global.GlyphWidth;
            int    textOffset = (windowArea.Width - textWidth) / 2;
            header = AddText(offset + new Position(textOffset, 16), headerText, TextColor.BrightGray);

            fadeArea         = renderView.ColoredRectFactory.Create(Global.VirtualScreenWidth, Global.VirtualScreenHeight, Render.Color.Black, 255);
            fadeArea.Layer   = renderView.GetLayer(Layer.Effects);
            fadeArea.X       = 0;
            fadeArea.Y       = 0;
            fadeArea.Visible = true;
            fadeInStartTime  = DateTime.Now;
        }