Пример #1
0
        public Popup(Game game, IRenderView renderView, Position position, int columns, int rows, bool transparent,
                     byte displayLayerOffset = 0)
        {
            if (columns < 3 || rows < 3)
            {
                throw new AmbermoonException(ExceptionScope.Application, "Popups must at least have 3 columns and 3 rows.");
            }

            DisplayLayer    = (byte)Math.Min(255, BaseDisplayLayer + displayLayerOffset);
            this.game       = game;
            this.renderView = renderView;
            textureAtlas    = TextureAtlasManager.Instance.GetOrCreate(Layer.UI);

            void AddBorder(PopupFrame frame, int column, int row)
            {
                var sprite = renderView.SpriteFactory.Create(16, 16, true, DisplayLayer) as ILayerSprite;

                sprite.Layer = renderView.GetLayer(Layer.UI);
                sprite.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.GetPopupFrameGraphicIndex(frame));
                sprite.PaletteIndex       = game.UIPaletteIndex;
                sprite.X       = position.X + column * 16;
                sprite.Y       = position.Y + row * 16;
                sprite.Visible = true;
                borders.Add(sprite);
            }

            if (!transparent)
            {
                // 4 corners
                AddBorder(PopupFrame.FrameUpperLeft, 0, 0);
                AddBorder(PopupFrame.FrameUpperRight, columns - 1, 0);
                AddBorder(PopupFrame.FrameLowerLeft, 0, rows - 1);
                AddBorder(PopupFrame.FrameLowerRight, columns - 1, rows - 1);

                // top and bottom border
                for (int i = 0; i < columns - 2; ++i)
                {
                    AddBorder(PopupFrame.FrameTop, i + 1, 0);
                    AddBorder(PopupFrame.FrameBottom, i + 1, rows - 1);
                }

                // left and right border
                for (int i = 0; i < rows - 2; ++i)
                {
                    AddBorder(PopupFrame.FrameLeft, 0, i + 1);
                    AddBorder(PopupFrame.FrameRight, columns - 1, i + 1);
                }

                // fill
                // TODO: use named palette color
                fill = renderView.ColoredRectFactory.Create((columns - 2) * 16, (rows - 2) * 16,
                                                            game.GetUIColor(28), DisplayLayer);
                fill.Layer   = renderView.GetLayer(Layer.UI);
                fill.X       = position.X + 16;
                fill.Y       = position.Y + 16;
                fill.Visible = true;

                ContentArea = new Rect(fill.X, fill.Y, fill.Width, fill.Height);
            }
        }
Пример #2
0
        public Outro(IRenderView renderView, OutroData outroData, Font outroFont, Font outroFontLarge, Action finishAction)
        {
            this.finishAction    = finishAction;
            this.outroData       = outroData;
            this.outroFont       = outroFont;
            this.outroFontLarge  = outroFontLarge;
            this.renderView      = renderView;
            renderLayer          = renderView.GetLayer(Layer.OutroGraphics);
            picture              = renderView.SpriteFactory.Create(160, 128, true, 1) as ILayerSprite;
            picture.Layer        = renderLayer;
            picture.PaletteIndex = paletteOffset = renderView.GraphicProvider.FirstOutroPaletteIndex;
            picture.Visible      = false;
            renderTextFactory    = renderView.RenderTextFactory;
            textProcessor        = renderView.TextProcessor;

            fadeArea         = renderView.ColoredRectFactory.Create(Global.VirtualScreenWidth, Global.VirtualScreenHeight, Color.Black, 255);
            fadeArea.Layer   = renderView.GetLayer(Layer.Effects);
            fadeArea.X       = 0;
            fadeArea.Y       = 0;
            fadeArea.Visible = false;

            graphicInfos = outroData.GraphicInfos;

            EnsureTextures(renderView, outroData, outroFont, outroFontLarge);
        }
Пример #3
0
        public ListBox(Interface interf, TextRenderType renderType = TextRenderType.NewUI)
            : base(interf)
        {
            background       = interf.RenderView.ColoredRectFactory.Create(0, 0, colorBackground, BaseDisplayLayer);
            background.Layer = Layer;

            selectionBackground       = interf.RenderView.ColoredRectFactory.Create(0, 0, colorFocus, (byte)(BaseDisplayLayer + 1));
            selectionBackground.Layer = Layer;
            this.renderType           = renderType;
        }
Пример #4
0
        ListBox(IRenderView renderView, Game game, Popup popup, List <KeyValuePair <string, Action <int, string> > > items,
                Rect area, Position itemBasePosition, int itemHeight, int hoverBoxWidth, Position relativeHoverBoxOffset,
                bool withIndex, int maxItems, char?fallbackChar = null, bool canEdit = false,
                Func <string, TextColor> colorProvider          = null)
        {
            this.game                   = game;
            this.renderView             = renderView;
            this.items                  = items;
            this.relativeHoverBoxOffset = relativeHoverBoxOffset;
            this.maxItems               = maxItems;
            this.canEdit                = canEdit;
            this.colorProvider          = colorProvider;

            popup.AddSunkenBox(area);
            hoverBox = popup.FillArea(new Rect(itemBasePosition + relativeHoverBoxOffset, new Size(hoverBoxWidth, itemHeight)),
                                      game.GetTextColor(TextColor.Bright), 3);
            hoverBox.Visible = false;

            for (int i = 0; i < Util.Min(maxItems, items.Count); ++i)
            {
                var color = items[i].Value == null ? TextColor.Disabled
                    : colorProvider?.Invoke(items[i].Key) ?? TextColor.Bright;

                if (withIndex)
                {
                    int y = itemBasePosition.Y + i * itemHeight;
                    itemIndices.Add(popup.AddText(new Position(itemBasePosition.X, y), $"{i + 1,2}", color, true, 4));
                    itemTexts.Add(popup.AddText(new Position(itemBasePosition.X + 17, y), items[i].Key, color, true, 4, fallbackChar));
                }
                else
                {
                    itemTexts.Add(popup.AddText(new Position(itemBasePosition.X, itemBasePosition.Y + i * itemHeight),
                                                items[i].Key, color, true, 4, fallbackChar));
                }
                itemAreas.Add(new Rect(itemBasePosition.X, itemBasePosition.Y + i * itemHeight, area.Right - itemBasePosition.X - 1, itemHeight));
            }

            if (canEdit && itemTexts.Count != 0)
            {
                editInput = new TextInput(game, renderView, new Position(), (itemTexts[0].Width / Global.GlyphWidth) - 1,
                                          (byte)(popup.DisplayLayer + 6), TextInput.ClickAction.Submit, TextInput.ClickAction.Abort, TextAlign.Left)
                {
                    ClearOnNewInput     = false,
                    DigitsOnly          = false,
                    ReactToGlobalClicks = true
                };
                editInput.InputSubmitted += _ => CommitEdit();
            }
        }
Пример #5
0
 void Cleanup()
 {
     borders.ForEach(b => b?.Delete());
     backgroundFill?.Delete();
     header?.Delete();
     leftButton?.Destroy();
     rightButton?.Destroy();
     maleButton?.Destroy();
     femaleButton?.Destroy();
     okButton?.Destroy();
     portraitBackground?.Delete();
     portrait?.Delete();
     portraitBorders.ForEach(b => b?.Delete());
     nameInput?.Destroy();
     sunkenBoxParts.ForEach(b => b?.Delete());
     fadeArea.Delete();
     fadeArea = null;
 }
Пример #6
0
        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;
        }