diff --git a/src/bmfont_renderer.rs b/src/bmfont_renderer.rs index 5ff6ac7..a227cc0 100644 --- a/src/bmfont_renderer.rs +++ b/src/bmfont_renderer.rs @@ -267,7 +267,11 @@ impl BMFontRenderer { for chr in iter { if let Some(glyph) = self.font.chars.get(&chr) { if let Some(rect) = rect_map.get(&chr) { - sprite_rects.push((offset_x, self.line_height(constants) - rect.height() as f32 / 2.0, rect)); + sprite_rects.push(( + offset_x, + y + self.line_height(constants) / 2.0 - rect.height() as f32 / 2.0, + rect, + )); offset_x += rect.width() as f32; } else { batch.add_rect_scaled_tinted( @@ -308,7 +312,11 @@ impl BMFontRenderer { for (chr, glyph) in chars.iter() { if let Some(rect) = rect_map.get(&chr) { - sprite_rects.push((offset_x, self.line_height(constants) - rect.height() as f32 / 2.0, rect)); + sprite_rects.push(( + offset_x, + y + self.line_height(constants) / 2.0 - rect.height() as f32 / 2.0, + rect, + )); offset_x += rect.width() as f32; } else { if glyph.page == page { diff --git a/src/components/text_boxes.rs b/src/components/text_boxes.rs index 8fb08be..505a57a 100644 --- a/src/components/text_boxes.rs +++ b/src/components/text_boxes.rs @@ -225,21 +225,25 @@ impl GameEntity<()> for TextBoxes { for (idx, line) in lines.iter().enumerate() { if !line.is_empty() { if state.constants.textscript.text_shadow { - state.font.draw_text_with_shadow( + state.font.draw_text_with_shadow_and_rects( line.iter().copied(), left_pos + text_offset + 14.0, top_pos + 10.0 + idx as f32 * 16.0 - y_offset, &state.constants, &mut state.texture_set, + &state.textscript_vm.substitution_rect_map, + Some("TextBox".into()), ctx, )?; } else { - state.font.draw_text( + state.font.draw_text_with_rects( line.iter().copied(), left_pos + text_offset + 14.0, top_pos + 10.0 + idx as f32 * 16.0 - y_offset, &state.constants, &mut state.texture_set, + &state.textscript_vm.substitution_rect_map, + Some("TextBox".into()), ctx, )?; } @@ -251,15 +255,27 @@ impl GameEntity<()> for TextBoxes { if tick > 10 { let (mut x, y) = match state.textscript_vm.current_line { TextScriptLine::Line1 => ( - state.font.text_width(state.textscript_vm.line_1.iter().copied(), &state.constants), + state.font.text_width_with_rects( + state.textscript_vm.line_1.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ), top_pos + 10.0, ), TextScriptLine::Line2 => ( - state.font.text_width(state.textscript_vm.line_2.iter().copied(), &state.constants), + state.font.text_width_with_rects( + state.textscript_vm.line_2.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ), top_pos + 10.0 + 16.0, ), TextScriptLine::Line3 => ( - state.font.text_width(state.textscript_vm.line_3.iter().copied(), &state.constants), + state.font.text_width_with_rects( + state.textscript_vm.line_3.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ), top_pos + 10.0 + 32.0, ), }; diff --git a/src/engine_constants/mod.rs b/src/engine_constants/mod.rs index cf3c482..049cc4f 100644 --- a/src/engine_constants/mod.rs +++ b/src/engine_constants/mod.rs @@ -222,6 +222,7 @@ pub struct TextScriptConsts { pub textbox_rect_bottom: Rect, pub textbox_rect_yes_no: Rect, pub textbox_rect_cursor: Rect, + pub textbox_item_marker_rect: Rect, pub inventory_rect_top: Rect, pub inventory_rect_middle: Rect, pub inventory_rect_bottom: Rect, @@ -1486,6 +1487,7 @@ impl EngineConstants { textbox_rect_bottom: Rect { left: 0, top: 16, right: 244, bottom: 24 }, textbox_rect_yes_no: Rect { left: 152, top: 48, right: 244, bottom: 80 }, textbox_rect_cursor: Rect { left: 112, top: 88, right: 128, bottom: 104 }, + textbox_item_marker_rect: Rect { left: 64, top: 48, right: 70, bottom: 54 }, inventory_rect_top: Rect { left: 0, top: 0, right: 244, bottom: 8 }, inventory_rect_middle: Rect { left: 0, top: 8, right: 244, bottom: 16 }, inventory_rect_bottom: Rect { left: 0, top: 16, right: 244, bottom: 24 }, diff --git a/src/scripting/tsc/text_script.rs b/src/scripting/tsc/text_script.rs index ab59503..9f81e5c 100644 --- a/src/scripting/tsc/text_script.rs +++ b/src/scripting/tsc/text_script.rs @@ -133,6 +133,7 @@ pub struct TextScriptVM { pub current_illustration: Option, pub illustration_state: IllustrationState, prev_char: char, + pub substitution_rect_map: HashMap>, } pub struct Scripts { @@ -199,6 +200,7 @@ impl TextScriptVM { current_illustration: None, illustration_state: IllustrationState::Hidden, prev_char: '\x00', + substitution_rect_map: HashMap::new(), } } @@ -234,6 +236,10 @@ impl TextScriptVM { scripts.stage_select_script = script; } + pub fn set_substitution_rect_map(&mut self, rect_map: HashMap>) { + self.substitution_rect_map = rect_map; + } + pub fn reset(&mut self) { self.state = TextScriptExecutionState::Ended; self.flags.0 = 0; @@ -347,8 +353,11 @@ impl TextScriptVM { state.textscript_vm.prev_char = chr; state.textscript_vm.line_1.push(chr); - let text_len = - state.font.text_width(state.textscript_vm.line_1.iter().copied(), &state.constants); + let text_len = state.font.text_width_with_rects( + state.textscript_vm.line_1.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ); if text_len >= 284.0 { state.textscript_vm.current_line = TextScriptLine::Line2; } @@ -357,8 +366,11 @@ impl TextScriptVM { state.textscript_vm.prev_char = chr; state.textscript_vm.line_2.push(chr); - let text_len = - state.font.text_width(state.textscript_vm.line_2.iter().copied(), &state.constants); + let text_len = state.font.text_width_with_rects( + state.textscript_vm.line_2.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ); if text_len >= 284.0 { state.textscript_vm.current_line = TextScriptLine::Line3; } @@ -367,8 +379,11 @@ impl TextScriptVM { state.textscript_vm.prev_char = chr; state.textscript_vm.line_3.push(chr); - let text_len = - state.font.text_width(state.textscript_vm.line_3.iter().copied(), &state.constants); + let text_len = state.font.text_width_with_rects( + state.textscript_vm.line_3.iter().copied(), + &state.textscript_vm.substitution_rect_map, + &state.constants, + ); if text_len >= 284.0 { new_line = true; } diff --git a/src/shared_game_state.rs b/src/shared_game_state.rs index d0dc4dc..3254cae 100644 --- a/src/shared_game_state.rs +++ b/src/shared_game_state.rs @@ -522,6 +522,9 @@ impl SharedGameState { let stage_select_script = TextScript::load_from(stage_select_tsc, &self.constants)?; self.textscript_vm.set_stage_select_script(stage_select_script); + let substitution_rect_map = HashMap::from([('=', self.constants.textscript.textbox_item_marker_rect)]); + self.textscript_vm.set_substitution_rect_map(substitution_rect_map); + let credit_tsc = filesystem::open_find(ctx, &self.constants.base_paths, "Credit.tsc")?; let credit_script = CreditScript::load_from(credit_tsc, &self.constants)?; self.creditscript_vm.set_script(credit_script);