Skip to content

Commit

Permalink
Engine: refactor passing text_color into display_main()
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Jan 10, 2025
1 parent 1c93e08 commit 2017881
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Common/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
// Stream offset type
typedef int64_t soff_t;

#define fixed_t int32_t // fixed point type
#define color_t int32_t
typedef int32_t fixed_t; // fixed point type
typedef int32_t color_t; // AGS color number type (meaning depends on game's setting)

// TODO: use distinct fixed point class
enum
Expand Down
11 changes: 4 additions & 7 deletions Engine/ac/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2526,11 +2526,8 @@ void _displayspeech(const char*texx, int aschar, int xx, int yy, int widd, int i
return;
}

int textcol = speakingChar->talkcolor;

// if it's 0, it won't be recognised as speech
if (textcol == 0)
textcol = 16;
const color_t text_color = speakingChar->talkcolor;
DisplayTextFlags disp_flags = kDisplayText_Overchar;

Rect ui_view = play.GetUIViewport();
int allowShrink = 0;
Expand Down Expand Up @@ -2843,7 +2840,7 @@ void _displayspeech(const char*texx, int aschar, int xx, int yy, int widd, int i
facetalkchar = &game.chars[aschar];
if (facetalkchar->blinktimer < 0)
facetalkchar->blinktimer = facetalkchar->blinkinterval;
textcol=-textcol;
disp_flags = kDisplayText_TextWindow;
overlayPositionFixed = true;
// Process the first portrait view frame
const int frame_vol = charextra[facetalkchar->index_id].GetFrameSoundVolume(facetalkchar);
Expand Down Expand Up @@ -2911,7 +2908,7 @@ void _displayspeech(const char*texx, int aschar, int xx, int yy, int widd, int i
char_thinking = aschar;

set_our_eip(155);
display_main(tdxp, tdyp, bwidth, texx, nullptr, DISPLAYTEXT_SPEECH, FONT_SPEECH, textcol, isThought, allowShrink, overlayPositionFixed);
display_main(tdxp, tdyp, bwidth, texx, nullptr, DISPLAYTEXT_SPEECH, FONT_SPEECH, text_color, disp_flags, isThought, allowShrink, overlayPositionFixed);
set_our_eip(156);
if ((play.in_conversation > 0) && (game.options[OPT_SPEECHTYPE] == 3))
closeupface = nullptr;
Expand Down
62 changes: 35 additions & 27 deletions Engine/ac/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ class DisplayMessageState : public GameState


// Generates a textual image and returns a disposable bitmap
Bitmap *create_textual_image(const char *text, int asspch, int isThought,
Bitmap *create_textual_image(const char *text, int text_color, DisplayTextFlags disp_flags, int isThought,
int &xx, int &yy, int &adjustedXX, int &adjustedYY, int wii, int usingfont, int allowShrink,
bool &alphaChannel, const TopBarSettings *topbar)
{
//
// Configure the textual image
//

const bool use_speech_textwindow = (asspch < 0) && (game.options[OPT_SPEECHTYPE] >= 2);
const bool use_speech_textwindow = (disp_flags & kDisplayText_TextWindow) && (game.options[OPT_SPEECHTYPE] >= 2);
const bool use_thought_gui = (isThought) && (game.options[OPT_THOUGHTGUI] > 0);

alphaChannel = false;
Expand Down Expand Up @@ -186,7 +186,7 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
// centre text in middle of screen
else if (yy<0) yy = ui_view.GetHeight() / 2 - disp.FullTextHeight / 2 - padding;
// speech, so it wants to be above the character's head
else if (asspch > 0) {
else if (disp_flags & kDisplayText_Overchar) {
yy -= disp.FullTextHeight;
if (yy < 5) yy = 5;
yy = adjust_y_for_guis(yy);
Expand All @@ -195,9 +195,8 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
if (longestline < wii - paddingDoubledScaled) {
// shrink the width of the dialog box to fit the text
int oldWid = wii;
//if ((asspch >= 0) || (allowShrink > 0))
// If it's not speech, or a shrink is allowed, then shrink it
if ((asspch == 0) || (allowShrink > 0))
if ((disp_flags & kDisplayText_StandardBox) || (allowShrink > 0))
wii = longestline + paddingDoubledScaled;

// shift the dialog box right to align it, if necessary
Expand All @@ -218,7 +217,6 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
else if (xx<0) xx = ui_view.GetWidth() / 2 - wii / 2;

const int extraHeight = paddingDoubledScaled;
color_t text_color = MakeColor(15);
const int bmp_width = std::max(2, wii);
const int bmp_height = std::max(2, disp.FullTextHeight + extraHeight);
Bitmap *text_window_ds = BitmapHelper::CreateTransparentBitmap(bmp_width, bmp_height, game.GetColorDepth());
Expand All @@ -234,24 +232,30 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
adjustedXX = xx;
adjustedYY = yy;

if ((strlen(todis) < 1) || (strcmp(todis, " ") == 0) || (wii == 0));
// if it's an empty speech line, don't draw anything
else if (asspch) { //text_color = ds->GetCompatibleColor(12);
if ((strlen(todis) < 1) || (strcmp(todis, " ") == 0) || (wii == 0))
return text_window_ds;

if ((disp_flags & kDisplayText_StandardBox) == 0)
{
// Textual overlay purposed for character speech
int ttxleft = 0, ttxtop = paddingScaled, oriwid = wii - padding * 2;
int drawBackground = 0;

if (use_speech_textwindow) {
if (use_speech_textwindow)
{
drawBackground = 1;
}
else if (use_thought_gui) {
else if (use_thought_gui)
{
// make it treat it as drawing inside a window now
if (asspch > 0)
asspch = -asspch;
disp_flags = (DisplayTextFlags)((disp_flags & ~kDisplayText_LookStyleMask) | kDisplayText_TextWindow);
drawBackground = 1;
}

if (drawBackground)
{
text_color = 15; // use fixed standard color here
draw_text_window_and_bar(&text_window_ds, wantFreeScreenop, topbar, disp,
&ttxleft, &ttxtop, &adjustedXX, &adjustedYY, &wii, &text_color, 0, usingGui);
if (usingGui > 0)
Expand All @@ -262,28 +266,32 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
else if ((ShouldAntiAliasText()) && (game.GetColorDepth() >= 24))
alphaChannel = true;

for (size_t ee = 0; ee<Lines.Count(); ee++) {
//int ttxp=wii/2 - get_text_width_outlined(lines[ee], usingfont)/2;
for (size_t ee = 0; ee<Lines.Count(); ee++)
{
int ttyp = ttxtop + ee * disp.Linespacing;
// asspch < 0 means that it's inside a text box so don't
// centre the text
if (asspch < 0) {
// if it's inside a text box then don't centre the text
if (disp_flags & kDisplayText_TextWindow)
{
if ((usingGui >= 0) &&
((game.options[OPT_SPEECHTYPE] >= 2) || (isThought)))
text_color = text_window_ds->GetCompatibleColor(guis[usingGui].FgColor);
else
text_color = text_window_ds->GetCompatibleColor(-asspch);
text_color = text_window_ds->GetCompatibleColor(text_color);

wouttext_aligned(text_window_ds, ttxleft, ttyp, oriwid, usingfont, text_color, Lines[ee].GetCStr(), play.text_align);
}
else {
text_color = text_window_ds->GetCompatibleColor(asspch);
else
{
text_color = text_window_ds->GetCompatibleColor(text_color);
wouttext_aligned(text_window_ds, ttxleft, ttyp, wii, usingfont, text_color, Lines[ee].GetCStr(), play.speech_text_align);
}
}
}
else {
else
{
// Textual overlay purposed for the standard message box
int xoffs, yoffs, oriwid = wii - padding * 2;
text_color = 15; // use fixed standard color here
draw_text_window_and_bar(&text_window_ds, wantFreeScreenop, topbar, disp, &xoffs, &yoffs, &adjustedXX, &adjustedYY, &wii, &text_color);

if (game.options[OPT_TWCUSTOM] > 0)
Expand All @@ -296,7 +304,6 @@ Bitmap *create_textual_image(const char *text, int asspch, int isThought,
for (size_t ee = 0; ee<Lines.Count(); ee++)
wouttext_aligned(text_window_ds, xoffs, yoffs + ee * disp.Linespacing, oriwid, usingfont, text_color, Lines[ee].GetCStr(), play.text_align);
}

return text_window_ds;
}

Expand Down Expand Up @@ -351,14 +358,14 @@ bool display_check_user_input(int skip)
// pass blocking=2 to create permanent overlay
ScreenOverlay *display_main(int xx, int yy, int wii, const char *text,
const TopBarSettings *topbar, int disp_type, int usingfont,
int asspch, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer)
color_t text_color, DisplayTextFlags disp_flags, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer)
{
//
// Prepare for the message display
//

// AGS 2.x: If the screen is faded out, fade in again when displaying a message box.
if (!asspch && (loaded_game_file_version <= kGameVersion_272))
if ((disp_flags & kDisplayText_StandardBox) && (loaded_game_file_version <= kGameVersion_272))
play.screen_is_faded_out = 0;

// if it's a normal message box and the game was being skipped,
Expand All @@ -378,7 +385,7 @@ ScreenOverlay *display_main(int xx, int yy, int wii, const char *text,
disp_type = DISPLAYTEXT_SPEECH;
}

if ((asspch > 0) && (disp_type < DISPLAYTEXT_NORMALOVERLAY))
if ((disp_flags & kDisplayText_Overchar) && (disp_type < DISPLAYTEXT_NORMALOVERLAY))
{
// update the all_buttons_disabled variable in advance
// of the adjust_x/y_for_guis calls
Expand Down Expand Up @@ -413,7 +420,7 @@ ScreenOverlay *display_main(int xx, int yy, int wii, const char *text,

int adjustedXX, adjustedYY;
bool alphaChannel;
Bitmap *text_window_ds = create_textual_image(text, asspch, isThought,
Bitmap *text_window_ds = create_textual_image(text, text_color, disp_flags, isThought,
xx, yy, adjustedXX, adjustedYY, wii, usingfont, allowShrink, alphaChannel, topbar);

size_t nse = add_screen_overlay(roomlayer, xx, yy, ovrtype, text_window_ds, adjustedXX - xx, adjustedYY - yy, alphaChannel);
Expand Down Expand Up @@ -463,7 +470,8 @@ void display_at(int xx, int yy, int wii, const char *text, const TopBarSettings
// Start voice-over, if requested by the tokens in speech text
try_auto_play_speech(text, text, play.narrator_speech);

display_main(xx, yy, wii, text, topbar, DISPLAYTEXT_MESSAGEBOX, FONT_NORMAL, 0, 0, 0, false);
display_main(xx, yy, wii, text, topbar, DISPLAYTEXT_MESSAGEBOX, FONT_NORMAL,
0 /* color */, kDisplayText_StandardBox, 0 /* not is thought */, 0 /* no shrink */, false /* not fixed pos */, false /* screen layer */);

// Stop any blocking voice-over, if was started by this function
if (play.IsBlockingVoiceSpeech())
Expand Down
28 changes: 18 additions & 10 deletions Engine/ac/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,36 @@ struct DisplayVars
: Linespacing(linespacing), FullTextHeight(fulltxheight) {}
};

// Flags for displaying a text message
enum DisplayTextFlags
{
kDisplayText_None = 0,
kDisplayText_StandardBox = 0x0001,
kDisplayText_TextWindow = 0x0002,
kDisplayText_Overchar = 0x0004,
// Mask for the look style flags
kDisplayText_LookStyleMask = 0x0007,
// TODO: expand with other flag-like options, see isThought, allowShrink etc
};

// Generates a textual image from the given text and parameters;
// see _display_main's comment below for parameters description.
// NOTE: this function treats text as-is, not doing any processing over it.
// TODO: refactor this collection of args into 1-2 structs with params.
Common::Bitmap *create_textual_image(const char *text, int asspch, int isThought,
Common::Bitmap *create_textual_image(const char *text, int text_color, DisplayTextFlags disp_flags, int isThought,
int &xx, int &yy, int &adjustedXX, int &adjustedYY, int wii, int usingfont, int allowShrink,
bool &alphaChannel, const TopBarSettings *topbar);
// Creates a textual overlay using the given parameters;
// Pass yy = -1 to find Y co-ord automatically
// allowShrink = 0 for none, 1 for leftwards, 2 for rightwards
// pass blocking=2 to create permanent overlay
// asspch has several meanings, which affect how the message is positioned
// == 0 - standard display box
// != 0 - text color for a speech or a regular textual overlay, where
// < 0 - use text window if applicable
// > 0 - suppose it's a classic LA-style speech above character's head
// Pass yy = -1 to find Y co-ord automatically;
// allowShrink = 0 for none, 1 for leftwards, 2 for rightwards;
// pass blocking=2 to create permanent overlay;
// disp_flags define how the message should look or be positioned (see DisplayTextFlags);
// NOTE: this function treats the text as-is; it assumes that any processing
// (translation, parsing voice token) was done prior to its call.
// TODO: refactor this collection of args into few args + 1-2 structs with extended params.
ScreenOverlay *display_main(int xx, int yy, int wii, const char *text,
const TopBarSettings *topbar, int disp_type, int usingfont,
int asspch, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer = false);
color_t text_color, DisplayTextFlags disp_flags, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer = false);
// Displays a standard blocking message box at a given position
void display_at(int xx, int yy, int wii, const char *text, const TopBarSettings *topbar);
// Cleans up display message state
Expand Down
8 changes: 4 additions & 4 deletions Engine/ac/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ void Overlay_SetText(ScreenOverlay &over, int x, int y, int width, int fontid, i
// Recreate overlay image
int dummy_x = x, dummy_y = y, adj_x = x, adj_y = y;
bool has_alpha = false;
// NOTE: we pass text_color negated to let optionally use textwindow (if applicable)
// this is a generic ugliness of _display_main args, need to refactor later.
Bitmap *image = create_textual_image(draw_text, -text_color, 0, dummy_x, dummy_y, adj_x, adj_y,
Bitmap *image = create_textual_image(draw_text, text_color, kDisplayText_TextWindow,
0 /* not thought */, dummy_x, dummy_y, adj_x, adj_y,
width, fontid, allow_shrink, has_alpha, nullptr);

// Update overlay properties
Expand Down Expand Up @@ -245,7 +244,8 @@ ScreenOverlay *Overlay_CreateTextCore(bool room_layer, int x, int y, int width,
if (text_color == 0) text_color = 16;
// Skip a voice-over token, if present
const char *draw_text = skip_voiceover_token(text);
return display_main(x, y, width, draw_text, nullptr, disp_type, font, -text_color, 0, allow_shrink, false, room_layer);
return display_main(x, y, width, draw_text, nullptr, disp_type, font, text_color, kDisplayText_TextWindow,
0 /* not thought*/, allow_shrink, false, room_layer);
}

ScriptOverlay* Overlay_CreateGraphicalImpl(bool room_layer, int x, int y, int slot, bool transparent, bool clone)
Expand Down

0 comments on commit 2017881

Please sign in to comment.