This repository has been archived by the owner on Nov 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.cs
144 lines (106 loc) · 5.1 KB
/
Client.cs
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
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Aragas.Core.Wrappers;
using MineLib.Core.Loader;
using MineLib.PGL.Components;
using MineLib.PGL.Screens.InMenu;
using PCLStorage;
namespace MineLib.PGL
{
public sealed class Client : Game
{
public static Point DefaultResolution => new Point(800, 600);
public static Texture2D Blocks { get; private set; }
public ScreenManagerComponent ScreenManager { get; private set; }
public TextureStorageComponent TextureStorage { get; private set; }
private GraphicsDeviceManager Graphics { get; }
public ProtocolAssembly DefaultModule { get; private set; }
private const string DefaultModuleSettings = "DefaultModule.json";
public Client(Action<Game> platformCode, bool fullscreen = false)
{
Graphics = new GraphicsDeviceManager(this);
Graphics.IsFullScreen = fullscreen;
Graphics.ApplyChanges();
Content.RootDirectory = "Content";
platformCode?.Invoke(this);
}
protected override void LoadContent()
{
Blocks = Content.Load<Texture2D>("Texture");
//Blocks = Content.Load<Texture2D>("Effects\\terrain");
var contentFolder = FileSystemWrapper.ContentFolder;
if (contentFolder != null && contentFolder.CheckExistsAsync("texturepack.zip").Result == ExistenceCheckResult.FileExists)
using (var reader = new StreamReader(contentFolder.GetFileAsync("texturepack.zip").Result.OpenAsync(FileAccess.Read).Result))
{
var minecraftFiles = new ZipFile(reader.BaseStream);
TextureStorage = new TextureStorageComponent(this, minecraftFiles);
TextureStorage.ParseGUITextures();
}
else if (contentFolder != null && contentFolder.CheckExistsAsync("minecraft.jar").Result == ExistenceCheckResult.FileExists)
using (var reader = new StreamReader(contentFolder.GetFileAsync("minecraft.jar").Result.OpenAsync(FileAccess.Read).Result))
{
var minecraftFiles = new ZipFile(reader.BaseStream);
TextureStorage = new TextureStorageComponent(this, minecraftFiles);
TextureStorage.ParseGUITextures();
}
var list = FileSystemWrapper.AssemblyFolder.GetFilesAsync().Result;
DefaultModule = list.Count > 0 ? new ProtocolAssembly(list[0].Path) : default(ProtocolAssembly);
FileSystemWrapper.LoadSettings(DefaultModuleSettings, DefaultModule);
ScreenManager = new ScreenManagerComponent(this);
Components.Add(ScreenManager);
ScreenManager.AddScreen(new MainMenuScreen(this));
#if DEBUG
Components.Add(new DebugComponent(this));
#endif
}
public void OnResize(object sender, EventArgs e)
{
if (Graphics.GraphicsDevice.Viewport.Width < DefaultResolution.X || Graphics.GraphicsDevice.Viewport.Height < DefaultResolution.Y)
{
Resize(DefaultResolution);
return;
}
ScreenManager.OnResize();
}
public void Resize(Point size)
{
if (size.X < DefaultResolution.X || size.Y < DefaultResolution.Y)
return;
Graphics.PreferredBackBufferWidth = size.X;
Graphics.PreferredBackBufferHeight = size.Y;
Graphics.ApplyChanges();
}
protected override void Update(GameTime gameTime)
{
InputManager.Update(gameTime);
if (InputManager.IsOncePressed(Keys.L))
{
Graphics.SynchronizeWithVerticalRetrace = !Graphics.SynchronizeWithVerticalRetrace;
Graphics.ApplyChanges();
IsFixedTimeStep = !IsFixedTimeStep;
}
if (InputManager.IsOncePressed(Keys.M))
TargetElapsedTime = new TimeSpan((long) (1000f / 144f * TimeSpan.TicksPerMillisecond));
if (InputManager.IsOncePressed(Keys.N))
TargetElapsedTime = new TimeSpan((long) (1000f / 60f * TimeSpan.TicksPerMillisecond));
if (InputManager.IsOncePressed(Keys.B))
TargetElapsedTime = new TimeSpan((long) (1000f / 30f * TimeSpan.TicksPerMillisecond));
if (InputManager.IsOncePressed(Keys.Y))
Resize(new Point(800, 600));
if (InputManager.IsOncePressed(Keys.U))
Resize(new Point(1440, 900));
if (InputManager.IsOncePressed(Keys.I))
Resize(new Point(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height));
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}