forked from Thraka/SadConsole
-
Notifications
You must be signed in to change notification settings - Fork 1
/
monogame with sadconsole example.txt
169 lines (134 loc) · 6.74 KB
/
monogame with sadconsole example.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.Screens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
public class SadConsoleScreen : GameScreen
{
// How many columns/rows the screen for sadcosnole will display at normal font size
public const int WidthCellCount = 80;
public const int HeightCellCount = 25;
SpriteBatch spriteBatch;
public SadConsoleScreen(Game game)
: base(game)
{
// Basics used for rendering
SadConsole.Global.GraphicsDevice = GraphicsDevice;
SadConsole.Global.SpriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(GraphicsDevice);
// Load the default font. This is an internal method so use reflection
// SadConsole.Global.LoadEmbeddedFont();
if (SadConsole.Global.Fonts.Count == 0)
typeof(SadConsole.Global).InvokeMember("LoadEmbeddedFont", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic, null, null, null);
SadConsole.Global.RenderWidth = WidthCellCount * SadConsole.Global.FontDefault.Size.X;
SadConsole.Global.RenderHeight = HeightCellCount * SadConsole.Global.FontDefault.Size.Y;
SadConsole.Global.RenderOutput = new RenderTarget2D(GraphicsDevice, SadConsole.Global.RenderWidth, SadConsole.Global.RenderHeight);
SadConsole.Global.RenderRect = new Rectangle(0, 0, SadConsole.Global.RenderWidth, SadConsole.Global.RenderHeight);
SadConsole.Global.RenderScale = new Vector2(1);
spriteBatch = new SpriteBatch(GraphicsDevice);
}
public override void Initialize()
{
//var startingConsole = new TestConsole();
var startingConsole = new SadConsole.Console(10, 10);
startingConsole.FillWithRandomGarbage();
SadConsole.Global.CurrentScreen = startingConsole;
base.Initialize();
}
public override void LoadContent()
{
base.LoadContent();
}
public override void Draw(GameTime gameTime)
{
if (SadConsole.Settings.DoDraw)
{
SadConsole.Global.GameTimeRender = gameTime;
SadConsole.Global.GameTimeElapsedRender = gameTime.ElapsedGameTime.TotalSeconds;
// Clear draw calls for next run
SadConsole.Global.DrawCalls.Clear();
// Make sure all items in the screen are drawn. (Build a list of draw calls)
SadConsole.Global.CurrentScreen?.Draw(gameTime.ElapsedGameTime);
// Comment this out as it's global logic used by a standalone sadconsole game. You really can just add your own logic here. Or uncomment it and use it.
//SadConsole.Game.OnDraw?.Invoke(gameTime);
// Render to the global output texture
GraphicsDevice.SetRenderTarget(SadConsole.Global.RenderOutput);
GraphicsDevice.Clear(SadConsole.Settings.ClearColor);
// Render each draw call
SadConsole.Global.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone);
foreach (SadConsole.DrawCalls.IDrawCall call in SadConsole.Global.DrawCalls)
{
call.Draw();
}
SadConsole.Global.SpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
// If we're going to draw to the screen, do it.
if (SadConsole.Settings.DoFinalDraw)
{
// This is the original draw to screen code from SadConsole
//Global.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone);
//Global.SpriteBatch.Draw(Global.RenderOutput, Global.RenderRect, Color.White);
//Global.SpriteBatch.End();
// This is the code you wrote but modified to draw the output texture from SadConsole.
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
SamplerState.LinearClamp, DepthStencilState.Default,
RasterizerState.CullNone);
spriteBatch.Draw(SadConsole.Global.RenderOutput, new Rectangle(0, 0, 300, 100), Color.Red);
spriteBatch.End();
}
}
}
public override void Update(GameTime gameTime)
{
if (SadConsole.Settings.DoUpdate)
{
SadConsole.Global.GameTimeUpdate = gameTime;
SadConsole.Global.GameTimeElapsedUpdate = gameTime.ElapsedGameTime.TotalSeconds;
if (Game.IsActive)
{
if (SadConsole.Settings.Input.DoKeyboard)
{
SadConsole.Global.KeyboardState.Update(gameTime);
SadConsole.Global.KeyboardState.Process();
}
if (SadConsole.Settings.Input.DoMouse)
{
SadConsole.Global.MouseState.Update(gameTime);
SadConsole.Global.MouseState.Process();
}
}
SadConsole.Global.CurrentScreen?.Update(gameTime.ElapsedGameTime);
// Comment this out as it's global logic used by a standalone sadconsole game. You really can just add your own logic here. Or uncomment it and use it.
//SadConsole.Game.OnUpdate?.Invoke(gameTime);
}
}
class Program
{
static void Main(string[] args)
{
new MonoGameGame().Run();
}
}
// My test game to make this code work. you didn't provide this so I came up with this :)
class MonoGameGame : Microsoft.Xna.Framework.Game
{
public GraphicsDeviceManager GraphicsDeviceManager;
public MonoGameGame()
{
GraphicsDeviceManager = new GraphicsDeviceManager(this);
}
protected override void Initialize()
{
base.Initialize();
ScreenManager manager = new ScreenManager();
manager.LoadScreen(new SadConsoleScreen(this));
Components.Add(manager);
}
}
}
}