-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoWindow.cs
101 lines (87 loc) · 4.65 KB
/
InfoWindow.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace FFRMapEditorMono
{
public class InfoWindow
{
public Vector2 Position { get; set; }
public bool Show { get; set; }
protected Texture2D infoTexture;
protected SpriteFont font;
protected float zoom;
protected List<(string name, EditorTasks lefttask, EditorTasks righttask)> options;
protected Button okButton;
protected Vector2 windowDimensions;
protected int windowWidth;
protected string windowText;
public InfoWindow(Texture2D _window, SpriteFont _font, Texture2D _buttonTexture, Point resolution)
{
infoTexture = _window;
font = _font;
Show = false;
zoom = 3.0f;
windowWidth = 28 * 8;
okButton = new(_font, "OK", _buttonTexture, new() { new EditorTask() { Type = EditorTasks.ToggleInfoWindow, Value = 10 } });
windowText = "FFR Map Editor v1.03\n\n" +
"Main Developer\n wildham\n\n" +
"Icons Designer\n DarkmoonEX\n\n" +
"Based on the work of\n" +
" tetron (Overworld Map Format)\n" +
" madmartin (Enabling Logic)\n\n" +
"Source code at\n" +
" https://github.com/wildham0/FFRMapEditorMono\n\n" +
"Randomizer\n" +
" ffrando.com";
var windowHeight = windowText.Count(c => c == '\n') * 8;
windowDimensions = new Vector2(windowWidth, windowHeight);
UpdatePosition(resolution);
}
public void UpdatePosition(Point newres)
{
Position = new Vector2((newres.X - (windowDimensions.X * zoom)) / 2, (newres.Y - (windowDimensions.Y * zoom)) / 2);
}
public List<EditorTask> ProcessInput(MouseState mouse)
{
okButton.Show = Show;
return okButton.OnClick(mouse);
}
public bool MouseHovering(Vector2 mousecursor)
{
Rectangle window = new Rectangle((int)Position.X, (int)Position.Y, (int)(windowDimensions.X * zoom), (int)(windowDimensions.Y * zoom));
okButton.MouseHovering(mousecursor);
return window.Contains(mousecursor) && Show;
}
public void Draw(SpriteBatch spriteBatch)
{
if (!Show)
{
return;
}
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
// Draw Corners
spriteBatch.Draw(infoTexture, Position, new Rectangle(0, 0, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), zoom, SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (windowDimensions.X - 8) * zoom, Position.Y), new Rectangle(16, 0, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), zoom, SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X, Position.Y + (windowDimensions.Y - 8) * zoom), new Rectangle(0, 16, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), zoom, SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (windowDimensions.X - 8) * zoom, Position.Y + (windowDimensions.Y - 8) * zoom), new Rectangle(16, 16, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), zoom, SpriteEffects.None, 0.0f);
// Draw Borders
float borderwidth = Math.Max(0, (windowDimensions.X - 16) / 8);
float borderheight = Math.Max(0, (windowDimensions.Y - 16) / 8);
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (8 * zoom), Position.Y), new Rectangle(8, 0, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), new Vector2(zoom * borderwidth, zoom), SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (8 * zoom), Position.Y + (windowDimensions.Y - 8) * zoom), new Rectangle(8, 16, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), new Vector2(zoom * borderwidth, zoom), SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X, Position.Y + (8 * zoom)), new Rectangle(0, 8, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), new Vector2(zoom, zoom * borderheight), SpriteEffects.None, 0.0f);
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (windowDimensions.X - 8) * zoom, Position.Y + (8 * zoom)), new Rectangle(16, 8, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), new Vector2(zoom, zoom * borderheight), SpriteEffects.None, 0.0f);
// Draw Center
spriteBatch.Draw(infoTexture, new Vector2(Position.X + (8 * zoom), Position.Y + (8 * zoom)), new Rectangle(8, 8, 8, 8), Color.White, 0.0f, new Vector2(0.0f, 0.0f), new Vector2(zoom * borderwidth, zoom * borderheight), SpriteEffects.None, 0.0f);
spriteBatch.DrawString(font, windowText, new Vector2(Position.X + 20, Position.Y + 20), Color.White);
spriteBatch.End();
okButton.Position = new Vector2(Position.X + (windowDimensions.X * zoom - 144), Position.Y + (windowDimensions.Y * zoom - 64));
okButton.Draw(spriteBatch);
}
}
}