]> git.lizzy.rs Git - mt_net.git/blob - src/to_clt/hud.rs
Implement SkyParams
[mt_net.git] / src / to_clt / hud.rs
1 use super::*;
2
3 #[mt_derive(to = "clt", repr = "u32", enumset)]
4 pub enum HudStyleFlag {
5     Bold,
6     Italic,
7     Mono,
8 }
9
10 #[mt_derive(to = "clt", repr = "u8", tag = "attribute", content = "value")]
11 pub enum HudChange {
12     Pos([f32; 2]) = 0,
13     Name(String),
14     Scale([f32; 2]),
15     Text(String),
16     Number(u32),
17     Item(u32),
18     Dir(u32),
19     Align([f32; 2]),
20     Offset([f32; 2]),
21     WorldPos([f32; 3]),
22     Size([i32; 2]),
23     ZIndex(i32), // this is i16 in HudAdd, minetest is weird
24     Text2(String),
25     Style(EnumSet<HudStyleFlag>),
26 }
27
28 #[mt_derive(to = "clt", repr = "u8")]
29 pub enum HudType {
30     Image = 0,
31     Text,
32     Statbar,
33     Inv,
34     Waypoint,
35     ImageWaypoint,
36 }
37
38 #[mt_derive(to = "clt")]
39 pub struct HudElement {
40     pub hud_type: HudType,
41     pub pos: [f32; 2],
42     pub name: String,
43     pub scale: [f32; 2],
44     pub text: String,
45     pub number: u32,
46     pub item: u32,
47     pub dir: u32,
48     pub align: [f32; 2],
49     pub offset: [f32; 2],
50     pub world_pos: [f32; 3],
51     pub size: [i32; 2],
52     pub z_index: i16,
53     pub text_2: String,
54     pub style: EnumSet<HudStyleFlag>,
55 }
56
57 impl HudElement {
58     pub fn apply_change(&mut self, change: HudChange) {
59         use HudChange::*;
60
61         match change {
62             Pos(v) => self.pos = v,
63             Name(v) => self.name = v,
64             Scale(v) => self.scale = v,
65             Text(v) => self.text = v,
66             Number(v) => self.number = v,
67             Item(v) => self.item = v,
68             Dir(v) => self.dir = v,
69             Align(v) => self.align = v,
70             Offset(v) => self.offset = v,
71             WorldPos(v) => self.world_pos = v,
72             Size(v) => self.size = v,
73             ZIndex(v) => self.z_index = v.try_into().unwrap_or(0),
74             Text2(v) => self.text_2 = v,
75             Style(v) => self.style = v,
76         }
77     }
78 }
79
80 #[mt_derive(to = "clt", repr = "u32", enumset)]
81 pub enum HudFlag {
82     Hotbar,
83     HealthBar,
84     Crosshair,
85     WieldedItem,
86     BreathBar,
87     Minimap,
88     RadarMinimap,
89 }
90
91 #[mt_derive(to = "clt", repr = "u16", tag = "attribute", content = "value")]
92 pub enum HotbarParam {
93     Size(#[mt(const_before = "4u16")] u32) = 1,
94     Image(String),
95     SelectionImage(String),
96 }
97
98 #[mt_derive(to = "clt", repr = "u16")]
99 pub enum MinimapType {
100     None = 0,
101     Surface,
102     Radar,
103     Texture,
104 }
105
106 #[mt_derive(to = "clt")]
107 pub struct MinimapMode {
108     pub minimap_type: MinimapType,
109     pub label: String,
110     pub size: u16,
111     pub texture: String,
112     pub scale: u16,
113 }
114
115 #[mt_derive(to = "clt", custom)]
116 pub struct MinimapModesPkt {
117     current: u16,
118     modes: Vec<MinimapMode>,
119 }
120
121 #[cfg(feature = "server")]
122 impl MtSerialize for MinimapModesPkt {
123     fn mt_serialize<C: MtCfg>(
124         &self,
125         writer: &mut impl std::io::Write,
126     ) -> Result<(), mt_ser::SerializeError> {
127         DefCfg::write_len(self.modes.len(), writer)?;
128         self.current.mt_serialize::<DefCfg>(writer)?;
129         self.modes.mt_serialize::<()>(writer)?;
130
131         Ok(())
132     }
133 }
134
135 #[cfg(feature = "client")]
136 impl MtDeserialize for MinimapModesPkt {
137     fn mt_deserialize<C: MtCfg>(
138         reader: &mut impl std::io::Read,
139     ) -> Result<Self, mt_ser::DeserializeError> {
140         let len = DefCfg::read_len(reader)?;
141         let current = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
142         let modes = mt_ser::mt_deserialize_sized_seq::<DefCfg, _>(&len, reader)?.try_collect()?;
143
144         Ok(Self { current, modes })
145     }
146 }
147
148 /*
149 TODO: rustify this
150
151 var DefaultMinimap = []MinimapMode{
152     {Type: NoMinimap},
153     {Type: SurfaceMinimap, Size: 256},
154     {Type: SurfaceMinimap, Size: 128},
155     {Type: SurfaceMinimap, Size: 64},
156     {Type: RadarMinimap, Size: 512},
157     {Type: RadarMinimap, Size: 256},
158     {Type: RadarMinimap, Size: 128},
159 }
160 */