Esempio n. 1
0
        void UpdateTriangleUp(int index, int yOffset, int height, int left, int right, MapPos position)
        {
            if (((left - height) < -4) || ((left - height) > 4))
            {
                throw new ExceptionFreeserf(ErrorSystemType.Render, "Failed to draw triangle up (1).");
            }
            if (((right - height) < -4) || ((right - height) > 4))
            {
                throw new ExceptionFreeserf(ErrorSystemType.Render, "Failed to draw triangle up (2).");
            }

            int mask = 4 + height - left + 9 * (4 + height - right);

            if (TileMaskUp[mask] < 0)
            {
                throw new ExceptionFreeserf(ErrorSystemType.Render, "Failed to draw triangle up (3).");
            }

            var  terrain     = map.TypeUp(map.MoveUp(position));
            int  spriteIndex = (int)terrain * 8 + TileMaskUp[mask];
            uint sprite      = TileSprites[spriteIndex];

            triangles[index].Y = yOffset + maskOffsets[(uint)mask].Y;
            triangles[index].TextureAtlasOffset     = textureAtlasTiles.GetOffset(sprite);
            triangles[index].MaskTextureAtlasOffset = textureAtlasTiles.GetOffset((uint)MaskUpSprites[mask]);
        }
Esempio n. 2
0
        void UpdateTiles()
        {
            var backLayer  = renderView.GetLayer((Layer)((uint)Layer.MapBackground1 + tileset.Index - 1));
            var frontLayer = renderView.GetLayer((Layer)((uint)Layer.MapForeground1 + tileset.Index - 1));

            textureAtlas = TextureAtlasManager.Instance.GetOrCreate((Layer)((uint)Layer.MapBackground1 + tileset.Index - 1));
            int index = 0;

            for (uint row = 0; row < NUM_VISIBLE_TILES_Y; ++row)
            {
                for (uint column = 0; column < NUM_VISIBLE_TILES_X; ++column)
                {
                    var tile = this[ScrollX + column, ScrollY + row];

                    backgroundTileSprites[index].Layer             = backLayer;
                    backgroundTileSprites[index].TextureAtlasWidth = textureAtlas.Texture.Width;
                    backgroundTileSprites[index].PaletteIndex      = (byte)(Map.PaletteIndex - 1);
                    foregroundTileSprites[index].Layer             = frontLayer;
                    foregroundTileSprites[index].TextureAtlasWidth = textureAtlas.Texture.Width;
                    foregroundTileSprites[index].PaletteIndex      = (byte)(Map.PaletteIndex - 1);

                    if (tile.BackTileIndex == 0)
                    {
                        backgroundTileSprites[index].Visible = false;
                    }
                    else
                    {
                        var backTile         = tileset.Tiles[(int)tile.BackTileIndex - 1];
                        var backGraphicIndex = backTile.GraphicIndex;
                        backgroundTileSprites[index].TextureAtlasOffset = textureAtlas.GetOffset(backGraphicIndex - 1);
                        backgroundTileSprites[index].NumFrames          = (uint)backTile.NumAnimationFrames;
                        backgroundTileSprites[index].CurrentFrame       = 0;
                        backgroundTileSprites[index].Alternate          = backTile.Flags.HasFlag(Tileset.TileFlags.AlternateAnimation);
                        backgroundTileSprites[index].Visible            = true;
                        backgroundTileSprites[index].BaseLineOffset     = 0;
                    }

                    if (tile.FrontTileIndex == 0)
                    {
                        foregroundTileSprites[index].Visible = false;
                    }
                    else
                    {
                        var frontTile         = tileset.Tiles[(int)tile.FrontTileIndex - 1];
                        var frontGraphicIndex = frontTile.GraphicIndex;
                        foregroundTileSprites[index].TextureAtlasOffset = textureAtlas.GetOffset(frontGraphicIndex - 1);
                        foregroundTileSprites[index].NumFrames          = (uint)frontTile.NumAnimationFrames;
                        foregroundTileSprites[index].CurrentFrame       = 0;
                        foregroundTileSprites[index].Visible            = true;
                        foregroundTileSprites[index].Alternate          = frontTile.Flags.HasFlag(Tileset.TileFlags.AlternateAnimation);
                        foregroundTileSprites[index].BaseLineOffset     = frontTile.BringToFront ? TILE_HEIGHT + 2 : frontTile.Background ? -1 : 0;
                    }

                    ++index;
                }
            }

            Update(0, game.GameTime, false, null);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        void UpdateWave(MapPos position, int index, int tick, int x, int y)
        {
            int sprite = ((int)(position ^ 5) + (tick >> 3)) & 0xf;

            if (map.TypeUp(position) <= Map.Terrain.Water3 && map.TypeDown(position) <= Map.Terrain.Water3)
            {
                waves[index].X = x;
                waves[index].Y = y;
                waves[index].TextureAtlasOffset     = textureAtlasWaves.GetOffset((uint)sprite);
                waves[index].MaskTextureAtlasOffset = textureAtlasWaves.GetOffset(WaveMaskFull);
                waves[index].Visible = true;
            }
            else if (map.TypeDown(position) <= Map.Terrain.Water3)
            {
                waves[index].X = x + maskOffsets[81 + 40].X + TILE_WIDTH / 2;
                waves[index].Y = y + maskOffsets[81 + 40].Y + TILE_HEIGHT;
                waves[index].TextureAtlasOffset     = textureAtlasWaves.GetOffset((uint)sprite);
                waves[index].MaskTextureAtlasOffset = textureAtlasWaves.GetOffset(WaveMaskDown);
                waves[index].Visible = true;
            }
            else if (map.TypeUp(position) <= Map.Terrain.Water3)
            {
                waves[index].X = x + maskOffsets[40].X;
                waves[index].Y = y + maskOffsets[40].Y;
                waves[index].TextureAtlasOffset     = textureAtlasWaves.GetOffset((uint)sprite);
                waves[index].MaskTextureAtlasOffset = textureAtlasWaves.GetOffset(WaveMaskUp);
                waves[index].Visible = true;
            }
            else
            {
                waves[index].Visible = false;
            }
        }
Esempio n. 5
0
        internal void UpdateTile(uint x, uint y)
        {
            if (x < ScrollX || y < ScrollY || x >= ScrollX + NUM_VISIBLE_TILES_X || y >= ScrollY + NUM_VISIBLE_TILES_Y)
            {
                return; // not visible
            }
            int spriteIndex = (int)(x - ScrollX + (y - ScrollY) * NUM_VISIBLE_TILES_X);
            var tile        = this[x, y];

            if (tile.BackTileIndex == 0)
            {
                backgroundTileSprites[spriteIndex].Visible = false;
            }
            else
            {
                var backTile         = tileset.Tiles[(int)tile.BackTileIndex - 1];
                var backGraphicIndex = backTile.GraphicIndex;
                backgroundTileSprites[spriteIndex].TextureAtlasOffset = textureAtlas.GetOffset(backGraphicIndex - 1);
                backgroundTileSprites[spriteIndex].NumFrames          = (uint)backTile.NumAnimationFrames;
                backgroundTileSprites[spriteIndex].CurrentFrame       = 0;
                backgroundTileSprites[spriteIndex].Alternate          = backTile.Flags.HasFlag(Tileset.TileFlags.AlternateAnimation);
                backgroundTileSprites[spriteIndex].Visible            = true;
            }

            if (tile.FrontTileIndex == 0)
            {
                foregroundTileSprites[spriteIndex].Visible = false;
            }
            else
            {
                var frontTile         = tileset.Tiles[(int)tile.FrontTileIndex - 1];
                var frontGraphicIndex = frontTile.GraphicIndex;
                foregroundTileSprites[spriteIndex].TextureAtlasOffset = textureAtlas.GetOffset(frontGraphicIndex - 1);
                foregroundTileSprites[spriteIndex].NumFrames          = (uint)frontTile.NumAnimationFrames;
                foregroundTileSprites[spriteIndex].CurrentFrame       = 0;
                foregroundTileSprites[spriteIndex].Alternate          = frontTile.Flags.HasFlag(Tileset.TileFlags.AlternateAnimation);
                foregroundTileSprites[spriteIndex].Visible            = true;
                foregroundTileSprites[spriteIndex].BaseLineOffset     = frontTile.BringToFront ? TILE_HEIGHT + 2 : frontTile.Background ? -1 : 0;
            }
        }
Esempio n. 6
0
        public Button(IRenderView renderView, Position position,
                      TextureAtlasManager textureAtlasManager = null)
        {
            Area = new Rect(position, new Size(Width, Height));
            byte paletteIndex = (byte)(renderView.GraphicProvider.PrimaryUIPaletteIndex - 1);

            frameSprite    = renderView.SpriteFactory.Create(Width, Height, true, 3) as ILayerSprite;
            disableOverlay = renderView.SpriteFactory.Create(Width, Height - 6, true, 5) as ILayerSprite;
            iconSprite     = renderView.SpriteFactory.Create(Width, Height - 4, true, 4) as ILayerSprite;

            var layer = renderView.GetLayer(Layer.UI);

            frameSprite.Layer    = layer;
            disableOverlay.Layer = layer;
            iconSprite.Layer     = layer;

            textureAtlas = (textureAtlasManager ?? TextureAtlasManager.Instance).GetOrCreate(Layer.UI);
            frameSprite.TextureAtlasOffset    = textureAtlas.GetOffset(Graphics.GetUIGraphicIndex(UIGraphic.ButtonFrame));
            disableOverlay.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.GetUIGraphicIndex(UIGraphic.ButtonDisabledOverlay));
            iconSprite.TextureAtlasOffset     = textureAtlas.GetOffset(Graphics.GetButtonGraphicIndex(ButtonType.Empty));

            frameSprite.PaletteIndex    = paletteIndex;
            disableOverlay.PaletteIndex = paletteIndex;
            iconSprite.PaletteIndex     = paletteIndex;

            frameSprite.X    = position.X;
            frameSprite.Y    = position.Y;
            disableOverlay.X = position.X;
            disableOverlay.Y = position.Y + 3;
            iconSprite.X     = position.X;
            iconSprite.Y     = position.Y + 2;

            frameSprite.Visible    = true;
            disableOverlay.Visible = false;
            iconSprite.Visible     = true;
        }
