summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2018-07-19 09:35:24 +0200
committerRicardo Wurmus <rekado@elephly.net>2018-07-27 17:15:46 +0200
commit9c43f7a9472a4fe0c50250f25c9605a898c568ef (patch)
treedce9545c466ff01d98d302157fe9bc56d5e66622
parent0f5e033cfe33049f3f81faa6503aa48740fdfd24 (diff)
Use new procedures to render texts.
-rw-r--r--scenes/game.scm55
1 files changed, 27 insertions, 28 deletions
diff --git a/scenes/game.scm b/scenes/game.scm
index d0897f8..f34787d 100644
--- a/scenes/game.scm
+++ b/scenes/game.scm
@@ -466,45 +466,44 @@ given MAX-WIDTH. Return a list of lines."
(unless (speaking? who)
(let ((bubble (child-ref (parent (parent player)) 'text-bubble))
(messages (accepted-messages who)))
- (for-each (lambda (message i)
- (match message
- ((message text)
- (when (zero? i)
- (attach bubble
- (make <filled-rect>
- #:name 'dialog-selection-indicator
- #:region (make-rect 0.0 0.0 10 10)
- #:position (vec2 0 40)
- #:color region)))
- (attach bubble (make <label>
- #:name (symbol-append 'dialog- message)
- #:font game-font
- #:text text
- #:color color
- #:position (vec2 16.0 (- 40 (* 16.0 i))))))))
- messages
- (iota (length messages))))))
(clear-messages bubble)
+ (fold (lambda (message n lines)
+ (match message
+ ((message text)
+ (when (zero? n)
+ (attach bubble
+ (make <filled-rect>
+ #:name 'dialog-selection-indicator
+ #:region (make-rect 0.0 0.0 10 10)
+ #:position (vec2 0 40)
+ #:color region)))
+ (+ lines
+ (render-text bubble text
+ #:suffix message
+ #:y-offset
+ (+ (* n %message-margin)
+ (* lines %line-height)))))))
+ 0
+ messages
+ (iota (length messages))))))
(define-method (talk (player <player>) (who <character>) message)
(let ((bubble (child-ref (parent (parent player)) 'text-bubble)))
- (when (eq? message 'hello)
+ (when (not (talking? player))
(set! (visible? bubble) #t))
- (set! (talking? player) who)
-
- ;; Send message, display text, record possible continuations
(match (assoc-ref (conversations who) message)
((text next)
+ (set! (talking? player) who)
(set! (speaking? who) #t)
- ;; TODO: split text
- (attach bubble (make <label>
- #:name 'dialog
- #:font game-font
- #:text text
- #:position (vec2 16.0 40)))
+
;; Clear any shown messages.
(clear-messages bubble)
+
+ ;; Display new message.
+ (render-text bubble text)
+
+ ;; Record continuations.
(set! (accepted-messages who) next))
;; This should never happen, because there should always be a
;; conversation matching a message.