Skip to content

Commit

Permalink
Merge pull request #221 from SadConsole/develop
Browse files Browse the repository at this point in the history
Release for 8.9.0
  • Loading branch information
SadConsole authored Sep 7, 2019
2 parents 925ef1f + 98c8900 commit c060ed3
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 132 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 07/27/2019 V8.8.1
## 08/20/2019 V8.9.0

- Add `Console.Erase`
- Add `Console.GetComponent` and `Console.GetComponents` to find components added to a console.
- Add `CellSurface.CreateLine` to create an array of int's for a line.
- Instructions supports a `RemoveOnFinished` property now.

## 07/27/2019 V8.8.1

- Fix docs

Expand Down
3 changes: 2 additions & 1 deletion src/DemoProject/SharedCode/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public Container()
//consoleReal,
//new CustomConsoles.AutoTypingConsole(),
//new CustomConsole(new CustomConsoles.MouseRenderingDebug(), "SadConsole.Instructions", "Automatic typing to a console."),
new CustomConsole(new CustomConsoles.BorderedConsole(), "Border Component", "A component that draws a border around a console"),
new CustomConsole(new CustomConsoles.SplashScreen() { SplashCompleted = MoveNextConsole }, "Splash Screen - Using instructions", "Chains multiple SadConsole.Instruction types to create an animation."),
new CustomConsole(new CustomConsoles.StringParsingConsole(), "String Parser", "Examples of using the string parser"),
new CustomConsole(new CustomConsoles.StretchedConsole(), "Font Zoom", "Console where font has been zoomed x2"),
new CustomConsole(new CustomConsoles.ControlsTest(), "Controls Test", "Interact with SadConsole controls"),
new CustomConsole(new CustomConsoles.EntityConsole(), "Game object", "Use the cursor keys to move the little character"),
new CustomConsole(new CustomConsoles.ScrollableConsole(20, 10, 60), "Text scrolling", "Renders a tiny console with a cursor along with a scroll bar"),
new CustomConsole(new CustomConsoles.DOSConsole(), "Prompt Console", "Emulates a command prompt"),
new CustomConsole(new CustomConsoles.SerializationTests(), "Serialization Tests", "Test serializing various types from SadConsole"),
new CustomConsole(new CustomConsoles.AnsiConsole(), "Ansi parsing", "Read in old DOS ANSI files."),
new CustomConsole(new CustomConsoles.ScrollableConsole(20, 10, 60), "Text scrolling", "Renders a tiny console with a cursor along with a scroll bar"),
//new CustomConsole(new CustomConsoles.WorldGenerationConsole(), "Random world generator", "Generates a random world, displaying it at half-font size."),
new CustomConsole(new CustomConsoles.SubConsoleCursor(), "Subconsole Cursor", "Two consoles with a single backing TextSurface"),
new CustomConsole(new CustomConsoles.ViewsAndSubViews(), "Sub Views", "Single text surface with two views into it. Click on either view."),
Expand Down
130 changes: 102 additions & 28 deletions src/DemoProject/SharedCode/CustomConsoles/BorderedConsole.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,125 @@
using Microsoft.Xna.Framework;
using System;
using Microsoft.Xna.Framework;

using SadConsole;
using SadConsole.Components;
using SadConsole.Input;
using Console = SadConsole.Console;

