Vary dialogue-position by speaker/etc
This commit is contained in:
parent
9c5892f2f8
commit
fe9b74a600
|
@ -135,23 +135,27 @@ 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!
|
||||||
(- width text-x-margin)
|
(if rightp
|
||||||
(- (getf coords :x) 3)))
|
(- width text-x-margin)
|
||||||
|
(- (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 text’ll 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 speaker’s 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))
|
||||||
text-x-margin)))
|
text-x-margin)))
|
||||||
(list (list :x x :y y) ;; Coords
|
(list (list :x x :y y) ;; Coords
|
||||||
(+ x text-width) ;; Max column
|
(+ x text-width) ;; Max column
|
||||||
height))))) ;; Max row
|
height))))) ;; Max row
|
||||||
|
|
||||||
|
|
||||||
(defun optimal-speech-layout-vertical (text coords &key (downp nil) (width 72) (height 20))
|
(defun optimal-speech-layout-vertical (text coords &key (downp nil) (width 72) (height 20))
|
||||||
|
@ -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 wide’s illegible! So ⅗-screen.
|
(text-width (floor (* width 3/5))) ;; Too wide’s 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~ 🎵
|
||||||
|
|
Ŝarĝante…
Reference in New Issue