-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22fb42c
commit 7e6a3d4
Showing
27 changed files
with
315 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "dynamic-menu" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[package.metadata.td-rs] | ||
type = "dat" | ||
|
||
[lib] | ||
name = "dynamic_menu" | ||
crate-type = ["staticlib"] | ||
|
||
[dependencies] | ||
td-rs-dat = { path = "../../../td-rs-dat" } | ||
td-rs-derive = { path = "../../../td-rs-derive" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use td_rs_dat::chop::ChopInput; | ||
use td_rs_dat::*; | ||
use td_rs_derive::{Param, Params}; | ||
|
||
#[derive(Params, Default, Clone, Debug)] | ||
struct DynamicMenuDatParams { | ||
#[param(label = "Menu")] | ||
menu: DynamicMenuParam, | ||
} | ||
|
||
/// Struct representing our DAT's state | ||
pub struct DynamicMenuDat { | ||
params: DynamicMenuDatParams, | ||
} | ||
|
||
impl OpNew for DynamicMenuDat { | ||
fn new(_info: NodeInfo) -> Self { | ||
Self { | ||
params: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl OpInfo for DynamicMenuDat { | ||
const OPERATOR_TYPE: &'static str = "Dynamicmenu"; | ||
const OPERATOR_LABEL: &'static str = "Dynamic Menu"; | ||
const MIN_INPUTS: usize = 1; | ||
// This Dat takes no input | ||
const MAX_INPUTS: usize = 1; | ||
} | ||
|
||
impl Op for DynamicMenuDat { | ||
fn params_mut(&mut self) -> Option<Box<&mut dyn OperatorParams>> { | ||
Some(Box::new(&mut self.params)) | ||
} | ||
} | ||
|
||
impl Dat for DynamicMenuDat { | ||
fn general_info(&self, _inputs: &OperatorInputs<DatInput>) -> DatGeneralInfo { | ||
DatGeneralInfo { | ||
cook_every_frame: false, | ||
cook_every_frame_if_asked: false, | ||
} | ||
} | ||
|
||
fn execute(&mut self, output: DatOutput, inputs: &OperatorInputs<DatInput>) { | ||
if let Some(input) = inputs.input(0) { | ||
match input.dat_type() { | ||
DatType::Text => { | ||
if let Some(output_text) = &self.params.menu.0 { | ||
output | ||
.text() | ||
.set_text(&format!("Selected: {}", output_text)); | ||
} else { | ||
output.text().set_text(""); | ||
} | ||
} | ||
_ => self.set_warning("Input must be a text DAT"), | ||
} | ||
} | ||
} | ||
|
||
fn build_dynamic_menu( | ||
&mut self, | ||
inputs: &OperatorInputs<DatInput>, | ||
menu_info: &mut DynamicMenuInfo, | ||
) { | ||
if menu_info.param_name() == "Menu" { | ||
if let Some(input) = inputs.input(0) { | ||
match input.dat_type() { | ||
DatType::Text => { | ||
let text = input.text(); | ||
let labels = text | ||
.split('\n') | ||
.map(|s| s.to_string()) | ||
.collect::<Vec<String>>(); | ||
for label in labels { | ||
let name = label.replace(" ", ""); | ||
menu_info.add_menu_entry(&name, &label); | ||
} | ||
} | ||
_ => self.set_warning("Input must be a text DAT"), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl DynamicMenuDat {} | ||
|
||
dat_plugin!(DynamicMenuDat); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.