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); }
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); } }
IColoredRect FillArea(Rect area, Render.Color color, byte displayLayer = 1) { var filledArea = renderView.ColoredRectFactory.Create(area.Width, area.Height, color, displayLayer); filledArea.Layer = renderView.GetLayer(Layer.UI); filledArea.X = area.Left; filledArea.Y = area.Top; filledArea.Visible = true; return(filledArea); }
readonly List <SpriteInfo> characterSpritesNew = new List <SpriteInfo>(); // shared by all texts public TextRenderer(IRenderView renderView) { spriteFactory = renderView.SpriteFactory; layerLegacy = renderView.GetLayer(Layer.Gui); layerNewFont = renderView.GetLayer(Layer.GuiFont); // original size is 8x8 pixels characterSizeLegacy = new Size(8, 8); // new font uses a different size characterSizeNew = new Size(Global.UIFontCharacterWidth, Global.UIFontCharacterHeight); }
static void EnsureTextures(IRenderView renderView, OutroData outroData, Font outroFont, Font outroFontLarge) { if (textureAtlas == null) { TextureAtlasManager.Instance.AddFromGraphics(Layer.OutroGraphics, outroData.Graphics.Select((g, i) => new { Graphic = g, Index = i }).ToDictionary(g => (uint)g.Index, g => g.Graphic)); textureAtlas = TextureAtlasManager.Instance.GetOrCreate(Layer.OutroGraphics); renderView.GetLayer(Layer.OutroGraphics).Texture = textureAtlas.Texture; TextureAtlasManager.Instance.AddFromGraphics(Layer.OutroText, outroFont.GlyphGraphics); TextureAtlasManager.Instance.AddFromGraphics(Layer.OutroText, outroFontLarge.GlyphGraphics); renderView.GetLayer(Layer.OutroText).Texture = TextureAtlasManager.Instance.GetOrCreate(Layer.OutroText).Texture; } }
public IRenderText AddText(Position position, string text, TextColor textColor, bool shadow = true, byte displayLayer = 1, char?fallbackChar = null) { var renderText = renderView.RenderTextFactory.Create(renderView.GetLayer(Layer.Text), renderView.TextProcessor.CreateText(text, fallbackChar), textColor, shadow); renderText.DisplayLayer = (byte)Util.Min(255, this.DisplayLayer + displayLayer); renderText.PaletteIndex = game.UIPaletteIndex; renderText.X = position.X; renderText.Y = position.Y; renderText.Visible = true; texts.Add(new UIText(renderText)); return(renderText); }
public Text(IRenderView renderView, Layer layer, string text, IReadOnlyDictionary <char, Glyph> glyphs, List <char> characters, byte displayLayer, int spaceWidth, bool upperOnly, uint textureAtlasIndexOffset) { totalWidth = 0; var textureAtlas = TextureAtlasManager.Instance.GetOrCreate(layer); if (upperOnly) { text = text.ToUpper(); } foreach (char ch in text) { if (ch == ' ') { totalWidth += spaceWidth; } else if (glyphs.TryGetValue(ch, out var glyph)) { var sprite = renderView.SpriteFactory.Create(glyph.Graphic.Width, glyph.Graphic.Height, true, displayLayer) as ILayerSprite; sprite.TextureAtlasOffset = textureAtlas.GetOffset((uint)characters.IndexOf(ch) + textureAtlasIndexOffset); sprite.X = totalWidth; sprite.Y = 0; sprite.Layer = renderView.GetLayer(layer); sprite.PaletteIndex = (byte)(renderView.GraphicProvider.PrimaryUIPaletteIndex - 1); sprite.Visible = false; renderGlyphs.Add(sprite); totalWidth += glyph.Advance; } } }
public void PlaceTransport(uint mapIndex, uint x, uint y, TravelType travelType) { var position = new Position((int)x, (int)y); if (mapIndex != Map.Index) { if (mapIndex != adjacentMaps[0].Index && mapIndex != adjacentMaps[1].Index && mapIndex != adjacentMaps[2].Index) { return; } if (mapIndex == adjacentMaps[0].Index || mapIndex == adjacentMaps[2].Index) { position.X += Map.Width; } if (mapIndex == adjacentMaps[1].Index || mapIndex == adjacentMaps[2].Index) { position.Y += Map.Height; } } if (!transportSprites.ContainsKey(position)) { var stationaryImage = travelType.ToStationaryImage(); var info = renderView.GameData.StationaryImageInfos[stationaryImage]; var textureAtlas = TextureAtlasManager.Instance.GetOrCreate(Layer.Characters); var sprite = renderView.SpriteFactory.Create(info.Width, info.Height, false); var offset = new Position((TILE_WIDTH - info.Width) / 2 - 2, (TILE_HEIGHT - info.Height) / 2 - 2); sprite.Layer = renderView.GetLayer(Layer.Characters); sprite.ClipArea = Game.Map2DViewArea; sprite.BaseLineOffset = TILE_HEIGHT / 2; sprite.PaletteIndex = (byte)game.GetPlayerPaletteIndex(); sprite.TextureAtlasOffset = textureAtlas.GetOffset(3 * 17 + 11 * 4 + stationaryImage.AsIndex()); sprite.X = Global.Map2DViewX + (position.X - (int)ScrollX) * TILE_WIDTH + offset.X; sprite.Y = Global.Map2DViewY + (position.Y - (int)ScrollY) * TILE_HEIGHT + offset.Y; sprite.Visible = true; transportSprites.Add(position, new KeyValuePair <ISprite, Position>(sprite, offset)); } }
private MapCharacter2D(Game game, IRenderView renderView, Layer layer, IMapManager mapManager, RenderMap2D map, uint characterIndex, Map.CharacterReference characterReference) : base(game, renderView.GetLayer(layer), TextureAtlasManager.Instance.GetOrCreate(layer), renderView.SpriteFactory, () => AnimationProvider(game, map.Map, mapManager, characterReference, renderView.GraphicProvider), map, GetStartPosition(characterReference), () => Math.Max(1, map.Map.PaletteIndex) - 1, () => NullOffset) { this.game = game; this.map = map.Map; tileset = mapManager.GetTilesetForMap(this.map); this.characterIndex = characterIndex; this.characterReference = characterReference; lastTimeSlot = game.GameTime.TimeSlot; }
public Cursor(IRenderView renderView, IReadOnlyList <Position> cursorHotspots, TextureAtlasManager textureAtlasManager = null) { this.renderView = renderView; textureAtlas = (textureAtlasManager ?? TextureAtlasManager.Instance).GetOrCreate(Layer.Cursor); sprite = renderView.SpriteFactory.Create(16, 16, true); sprite.PaletteIndex = 0; sprite.Layer = renderView.GetLayer(Layer.Cursor); for (int i = 0; i < cursorHotspots.Count; ++i) { this.cursorHotspots.Add((CursorType)i, cursorHotspots[i]); } UpdateCursor(); }
public Interface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer) : base(renderView, audioInterface) { RenderView = renderView; AudioInterface = audioInterface; Viewer = viewer; TextRenderer = new TextRenderer(renderView); displayed = true; config = UserConfig.Game.Options; mapCursorSprites[0] = new SpriteLocation { Sprite = 31 }; mapCursorSprites[1] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[2] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[3] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[4] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[5] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[6] = new SpriteLocation { Sprite = 32 }; cursorSprite = renderView.SpriteFactory.Create(16, 16, 0, 0, false, false, 255); cursorSprite.Layer = renderView.GetLayer(Freeserf.Layer.Cursor); cursorSprite.Visible = true; SetSize(640, 480); // original size Viewport = null; PanelBar = new PanelBar(this); AddChild(PanelBar, 0, 0, false); Layout(); }
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; }
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; }