Orient dialogue vertically! How exciting!

This commit is contained in:
Jaidyn Ann 2023-06-20 20:43:27 -05:00
parent 82254570b1
commit 9c5892f2f8

View File

@ -131,27 +131,53 @@ should be printed on the screen at any given moment."
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
;;; Dialogue drawing ;;; Dialogue drawing
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
(defun optimal-speech-layout-horizontally (text coords &key (right-p nil) (width 72) (height 20)) (defun optimal-speech-layout-horizontally (text coords &key (rightp nil) (width 72) (height 20))
(let* ((text-margin (if right-p (let* ((text-x-margin (if rightp
(+ (getf coords :x) 3) (+ (getf coords :x) 3)
0)) 0))
(text-width (if right-p (text-width (if rightp
(- width text-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)))
(format *error-output* "Margin: ~A Width: ~A Right: ~A" text-margin text-width right-p) (text-height (length lines)))
(when (and (> text-width 0) (when (and lines (>= height text-height)
lines) lines)
(let ((y (:at-least 0 (- (getf coords :y) (let ((y (:at-least 0 (- (getf coords :y)
(floor (/ (length lines) 2)) (floor (/ (length lines) 2))
1))) 1)))
(x (if (and (not right-p) (x (if (and (not rightp)
(eq (length lines) 1)) (eq (length lines) 1))
(- text-width (length text)) (- text-width (length text))
text-margin))) text-x-margin)))
(list (list :x x :y y) (list (list :x x :y y) ;; Coords
(+ x text-width) (+ x text-width) ;; Max column
height))))) height))))) ;; Max row
(defun optimal-speech-layout-vertical (text coords &key (downp nil) (width 72) (height 20))
(let* ((text-y-margin (if downp
(+ (getf coords :y) 1)
(- (getf coords :y) 2)))
(text-height (if downp
(- height text-y-margin)
(- text-y-margin 1)))
(text-width (floor (* width 3/5))) ;; Too wides illegible! So ⅗-screen.
(lines (ignore-errors (:split-string-by-length text text-width))))
(when (and lines (>= text-height (length lines)))
(let ((y (:at-least
0
(if downp
text-y-margin
(- text-y-margin (length lines)))))
(x (:at-least
0
(- (getf coords :x)
(if (eq (length lines) 1)
(floor (/ (length (car lines)) 2))
(floor (/ text-width 2)))))))
(list (list :x x :y y) ;; Coords
(+ x text-width) ;; Max column
(+ y text-height)))))) ;; Max row
(defun optimal-speech-layout (map dialogue &key (width 72) (height 20)) (defun optimal-speech-layout (map dialogue &key (width 72) (height 20))
@ -159,7 +185,8 @@ should be printed on the screen at any given moment."
(direction (🌍:getf-entity-data map speaker-id :direction)) (direction (🌍:getf-entity-data map speaker-id :direction))
(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))))
(optimal-speech-layout-horizontally text coords :right-p 't :width width :height height))) (or (optimal-speech-layout-horizontally text coords :rightp 't :width width :height height)
(optimal-speech-layout-vertical text coords :downp nil :width width :height height))))
(defun render-dialogue-block (matrix map dialogue) (defun render-dialogue-block (matrix map dialogue)