public CharacterViewer() : base(27, 20) { //DefaultShowLocation = StartupLocation.CenterScreen; //Fill(Color.White, Color.Black, 0, null); Title = (char)198 + "Character" + (char)198; TitleAlignment = System.Windows.HorizontalAlignment.Left; //SetTitle(" Characters ", System.Windows.HorizontalAlignment.Center, Color.Blue, Color.LightGray); CloseOnESC = true; // CHARACTER SCROLL _charScrollBar = ScrollBar.Create(System.Windows.Controls.Orientation.Vertical, 16); _charScrollBar.Position = new Point(17, 1); _charScrollBar.Name = "ScrollBar"; _charScrollBar.Maximum = textSurface.Font.Rows - 16; _charScrollBar.Value = 0; _charScrollBar.ValueChanged += new EventHandler(_charScrollBar_ValueChanged); _charScrollBar.IsEnabled = textSurface.Font.Rows > 16; // Effects effects = new EffectsManager(textSurface); // Add all controls this.Add(_charScrollBar); _closeButton = new Button(6) { Text = "Ok", Position = new Point(19, 1) }; Add(_closeButton); _closeButton.Click += (sender, e) => { DialogResult = true; Hide(); }; _highlightedCellEffect.Foreground = Color.Blue; _highlightedCellEffect.Background = ColorHelper.DarkGray; // The frame will have been drawn by the base class, so redraw and our close button will be put on top of it Redraw(); }
public static EffectsManager Load(string file, ISurface surface) { EffectsManagerSerialized data = Serializer.Load <EffectsManagerSerialized>(file); EffectsManager manager = new EffectsManager(surface); foreach (var effect in data.Effects.Keys) { int[] effectCellIndexes = data.Effects[effect]; List <Cell> cells = new List <Cell>(effectCellIndexes.Length); foreach (var index in effectCellIndexes) { cells.Add(surface.Cells[index]); } var effectData = new CellEffectData(effect) { Cells = cells }; manager._effects.Add(effect, effectData); foreach (var cell in cells) { manager._effectCells.Add(cell, effectData); } } return(manager); }
public static void Save(EffectsManager effectsManager, ISurface surface, string file) { EffectsManagerSerialized data = new EffectsManagerSerialized(); data.Effects = new Dictionary <ICellEffect, int[]>(effectsManager._effects.Count); List <Cell> currentCells = new List <Cell>(surface.Cells); foreach (var effectData in effectsManager._effects.Values) { List <int> effectCellPositions = new List <int>(effectData.Cells.Count); foreach (var cell in effectData.Cells) { effectCellPositions.Add(currentCells.IndexOf(cell)); } data.Effects.Add(effectData.Effect, effectCellPositions.ToArray()); } SadConsole.Serializer.Save(data, file); }
public SplashScreen() : base(80, 25) { IsVisible = false; effectsManager = new EffectsManager(this.TextSurface); // Setup the console text background string textTemplate = "sole SadCon"; System.Text.StringBuilder text = new System.Text.StringBuilder(2200); for (int i = 0; i < TextSurface.Width * TextSurface.Height; i++) { text.Append(textTemplate); } Print(0, 0, text.ToString(), Color.Black, Color.Transparent); // Load the logo System.IO.Stream imageStream = System.IO.File.OpenRead("sad.png"); var image = Texture2D.FromStream(Engine.Device, imageStream); imageStream.Dispose(); // Configure the logo _consoleImage = image.ToSurface(Engine.DefaultFont, false); _consoleImagePosition = new Point(TextSurface.Width / 2 - _consoleImage.Width / 2, -1); _consoleImage.Tint = Color.Black; // Configure the animations _animation = new InstructionSet(); _animation.Instructions.AddLast(new Wait() { Duration = 0.3f }); // Animation to move the angled gradient spotlight effect. var moveGradientInstruction = new CodeInstruction(); moveGradientInstruction.CodeCallback = (inst) => { _x += 1; if (_x > TextSurface.Width + 50) { inst.IsFinished = true; } Color[] colors = new Color[] { Color.Black, Color.Blue, Color.White, Color.Blue, Color.Black }; float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }; Algorithms.GradientFill(TextSurface.Font.Size, new Point(_x, 12), 10, 45, new Rectangle(0, 0, TextSurface.Width, TextSurface.Height), new ColorGradient(colors, colorStops), SetForeground); }; _animation.Instructions.AddLast(moveGradientInstruction); // Animation to clear the SadConsole text. _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; } }); // Animation for the logo text. var logoText = new ColorGradient(new Color[] { Color.Magenta, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]"); logoText.SetEffect(new SadConsole.Effects.Fade() { DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true }); _animation.Instructions.AddLast(new DrawString(this) { Position = new Point(26, this.TextSurface.Height - 1), Text = logoText, TotalTimeToPrint = 1f }); // Animation for fading in the logo picture. _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000))); // Animation to blink SadConsole in the logo text _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade(); fadeEffect.AutoReverse = true; fadeEffect.DestinationForeground = new ColorGradient(Color.Blue, Color.Yellow); fadeEffect.FadeForeground = true; fadeEffect.UseCellForeground = false; fadeEffect.Repeat = true; fadeEffect.FadeDuration = 0.7f; fadeEffect.RemoveOnFinished = true; List<Cell> cells = new List<Cell>(); for (int index = 0; index < 10; index++) { var point = new Point(26, this.TextSurface.Height - 1).ToIndex(this.TextSurface.Width) + 14 + index; cells.Add(textSurface.Cells[point]); cellindexes.Add(point); } effectsManager.SetEffect(cells, fadeEffect); i.IsFinished = true; } }); // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself. _animation.Instructions.AddLast(new Wait() { Duration = 2.5f }); _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000))); _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { SplashCompleted?.Invoke(); i.IsFinished = true; } }); }
public static void Save(EffectsManager effectsManager, ITextSurface surface, string file) { EffectsManagerSerialized data = new EffectsManagerSerialized(); data.Effects = new Dictionary<ICellEffect, int[]>(effectsManager._effects.Count); List<Cell> currentCells = new List<Cell>(surface.Cells); foreach (var effectData in effectsManager._effects.Values) { List<int> effectCellPositions = new List<int>(effectData.Cells.Count); foreach (var cell in effectData.Cells) effectCellPositions.Add(currentCells.IndexOf(cell)); data.Effects.Add(effectData.Effect, effectCellPositions.ToArray()); } SadConsole.Serializer.Save(data, file); }
public static EffectsManager Load(string file, ITextSurface surface) { EffectsManagerSerialized data = Serializer.Load<EffectsManagerSerialized>(file); EffectsManager manager = new EffectsManager(surface); foreach (var effect in data.Effects.Keys) { int[] effectCellIndexes = data.Effects[effect]; List<Cell> cells = new List<Cell>(effectCellIndexes.Length); foreach (var index in effectCellIndexes) cells.Add(surface.Cells[index]); var effectData = new CellEffectData(effect) { Cells = cells }; manager._effects.Add(effect, effectData); foreach (var cell in cells) manager._effectCells.Add(cell, effectData); } return manager; }
/// <summary> /// Called when the <see cref="TextSurface"/> property is changed. Sets <see cref="Effects"/> to a new instance of <see cref="EffectsManager"/>. /// </summary> /// <param name="oldSurface">The previous text surface.</param> /// <param name="newSurface">The new text surface.</param> protected virtual void OnSurfaceChanged(ITextSurface oldSurface, ITextSurface newSurface) { Effects = new EffectsManager(newSurface); }