1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | |
---|
7 | using Microsoft.Xna.Framework; |
---|
8 | using Microsoft.Xna.Framework.Graphics; |
---|
9 | |
---|
10 | public class DialogBox |
---|
11 | { |
---|
12 | List<BetterLabel> Rows = new List<BetterLabel>(); |
---|
13 | int rowCount = 0; |
---|
14 | public int MaxRowCount = 4; |
---|
15 | //public float LineSpacing = -5.0f; |
---|
16 | public double LineSpacing = 30; |
---|
17 | |
---|
18 | public BetterLabel TextLabelBase { get; set; } |
---|
19 | |
---|
20 | public Vector TextPosition { get; set; } |
---|
21 | public bool DrawTextBox = true; |
---|
22 | public bool DrawIconBox = true; |
---|
23 | public Image Icon; |
---|
24 | public Widget TextBox { get; set; } |
---|
25 | public Widget IconBox { get; set; } |
---|
26 | Widget _Icon { get; set; } |
---|
27 | |
---|
28 | public event Action OnExiting; |
---|
29 | public bool DestroyOnExit = true; |
---|
30 | public bool LoadControls = true; |
---|
31 | |
---|
32 | public DialogBox() |
---|
33 | { |
---|
34 | TextPosition = new Vector(-455, -224); |
---|
35 | |
---|
36 | TextBox = new Widget(Images.HUD.DialogBox.Width, Images.HUD.DialogBox.Height); |
---|
37 | TextBox.Image = Images.HUD.DialogBox; |
---|
38 | TextBox.Position = new Vector(-0.5, -265.5); |
---|
39 | |
---|
40 | IconBox = new Widget(Images.HUD.IconBox.Width, Images.HUD.IconBox.Height); |
---|
41 | IconBox.Image = Images.HUD.IconBox; |
---|
42 | IconBox.Position = new Vector(-396, -113); |
---|
43 | } |
---|
44 | |
---|
45 | public void WriteRow(string text) |
---|
46 | { |
---|
47 | if (rowCount < MaxRowCount) |
---|
48 | { |
---|
49 | BetterLabel TextRow = new BetterLabel(TextLabelBase.CurrentFont, Vector2.Zero, text, TextLabelBase.Alignment); |
---|
50 | TextRow.DrawTextBorders = TextLabelBase.DrawTextBorders; |
---|
51 | TextRow.BorderType = TextLabelBase.BorderType; |
---|
52 | TextRow.BorderSize = TextLabelBase.BorderSize; |
---|
53 | TextRow.TextColor = TextLabelBase.TextColor; |
---|
54 | TextRow.TextBorderColor = TextLabelBase.TextBorderColor; |
---|
55 | |
---|
56 | Rows.Add(TextRow); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | public void SetTextBase(SpriteFont Font, TextAlignment Alignment) |
---|
61 | { |
---|
62 | TextLabelBase = new BetterLabel(Font, Vector2.Zero, "null", Alignment); |
---|
63 | TextLabelBase.TextColor = Microsoft.Xna.Framework.Color.White; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | public void DrawDialogBox() |
---|
68 | { |
---|
69 | JRPG.Game.ClearControls(); |
---|
70 | |
---|
71 | if(DrawTextBox) JRPG.Game.Add(TextBox); |
---|
72 | if (DrawIconBox) JRPG.Game.Add(IconBox); |
---|
73 | if (Icon != null) |
---|
74 | { |
---|
75 | _Icon = new Widget(Icon.Width, Icon.Height); |
---|
76 | _Icon.Position = IconBox.Position; |
---|
77 | _Icon.Image = Icon; |
---|
78 | JRPG.Game.Add(_Icon); |
---|
79 | } |
---|
80 | |
---|
81 | for (int i = 0; i < Rows.Count; i++) |
---|
82 | { |
---|
83 | Rows[i].FontPosition = VectorConverter.JypeliVectorToXNA(TextPosition + (new Vector(0, -LineSpacing) * i)); |
---|
84 | JRPG.Game.Add(Rows[i]); |
---|
85 | } |
---|
86 | |
---|
87 | LoadDialogBoxControlsKeyboard(); |
---|
88 | LoadDialogBoxControlsXboxController(); |
---|
89 | } |
---|
90 | |
---|
91 | void LoadDialogBoxControlsKeyboard() |
---|
92 | { |
---|
93 | JRPG.Game.Keyboard.Listen(Key.Z, ButtonState.Pressed, Exit, null); |
---|
94 | JRPG.Game.Keyboard.Listen(Key.X, ButtonState.Pressed, Exit, null); |
---|
95 | JRPG.Game.Keyboard.Listen(Key.Enter, ButtonState.Pressed, Exit, null); |
---|
96 | JRPG.Game.Keyboard.Listen(Key.Space, ButtonState.Pressed, Exit, null); |
---|
97 | JRPG.Game.Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, null); |
---|
98 | } |
---|
99 | void LoadDialogBoxControlsXboxController() |
---|
100 | { |
---|
101 | JRPG.Game.ControllerOne.Listen(Button.A, ButtonState.Pressed, Exit, null); |
---|
102 | JRPG.Game.ControllerOne.Listen(Button.B, ButtonState.Pressed, Exit, null); |
---|
103 | JRPG.Game.ControllerOne.Listen(Button.Start, ButtonState.Pressed, Exit, null); |
---|
104 | JRPG.Game.ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, null); |
---|
105 | } |
---|
106 | |
---|
107 | void Exit() |
---|
108 | { |
---|
109 | if (LoadControls) |
---|
110 | { |
---|
111 | JRPG.Game.LoadOWControlsKeyboard(); |
---|
112 | JRPG.Game.LoadOWControlsXboxController(); |
---|
113 | } |
---|
114 | |
---|
115 | if (OnExiting != null) OnExiting.Invoke(); |
---|
116 | |
---|
117 | if(DestroyOnExit) Destroy(); |
---|
118 | } |
---|
119 | |
---|
120 | public void Destroy() |
---|
121 | { |
---|
122 | TextBox.Destroy(); |
---|
123 | IconBox.Destroy(); |
---|
124 | if (_Icon != null) _Icon.Destroy(); |
---|
125 | |
---|
126 | for (int i = 0; i < Rows.Count; i++) |
---|
127 | { |
---|
128 | Rows[i].Destroy(); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|