Skip to content

Commit

Permalink
Merge pull request #49 from Lamby777/dialog-choices
Browse files Browse the repository at this point in the history
Dialog box choice stuff (mega-PR lol)
  • Loading branch information
Lamby777 authored Jan 17, 2024
2 parents e8686f4 + 075d0c4 commit 04caf31
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 399 deletions.
7 changes: 4 additions & 3 deletions pets-gd/scenes/dialogchoice.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[gd_scene format=3 uid="uid://ckyanktf41aox"]

[node name="DChoice" type="DChoice"]
offset_right = 40.0
offset_bottom = 40.0
offset_right = 200.0
offset_bottom = 200.0

[node name="Label" type="RichTextLabel" parent="."]
layout_mode = 2
size_flags_vertical = 8
theme_override_colors/default_color = Color(0.803922, 0.839216, 0.956863, 1)
theme_override_font_sizes/normal_font_size = 56
bbcode_enabled = true
text = "Amogus"
text = "Sample Text Words Words More Words"
fit_content = true
scroll_active = false
autowrap_mode = 0
48 changes: 32 additions & 16 deletions pets-lib/src/battle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct BattleEngine {
#[base]
node: Base<Node2D>,

choices: ChoiceList<BattleChoice, RichTextLabel>,
choices: Wrapped<(BattleChoice, Gd<RichTextLabel>)>,
state: BattleState,
}

Expand Down Expand Up @@ -96,26 +96,42 @@ fn tween_choice_to(is_picked: bool, node: Gd<RichTextLabel>) {
#[godot_api]
impl INode2D for BattleEngine {
fn ready(&mut self) {
use BattleChoice::*;

// The node that contains the text labels below
let cont = self.base().get_node_as("%Choices");

self.choices = ChoiceList::from_children_of(cont, tween_choice_to, |choice| {
// call different functions depending on the choice
match choice {
Attack => todo!(),
Skills => todo!(),
Items => todo!(),
Run => {
// TODO roll, don't always succeed
change_scene!("world");
}
}
});
use crate::wrapped::from_children_of;
self.choices = from_children_of(cont);
}

fn process(&mut self, _delta: f64) {
self.choices.process_input();
use crate::wrapped::*;
let action = process_input(&mut self.choices, ListDir::TopToBottom);

use ListOperation::*;
match action {
Walk(old, (_, new_node)) => {
if let Some((_, old_node)) = old {
tween_choice_to(false, old_node.clone());
}

tween_choice_to(true, new_node.clone());
}

Pick(_, (choice, _)) => {
// call different functions depending on the choice
use BattleChoice::*;
match choice {
Attack => todo!(),
Skills => todo!(),
Items => todo!(),
Run => {
// TODO roll, don't always succeed
change_scene!("world");
}
}
}

Nothing => {}
}
}
}
4 changes: 2 additions & 2 deletions pets-lib/src/battle/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BattleIcon {
self.velocity *= self.friction;

// check inputs
let mut input_vector = Vector2::new(0.0, 0.0);
let mut input_vector = Vector2::ZERO;
for (k, v) in BATTLE_DIRECTIONS.iter() {
if input.is_action_pressed(k.clone()) {
input_vector += *v;
Expand Down Expand Up @@ -79,7 +79,7 @@ impl INode2D for BattleIcon {
speed: 400.0,
acceleration: 80.0,
friction: 0.96,
velocity: Vector2::new(0.0, 0.0),
velocity: Vector2::ZERO,
}
}

Expand Down
112 changes: 0 additions & 112 deletions pets-lib/src/choicelist.rs

This file was deleted.

13 changes: 8 additions & 5 deletions pets-lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! All the "important" constants for configuring
//! how the game works. Tinker all you want. Go nuts. :)
//!
use godot::engine::tween::TransitionType;

pub mod playercb {
// Movement physics stuff
Expand All @@ -14,7 +15,7 @@ pub mod playercb {
}

pub mod dialogue {
use godot::engine::tween::TransitionType;
use super::*;

pub const NARRATOR_DISPLAYNAME: &str = "";
pub const UNKNOWN_DISPLAYNAME: &str = "???";
Expand All @@ -29,16 +30,18 @@ pub mod dialogue {
/// to avoid the glow effect from showing while it's not active
pub const DBOX_Y_BELOW_VIEWPORT: f32 = 20.0;

// pub const DBOX_CHOICE_TWEEN_TIME: f64 = DBOX_TWEEN_TIME;
// pub const DBOX_CHOICE_TWEEN_TRANS: TransitionType = DBOX_TWEEN_TRANS;
pub const DBOX_CHOICE_TWEEN_TIME: f64 = main_menu::MENU_TWEEN_TIME;
pub const DBOX_CHOICE_TWEEN_TRANS: TransitionType = DBOX_TWEEN_TRANS;
pub const DBOX_CHOICE_HEIGHT: f32 = 60.0;
pub const DBOX_CHOICE_WAVE_TIME: f64 = 0.1;

pub const DBOX_SELECTION_BBCODE: &str = "[wave amp=100 freq=-6]";
}

pub mod main_menu {
use godot::engine::tween::TransitionType;
use super::*;

pub const MENU_TWEEN_TIME: f64 = 0.1;
pub const MENU_TWEEN_TRANS: TransitionType = TransitionType::TRANS_QUAD;
pub const MENU_WAVE_BBCODE: &str = "[wave amp=100 freq=-6]";
pub const MENU_WAVE_BBCODE: &str = dialogue::DBOX_SELECTION_BBCODE;
}
86 changes: 0 additions & 86 deletions pets-lib/src/dialogue/dbox/choice.rs

This file was deleted.

Loading

0 comments on commit 04caf31

Please sign in to comment.