From da4c9976feb8fe6cb5224f4f5e9828596b9912ae Mon Sep 17 00:00:00 2001 From: e Date: Sun, 21 Apr 2024 12:53:31 -0300 Subject: [PATCH] more code duplication reduction --- fancy_demo/fancy.asc | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/fancy_demo/fancy.asc b/fancy_demo/fancy.asc index 64b3bb4..80fdff4 100644 --- a/fancy_demo/fancy.asc +++ b/fancy_demo/fancy.asc @@ -621,6 +621,13 @@ int _get_speech_width(Character* c, int width) return width; } +DynamicSprite* _create_textbox_from_text_spr(DynamicSprite* text_spr, Fancy9Piece* f9p) +{ + if(f9p == null) + return text_spr; + return _create_textbox_from_textgraphic(f9p, text_spr.Width, text_spr.Height, text_spr.Graphic); +} + DynamicSprite* _create_text_sprite(FancyTextToken* tk_arr[], int tk_count, FancyState* fs, String text, int typed_token_len, int width, FancyConfig* cfg) { DynamicSprite* text_spr = DynamicSprite.Create(fs.BoxWidth, fs.BoxHeight, true); @@ -1044,20 +1051,8 @@ DynamicSprite* FancyTextBox::CreateTextBoxSprite() if(this._cfg == null) this._cfg = _default_cfg.Clone(); DynamicSprite* text_spr = _create_text_sprite(this._tk_arr, this._tk_count, this._fs, this._text, -1, this._width, this._cfg); - - if(this._f9p == null) return text_spr; - - int w = text_spr.Width; - int h = text_spr.Height; - DynamicSprite* box_spr = _create_textbox(w, h, this._f9p); - DrawingSurface* surf = box_spr.GetDrawingSurface(); - - surf.DrawImage(this._f9p.BorderLeft, this._f9p.BorderTop, text_spr.Graphic); - surf.Release(); - - text_spr.Delete(); - return box_spr; + return _create_textbox_from_text_spr(text_spr, this._f9p); } DynamicSprite* FancyTypedText::CreateTypedSprite() @@ -1067,19 +1062,7 @@ DynamicSprite* FancyTypedText::CreateTypedSprite() DynamicSprite* text_spr = _create_text_sprite(this._tk_arr, this._typed_token_count, this._fs, this._text, this._typed_token_len, this._width, this._cfg); - if(this._f9p == null) return text_spr; - - int w = text_spr.Width; - int h = text_spr.Height; - - DynamicSprite* box_spr = _create_textbox(w, h, this._f9p); - DrawingSurface* surf = box_spr.GetDrawingSurface(); - - surf.DrawImage(this._f9p.BorderLeft, this._f9p.BorderTop, text_spr.Graphic); - surf.Release(); - - text_spr.Delete(); - return box_spr; + return _create_textbox_from_text_spr(text_spr, this._f9p); } bool get_IsTextBeingTyped(this FancyTypedText*)