-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.cs
More file actions
169 lines (142 loc) · 4.1 KB
/
Copy pathGame1.cs
File metadata and controls
169 lines (142 loc) · 4.1 KB
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 FFRMapEditorMono.FFR;
using Microsoft.VisualBasic.Devices;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace FFRMapEditorMono
{
public class Game1 : Game
{
// Set mode to switch between FFR or FFMQ editing mode
private GameMode gameMode = GameMode.FFR;
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private EditorMode editorMode;
private Point windowSize = new(1200, 800);
private FileManager fileManager;
private MouseState mouse;
private KeyboardState keyboard;
private TaskManager editorTasks;
private int timeToBackup;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
_graphics.PreferredBackBufferWidth = windowSize.X;
_graphics.PreferredBackBufferHeight = windowSize.Y;
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
Window.Title = "FFR Map Editor";
Window.AllowUserResizing = true;
// Init Tasks list
editorTasks = new();
// Init Inputs
mouse = new();
keyboard = new(editorTasks);
// Init Editor Mode
editorMode = gameMode == GameMode.FFR ? new FFR.FFREditorMode() : new MysticQuest.MQEditorMode();
// Create File Manager
fileManager = new FileManager(gameMode);
fileManager.LoadSettings();
windowSize = fileManager.Settings.GetResolution();
timeToBackup = fileManager.Settings.GetBackupDelay();
_graphics.PreferredBackBufferWidth = windowSize.X;
_graphics.PreferredBackBufferHeight = windowSize.Y;
_graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
editorMode.LoadContent(Content, GraphicsDevice, _spriteBatch, mouse, keyboard, fileManager, editorTasks);
}
protected override void Update(GameTime gameTime)
{
if (editorTasks.Pop(EditorTasks.ResetBackupCounter))
{
timeToBackup = fileManager.Settings.GetBackupDelay();
}
else if (timeToBackup > 0)
{
timeToBackup--;
}
else
{
editorTasks.Add(new EditorTask(EditorTasks.SaveBackupMap));
timeToBackup = fileManager.Settings.GetBackupDelay();
}
if (editorTasks.Pop(EditorTasks.ExitProgram))
{
if (editorMode.UnsavedChanges)
{
editorTasks.Add(EditorTasks.ExitWarningOpen);
editorTasks.Prune(EditorTasks.ExitProgram);
}
else
{
Exit();
}
}
if (editorTasks.Pop(EditorTasks.ExitProgramHard))
{
Exit();
}
// Check if window is active to reduce misclicks
if (!IsActive)
{
return;
}
// Remove None tasks
editorTasks.Prune(EditorTasks.None);
// Update Input Statuts
mouse.Update();
keyboard.Update();
// Check if window was resized
bool windowResized = WindowResized();
// Process Editor
editorMode.Update(fileManager, editorTasks, keyboard, windowSize, windowResized);
// Update Window title
if (fileManager.FilenameUpdated)
{
Window.Title = "FFR Map Editor" + fileManager.GetFileName();
fileManager.FilenameUpdated = false;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
editorMode.Draw(windowSize);
base.Draw(gameTime);
}
private bool WindowResized()
{
if ((_graphics.PreferredBackBufferWidth != _graphics.GraphicsDevice.Viewport.Width) ||
(_graphics.PreferredBackBufferHeight != _graphics.GraphicsDevice.Viewport.Height))
{
_graphics.PreferredBackBufferWidth = _graphics.GraphicsDevice.Viewport.Width;
_graphics.PreferredBackBufferHeight = _graphics.GraphicsDevice.Viewport.Height;
_graphics.ApplyChanges();
windowSize = new Point(_graphics.GraphicsDevice.Viewport.Width, _graphics.GraphicsDevice.Viewport.Height);
return true;
}
else
{
return false;
}
}
protected override void OnExiting(Object sender, EventArgs args)
{
// Save Setting
fileManager.Settings.SetResolution(windowSize);
fileManager.SaveSettings();
base.OnExiting(sender, args);
}
}
}