1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
type Layer = struct {
blocks_input: *fn() bool,
input: *fn(InputEvent) bool,
is_opaque: *fn() bool,
render: *fn() void,
};
type InputEvent = (CancelEvent | KeyEvent |
MouseButtonEvent | MouseOverEvent);
type CancelEvent = void;
type KeyEvent = struct {
status: ButtonStatus,
key: Key,
};
type Key = uint;
type MouseButtonEvent = struct {
status: ButtonStatus,
button: MouseButton,
};
type MouseButton = enum u8 {
LEFT,
MIDDLE,
RIGHT,
X1,
X2,
};
type ButtonStatus = enum u8 {
UP,
HELD,
DOWN,
};
type MouseOverEvent = struct {
covered: bool,
};
const LAYERS = [
&LAYER_GAME,
&LAYER_HUD,
&LAYER_DEATH,
&LAYER_GAME_WAITING,
&LAYER_CLIENT_WAITING,
];
fn layers_input(event: InputEvent, top: size, all: bool) size = {
for (top > 0) {
top -= 1;
if (LAYERS[top].input(event) && !all) {
break;
};
};
return top;
};
fn layers_render() void = {
let bottom = len(LAYERS);
for (bottom != 0) {
bottom -= 1;
if (LAYERS[bottom].is_opaque()) {
break;
};
};
for (let i = bottom; i < len(LAYERS); i += 1) {
LAYERS[i].render();
};
};
|