use concinnity_core::ecs::World;
use crate::editor::hook::EditorHook;
use crate::editor::notify;
use crate::editor::panels::registry::PanelKey;
use crate::editor::toast_overlay;
impl EditorHook {
pub(in crate::editor::hook) fn drive_toasts(
&mut self,
world: &mut World,
vp: [f32; 2],
shown: bool,
mouse: [f32; 2],
) {
if !shown || vp[0] <= 0.0 || self.notifier.is_empty() {
if !self.toasts_hidden {
toast_overlay::hide(world);
self.toasts_hidden = true;
}
return;
}
let stack = self.notifier.stack();
if stack.cards.is_empty() {
if !self.toasts_hidden {
toast_overlay::hide(world);
self.toasts_hidden = true;
}
return;
}
toast_overlay::place(world, &stack, vp, mouse);
self.toasts_hidden = false;
}
pub(in crate::editor::hook) fn try_toast_press(
&mut self,
mx: f32,
my: f32,
vp: [f32; 2],
world: &mut World,
) -> bool {
if self.toasts_hidden || self.notifier.is_empty() {
return false;
}
let stack = self.notifier.stack();
match toast_overlay::hit(mx, my, vp, &stack) {
Some(toast_overlay::Hit::Card(slot)) => {
if let Some(action) = self.notifier.click_card(slot) {
self.run_toast_action(action, world);
}
true
}
Some(toast_overlay::Hit::Op) => true,
Some(toast_overlay::Hit::Overflow) => {
self.open_console_panel(world);
true
}
None => false,
}
}
fn run_toast_action(&mut self, action: notify::Action, world: &mut World) {
match action {
notify::Action::OpenConsole => self.open_console_panel(world),
notify::Action::GoToBehaviorFault => {
if !self.behavior.open {
self.behavior.open = true;
self.open_behavior(world);
}
self.focus_panel(PanelKey::Behavior);
self.select_behavior_fault(world);
}
}
}
fn open_console_panel(&mut self, world: &mut World) {
if self.console.open {
self.focus_panel(PanelKey::Console);
} else {
self.toggle_console(world);
}
}
pub(in crate::editor::hook) fn notify_behavior_fault(&mut self, prev_fault: Option<String>) {
let Some(message) = self.behavior.status.as_ref().and_then(|s| s.error()) else {
return;
};
if prev_fault.as_deref() == Some(message) {
return;
}
self.notifier.push_with(
notify::Level::Error,
&format!("Behavior: {message}"),
Some(notify::Action::GoToBehaviorFault),
);
}
pub(in crate::editor::hook) fn behavior_fault_message(&self) -> Option<String> {
self.behavior
.status
.as_ref()
.and_then(|s| s.error())
.map(String::from)
}
}