Skip to content

Commit 9e4f77e

Browse files
committed
TypedTextDemo: updated to latest modules
1 parent f429663 commit 9e4f77e

10 files changed

Lines changed: 66 additions & 34 deletions

demos/TypedTextDemo/Game.agf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@
17031703
<Name>TypedText</Name>
17041704
<Description>Module performs continious text typing over time, in typewriter style</Description>
17051705
<Author>Ivan Mogilko</Author>
1706-
<Version>0.7.0</Version>
1706+
<Version>1.0.0</Version>
17071707
<Key>990857917</Key>
17081708
<IsHeader>False</IsHeader>
17091709
</Script>
@@ -1721,7 +1721,7 @@
17211721
<Name>TypedTextDrawing</Name>
17221722
<Description>Module performs rendering of TypedText state to the provided DrawingSurface</Description>
17231723
<Author>Ivan Mogilko</Author>
1724-
<Version>0.7.0</Version>
1724+
<Version>1.0.0</Version>
17251725
<Key>1167863979</Key>
17261726
<IsHeader>False</IsHeader>
17271727
</Script>
@@ -1739,7 +1739,7 @@
17391739
<Name>TypedTextHelper</Name>
17401740
<Description>Collection of helper structs and functions for simplified TypedText usage</Description>
17411741
<Author>Ivan Mogilko</Author>
1742-
<Version>0.7.0</Version>
1742+
<Version>1.0.0</Version>
17431743
<Key>1687351331</Key>
17441744
<IsHeader>False</IsHeader>
17451745
</Script>

