From a94aef5e58935c07a568ae95475aca0ef63e977b Mon Sep 17 00:00:00 2001 From: Alula Date: Thu, 10 Sep 2020 14:34:42 +0200 Subject: [PATCH] add , pub textbox_rect_yes_no: Rect, pub textbox_rect_cursor: Rect, + pub get_item_top_left: Rect, + pub get_item_bottom_left: Rect, + pub get_item_top_right: Rect, + pub get_item_right: Rect, + pub get_item_bottom_right: Rect, } #[derive(Debug)] @@ -845,6 +850,11 @@ 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 }, + get_item_top_left: Rect { left: 0, top: 0, right: 72, bottom: 16 }, + get_item_bottom_left: Rect { left: 0, top: 8, right: 72, bottom: 24 }, + get_item_top_right: Rect { left: 240, top: 0, right: 244, bottom: 8 }, + get_item_right: Rect { left: 240, top: 8, right: 244, bottom: 16 }, + get_item_bottom_right: Rect { left: 240, top: 16, right: 244, bottom: 24 }, }, font_path: str!("builtin/builtin_font.fnt"), font_scale: 1.0, diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index 4729e0e..77e70ee 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -331,6 +331,21 @@ impl GameScene { batch.add_rect(left_pos, top_pos + 56.0, &state.constants.textscript.textbox_rect_bottom); } + if state.textscript_vm.item != 0 { + batch.add_rect((state.canvas_size.0 / 2.0 - 40.0).floor(), state.canvas_size.1 - 112.0, + &state.constants.textscript.get_item_top_left); + batch.add_rect((state.canvas_size.0 / 2.0 - 40.0).floor(), state.canvas_size.1 - 96.0, + &state.constants.textscript.get_item_bottom_left); + batch.add_rect((state.canvas_size.0 / 2.0 + 32.0).floor(), state.canvas_size.1 - 112.0, + &state.constants.textscript.get_item_top_right); + batch.add_rect((state.canvas_size.0 / 2.0 + 32.0).floor(), state.canvas_size.1 - 104.0, + &state.constants.textscript.get_item_right); + batch.add_rect((state.canvas_size.0 / 2.0 + 32.0).floor(), state.canvas_size.1 - 96.0, + &state.constants.textscript.get_item_right); + batch.add_rect((state.canvas_size.0 / 2.0 + 32.0).floor(), state.canvas_size.1 - 88.0, + &state.constants.textscript.get_item_bottom_right); + } + if let TextScriptExecutionState::WaitConfirmation(_, _, _, wait, selection) = state.textscript_vm.state { let pos_y = if wait > 14 { state.canvas_size.1 - 96.0 - (wait as f32 - 2.0) * 4.0 @@ -365,6 +380,34 @@ impl GameScene { batch.draw(ctx)?; } + if state.textscript_vm.item != 0 { + let mut rect = Rect::::new(0, 0, 0, 0); + + if state.textscript_vm.item < 1000 { + let item_id = state.textscript_vm.item as usize; + + rect.left = (item_id % 16) * 16; + rect.right = rect.left + 16; + rect.top = (item_id / 16) * 16; + rect.bottom = rect.top + 16; + + let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "ArmsImage")?; + batch.add_rect((state.canvas_size.0 / 2.0 - 12.0).floor(), state.canvas_size.1 - 104.0, &rect); + batch.draw(ctx)?; + } else { + let item_id = state.textscript_vm.item as usize - 1000; + + rect.left = (item_id % 8) * 32; + rect.right = rect.left + 32; + rect.top = (item_id / 8) * 16; + rect.bottom = rect.top + 16; + + let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "ItemImage")?; + batch.add_rect((state.canvas_size.0 / 2.0 - 20.0).floor(), state.canvas_size.1 - 104.0, &rect); + batch.draw(ctx)?; + } + } + let text_offset = if state.textscript_vm.face == 0 { 0.0 } else { 56.0 }; // todo: proper text rendering diff --git a/src/scene/loading_scene.rs b/src/scene/loading_scene.rs index 0a14584..330845c 100644 --- a/src/scene/loading_scene.rs +++ b/src/scene/loading_scene.rs @@ -29,7 +29,7 @@ impl Scene for LoadingScene { state.npc_table = npc_table; let head_script = TextScript::load_from(filesystem::open(ctx, [&state.base_path, "/Head.tsc"].join(""))?)?; state.textscript_vm.set_global_script(head_script); - + let mut next_scene = GameScene::new(state, ctx, 13)?; next_scene.player.x = 10 * 16 * 0x200; next_scene.player.y = 8 * 16 * 0x200;