intermission.lisp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;;;; Copyright © 2023, Jaidyn Ann <jadedctrl@posteo.at>
  2. ;;;;
  3. ;;;; This program is free software: you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU General Public License as
  5. ;;;; published by the Free Software Foundation, either version 3 of
  6. ;;;; the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This program is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;;;; GNU General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU General Public License
  14. ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;;; FLORA-SEARCH-AURORA.INTERMISSION
  16. ;;;; Used to render flashy little transitions in-between scenes/maps/etc.
  17. (in-package :flora-search-aurora.intermission)
  18. ;;; ———————————————————————————————————
  19. ;;; Intermission loop logic
  20. ;;; ———————————————————————————————————
  21. (defun intermission-state-update (title subtitle side-text progress return)
  22. "The input-taking/logic-handling component of the inventory state-function.
  23. Part of INVENTORY-STATE."
  24. (if (and (⌨:pressed-enter-p) (> progress 60))
  25. return
  26. (list :parameters
  27. (list :title title
  28. :subtitle subtitle
  29. :side-text side-text
  30. :return return
  31. :progress (…:at-most 107 (+ progress .5))))))
  32. ;;; ———————————————————————————————————
  33. ;;; Intermission loop drawing
  34. ;;; ———————————————————————————————————
  35. (defun render-centered-line (matrix string &key (y 0))
  36. "Given a STRING and a Y-position, render it to the MATRIX centered horizontally."
  37. (✎:render-line
  38. matrix
  39. string
  40. (list :y y
  41. :x (floor (/ (- (second (array-dimensions matrix))
  42. (length string))
  43. 2)))))
  44. (defun intermission-state-draw (matrix title subtitle side-text progress)
  45. "The drawing component of the inventory state-function.
  46. Part of INVENTORY-STATE."
  47. (let* ((title (…:getf-lang title))
  48. (title-border (subseq (make-string (length title) :initial-element #\=)
  49. 0 (…:at-least 0 (…:at-most (length title)
  50. (floor (- progress 35)))))))
  51. ;; Add a bit of a “blank” between scenes.
  52. ;; Why? Pacing, of course!
  53. (when (> progress 35)
  54. ;; Render the title
  55. (render-centered-line matrix title :y 1)
  56. ;; Render the borders surrounding the title
  57. (render-centered-line matrix title-border :y 0)
  58. (render-centered-line matrix title-border :y 2)
  59. ;; Now the sub-title…
  60. (render-centered-line matrix (…:getf-lang subtitle) :y 4)
  61. ;; And the side-text…!
  62. (✎:render-string matrix (…:getf-lang side-text) '(:x 15 :y 10) :width 47)
  63. ;; A little touch; a simple animation-ish line down the middle.
  64. (✎:render-line
  65. matrix
  66. (subseq (make-string (second (array-dimensions matrix))
  67. :initial-element #\~)
  68. 0 (…:at-least 0 (floor (- progress 35))))
  69. '(:x 0 :y 9)))))
  70. ;;; ———————————————————————————————————
  71. ;;; Intermission loop
  72. ;;; ———————————————————————————————————
  73. (defun intermission-state (matrix &key title subtitle side-text progress return)
  74. "A state-function for use with STATE-LOOP."
  75. (sleep .02)
  76. (intermission-state-draw matrix title subtitle side-text progress)
  77. (intermission-state-update title subtitle side-text progress return))
  78. (defun make-intermission-function (title subtitle side-text return)
  79. "Return a state-function for intermission, for use with STATE-LOOP."
  80. (lambda (matrix &key (title title) (subtitle subtitle) (side-text side-text) (return return) (progress 0))
  81. (funcall #'intermission-state
  82. matrix :title title :subtitle subtitle :side-text side-text :progress progress :return return)))
  83. (defun make-intermission-state (title subtitle side-text return)
  84. "Return a state-plist for intermission, for use with STATE-LOOP."
  85. (list :parameters nil
  86. :function
  87. (make-intermission-function title subtitle side-text return)))