-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.lisp
55 lines (42 loc) · 1.57 KB
/
ui.lisp
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
(in-package #:spacepilot)
(define-shader-pass ui (org.shirakumo.fraf.trial.alloy:base-ui)
())
(defmethod org.shirakumo.alloy.renderers.opengl.msdf:fontcache-directory ((ui ui))
(pool-path 'spacepilot "font-cache/"))
(defun format-score (score)
(format NIL "SCORE ~6,'0d" score))
(defclass score-display (alloy:label)
())
(defmethod alloy:text ((display score-display))
(format-score (alloy:value display)))
(presentations:define-realization (ui score-display)
((label simple:text)
(alloy:margins -10)
alloy:text
:size (alloy:un 40)
:font "PromptFont"
:pattern colors:white
:halign :right
:valign :bottom))
(presentations:define-update (ui score-display)
(label
:text alloy:text))
(defclass icon (alloy:direct-value-component alloy:icon)
())
(presentations:define-update (ui icon)
(:icon
:image alloy:value
:sizing :contain))
(defclass hud (trial-alloy:panel)
())
(defmethod initialize-instance :after ((hud hud) &key player)
(let* ((layout (make-instance 'org.shirakumo.alloy.layouts.constraint:layout)))
(loop repeat (lives player)
for i from 0
do (alloy:enter (make-instance 'icon :value (// 'spacepilot-images 'player-life))
layout :constraints `((:right (+ 30 (* ,i 90)))
(:top 100)
(:size 80 80))))
(alloy:enter (alloy:represent (score player) 'score-display)
layout :constraints `((:right 30) (:top 30) (:size 100 50)))
(alloy:finish-structure hud layout NIL)))