siglus_scene_vm/runtime/commands/
text.rs1use anyhow::Result;
2
3use crate::runtime::forms::stage;
4use crate::runtime::{Command, CommandContext, Value};
5
6use super::util::strip_vm_meta;
7
8pub fn handle(ctx: &mut CommandContext, cmd: &Command) -> Result<bool> {
9 let name = cmd.name.to_ascii_uppercase();
10
11 if !matches!(
12 name.as_str(),
13 "MSG"
14 | "MES"
15 | "MESSAGE"
16 | "TEXT"
17 | "NAME"
18 | "MWND"
19 | "MWNDOPEN"
20 | "MWNDCLOSE"
21 | "MSGWAIT"
22 | "MSG_WAIT"
23 | "TEXTWAIT"
24 | "TEXT_WAIT"
25 | "WAITMSG"
26 | "WAIT_TEXT"
27 | "CLRMSG"
28 | "CLEARMSG"
29 | "CLR_TEXT"
30 ) {
31 return Ok(false);
32 }
33
34 let args = strip_vm_meta(&cmd.args);
35
36 match name.as_str() {
37 "MSGWAIT" | "MSG_WAIT" | "TEXTWAIT" | "TEXT_WAIT" | "WAITMSG" | "WAIT_TEXT" => {
38 ctx.wait.wait_key();
39 ctx.ui.begin_wait_message();
40 ctx.push(Value::Int(0));
41 }
42 "CLRMSG" | "CLEARMSG" | "CLR_TEXT" => {
43 ctx.ui.clear_message();
44 ctx.ui.clear_name();
45 ctx.ui.show_message_bg(false);
46 ctx.push(Value::Int(0));
47 }
48 "MWND" | "MWNDOPEN" => {
49 ctx.ui.show_message_bg(true);
50 ctx.push(Value::Int(0));
51 }
52 "MWNDCLOSE" => {
53 ctx.ui.show_message_bg(false);
54 ctx.push(Value::Int(0));
55 }
56 "NAME" => {
57 if let Some(Value::Str(s)) = args.first() {
58 ctx.ui.show_message_bg(true);
59 if !stage::cd_name_current_mwnd(ctx, s) {
60 ctx.ui.set_name(s.clone());
61 }
62 }
63 ctx.push(Value::Int(0));
64 }
65 _ => {
66 if let Some(Value::Str(s)) = args.first() {
67 ctx.ui.show_message_bg(true);
68 ctx.ui.set_message(s.clone());
69 eprintln!("[VM-MSG] {}", s);
70 }
71 ctx.push(Value::Int(0));
72 }
73 }
74
75 Ok(true)
76}