Skip to content

Commit 08f0858

Browse files
committed
DUMP: WallOfText
1 parent 3f4ecae commit 08f0858

2 files changed

Lines changed: 280 additions & 0 deletions

File tree

scripts/_dump/WallOfText.asc

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
#define WOT_SPACING 10
2+
#define WOT_SCROLLWIDTH 21
3+
#define WOT_SCROLLARR_SIZE 17
4+
#define WOT_SCROLLARR_VSPACING 0
5+
#define WOT_SCROLLBAR_W 17
6+
#define WOT_SCROLLBAR_VSPACING 1
7+
#define WOT_SCROLL_SPEED 3
8+
#define WOT_SCROLL_DRAWBORDER false
9+
10+
int WOT_ContentMin;
11+
int WOT_ContentMax;
12+
int WOT_ScrollDisplay;
13+
int WOT_ScrollMin;
14+
int WOT_ScrollMax;
15+
int WOT_CurScroll;
16+
DynamicSprite* WOT_SprScroll;
17+
18+
static void WallOfText::Redraw()
19+
{
20+
lblWallOfText.Y = -WOT_CurScroll;
21+
22+
DrawingSurface* ds = WOT_SprScroll.GetDrawingSurface();
23+
ds.Clear(COLOR_TRANSPARENT);
24+
ds.DrawingColor = 0;
25+
if (WOT_SCROLL_DRAWBORDER) {
26+
ds.DrawFrame(0, 0, ds.Width - 1, ds.Height - 1);
27+
}
28+
int arrow_off = (WOT_SCROLLWIDTH - WOT_SCROLLARR_SIZE) / 2;
29+
int tx = arrow_off;
30+
int ty = WOT_SCROLLARR_VSPACING + arrow_off;
31+
ds.DrawTriangle(tx, ty + WOT_SCROLLARR_SIZE - 1, tx + WOT_SCROLLARR_SIZE / 2, ty, tx + WOT_SCROLLARR_SIZE - 1, ty + WOT_SCROLLARR_SIZE - 1);
32+
ty = ds.Height - 1 - WOT_SCROLLARR_VSPACING - ty;
33+
ds.DrawTriangle(tx, ty - WOT_SCROLLARR_SIZE + 1, tx + WOT_SCROLLARR_SIZE / 2, ty, tx + WOT_SCROLLARR_SIZE - 1, ty - WOT_SCROLLARR_SIZE + 1);
34+
35+
int bar_x = (WOT_SCROLLWIDTH - WOT_SCROLLBAR_W) / 2;
36+
int bar_y = WOT_SCROLLARR_VSPACING + arrow_off + WOT_SCROLLARR_SIZE + WOT_SCROLLBAR_VSPACING;
37+
int bar_w = WOT_SCROLLBAR_W;
38+
int bar_h = ds.Height - (WOT_SCROLLARR_VSPACING + arrow_off + WOT_SCROLLARR_SIZE + WOT_SCROLLBAR_VSPACING) * 2;
39+
40+
int r_y1 = FloatToInt(IntToFloat(WOT_CurScroll * bar_h) / IntToFloat(WOT_ContentMax));
41+
int r_y2 = FloatToInt(IntToFloat((WOT_CurScroll + WOT_ScrollDisplay - 1) * bar_h) / IntToFloat(WOT_ContentMax));
42+
ds.DrawRectangle(bar_x, bar_y + r_y1, bar_x + bar_w - 1, bar_y + r_y2);
43+
ds.Release();
44+
}
45+
46+
static void WallOfText::Show(String info, int font, int x, int y, int w, int h)
47+
{
48+
int textw = w - WOT_SPACING - WOT_SCROLLWIDTH;
49+
int texth = GetTextHeight(info, font, textw);
50+
int fonth = GetFontHeight(font);
51+
int lines = texth / fonth;
52+
// Accomodate Label's adding 1 to font's line spacing
53+
texth += (lines - 1);
54+
55+
// HACKS
56+
if (font == eFontTypewriter || font == eFontTypewriter2) {
57+
texth += 4;
58+
}
59+
60+
gBriefing.X = x;
61+
gBriefing.Y = y;
62+
gBriefing.Width = w;
63+
gBriefing.Height = h;
64+
lblWallOfText.X = 0;
65+
lblWallOfText.Y = 0;
66+
lblWallOfText.Width = textw;
67+
lblWallOfText.Height = texth;
68+
lblWallOfText.Font = font;
69+
lblWallOfText.Text = info;
70+
WOT_SprScroll = DynamicSprite.Create(WOT_SCROLLWIDTH, h);
71+
btnWOTScroll.X = w - WOT_SCROLLWIDTH;
72+
btnWOTScroll.Y = 0;
73+
btnWOTScroll.Width = WOT_SCROLLWIDTH;
74+
btnWOTScroll.Height = h;
75+
btnWOTScroll.NormalGraphic = WOT_SprScroll.Graphic;
76+
gBriefing.Visible = true;
77+
78+
WOT_ScrollDisplay = h;
79+
WOT_ScrollMin = 0;
80+
WOT_ContentMax = texth;
81+
if (WOT_ScrollDisplay > WOT_ContentMax) { WOT_ScrollDisplay = WOT_ContentMax; }
82+
WOT_ScrollMax = texth - WOT_ScrollDisplay;
83+
if (WOT_ScrollMax < 0) { WOT_ScrollMax = 0; }
84+
WOT_CurScroll = 0;
85+
86+
WallOfText.Redraw();
87+
}
88+
89+
static void WallOfText::Hide()
90+
{
91+
gBriefing.Visible = false;
92+
btnWOTScroll.NormalGraphic = 0;
93+
if (WOT_SprScroll != null) {
94+
WOT_SprScroll.Delete();
95+
WOT_SprScroll = null;
96+
}
97+
}
98+
99+
#define WOT_BORDER 1
100+
#define WOT_HEADER_PADDING 4
101+
#define WOT_HEADER_SPACING 4
102+
#define WOT_PADDING_LEFT 5
103+
#define WOT_DRAW_BORDER false
104+
DynamicSprite* WOT_Wrapper;
105+
int WOT_TitleHeight;
106+
107+
static void TitledWallOfText::Redraw()
108+
{
109+
DrawingSurface* ds = WOT_Wrapper.GetDrawingSurface();
110+
ds.DrawingColor = 0;
111+
if (WOT_DRAW_BORDER) {
112+
ds.DrawFrame(0, 0, ds.Width - 1, ds.Height - 1);
113+
}
114+
ds.DrawRectangle(0, 0, ds.Width - 1, WOT_TitleHeight - 1);
115+
ds.Release();
116+
}
117+
118+
static void TitledWallOfText::Show(String title, String text, int title_font, int text_font, int x, int y, int w, int h, int bg_col)
119+
{
120+
int font_h = GetFontHeight(title_font);
121+
int title_h = WOT_HEADER_PADDING * 2 + font_h;
122+
int wot_w = w - WOT_BORDER * 2 - WOT_PADDING_LEFT;
123+
int wot_h = h - title_h - WOT_BORDER - WOT_HEADER_SPACING;
124+
int wot_x = x + WOT_BORDER + WOT_PADDING_LEFT;
125+
int wot_y = y + title_h + WOT_HEADER_SPACING;
126+
WallOfText.Show(text, text_font, wot_x, wot_y, wot_w, wot_h);
127+
128+
WOT_TitleHeight = title_h;
129+
lblWOTTitle.X = 0;
130+
lblWOTTitle.Y = (title_h - font_h) / 2;
131+
lblWOTTitle.Width = w;
132+
lblWOTTitle.Height = font_h;
133+
lblWOTTitle.Font = title_font;
134+
lblWOTTitle.Text = title;
135+
WOT_Wrapper = DynamicSprite.Create(w, h);
136+
gGuiWrapper.X = x;
137+
gGuiWrapper.Y = y;
138+
gGuiWrapper.Width = w;
139+
gGuiWrapper.Height = h;
140+
gGuiWrapper.BackgroundGraphic = WOT_Wrapper.Graphic;
141+
gGuiWrapper.Visible = true;
142+
143+
gGuiWrapper.BackgroundColor = bg_col;
144+
if (bg_col == 0) { gGuiWrapper.BorderColor = 0; }
145+
else { gGuiWrapper.BorderColor = Game.GetColorFromRGB(1, 1, 1); }
146+
147+
TitledWallOfText.Redraw();
148+
}
149+
150+
static void TitledWallOfText::Hide()
151+
{
152+
WallOfText.Hide();
153+
gGuiWrapper.Visible = false;
154+
gGuiWrapper.BackgroundGraphic = 0;
155+
if (WOT_Wrapper != null) {
156+
WOT_Wrapper.Delete();
157+
WOT_Wrapper = null;
158+
}
159+
}
160+
161+
162+
#define HINT_PADDING 5
163+
#define HINT_SPACING 5
164+
165+
static void HintGUI::Show(String text, int font, int x, int y, int w, int h, int bg_col)
166+
{
167+
gHint.X = x;
168+
gHint.Y = y;
169+
gHint.Width = w;
170+
gHint.Height = h;
171+
lblHint.X = HINT_PADDING;
172+
lblHint.Y = HINT_PADDING;
173+
lblHint.Width = w - HINT_PADDING * 2;
174+
lblHint.Height = h - HINT_PADDING * 2;
175+
lblHint.Text = text;
176+
lblHint.Font = font;
177+
178+
gHint.BackgroundColor = bg_col;
179+
if (bg_col == 0) { gHint.BorderColor = 0; }
180+
else { gHint.BorderColor = Game.GetColorFromRGB(1, 1, 1); }
181+
182+
gHint.Visible = true;
183+
}
184+
185+
static void HintGUI::Hide()
186+
{
187+
gHint.Visible = false;
188+
}
189+
190+
191+
static void PauseGUI::Show(String text, int x, int y, int w, int h, int bg_col)
192+
{
193+
gGamePause.X = x;
194+
gGamePause.Y = y;
195+
gGamePause.Width = w;
196+
gGamePause.Height = h;
197+
lblGameIsPaused.X = HINT_PADDING;
198+
lblGameIsPaused.Y = HINT_PADDING;
199+
lblGameIsPaused.Width = w - HINT_PADDING * 2;
200+
lblPauseText.X = HINT_PADDING;
201+
lblPauseText.Y = HINT_PADDING + lblGameIsPaused.Height + HINT_SPACING;
202+
lblPauseText.Width = w - HINT_PADDING * 2;
203+
lblPauseText.Height = h - HINT_PADDING - lblPauseText.Y;
204+
lblPauseText.Text = text;
205+
206+
gGamePause.BackgroundColor = bg_col;
207+
if (bg_col == 0) { gGamePause.BorderColor = 0; }
208+
else { gGamePause.BorderColor = Game.GetColorFromRGB(1, 1, 1); }
209+
210+
gGamePause.Visible = true;
211+
PauseGame();
212+
}
213+
214+
static void PauseGUI::Hide()
215+
{
216+
gGamePause.Visible = false;
217+
UnPauseGame();
218+
}
219+
220+
221+
function on_key_press(eKeyCode key)
222+
{
223+
if (gBriefing.Visible) {
224+
switch (key) {
225+
case eKeyUpArrow:
226+
case eKeyDownArrow:
227+
case eKeyHome:
228+
case eKeyEnd:
229+
ClaimEvent(); break;
230+
}
231+
}
232+
}
233+
234+
function repeatedly_execute()
235+
{
236+
if (gBriefing.Visible) {
237+
if (IsKeyPressed(eKeyUpArrow)) {
238+
WOT_CurScroll -= WOT_SCROLL_SPEED; if (WOT_CurScroll < WOT_ScrollMin) { WOT_CurScroll = WOT_ScrollMin; }
239+
WallOfText.Redraw();
240+
} else if (IsKeyPressed(eKeyDownArrow)) {
241+
WOT_CurScroll += WOT_SCROLL_SPEED;
242+
if (WOT_CurScroll > WOT_ScrollMax) { WOT_CurScroll = WOT_ScrollMax; }
243+
WallOfText.Redraw();
244+
} else if (IsKeyPressed(eKeyHome)) {
245+
WOT_CurScroll = WOT_ScrollMin;
246+
WallOfText.Redraw();
247+
} else if (IsKeyPressed(eKeyEnd)) {
248+
WOT_CurScroll = WOT_ScrollMax - WOT_ScrollDisplay;
249+
WallOfText.Redraw();
250+
}
251+
}
252+
}

scripts/_dump/WallOfText.ash

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
struct WallOfText
3+
{
4+
import static void Show(String text, int font, int x, int y, int w, int h);
5+
import static void Hide();
6+
7+
import static void Redraw();
8+
};
9+
10+
struct TitledWallOfText
11+
{
12+
import static void Show(String title, String text, int title_font, int text_font, int x, int y, int w, int h, int bg_col = 0);
13+
import static void Hide();
14+
15+
import static void Redraw();
16+
};
17+
18+
struct HintGUI
19+
{
20+
import static void Show(String text, int font, int x, int y, int w, int h, int bg_col = 0);
21+
import static void Hide();
22+
};
23+
24+
struct PauseGUI
25+
{
26+
import static void Show(String text, int x, int y, int w, int h, int bg_col = 0);
27+
import static void Hide();
28+
};

0 commit comments

Comments
 (0)