namespace StarterProject.CustomConsoles
{
class BorderComponent : IConsoleComponent
{
private Console _borderConsole;
private Cell _borderCellStyle;
private int[] _borderGlyphs;

public int SortOrder => 0;

public bool IsUpdate => false;

public bool IsDraw => false;

public bool IsMouse => false;

public bool IsKeyboard => false;

public BorderComponent(int[] connectedLineStyle, Color foreground, Color background)
{
if (!CellSurface.ValidateLineStyle(connectedLineStyle))
throw new ArgumentException("The connected line array is invalid.", nameof(connectedLineStyle));

_borderGlyphs = connectedLineStyle;
_borderCellStyle = new Cell(foreground, background);
}

public BorderComponent(int glyph, Color foreground, Color background)
{
_borderGlyphs = new int[] { glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph, glyph };
_borderCellStyle = new Cell(foreground, background);
}

public void UpdateSize(Console console)
{
_borderConsole.Resize(console.Width + 2, console.Height + 2, true);
_borderConsole.DrawBox(new Rectangle(0, 0, _borderConsole.Width, _borderConsole.Height), _borderCellStyle, null, _borderGlyphs);
}

public void OnAdded(Console console)
{
_borderConsole = new Console(console.Width + 2, console.Height + 2, console.Font);
_borderConsole.DrawBox(new Rectangle(0, 0, _borderConsole.Width, _borderConsole.Height), _borderCellStyle, null, _borderGlyphs);
_borderConsole.Position = new Point(-1, -1);
console.Children.Add(_borderConsole);
}

public void OnRemoved(Console console)
{
if (_borderConsole.Parent != null)
_borderConsole.Parent = null;

_borderConsole = null;
}

public void Draw(Console console, TimeSpan delta) => throw new NotImplementedException();

public void ProcessKeyboard(Console console, Keyboard info, out bool handled) => throw new NotImplementedException();

public void ProcessMouse(Console console, MouseConsoleState state, out bool handled) => throw new NotImplementedException();

public void Update(Console console, TimeSpan delta) => throw new NotImplementedException();
}

class BorderedConsole: Console
{
public BorderedConsole()
: base(80, 25)
{
this.IsVisible = false;

// Get the default box shape definition. Defines which characters to use for the box.
SadConsole.Shapes.Box box = SadConsole.Shapes.Box.GetDefaultBox();
Print(1, 1, "Example of using a component to draw a border around consoles");

// Customize the box
box.Foreground = Color.Blue;
box.BorderBackground = Color.White;
box.FillColor = Color.White;
box.Fill = true;
box.Width = textSurface.Width;
box.Height = textSurface.Height;

// Draw the box shape onto the CellSurface that this console is displaying.
box.Draw(this);
var console = new Console(12, 4);
console.Print(1, 1, "Glyph line");
console.Components.Add(new BorderComponent(176, Color.Red, Color.Black));
console.Position = new Point(2, 5);
Children.Add(console);

this.Print(3, 1, "Shapes are easily created with only a few lines of code");
console = new Console(12, 4);
console.Print(1, 1, "Glyph line");
console.Components.Add(new BorderComponent(177, Color.Red, Color.Black));
console.Position = new Point(17, 5);
Children.Add(console);

// Get a circle
SadConsole.Shapes.Circle circle = new SadConsole.Shapes.Circle();
circle.BorderAppearance = new Cell(Color.YellowGreen, Color.White, 57);
circle.Center = new Point(60, 13);
circle.Radius = 10;
console = new Console(12, 4);
console.Print(1, 1, "Glyph line");
console.Components.Add(new BorderComponent(178, Color.Red, Color.Black));
console.Position = new Point(32, 5);
Children.Add(console);

circle.Draw(this);
console = new Console(12, 4);
console.Print(1, 1, "Glyph line");
console.Components.Add(new BorderComponent(219, Color.Red, Color.Black));
console.Position = new Point(47, 5);
Children.Add(console);

// Now time to make a line
SadConsole.Shapes.Line line = new SadConsole.Shapes.Line();
line.StartingLocation = new Point(10, 10);
line.EndingLocation = new Point(45, 18);
line.UseEndingCell = false;
line.UseStartingCell = false;
line.Cell = new Cell { Foreground = Color.Purple, Background = Color.White, Glyph = 88 };
console = new Console(12, 4);
console.Print(1, 1, "Thin line");
console.Components.Add(new BorderComponent(ConnectedLineThin, Color.Green, Color.Black));
console.Position = new Point(17, 12);
Children.Add(console);

line.Draw(this);
console = new Console(12, 4);
console.Print(1, 1, "Thick line");
console.Components.Add(new BorderComponent(ConnectedLineThick, Color.Orange, Color.Black));
console.Position = new Point(2, 12);
Children.Add(console);

console = new Console(12, 4);
console.Print(1, 1, "Extd. line");
console.Components.Add(new BorderComponent(console.Font.Master.IsSadExtended ? ConnectedLineThinExtended : ConnectedLineThin, Color.Purple, Color.Black));
console.Position = new Point(32, 12);
Children.Add(console);
}

}
Expand Down
109 changes: 58 additions & 51 deletions src/DemoProject/SharedCode/CustomConsoles/ScrollableConsole.cs
Original file line number Diff line number Diff line change
@@ -1,90 +1,97 @@
using Microsoft.Xna.Framework;

using System;
using System.Collections.Generic;
using System.Text;
using SadConsole.Input;
using System;
using Microsoft.Xna.Framework;
using SadConsole;
using Console = SadConsole.Console;
using SadConsole.Controls;
using SadConsole.Input;

namespace StarterProject.CustomConsoles
{
class ScrollableConsole : ScrollingConsole
public class ScrollableConsole : ScrollingConsole
{
SadConsole.ControlsConsole controlsContainer;
SadConsole.Controls.ScrollBar scrollBar;
private readonly ControlsConsole _controlsContainer;
private readonly ScrollBar _scrollBar;

int scrollingCounter;
///<summary>Scroll bar position.</summary>
public int ScrollOffset { get; private set; } = 0;

public bool ScrollbarIsVisible
{
get => _controlsContainer.IsVisible;
set => _controlsContainer.IsVisible = value;
}

public ScrollableConsole(int width, int height, int bufferHeight) : base(width - 1, bufferHeight, Global.FontDefault, new Rectangle(0,0,width - 1,height))
public ScrollableConsole(int width, int height, int bufferHeight) :
base(
width: width - 1,
height: bufferHeight,
font: Global.FontDefault,
viewPort: new Rectangle(0, 0, width - 1, height))
{
controlsContainer = new SadConsole.ControlsConsole(1, height);
_controlsContainer = new ControlsConsole(1, height);

ViewPort = new Rectangle(0, 0, width, height);

scrollBar = new SadConsole.Controls.ScrollBar(Orientation.Vertical, height);
scrollBar.IsEnabled = false;
scrollBar.ValueChanged += ScrollBar_ValueChanged;
_scrollBar = new ScrollBar(Orientation.Vertical, height);
_scrollBar.IsEnabled = false;
_scrollBar.ValueChanged += ScrollBar_ValueChanged;

controlsContainer.Add(scrollBar);
controlsContainer.Position = new Point(Position.X + width - 1, Position.Y);
controlsContainer.IsVisible = true;
_controlsContainer.Add(_scrollBar);
_controlsContainer.Position = new Point(Position.X + width - 1, Position.Y);
_controlsContainer.IsVisible = true;

Cursor.IsVisible = true;
Cursor.Print("Just start typing!");
IsVisible = false;

scrollingCounter = 0;
}

private void ScrollBar_ValueChanged(object sender, EventArgs e)
{
// Do our scroll according to where the scroll bar value is
ViewPort = new Rectangle(0, scrollBar.Value, Width, ViewPort.Height);
//Display viewable content based on our scroll offset.
ViewPort = new Rectangle(0, _scrollBar.Value, Width, ViewPort.Height);
}

protected override void OnPositionChanged(Point oldLocation)
{
// Keep the controls console (which is our scroll bar) in sync with where this console is.
controlsContainer.Position = new Point(Position.X + Width, Position.Y);
//Keep the controls console (which is our scroll bar) in sync with where this console is.
_controlsContainer.Position = new Point(Position.X + Width, Position.Y);
}

protected override void OnVisibleChanged()
{
// Show and hide the scroll bar.
controlsContainer.IsVisible = this.IsVisible;
_controlsContainer.IsVisible = this.IsVisible;
}

public override void Draw(TimeSpan delta)
{
// Draw our console and then draw the scroll bar.
base.Draw(delta);
controlsContainer.Draw(delta);
_controlsContainer.Draw(delta);
}

public override void Update(TimeSpan delta)
{
// Update our console and then update the scroll bar
base.Update(delta);
controlsContainer.Update(delta);
_controlsContainer.Update(delta);

// If we detect that this console has shifted the data up for any reason (like the virtual cursor reached the
// bottom of the entire text surface, OR we reached the bottom of the render area, we need to adjust the
// scroll bar and follow the cursor
if (TimesShiftedUp != 0 | Cursor.Position.Y == ViewPort.Height + scrollingCounter)
//If cursor position exceeds our displayable content viewport,
//move the ScrollOffset automatically to display new content.
if (TimesShiftedUp != 0 | Cursor.Position.Y >= ViewPort.Height + ScrollOffset)
{
// Once the buffer has finally been filled enough to need scrolling, turn on the scroll bar
scrollBar.IsEnabled = true;

// Make sure we've never scrolled the entire size of the buffer
if (scrollingCounter < Height - ViewPort.Height)
// Record how much we've scrolled to enable how far back the bar can see
scrollingCounter += TimesShiftedUp != 0 ? TimesShiftedUp : 1;

scrollBar.Maximum = (Height + scrollingCounter) - Height;

// This will follow the cursor since we move the render area in the event.
scrollBar.Value = scrollingCounter;
//Scollbar has to be enabled to read previous content.
_scrollBar.IsEnabled = true;

//Cursor offset cannot exceed our viewable data end row.
//Think about it, we would reach infinity and empty space D:
if (ScrollOffset < Height - ViewPort.Height)
{
//Automatically calculate our content viewport by scrolling the cursor
//Based on how much content is inaccessible.
ScrollOffset += TimesShiftedUp != 0 ? TimesShiftedUp : 1;
}
_scrollBar.Maximum = (Height + ScrollOffset) - Height;

//This will follow the cursor since we move the render area in the event.
_scrollBar.Value = ScrollOffset;

// Reset the shift amount.
TimesShiftedUp = 0;
Expand All @@ -93,17 +100,17 @@ public override void Update(TimeSpan delta)

public override bool ProcessMouse(MouseConsoleState state)
{
// Create a new temp state based on the our "behind the scenes" console that holds the scroll bar
var stateForScroll = new MouseConsoleState(controlsContainer, state.Mouse);
//Create a state based on our container that has the scroll bar.
var stateForScroll = new MouseConsoleState(_controlsContainer, state.Mouse);

// Check if this state, based on the console holding the scroll bar
//Check if this state based on the console holding the scroll bar.
if (stateForScroll.IsOnConsole)
{
controlsContainer.ProcessMouse(stateForScroll);
_controlsContainer.ProcessMouse(stateForScroll);
return true;
}

// if we're here, process the mouse like normal.
//If we're here, continue the mouse processing flow ordinarily.
return base.ProcessMouse(state);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/DemoProject/SharedCode/DemoProject.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ConsoleMetadata.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Container.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomConsoles\AnsiConsole.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomConsoles\BorderedConsole.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomConsoles\ControlsTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomConsoles\DOSConsole.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomConsoles\EntityConsole.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/DemoProject/SharedCode/DemoProjectCoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<ItemGroup>
<Compile Remove="CustomConsoles\AutoTypingConsole.cs" />
<Compile Remove="CustomConsoles\BorderedConsole.cs" />
<Compile Remove="CustomConsoles\CursorConsole.cs" />
<Compile Remove="CustomConsoles\FadeConsole.cs" />
<Compile Remove="CustomConsoles\HexConsole.cs" />
Expand Down
5 changes: 3 additions & 2 deletions src/DemoProject/SharedCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ static void Main(string[] args)
{
//SadConsole.Settings.UnlimitedFPS = true;
//SadConsole.Settings.UseHardwareFullScreen = true;

//SadConsole.Settings.UseDefaultExtendedFont = true;

// Setup the engine and creat the main window.
SadConsole.Game.Create(80, 25);
//SadConsole.Engine.Initialize("IBM.font", 80, 25, (g) => { g.GraphicsDeviceManager.HardwareModeSwitch = false; g.Window.AllowUserResizing = true; });
Expand Down Expand Up @@ -97,4 +98,4 @@ private static void Init()

}
}
}
}
Loading

0 comments on commit c060ed3

Please sign in to comment.