Skip to main content

unbanished_formats/ui/
dialogs.rs

1//! Dialog resources: a dialog's root element and the bindings of its named elements.
2
3use super::*;
4
5/// A controller attached to a dialog's element.
6#[derive(Debug, Clone)]
7pub struct DialogBinding {
8    /// Application controller type ID (CRC32 of its class name).
9    pub unknown: u32,
10    /// Optional element description created beneath the named host.
11    pub source: Ref,
12    /// Optional controller configuration resource.
13    pub target: Ref,
14    /// Host element path identifier, or empty for the dialog root.
15    pub name: String,
16}
17
18/// Original: `UI::Dialog`, Runtime `0x180115950`.
19#[derive(Debug, Clone)]
20pub struct Dialog {
21    /// Not identified yet.
22    pub unknown_40: u32,
23    /// The root element.
24    pub root: Ref,
25    /// The sprite sheet of the background drawn behind the dialog.
26    pub background_sheet: Ref,
27    /// The background's sprite name.
28    pub background_sprite: String,
29    /// Not identified yet.
30    pub unknown_30: u32,
31    /// Elements replaced by name: the replacement resource and the name of the element it replaces.
32    pub named: Vec<(Ref, String)>,
33    /// The dialog's elements.
34    pub children: Vec<Ref>,
35    /// The controllers attached to elements.
36    pub bindings: Vec<DialogBinding>,
37    /// Associated resources, including nested dialogs and string tables.
38    pub dialogs: Vec<Ref>,
39    /// Not identified yet.
40    pub unknown_34: i32,
41}
42
43/// Read a [`Dialog`] from the bytes of its resource.
44pub fn dialog(data: &[u8]) -> Result<Dialog> {
45    expect(data, "Dialog", |r| {
46        r.block(|r, _| {
47            let unknown_40 = r.u32()?;
48            let root = r.external_ref()?;
49            let background_sheet = r.external_ref()?;
50            let background_sprite = r.string()?;
51            let unknown_30 = r.u32()?;
52            let named = (0..r.count()?)
53                .map(|_| Ok((r.external_ref()?, r.string()?)))
54                .collect::<Result<_>>()?;
55            let children = refs(r)?;
56            let bindings = (0..r.count()?)
57                .map(|_| {
58                    Ok(DialogBinding {
59                        unknown: r.u32()?,
60                        source: r.external_ref()?,
61                        target: r.external_ref()?,
62                        name: r.string()?,
63                    })
64                })
65                .collect::<Result<_>>()?;
66            let dialogs = refs(r)?;
67            Ok(Dialog {
68                unknown_40,
69                root,
70                background_sheet,
71                background_sprite,
72                unknown_30,
73                named,
74                children,
75                bindings,
76                dialogs,
77                unknown_34: r.i32()?,
78            })
79        })
80    })
81}