Skip to content

Commit

Permalink
fix 40c
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Jun 17, 2024
1 parent e6f4864 commit 87e447d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pets-gd/scenes/rooms/cv-outdoors.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ scale = Vector2(3, -2)

[node name="DebugItem" parent="." index="3" instance=ExtResource("4_vwc65")]
function_name = "debug_skill"
prompt_location = NodePath("Node2D")
position = Vector2(-192, 64)

[node name="Node2D" type="Node2D" parent="DebugItem" index="1"]
position = Vector2(-192, 64)

[node name="House" parent="." index="4" instance=ExtResource("4_vwc65")]
Expand Down
17 changes: 15 additions & 2 deletions pets-lib/src/world/interaction/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ impl InteractionManager {
.get_node_as::<RichTextLabel>("%Action")
.set_text(tr(key));
}

fn move_prompt_to_zone(&mut self, zone: Gd<InteractionZone>) {
let custom_path = zone.bind().get_prompt_location();

let pos = if custom_path.is_empty() {
zone.get_global_position()
} else {
zone.get_node_as::<Node2D>(custom_path)
.get_global_position()
};

self.prompt.set_global_position(pos);
}
}

#[godot_api]
Expand All @@ -78,10 +91,10 @@ impl INode for InteractionManager {
};

// move the prompt to the zone
let prompt_tr_key = zone.bind().prompt_translation_key.clone();
let prompt_tr_key = zone.bind().get_prompt_translation_key();
self.set_prompt_text(prompt_tr_key);
self.prompt.show();
self.prompt.set_global_position(zone.get_global_position());
self.move_prompt_to_zone(zone);
}

fn unhandled_input(&mut self, event: Gd<InputEvent>) {
Expand Down
5 changes: 4 additions & 1 deletion pets-lib/src/world/interaction/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub struct InteractionZone {

#[export]
#[init(default = "INTERACT".into())]
pub prompt_translation_key: GString,
prompt_translation_key: GString,

#[export]
prompt_location: NodePath,
}

#[godot_api]
Expand Down

0 comments on commit 87e447d

Please sign in to comment.