Skip to content

Commit

Permalink
fix errors for trying to tween main menu stuff after its removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed May 12, 2024
1 parent 6834a0c commit 8d149e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pets-lib/src/dialogue/dbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ impl DialogBox {
self.set_choice_label_focus_directions();
}

/// makes it so that all the choice labels refer to each
/// other in their focus neighbor properties
pub fn set_choice_label_focus_directions(&self) {
let nodes = self.choice_nodes();
let Some(mut previous) = nodes.last().map(Gd::clone) else {
Expand Down
23 changes: 17 additions & 6 deletions pets-lib/src/util/choices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ impl ChoiceAgent {
pub fn focus_first(&mut self) {
let mut choices = self.choice_labels();
let guard = self.base_mut();

godot_print!("deferred grab focus on {}", choices[0].get_name());
choices[0].call_deferred("grab_focus".into(), &[]);

drop(guard);
}

Expand Down Expand Up @@ -209,6 +212,11 @@ fn _tween_choice(is_picked: bool, node: Gd<Control>) {
let on_off = if is_picked { "on" } else { "off" };
godot_print!("tweening {} {}", node.get_name(), on_off);

if !node.is_inside_tree() {
godot_print!("node to tween is not inside tree, returning");
return;
}

let node = node.try_cast::<RichTextLabel>().unwrap_or_else(|node| {
godot_print!("getting text inside container");
node.get_node_as("RichTextLabel")
Expand All @@ -227,26 +235,29 @@ fn _tween_choice(is_picked: bool, node: Gd<Control>) {
};

// tween x
tween(
let t1 = tween(
node.clone().upcast(),
"position:x",
None,
target_x,
CHOICE_TWEEN_TIME,
CHOICE_TWEEN_TRANS,
)
.unwrap();
);

// tween color
tween(
let t2 = tween(
node.clone().upcast(),
"theme_override_colors/default_color",
None,
target_col,
CHOICE_TWEEN_TIME,
CHOICE_TWEEN_TRANS,
)
.unwrap();
);

// if either errored...
if t1.and(t2).is_err() {
godot_warn!("failed to tween choice!");
}

bbcode_toggle(node, CHOICE_WAVE_BBCODE, is_picked);
}

0 comments on commit 8d149e5

Please sign in to comment.