-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageBox.cs
68 lines (56 loc) · 2.62 KB
/
MessageBox.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if Allow_XNA
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endif
namespace GamesLibrary
{
public class MessageBox : Window
{
private SpriteFont _spriteFont;
private string _text;
private Vector2 _v2TextSize;
private Button _buttonOK;
public MessageBox(string text, SpriteFont spriteFont, Vector2 v2Center, BaseGame baseGame)
: this(text, spriteFont, v2Center, baseGame, null)
{
}
public MessageBox(string text, SpriteFont spriteFont, Vector2 v2Center, BaseGame baseGame, EventHandler<PressEventArgs> OnOK) : base(v2Center, baseGame)
{
_text = text;
_spriteFont = spriteFont;
_buttonOK = new Button(new Rectangle(0, 0, 0, 0), "OK", _spriteFont, Color.Black, true);
_buttonOK.Press += new EventHandler<PressEventArgs>(_buttonOK_Press);
if (OnOK != null)
_buttonOK.Press += OnOK;
_v2TextSize = _spriteFont.MeasureString(_text);
int height = textTopBuffer + (int)(_v2TextSize.Y) + betweenBuffer + _buttonOK.bounds.Height + buttonBottomBuffer;
int width = leftBuffer + (int)(_v2TextSize.X) + rightBuffer;
Rectangle bounds = new Rectangle((int)this.v2Center.X, (int)this.v2Center.Y, width, height);
bounds.Offset(-(bounds.Width / 2), -(bounds.Height / 2));
this.bounds = bounds;
Rectangle boundsOK = new Rectangle((this.bounds.Width / 2) - (_buttonOK.bounds.Width / 2), this.bounds.Height - buttonBottomBuffer - _buttonOK.bounds.Height, _buttonOK.bounds.Width, _buttonOK.bounds.Height);
_buttonOK.bounds = boundsOK;
this.addButton(_buttonOK);
}
void _buttonOK_Press(object sender, PressEventArgs e)
{
this.baseGame.Hide(this);
}
public override void HandleInput(GameTime gameTime)
{
}
public override void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch)
{
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, Window.rasterizerState, null, this.mxTWindowToScreen);
spriteBatch.DrawString(_spriteFont, _text, new Vector2(this.center.X - (_v2TextSize.X / 2), textTopBuffer), Color.Black);
spriteBatch.End();
//_buttonOK.background = this.background;
_buttonOK.decorations = this.decorations;
_buttonOK.Draw(gameTime, gameState, spriteBatch, this.baseGame, this.mxTWindowToScreen);
}
}
}