Esempio n. 7
0
        void Process()
        {
            if (waitForClick || fadeMidAction != null)
            {
                return;
            }

            if (nextActionTicks > ticks)
            {
                Scroll();
                return;
            }

            if (actionIndex == actions.Count)
            {
                Active = false;
                finishAction?.Invoke();
                return;
            }

            var action = actions[actionIndex];

            switch (action.Command)
            {
            case OutroCommand.ChangePicture:
            {
                Fade(() =>
                    {
                        texts.ForEach(text => text.Destroy());
                        texts.Clear();
                        var graphicInfo            = graphicInfos[action.ImageOffset.Value];
                        picture.PaletteIndex       = (byte)(paletteOffset + graphicInfo.PaletteIndex);
                        picture.TextureAtlasOffset = textureAtlas.GetOffset(graphicInfo.GraphicIndex);
                        picture.Resize(graphicInfo.Width, graphicInfo.Height);
                        picture.X       = (Global.VirtualScreenWidth - graphicInfo.Width) / 2;
                        picture.Y       = (Global.VirtualScreenHeight - graphicInfo.Height) / 2;
                        picture.Visible = true;
                        ++actionIndex;
                    });
                break;
            }

            case OutroCommand.WaitForClick:
            {
                ++actionIndex;
                waitForClick = true;
                break;
            }

            case OutroCommand.PrintTextAndScroll:
            {
                if (action.TextIndex != null)
                {
                    PrintText(action.TextDisplayX, outroData.Texts[action.TextIndex.Value], action.LargeText);
                }
                double pixelsPerTick = PixelScrollPerSecond[speedIndex] / Game.TicksPerSecond;
                long   scrollTicks   = (long)Math.Round(action.ScrollAmount / pixelsPerTick);
                ++actionIndex;
                scrolledAmount   = 0;
                scrollStartTicks = ticks;
                nextActionTicks  = ticks + scrollTicks;
                break;
            }
            }
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
 void UpdatePortrait()
 {
     portrait.TextureAtlasOffset = textureAtlas.GetOffset(Graphics.PortraitOffset + (uint)portraitIndex - 1);
 }