Skip to content

Commit 2ccb1bf

Browse files
authored
Merge pull request #345 from Thraka/develop
10.0.3 release
2 parents 03627ff + 4d8a4fb commit 2ccb1bf

File tree

137 files changed

+5801
-2991
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+5801
-2991
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using SadConsole.Input;
2+
using SadConsole.UI.Controls;
3+
4+
namespace SadConsole.Examples;
5+
6+
internal class DemoControlsScrollbarTests : IDemo
7+
{
8+
public string Title => "Controls (Scrollbar)";
9+
10+
public string Description => "Test area";
11+
12+
public string CodeFile => "DemoControlsScrollbarTests.cs";
13+
14+
public IScreenSurface CreateDemoScreen() =>
15+
new ControlsTest3();
16+
17+
public override string ToString() =>
18+
Title;
19+
}
20+
21+
class ControlsTest3 : SadConsole.UI.ControlsConsole
22+
{
23+
public ControlsTest3() : base(GameSettings.ScreenDemoBounds.Width, GameSettings.ScreenDemoBounds.Height)
24+
{
25+
Controls.ThemeColors = GameSettings.ControlColorScheme;
26+
27+
CreateBox((1, 1), 10, 10);
28+
CreateBox((3, 3), 5, 10);
29+
CreateBox((6, 5), 10, 5);
30+
31+
CreateBox2((20, 1), 10, 1);
32+
CreateBox2((22, 3), 10, 2);
33+
CreateBox2((24, 5), 10, 5);
34+
CreateBox2((26, 7), 10, 10);
35+
CreateBox2((28, 9), 10, 15);
36+
CreateBox2((30, 11), 10, 7);
37+
CreateBox2((32, 13), 2, 7);
38+
CreateBox2((34, 15), 3, 7);
39+
CreateBox2((36, 17), 4, 7);
40+
CreateBox2((38, 19), 5, 7);
41+
42+
CreateBox3((54, 2), 10, 1);
43+
CreateBox3((54, 5), 10, 2);
44+
CreateBox3((54, 8), 10, 5);
45+
CreateBox3((54, 11), 10, 10);
46+
CreateBox3((54, 14), 10, 15);
47+
CreateBox3((54, 17), 10, 7);
48+
CreateBox3((54, 20), 2, 7);
49+
CreateBox3((54, 23), 3, 1);
50+
CreateBox3((65, 2), 4, 1);
51+
CreateBox3((65, 5), 5, 1);
52+
CreateBox3((65, 8), 6, 1);
53+
}
54+
55+
private (ScrollBar bar, Label label) CreateBox3(Point position, int height, int max)
56+
{
57+
ScrollBar bar1 = new(Orientation.Horizontal, height);
58+
Label label1 = new(10);
59+
bar1.Position = position;
60+
bar1.MaximumValue = max;
61+
bar1.ArrowsMoveGrip = true;
62+
bar1.Tag = label1;
63+
label1.PlaceRelativeTo(bar1, Direction.Types.Up, 0);
64+
label1.DisplayText = "Label";
65+
66+
bar1.ValueChanged += Bar2_ValueChanged;
67+
68+
Controls.Add(bar1);
69+
Controls.Add(label1);
70+
71+
Bar2_ValueChanged(bar1, EventArgs.Empty);
72+
73+
return (bar1, label1);
74+
}
75+
76+
private (ScrollBar bar, Label label) CreateBox2(Point position, int height, int max)
77+
{
78+
ScrollBar bar1 = new(Orientation.Vertical, height);
79+
Label label1 = new(10);
80+
bar1.Position = position;
81+
bar1.MaximumValue = max;
82+
bar1.MouseWheelMovesGrip = true;
83+
bar1.Tag = label1;
84+
label1.PlaceRelativeTo(bar1, Direction.Types.Right);
85+
label1.DisplayText = "Label";
86+
87+
bar1.ValueChanged += Bar2_ValueChanged;
88+
89+
Controls.Add(bar1);
90+
Controls.Add(label1);
91+
92+
Bar2_ValueChanged(bar1, EventArgs.Empty);
93+
94+
return (bar1, label1);
95+
}
96+
97+
private (ScrollBar bar, Label label) CreateBox(Point position, int height, int max)
98+
{
99+
ScrollBar bar1 = new(Orientation.Vertical, height);
100+
Label label1 = new(10);
101+
bar1.Position = position;
102+
bar1.MaximumValue = max;
103+
bar1.Tag = label1;
104+
label1.PlaceRelativeTo(bar1, Direction.Types.Right);
105+
label1.DisplayText = "Label";
106+
107+
bar1.ValueChanged += Bar1_ValueChanged;
108+
109+
Controls.Add(bar1);
110+
Controls.Add(label1);
111+
112+
Bar1_ValueChanged(bar1, EventArgs.Empty);
113+
114+
return (bar1, label1);
115+
}
116+
117+
private void Bar1_ValueChanged(object? sender, EventArgs e)
118+
{
119+
ScrollBar control = (ScrollBar)sender!;
120+
((Label)control.Tag!).DisplayText = $"{control.Value}/{control.MaximumValue} {control.Style.GripStart}";
121+
}
122+
123+
private void Bar2_ValueChanged(object? sender, EventArgs e)
124+
{
125+
ScrollBar control = (ScrollBar)sender!;
126+
((Label)control.Tag!).DisplayText = $"{control.Value}/{control.MaximumValue} {control.Style.GripStart}";
127+
}
128+
129+
public override bool ProcessMouse(MouseScreenObjectState state)
130+
{
131+
return base.ProcessMouse(state);
132+
}
133+
}
134+
135+
136+
137+

