Update scripts to use new protocol names

This commit is contained in:
mars 2022-11-16 19:27:54 -07:00
parent f8f59cb265
commit 53eccd7411
3 changed files with 49 additions and 43 deletions

View File

@ -4,10 +4,14 @@
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
use canary_script::*;
use api::*;
use canary_script::*;
canary_script::export_abi!(MusicPlayerPanel);
canary_script::export_abi!(bind_panel_impl);
pub fn bind_panel_impl(panel: Panel, _protocol: Message, message: Message) -> Box<dyn PanelImpl> {
MusicPlayerPanel::bind(panel, message)
}
const DISPLAY_FONT: &str = "Liberation Sans";
@ -17,19 +21,6 @@ pub struct MusicPlayerPanel {
label: Label,
}
impl BindPanel for MusicPlayerPanel {
fn bind(panel: Panel, message: Message) -> Box<dyn PanelImpl> {
let display_font = Font::new(DISPLAY_FONT);
let label = Label::new(display_font, "Hello, world!".into(), 1.2);
let panel = Self {
panel,
display_font,
label,
};
Box::new(panel)
}
}
impl PanelImpl for MusicPlayerPanel {
fn update(&mut self, dt: f32) {}
@ -42,20 +33,31 @@ impl PanelImpl for MusicPlayerPanel {
self.label.draw(&ctx, offset, size, color);
}
fn on_resize(&mut self, new_size: Vec2) {
}
fn on_resize(&mut self, new_size: Vec2) {}
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {}
fn on_message(&mut self, msg: Message) {
use canary_music_player::{InMsg, serde_json};
use canary_music_player::{serde_json, InMsg};
let msg = msg.to_vec();
let msg = serde_json::from_slice::<InMsg>(&msg);
self.label.set_text(format!("{:#?}", msg));
}
}
impl MusicPlayerPanel {
pub fn bind(panel: Panel, _message: Message) -> Box<dyn PanelImpl> {
let display_font = Font::new(DISPLAY_FONT);
let label = Label::new(display_font, "Hello, world!".into(), 1.2);
let panel = Self {
panel,
display_font,
label,
};
Box::new(panel)
}
}
pub struct Label {
font: Font,
text: String,

View File

@ -8,12 +8,16 @@ pub mod anim;
pub mod main_menu;
pub mod widgets;
use canary_script::*;
use api::*;
use widgets::Widget;
use canary_script::*;
use main_menu::MainMenuPanel;
use widgets::Widget;
export_abi!(MainMenuPanel);
export_abi!(bind_panel_impl);
fn bind_panel_impl(panel: Panel, _protocol: Message, msg: Message) -> Box<dyn PanelImpl> {
MainMenuPanel::bind(panel, msg)
}
pub const ICON_FONT: &str = "Iosevka Nerd Font";
pub const DISPLAY_FONT: &str = "Homenaje";
@ -24,18 +28,6 @@ pub struct ConfirmationDialogPanel {
dialog: widgets::dialog::Dialog,
}
impl BindPanel for ConfirmationDialogPanel {
fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl> {
let msg = msg.to_vec();
let info: DialogInfo = serde_json::from_slice(&msg).unwrap();
use widgets::dialog::*;
let style = DialogStyle::default();
let dialog = Dialog::new(style, &info);
Box::new(Self { panel, dialog })
}
}
impl PanelImpl for ConfirmationDialogPanel {
fn update(&mut self, dt: f32) {
self.dialog.update(dt);
@ -54,3 +46,15 @@ impl PanelImpl for ConfirmationDialogPanel {
fn on_message(&mut self, _msg: Message) {}
}
impl ConfirmationDialogPanel {
pub fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl> {
let msg = msg.to_vec();
let info: DialogInfo = serde_json::from_slice(&msg).unwrap();
use widgets::dialog::*;
let style = DialogStyle::default();
let dialog = Dialog::new(style, &info);
Box::new(Self { panel, dialog })
}
}

View File

@ -15,15 +15,6 @@ pub struct MainMenuPanel {
menu: MainMenu,
}
impl BindPanel for MainMenuPanel {
fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl> {
Box::new(Self {
panel,
menu: MainMenu::default(),
})
}
}
impl PanelImpl for MainMenuPanel {
fn update(&mut self, dt: f32) {
Widget::update(&mut self.menu, dt);
@ -43,6 +34,15 @@ impl PanelImpl for MainMenuPanel {
fn on_message(&mut self, msg: Message) {}
}
impl MainMenuPanel {
pub fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl> {
Box::new(Self {
panel,
menu: MainMenu::default(),
})
}
}
pub struct MainMenu {
pub menu: Offset<SlotMenu<RoundButton>>,
pub player_info: Reveal<Offset<PlayerInfo>>,