demos/TypedTextDemo/GlobalScript.asc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ function on_mouse_click(MouseButton button) // called when a mouse button is cli
3838
}
3939
else if (button == eMouseLeft)
4040
{
41+
#ifdef SCRIPT_API_v340
42+
Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
43+
#endif
44+
#ifndef SCRIPT_API_v340
4145
ProcessClick(mouse.x,mouse.y, mouse.Mode);
46+
#endif
4247
}
4348
else // right-click, so cycle cursor
4449
{

demos/TypedTextDemo/PhylactereTypewriter.asc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
/////////////////////////////////////////////////////////////////////////////
66

77
#ifndef Phylactere_VERSION
8+
9+
#ifdef SCRIPT_API_v350
10+
#define SCREEN_WIDTH Screen.Width
11+
#define SCREEN_HEIGHT Screen.Height
12+
#endif
13+
#ifndef SCRIPT_API_v350
14+
#define SCREEN_WIDTH System.ViewportWidth
15+
#define SCREEN_HEIGHT System.ViewportHeight
16+
#endif
17+
818
Phylactere_Param phylactere;
919
export phylactere;
1020

@@ -178,10 +188,10 @@ void SetupPhylactereTypewriter(Character* ch, String text, int delay)
178188
{
179189
phylactere_char = ch;
180190

181-
int max_width = System.ViewportWidth / 3;
182-
int max_height = System.ViewportHeight / 6;
191+
int max_width = SCREEN_WIDTH / 3;
192+
int max_height = SCREEN_HEIGHT / 6;
183193
int min_pos = 16;
184-
int max_pos = System.ViewportWidth - 16;
194+
int max_pos = SCREEN_WIDTH - 16;
185195

186196
FontType font = Game.SpeechFont;
187197
int text_width = GetTextWidth(text, font);

demos/TypedTextDemo/TypedText.asc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ static String TypedTextUtils::SplitText(String text, int max_width, FontType fon
7272
}
7373
}
7474

75+
// Make sure there's at least 1 line always;
76+
// this is bit inconsistent, but otherwise users may get confused
77+
if (max_lines < 1)
78+
max_lines = 1;
79+
7580
String split_text = "";
7681
int line_count = 0; // number of lines
7782
int line_start = 0; // first character in line
@@ -110,7 +115,7 @@ static String TypedTextUtils::SplitText(String text, int max_width, FontType fon
110115
}
111116

112117
// Move line end to just beyond the last found breakchar, if any
113-
if (last_break_index >= line_start)
118+
if ((line_end < text.Length) && (last_break_index >= line_start))
114119
line_end = last_break_index + 1;
115120

116121
if (split_text.Length > 0)

demos/TypedTextDemo/TypedText.ash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// TERMS OF USE - TypedText MODULE
44
//
5-
// Copyright (c) 2017-present Ivan Mogilko
5+
// Copyright (c) 2017-2024 Ivan Mogilko
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy of
88
// this software and associated documentation files (the "Software"), to deal in
@@ -41,7 +41,7 @@
4141
#ifndef __TYPEDTEXT_MODULE__
4242
#define __TYPEDTEXT_MODULE__
4343

44-
#define TYPEDTEXT_VERSION_00_00_70_00
44+
#define TYPEDTEXT_VERSION_00_01_00_00
4545

4646
/// Maximal allowed random sounds
4747
/// ( because pre-3.4.0 AGS does not support dynamic arrays in structs... :-( )

demos/TypedTextDemo/TypedTextDrawing.asc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Compatibility macros
2+
#ifndef SCRIPT_API_v350
3+
#define eAlignCenter eAlignCentre
4+
#endif
5+
16
//===========================================================================
27
//
38
// TypedTextDrawing::PrecalcText
@@ -33,7 +38,7 @@ void PrecalcText(this TypedTextDrawing*)
3338
String s = this._full.Substring(line_start, line_end - line_start);
3439
//Display(">>> '%s'",s);
3540
int linewidth = GetTextWidth(s, this._font);
36-
if (this._textAlign == eAlignCentre)
41+
if (this._textAlign == eAlignCenter)
3742
this._lineX[line_count] = (this._width - linewidth) / 2;
3843
else
3944
this._lineX[line_count] = this._width - linewidth;
@@ -81,7 +86,7 @@ void RecalcDisplay(this TypedTextDrawing*)
8186
if (this._maxVisLines > TYPEDTEXTDRAWING_MAXLINES)
8287
this._maxVisLines = TYPEDTEXTDRAWING_MAXLINES;
8388

84-
if (this._textAlign == eAlignCentre)
89+
if (this._textAlign == eAlignCenter)
8590
this._lineXDefault = this._width / 2;
8691
else if (this._textAlign == eAlignRight)
8792
this._lineXDefault = this._width - 1;
@@ -362,7 +367,7 @@ void DrawExplicitCaret(this TypedTextDrawing*, DrawingSurface *ds, int x, int y,
362367
}
363368

364369
caret_y = y;
365-
if (align == eAlignCentre)
370+
if (align == eAlignCenter)
366371
caret_x = x - caret_w / 2;
367372
else if (align == eAlignRight)
368373
caret_x = x - caret_w;

demos/TypedTextDemo/TypedTextDrawing.ash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// TERMS OF USE - TypedTextDrawing MODULE
44
//
5-
// Copyright (c) 2017-present Ivan Mogilko
5+
// Copyright (c) 2017-2024 Ivan Mogilko
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy of
88
// this software and associated documentation files (the "Software"), to deal in
@@ -42,7 +42,7 @@
4242
#error TypedTextDrawing requires TypedText module
4343
#endif
4444

45-
#define TYPEDTEXTDRAWING_VERSION_00_00_70_00
45+
#define TYPEDTEXTDRAWING_VERSION_00_01_00_00
4646

4747
// Maximal supported text lines
4848
#define TYPEDTEXTDRAWING_MAXLINES 32

demos/TypedTextDemo/TypedTextHelper.asc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static void TypewriterRunners::Cancel(int id)
400400

401401
//===========================================================================
402402
//
403-
// Button::TypewriterPrint()
403+
// Button::Typewriter()
404404
//
405405
//===========================================================================
406406
int Typewriter(this Button*, String text, BlockingStyle bs, int preset)
@@ -414,7 +414,6 @@ int Typewriter(this Button*, String text, BlockingStyle bs, int preset)
414414
TTButtons[twi].CaretFlashOffTime = Presets[preset].CaretFlashOffTime;
415415
TTButtons[twi].CaretStyle = Presets[preset].CaretStyle;
416416
TTButtons[twi].CaretString = Presets[preset].CaretString;
417-
TTButtons[twi].CaretStyle = Presets[preset].CaretStyle;
418417
TTButtons[twi].TextReadTime = Presets[preset].TextReadTime;
419418
TTButtons[twi].SetRandomTypeSounds(Presets[preset].GetTypeSoundArray(), Presets[preset].TypeSoundCount);
420419
TTButtons[twi].CaretSound = Presets[preset].CaretSound;
@@ -427,7 +426,7 @@ int Typewriter(this Button*, String text, BlockingStyle bs, int preset)
427426

428427
//===========================================================================
429428
//
430-
// Label::TypewriterPrint()
429+
// Label::Typewriter()
431430
//
432431
//===========================================================================
433432
int Typewriter(this Label*, String text, BlockingStyle bs, int preset)
@@ -441,7 +440,6 @@ int Typewriter(this Label*, String text, BlockingStyle bs, int preset)
441440
TTLabels[twi].CaretFlashOffTime = Presets[preset].CaretFlashOffTime;
442441
TTLabels[twi].CaretStyle = Presets[preset].CaretStyle;
443442
TTLabels[twi].CaretString = Presets[preset].CaretString;
444-
TTLabels[twi].CaretStyle = Presets[preset].CaretStyle;
445443
TTLabels[twi].TextReadTime = Presets[preset].TextReadTime;
446444
TTLabels[twi].SetRandomTypeSounds(Presets[preset].GetTypeSoundArray(), Presets[preset].TypeSoundCount);
447445
TTLabels[twi].CaretSound = Presets[preset].CaretSound;
@@ -454,22 +452,23 @@ int Typewriter(this Label*, String text, BlockingStyle bs, int preset)
454452

455453
//===========================================================================
456454
//
457-
// TypewriteOver()
455+
// Overlay::Typewriter()
456+
// TypewriteOnOverlay()
458457
//
459458
//===========================================================================
460459
#ifver 3.4.0
461-
int Typewriter(static Overlay, int x, int y, int color, FontType font, String text, BlockingStyle bs, int preset)
460+
int Typewriter(static Overlay, int x, int y, int width, int color, FontType font, String text, BlockingStyle bs, int preset)
462461
#endif
463462
#ifnver 3.4.0
464-
int TypewriteOnOverlay(int x, int y, int color, FontType font, String text, BlockingStyle bs, int preset)
463+
int TypewriteOnOverlay(int x, int y, int width, int color, FontType font, String text, BlockingStyle bs, int preset)
465464
#endif
466465
{
467466
int twi = CreateTypewriter(eTWOverlay, bs, preset);
468467

469468
// Start typewriter
470469
TTOverlays[twi].X = x;
471470
TTOverlays[twi].Y = y;
472-
TTOverlays[twi].Width = System.ViewportWidth - x * 2;
471+
TTOverlays[twi].Width = width;
473472
TTOverlays[twi].Color = color;
474473
TTOverlays[twi].Font = font;
475474
TTOverlays[twi].TypeDelayMin = Presets[preset].TypeDelayMin;
@@ -479,7 +478,6 @@ int TypewriteOnOverlay(int x, int y, int color, FontType font, String text, Bloc
479478
TTOverlays[twi].CaretFlashOffTime = Presets[preset].CaretFlashOffTime;
480479
TTOverlays[twi].CaretStyle = Presets[preset].CaretStyle;
481480
TTOverlays[twi].CaretString = Presets[preset].CaretString;
482-
TTOverlays[twi].CaretStyle = Presets[preset].CaretStyle;
483481
TTOverlays[twi].TextReadTime = Presets[preset].TextReadTime;
484482
TTOverlays[twi].SetRandomTypeSounds(Presets[preset].GetTypeSoundArray(), Presets[preset].TypeSoundCount);
485483
TTOverlays[twi].CaretSound = Presets[preset].CaretSound;
@@ -493,12 +491,12 @@ int TypewriteOnOverlay(int x, int y, int color, FontType font, String text, Bloc
493491

494492
//===========================================================================
495493
//
496-
// repeatedly_execute()
494+
// repeatedly_execute[_always]()
497495
//
498496
// Runs non-blocking typewriters
499497
//
500498
//===========================================================================
501-
function repeatedly_execute()
499+
function TYPEDTEXTHELPER_UPDATEFUNCTION()
502500
{
503501
int twi = 0;
504502
while (twi < TYPEDTEXTHELPER_MAXTYPEWRITERS)

demos/TypedTextDemo/TypedTextHelper.ash

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// TERMS OF USE - TypedTextHelper MODULE
44
//
5-
// Copyright (c) 2017-present Ivan Mogilko
5+
// Copyright (c) 2017-2024 Ivan Mogilko
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy of
88
// this software and associated documentation files (the "Software"), to deal in
@@ -34,7 +34,7 @@
3434
#error TypedTextHelper requires TypedText module
3535
#endif
3636

37-
#define TYPEDTEXTHELPER_VERSION_00_00_70_00
37+
#define TYPEDTEXTHELPER_VERSION_00_01_00_00
3838

3939
#ifver 3.4.0
4040
#ifdef SCRIPT_COMPAT_v321
@@ -45,6 +45,10 @@
4545
#define TYPEDTEXTHELPER_USEOLDOVERLAY
4646
#endif
4747

48+
/// This defines when to run typedtext updates:
49+
/// may be "repeatedly_execute", "repeatedly_execute_always" or "late_repeatedly_execute_always"
50+
#define TYPEDTEXTHELPER_UPDATEFUNCTION repeatedly_execute_always
51+
4852
/// Maximal supported presets, per each kind
4953
#define TYPEDTEXTHELPER_MAXPRESETS 8
5054
/// Maximal supported active typewriters (handled by TypedTextHelper module)
@@ -81,16 +85,16 @@ struct TypewriterRunners
8185
};
8286

8387
/// Print TypedText as a text on button; returns typewriter ID
84-
import int Typewriter(this Button*, String text, BlockingStyle bs, int preset = 0);
88+
import int Typewriter(this Button*, String text, BlockingStyle bs = eBlock, int preset = 0);
8589
/// Print TypedText as a text on label; returns typewriter ID
86-
import int Typewriter(this Label*, String text, BlockingStyle bs, int preset = 0);
90+
import int Typewriter(this Label*, String text, BlockingStyle bs = eBlock, int preset = 0);
8791
#ifver 3.4.0
8892
/// Print TypedText as a text on created overlay; returns typewriter ID
89-
import int Typewriter(static Overlay, int x, int y, int color, FontType font, String text, BlockingStyle bs, int preset = 0);
90-
#endif
93+
import int Typewriter(static Overlay, int x, int y, int width, int color, FontType font, String text, BlockingStyle bs = eBlock, int preset = 0);
94+
#endif // 3.4.0
9195
#ifdef TYPEDTEXTHELPER_USEOLDOVERLAY
9296
/// Print TypedText as a text on created overlay; returns typewriter ID
93-
import int TypewriteOnOverlay(int x, int y, int color, FontType font, String text, BlockingStyle bs, int preset = 0);
94-
#endif
97+
import int TypewriteOnOverlay(int x, int y, int width, int color, FontType font, String text, BlockingStyle bs = eBlock, int preset = 0);
98+
#endif // TYPEDTEXTHELPER_USEOLDOVERLAY
9599

96100
#endif // __TYPEDTEXTHELPER_MODULE__

demos/TypedTextDemo/room1.asc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// room script file
22

3+
// Compatibility macros
4+
#ifndef SCRIPT_API_v350
5+
#define eAlignCenter eAlignCentre
6+
#endif
7+
38
TypedTextDrawing ttdraw;
49
DynamicSprite *papersprite;
510
int paper_original_pos;
@@ -29,7 +34,7 @@ void StartTypewriter()
2934
ttdraw.Font = eFontFont3;
3035
ttdraw.BkgColor = Game.GetColorFromRGB(255, 255, 255);
3136
ttdraw.TextColor = Game.GetColorFromRGB(66, 44, 123);
32-
ttdraw.TextAlign = eAlignCentre;
37+
ttdraw.TextAlign = eAlignCenter;
3338
ttdraw.CaretSprite = 29;
3439
ttdraw.TypeDelayMin = 4;
3540
ttdraw.TypeDelayMax = 7;

0 commit comments

Comments
 (0)