PerformanceTests/SadConsole.PerformanceTests/BasicGameHost.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public override IRenderStep GetRendererStep(string name)
103103
return new RenderStep();
104104
}
105105

106-
public override void ResizeWindow(int width, int height) => throw new NotImplementedException();
107-
108106
public override void Run()
109107
{
110108
throw new NotImplementedException();
@@ -114,5 +112,10 @@ public override ITexture CreateTexture(int width, int height)
114112
{
115113
throw new NotImplementedException();
116114
}
115+
116+
public override void ResizeWindow(int width, int height, bool resizeOutputSurface = false)
117+
{
118+
throw new NotImplementedException();
119+
}
117120
}
118121
}

PerformanceTests/SadConsole.PerformanceTests/SadConsole.PerformanceTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
10-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
10+
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

README.md

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44
[![NuGet](https://img.shields.io/nuget/v/SadConsole.svg)][nuget]
55
[![kandi X-Ray](https://kandi.openweaver.com/badges/xray.svg)](https://kandi.openweaver.com/csharp/Thraka/SadConsole)
66

7-
SadConsole is a generic library that emulates old-school console game systems. It provides command prompt-style graphics where one or more tile textures are used to represent an ASCII character set. Console's are made up of a grid of cells, each of which can have its own foreground, background, glyph, and special effect applied to it.
7+
SadConsole is a C#-based .NET cross-platform terminal, ascii, console, game engine. It simulates these types of programs and with it you can make ascii-styled games for modern platforms. At its heart, SadConsole is really a giant tile-based game engine. However, its object model is conceptually similar to a traditional console app.
88

9-
While SadConsole is a generic library that doesn't provide any rendering capabilities, "host" libraries are provided that add renderers to SadConsole. The two hosts provided by this library are for **MonoGame** and **SFML**.
9+
While SadConsole is a generic library that doesn't provide any rendering capabilities, "host" libraries are provided that add renderers to SadConsole. The two hosts provided by this library are for **SadConsole.Host.MonoGame** and **SadConsole.Host.SFML**. When adding a host library to your project, you don't need to reference the base **SadConsole** package. If you use MonoGame, you'll also need to add a rendering NuGet package, such as **MonoGame.Framework.DesktopGL**.
1010

11-
_SadConsole currently targets .NET 6 and .NET 7_
11+
_SadConsole currently targets .NET 6, .NET 7, and .NET 8_
1212

1313
For the latest changes in this release, see the [notes below](#latest-changes)
1414

1515
## Features
1616

1717
Here are some of the features SadConsole supports:
1818

19-
- Show any number of consoles.
19+
- Show any number of consoles of any size.
2020
- Uses graphical tile-based images to build out an ASCII-character font with support for more than 256 characters.
21+
- Fonts are simply sprite sheet tilesets tied to ascii codes, you can use full graphical tiles if you want.
2122
- Use more than one font file. However, each console is restricted to a single font.
22-
- Independently controlled entities for game objects.
23-
- Keyboard and Mouse support.
24-
- Text UI control framework with windowing support.
23+
- Full GUI system for interactive controls such as list boxes, buttons, and text fields.
2524
- Importers for [DOS ANSI files](https://wikipedia.org/wiki/ANSI_art), [TheDraw text fonts](https://en.wikipedia.org/wiki/TheDraw), [RexPaint](https://www.gridsagegames.com/rexpaint/), and [Playscii](http://vectorpoem.com/playscii/).
26-
- Animated consoles.
25+
- Animated consoles and instruction system to chain commands together.
26+
- String encoding system for colors and effects while printing.
27+
- Entity support for drawing thousands of movable objects on the screen
2728
- Translating images to text-blocks.
29+
- Keyboard and mouse support.
2830
- Highly customizable framework.
2931

3032
#### String display and parsing
@@ -64,7 +66,7 @@ Builder startup = new Builder()
6466
.UseDefaultConsole()
6567
.OnStart(Game_Started)
6668
.IsStartingScreenFocused(true)
67-
.ConfigureFonts((config, game) => config.UseBuiltinFontExtended())
69+
.ConfigureFonts(true)
6870
;
6971

7072
// Setup the engine and start the game
@@ -100,9 +102,7 @@ Module Module1
100102
startup.UseDefaultConsole()
101103
startup.OnStart(AddressOf Game_Started)
102104
startup.IsStartingScreenFocused(True)
103-
startup.ConfigureFonts(Sub(config As FontConfig, gameObject As Game)
104-
config.UseBuiltinFontExtended()
105-
End Sub)
105+
startup.ConfigureFonts(True)
106106

107107
' Setup the engine and start the game
108108
SadConsole.Game.Create(startup)
@@ -125,19 +125,31 @@ Module Module1
125125
End Module
126126
```
127127

128-
## Latest changes v10.0.0 Beta 1 and 2 (10/11/2023)
129-
130-
- OnStart startup config is no longer an Action but is now an event.
131-
- Startup config changed again from the last alpha. Types were renamed and rewritten to be extensible. It works the same way as before except that everything is in the SadConsole.Configuration namespace. You must import that namespace to enable the extension methods that build the config. The type to build the config is Builder.
132-
- Tabs orientated left/right didn't display the text properly.
133-
- ColoredGlyph was renamed to ColoredGlyphBase and a new ColoredGlyph that inherits from the base class was added.
134-
- Scrollbars didn't behave properly when in a CompositeControl.
135-
- ListBox mouse logic was improved to use an "ItemsArea" property that designates when the mouse is over the items list specifically.
136-
- StringParser supports variables. There's a dictionary that invokes a delegate which returns a value for the variable. So the value can be determined as the variable is used. See DemoStringParsing.cs in the sample template.
137-
- AnimatedScreenObject's weren't rendering correctly.
138-
- Decorators are no longer array's but rented from a list pool. Use the CellDecoratorHelpers class to manage them. SadConsole does its best to rent and return from the pool as you add or remove decorators.
139-
- Default font used the wrong name. It's been corrected from "IBM_16x8" to "IBM_8x16".
140-
- The ToggleSwitch control wasn't drawing properly.
141-
- NumberBox supports cultured number parsing.
142-
- CellDecorator, as a readonly struct, now declares the properties with "get; init;" which allows mutation with the the "with" keyword.
143-
- EntityManager.AlternativeFont added to support different fonts for entities.
128+
## Latest changes
129+
130+
v10.0.3 (03/13/2024)
131+
132+
- [UI] `ScrollBar` has been completely rewritten. Minor breaking changes.
133+
- `.Maximum` has been changed to `.MaximumValue`.
134+
- Properties related to the style, such as `BarGlyph`, were moved to a `Style` property which controls how the control looks. Some property names have changed
135+
- [UI] `NumberBox` improvements.
136+
- Rendering code split from `Textbox`.
137+
- Added `ShowUpDownButtons` to show up\down buttons.
138+
- Fixed bug with `UseMinMax` messing up the value and setting it back to 0 when the control loses focus.
139+
- [UI] `ControlBase.FindThemeFont` helper method added.
140+
- [UI] Minor bug fixed where captured controls (such as a scroll bar) wouldn't process the mouse if the control was parented to a composite control and the mouse left the parent area.
141+
- [Core] Fixed `EffectSet` bug where the last effect wasn't applied.
142+
- [Core] `GlyphDefinition` has an init accessor now.
143+
- [Core] Added `ShapeParameter` docs and `CreateFilled` supports ignoring the border.
144+
- [Core] Added `RootComponent` class that can be added to `SadConsole.Game.Instance.RootComponents`. These components run logic before the keyboard and screen updates.
145+
- [Core] Splash screen collection is nulled after it runs, freeing memory.
146+
- [Extended] Classic keyboard handler has `IsReady` flag now to control when it's active.
147+
- [Extended] `ColorPickerPopup` would crash on invalid textbox values.
148+
- [Extended] `GlyphSelectPopup` added. You can use this to display a list of glyphs in your font while debugging your app.
149+
- [Extended] Fixed a bug in the table control that prevented the scroll bars from being displayed.
150+
- [Extended] Cleaned up code and enabled nullable.
151+
- [Host - SFML] Fix bug where it was always running at unlimited FPS.
152+
- [Host - MonoGame] Renderers can set backing texture usage.
153+
- [Host - FNA] Fix bug where the screen clear wasn't working and would default to violet.
154+
- [Host - All] Add `OptimizedScreenSurfaceRenderer` which renders.
155+
- [Host - All] Surface render step can accept an alternative surface with the `SetData` method.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using SadConsole.Components;
3+
using SadConsole.Input;
4+
5+
namespace SadConsole.Configuration;
6+
7+
/// <summary>
8+
/// Extensions to enable the ImGui debug UI.
9+
/// </summary>
10+
public static class DebugExtensions
11+
{
12+
/// <summary>
13+
/// Adds a <see cref="GameHost.RootComponents"/> component that uses the specified hotkey to invoke <see cref="Debug.MonoGame.Debugger.Start"/>.
14+
/// </summary>
15+
/// <param name="builder">The config builder.</param>
16+
/// <param name="hotkey">The keyboard key to start the debugger.</param>
17+
/// <returns>The config builder.</returns>
18+
public static Builder EnableImGuiDebug(this Builder builder, Keys hotkey)
19+
{
20+
ImGuiDebugConfig config = builder.GetOrCreateConfig<ImGuiDebugConfig>();
21+
config.HotKey = hotkey;
22+
return builder;
23+
}
24+
}
25+
26+
internal class ImGuiDebugConfig : RootComponent, IConfigurator
27+
{
28+
public Keys HotKey { get; set; }
29+
30+
public void Run(Builder config, Game game)
31+
{
32+
game.RootComponents.Add(this);
33+
}
34+
35+
public override void Run(TimeSpan delta)
36+
{
37+
if (Game.Instance.FrameNumber != 0 && Game.Instance.Keyboard.IsKeyReleased(HotKey) && !Debug.MonoGame.Debugger.IsOpened)
38+
Debug.MonoGame.Debugger.Start();
39+
}
40+
}

SadConsole.Debug.MonoGame/Debugger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public static void Start()
7474
_imGui.UIComponents.Add(new ScreenObjectsPanel());
7575
_imGui.UIComponents.Add(new GuiSurfacePreview());
7676

77-
ScreenObjectDetailsPanel.RegisteredPanels.Add(typeof(SadConsole.UI.Window), new WindowConsolePanel());
78-
ComponentsPanel.RegisteredPanels.Add(typeof(SadConsole.Components.Cursor), new ComponentEditorCursor());
77+
ScreenObjectDetailsPanel.RegisteredPanels.Add(typeof(SadConsole.UI.Window), new ScreenObjectEditors.WindowConsolePanel());
78+
ComponentsPanel.RegisteredPanels.Add(typeof(SadConsole.Components.Cursor), new SadComponentEditors.ComponentEditorCursor());
7979

8080
GuiState.GuiFinalOutputWindow = new FinalOutputWindow("Output preview", true);
8181
_imGui.UIComponents.Add(GuiState.GuiFinalOutputWindow);

SadConsole.Debug.MonoGame/GuiOutputPreview.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override void BuildUI(ImGuiRenderer renderer)
2828
{
2929
ImGui.SetNextWindowBgAlpha(1f);
3030

31-
if (ImGui.Begin(Title, ref IsOpen))
31+
if (ImGui.Begin(Title, ref IsOpen, ImGuiWindowFlags.HorizontalScrollbar))
3232
{
3333
if (SadConsole.Host.Global.RenderOutput != null)
3434
{

SadConsole.Debug.MonoGame/GuiSurfacePreview.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override void BuildUI(ImGuiRenderer renderer)
2020
{
2121
ImGui.SetNextWindowBgAlpha(1f);
2222
//ImGui.SetNextWindowSizeConstraints(new Vector2(200, 200), new Vector2(10000, 10000));
23-
if (ImGui.Begin("Surface preview", ref GuiState.ShowSurfacePreview))
23+
if (ImGui.Begin("Surface preview", ref GuiState.ShowSurfacePreview, ImGuiWindowFlags.HorizontalScrollbar))
2424
{
2525
// TODO:
2626
// New window that is an editor type for the parent object
@@ -55,7 +55,7 @@ public override void BuildUI(ImGuiRenderer renderer)
5555
}
5656

5757
// Render the target texture
58-
ImGuiExt.DrawTextureChild("output_preview_surface1", true, _zoom ? ImGuiExt.Zoom2x : ImGuiExt.ZoomNormal, targetTexture, renderer, out var isActive, out var isHovered);
58+
ImGuiExt.DrawTextureChild("output_preview_surface1", false, _zoom ? ImGuiExt.Zoom2x : ImGuiExt.ZoomNormal, targetTexture, renderer, out var isActive, out var isHovered);
5959

6060
// Peek the cell if the target type is the final
6161
if (GuiState._selectedScreenObjectState.SurfaceState.RenderStepSelectedItem == 0)

0 commit comments

Comments
 (0)