Skip to content

Commit

Permalink
fix say textbox going outside the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Apr 21, 2024
1 parent 8d6c80f commit 62ec25a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions fancy_demo/fancy.asc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ int _get_character_height(Character* c)
return ((Game.SpriteHeight[vf.Graphic] + c.z) * c.Scaling)/100;
}

int _adjust_speech_y(int y)
int _adjust_speech_y(int y) // meant to avoid occluding player head if possible
{
int y_limit = _clamp_i(_say_char_head_y-_sayspr.Height, Screen.Height, _sayspr.Height + 5);
return _clamp_i(y, y_limit, 0);
return _clamp_i(y, _clamp_i(_say_char_head_y-_sayspr.Height, Screen.Height, _sayspr.Height + 5), 0);
}

int _adjust_speech_x(int x, int width) // avoids text going outside screen
{
return _clamp_i(_clamp_i(x + width, Screen.Width-5, 5) - width, Screen.Width-5, 5);
}

void _fancy_say_set_overlay(Overlay* curSpeech)
{
curSpeech.Graphic = _sayspr.Graphic;
curSpeech.Y = _adjust_speech_y(curSpeech.Y);
curSpeech.X = _adjust_speech_x(curSpeech.X, curSpeech.Width);
}

int _get_character_top_head_y(Character* c)
Expand Down Expand Up @@ -1169,17 +1180,15 @@ void _fancy_say_update()
if(!_sayft._is_typed_text)
{
_sayspr = _sayft.CreateTextBoxSprite();
curSpeech.Y = _adjust_speech_y(curSpeech.Y);
curSpeech.Graphic = _sayspr.Graphic;
_fancy_say_set_overlay(curSpeech);
}
}

if(_say_started && _sayft._is_typed_text)
{
_sayft.Tick();
_sayspr = _sayft.CreateTypedSprite();
curSpeech.Graphic = _sayspr.Graphic;
curSpeech.Y = _adjust_speech_y(curSpeech.Y);
_fancy_say_set_overlay(curSpeech);
_say_ovr_tmp = Overlay.CreateGraphical(curSpeech.X, curSpeech.Y, _sayspr.Graphic, true, true);
_say_ovr_tmp.Transparency = 100;
}
Expand Down

0 comments on commit 62ec25a

Please sign in to comment.