Vary dialogue-position by speaker/etc

This commit is contained in:
Jaidyn Ann 2023-06-20 22:00:36 -05:00
parent 9c5892f2f8
commit fe9b74a600

View File

@ -135,16 +135,20 @@ should be printed on the screen at any given moment."
(let* ((text-x-margin (if rightp (let* ((text-x-margin (if rightp
(+ (getf coords :x) 3) (+ (getf coords :x) 3)
0)) 0))
(text-width (if rightp (text-width (:at-most (floor (* width 3/5)) ;; Not _too_ wide!
(if rightp
(- width text-x-margin) (- width text-x-margin)
(- (getf coords :x) 3))) (- (getf coords :x) 3))))
(lines (ignore-errors (:split-string-by-length text text-width))) (lines (ignore-errors (:split-string-by-length text text-width)))
(text-height (length lines))) (text-height (length lines)))
(when (and lines (>= height text-height) ;; When this layout is valid…
lines) (when (and lines
(>= height text-height) ;; If the textll fit on screen
(> text-width 10)) ;; If the text is wide enough to be legible
(let ((y (:at-least 0 (- (getf coords :y) (let ((y (:at-least 0 (- (getf coords :y)
(floor (/ (length lines) 2)) (if (eq (length lines) 1) ;; Align toward the speakers face
1))) 1 0)
(floor (/ (length lines) 2)))))
(x (if (and (not rightp) (x (if (and (not rightp)
(eq (length lines) 1)) (eq (length lines) 1))
(- text-width (length text)) (- text-width (length text))
@ -163,6 +167,7 @@ should be printed on the screen at any given moment."
(- text-y-margin 1))) (- text-y-margin 1)))
(text-width (floor (* width 3/5))) ;; Too wides illegible! So ⅗-screen. (text-width (floor (* width 3/5))) ;; Too wides illegible! So ⅗-screen.
(lines (ignore-errors (:split-string-by-length text text-width)))) (lines (ignore-errors (:split-string-by-length text text-width))))
;; When the text can be printed with this layout…
(when (and lines (>= text-height (length lines))) (when (and lines (>= text-height (length lines)))
(let ((y (:at-least (let ((y (:at-least
0 0
@ -183,10 +188,20 @@ should be printed on the screen at any given moment."
(defun optimal-speech-layout (map dialogue &key (width 72) (height 20)) (defun optimal-speech-layout (map dialogue &key (width 72) (height 20))
(let* ((speaker-id (dialogue-speaker dialogue)) (let* ((speaker-id (dialogue-speaker dialogue))
(direction (🌍:getf-entity-data map speaker-id :direction)) (direction (🌍:getf-entity-data map speaker-id :direction))
(playerp (eq speaker-id 'player))
(leftp (not (eq direction '🌍:right)))
(text (getf dialogue :text)) (text (getf dialogue :text))
(coords (🌍:world-coords->screen-coords (🌍:getf-entity-data map speaker-id :coords)))) (coords (🌍:world-coords->screen-coords (🌍:getf-entity-data map speaker-id :coords))))
(or (optimal-speech-layout-horizontally text coords :rightp 't :width width :height height) (format *error-output* "AAA ~A - ~A - ~A" leftp direction 'RIGHT)
(optimal-speech-layout-vertical text coords :downp nil :width width :height height)))) (or (optimal-speech-layout-horizontally text coords :width width :height height
:rightp leftp)
(optimal-speech-layout-vertical text coords :width width :height height
:downp playerp)
(optimal-speech-layout-horizontally text coords :width width :height height
:rightp (not leftp))
(optimal-speech-layout-vertical text coords :width width :height height
:downp (not playerp)))))
(defun render-dialogue-block (matrix map dialogue) (defun render-dialogue-block (matrix map dialogue)
@ -227,3 +242,7 @@ A state-function for use with STATE-LOOP."
(sleep .05) (sleep .05)
(dialogue-state-draw matrix map dialogue) (dialogue-state-draw matrix map dialogue)
(dialogue-state-update map dialogue)) (dialogue-state-update map dialogue))
;; Split a banana in two, bisection-fruit,
;; Yummy-yummy, toot-toot~ 🎵