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