213 lines
7.0 KiB
C#
213 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace MrAG {
|
|
public partial class Gui {
|
|
public class Dialog {
|
|
string Title;
|
|
|
|
int AddY = 62;
|
|
bool DoingHalf;
|
|
bool FullSize;
|
|
|
|
public Frame Frame;
|
|
|
|
public List<Button> Buttons = new List<Button>();
|
|
public List<Label> Labels = new List<Label>();
|
|
public List<TextBox> Textboxes = new List<TextBox>();
|
|
|
|
private bool FistInputkak = true;
|
|
|
|
public Dialog(string title, string text){
|
|
this.Title = title;
|
|
int tw = 0;
|
|
|
|
List<string> lines = new List<string>();
|
|
foreach (string line in text.Split('\n')) {
|
|
string curline = "";
|
|
for (int i = 0; i < line.Length; i++) {
|
|
Vector2 TSize = MrAG.Draw.GetTextSize(curline + line[i]);
|
|
|
|
if (TSize.X > 380) {
|
|
lines.Add(curline);
|
|
curline = "";
|
|
this.FullSize = true;
|
|
} else {
|
|
curline += line[i];
|
|
}
|
|
}
|
|
|
|
if (curline.Length > 0) {
|
|
lines.Add(curline);
|
|
tw = (int)MrAG.Draw.GetTextSize(curline).X;
|
|
}
|
|
}
|
|
|
|
this.Frame = new Frame();
|
|
this.Frame.Text = title;
|
|
this.Frame.SetSize(500, 62 + (lines.Count * 20));
|
|
this.Frame.Center();
|
|
this.Frame.ContentBackColor = new Color(20, 20, 20, 255);
|
|
|
|
GroupBox gb = new GroupBox();
|
|
gb.SetParent(this.Frame);
|
|
gb.SetSize((this.FullSize ? 380 : tw) + 20, (lines.Count * 20) + 12);
|
|
gb.SetPos(240 - ((this.FullSize ? 380 : tw) / 2), 17);
|
|
gb.DrawLines = false;
|
|
gb.BackColor = new Color(39, 155, 255, 100);
|
|
|
|
for (int i = 0; i < lines.Count; i++){
|
|
Label l = new Label();
|
|
l.Text = lines[i];
|
|
l.AlignmentX = MrAG.Draw.TextAlignmentX.Center;
|
|
l.SetParent(this.Frame);
|
|
l.SetPos(250, 23 + (i * 20));
|
|
l.Color = new Color(255, 255, 255, 255);
|
|
}
|
|
}
|
|
|
|
public Button AddButton(string text, Action onclick) {
|
|
this.DoingHalf = false;
|
|
|
|
Button btn = new Button();
|
|
btn.SetParent(this.Frame);
|
|
btn.SetSize(400, 25);
|
|
btn.SetPos(50, AddY);
|
|
btn.Text = text;
|
|
btn.TextColor = Color.White;
|
|
|
|
if (onclick == null)
|
|
btn.OnLeftMouseClick = new Action(delegate { this.Frame.Remove(); });
|
|
else
|
|
btn.OnLeftMouseClick = onclick;
|
|
|
|
AddY += 30;
|
|
this.Frame.SetSize(500, AddY);
|
|
this.Frame.Center();
|
|
|
|
this.Buttons.Add(btn);
|
|
return btn;
|
|
}
|
|
|
|
public Button AddHalfButton(string text, Action onclick) {
|
|
Button btn = new Button();
|
|
btn.SetParent(this.Frame);
|
|
btn.SetSize(195, 25);
|
|
btn.SetPos(this.DoingHalf ? 255 : 50, this.DoingHalf ? this.AddY - 30 : this.AddY);
|
|
btn.Text = text;
|
|
btn.TextColor = Color.White;
|
|
|
|
this.DoingHalf = !this.DoingHalf;
|
|
if (this.DoingHalf) {
|
|
this.AddY += 30;
|
|
}
|
|
|
|
if (onclick == null)
|
|
btn.OnLeftMouseClick = new Action(delegate { this.Frame.Remove(); });
|
|
else
|
|
btn.OnLeftMouseClick = onclick;
|
|
|
|
this.Frame.SetSize(500, this.AddY);
|
|
this.Frame.Center();
|
|
|
|
this.Buttons.Add(btn);
|
|
return btn;
|
|
}
|
|
|
|
public Label AddLabel(string text) {
|
|
this.DoingHalf = false;
|
|
|
|
Label lbl = new Label();
|
|
lbl.SetParent(this.Frame);
|
|
lbl.SetSize(400, 25);
|
|
lbl.SetPos(50, AddY);
|
|
lbl.Text = text;
|
|
|
|
AddY += 30;
|
|
this.Frame.SetSize(500, AddY);
|
|
this.Frame.Center();
|
|
|
|
this.Labels.Add(lbl);
|
|
return lbl;
|
|
}
|
|
|
|
public Label AddHalfLabel(string text) {
|
|
Label lbl = new Label();
|
|
lbl.SetParent(this.Frame);
|
|
lbl.SetSize(195, 25);
|
|
lbl.SetPos(this.DoingHalf ? 255 : 50, this.DoingHalf ? this.AddY - 30 : this.AddY);
|
|
lbl.Text = text;
|
|
|
|
this.DoingHalf = !this.DoingHalf;
|
|
if (this.DoingHalf) {
|
|
this.AddY += 30;
|
|
}
|
|
|
|
this.Frame.SetSize(500, this.AddY);
|
|
this.Frame.Center();
|
|
|
|
this.Labels.Add(lbl);
|
|
return lbl;
|
|
}
|
|
|
|
public TextBox AddTextbox(string text) {
|
|
this.DoingHalf = false;
|
|
|
|
TextBox tb = new TextBox();
|
|
tb.SetParent(this.Frame);
|
|
tb.SetSize(400, 25);
|
|
tb.SetPos(50, AddY);
|
|
tb.Text = text;
|
|
|
|
AddY += 30;
|
|
this.Frame.SetSize(500, AddY);
|
|
this.Frame.Center();
|
|
|
|
if (this.FistInputkak) {
|
|
tb.SetFocus();
|
|
this.FistInputkak = false;
|
|
}
|
|
|
|
this.Textboxes.Add(tb);
|
|
return tb;
|
|
}
|
|
|
|
public TextBox AddHalfTextbox(string text) {
|
|
TextBox tb = new TextBox();
|
|
tb.SetParent(this.Frame);
|
|
tb.SetSize(195, 25);
|
|
tb.SetPos(this.DoingHalf ? 255 : 50, this.DoingHalf ? this.AddY - 30 : this.AddY);
|
|
tb.Text = text;
|
|
|
|
if (this.FistInputkak) {
|
|
tb.SetFocus();
|
|
this.FistInputkak = false;
|
|
}
|
|
|
|
this.DoingHalf = !this.DoingHalf;
|
|
if (this.DoingHalf) {
|
|
this.AddY += 30;
|
|
}
|
|
|
|
this.Frame.SetSize(500, this.AddY);
|
|
this.Frame.Center();
|
|
|
|
this.Textboxes.Add(tb);
|
|
return tb;
|
|
}
|
|
|
|
public void Close() {
|
|
this.Frame.Remove();
|
|
}
|
|
|
|
public void Remove() {
|
|
this.Frame.Remove();
|
|
}
|
|
}
|
|
}
|
|
}
|