diff --git a/crates/horizon-client-core/src/component.rs b/crates/horizon-client-core/src/component.rs index 248c78617..0826245f0 100644 --- a/crates/horizon-client-core/src/component.rs +++ b/crates/horizon-client-core/src/component.rs @@ -195,6 +195,11 @@ fn object_style(o: &serde_json::Map) -> Style { Some("copy_to_clipboard") => { text("value").map(crate::text::ClickEvent::CopyToClipboard) } + // ClickEvent.ShowDialog.CODEC: a `minecraft:dialog` registry id or + // the dialog itself; the server may send it (isAllowedFromServer). + Some("show_dialog") => e.get("dialog").map(|dialog| { + crate::text::ClickEvent::ShowDialog(crate::scoreboard::json_to_tag(dialog)) + }), _ => None, }; } diff --git a/crates/horizon-client-core/src/text.rs b/crates/horizon-client-core/src/text.rs index 243a3ae3c..12cc196d9 100644 --- a/crates/horizon-client-core/src/text.rs +++ b/crates/horizon-client-core/src/text.rs @@ -50,6 +50,9 @@ pub enum ClickEvent { /// `ClickEvent.RunCommand`: the command, with or without its `/`. RunCommand(String), CopyToClipboard(String), + /// `ClickEvent.ShowDialog`: a `minecraft:dialog` registry id, or the + /// dialog itself as the component carried it. + ShowDialog(horizon_world::nbt::Tag), /// A local file to open with the system handler. /// Only allow this in locally constructed messages, never server/LAN text. OpenFile(String), @@ -557,6 +560,11 @@ fn style_json(style: &Style) -> Vec<(String, Value)> { ClickEvent::RunCommand(command) => { json!({ "action": "run_command", "command": command }) } + // ClickEvent.ShowDialog.CODEC: the dialog the server sent it with. + ClickEvent::ShowDialog(dialog) => json!({ + "action": "show_dialog", + "dialog": crate::scoreboard::tag_to_json(dialog), + }), ClickEvent::OpenFile(path) => json!({ "action": "open_file", "path": path }), }; out.push(("click_event".to_owned(), event)); diff --git a/crates/horizon-client/src/game/books.rs b/crates/horizon-client/src/game/books.rs index 4c1a03129..18616ac57 100644 --- a/crates/horizon-client/src/game/books.rs +++ b/crates/horizon-client/src/game/books.rs @@ -151,6 +151,9 @@ impl Game<'_> { use horizon_client::clipboard::Clipboard; self.clipboard.set(&value); } + // BookViewScreen.handleClickEvent: the rest is + // Screen.defaultHandleGameClickEvent's. + ClickEvent::ShowDialog(dialog) => self.show_dialog_ref(&dialog), _ => {} } } diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index 00e1b0abf..229929d06 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -786,6 +786,9 @@ impl Game<'_> { } } Some(ClickEvent::RunCommand(command)) => self.click_command(&command), + // Screen.defaultHandleGameClickEvent: the dialog opens over the + // screen, and closes back to it. + Some(ClickEvent::ShowDialog(dialog)) => self.show_dialog_ref(&dialog), // Screen.defaultHandleClickEvent: a page link means nothing in chat. Some(ClickEvent::ChangePage(_)) | None => {} } diff --git a/crates/horizon-client/src/game/dialogs.rs b/crates/horizon-client/src/game/dialogs.rs index 4928b0aa8..9a8a23017 100644 --- a/crates/horizon-client/src/game/dialogs.rs +++ b/crates/horizon-client/src/game/dialogs.rs @@ -163,7 +163,7 @@ impl Game<'_> { } /// A `show_dialog` click event's dialog: a registry id or the dialog itself. - fn show_dialog_ref(&mut self, dialog: &Tag) { + pub(super) fn show_dialog_ref(&mut self, dialog: &Tag) { match dialog { Tag::String(id) => { let id = id.to_string_lossy();