2023-06-27 21:36:13 -05:00
|
|
|
|
;;;; Copyright © 2023, Jaidyn Ann <jadedctrl@posteo.at>
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; This program is free software: you can redistribute it and/or
|
|
|
|
|
;;;; modify it under the terms of the GNU General Public License as
|
|
|
|
|
;;;; published by the Free Software Foundation, either version 3 of
|
|
|
|
|
;;;; the License, or (at your option) any later version.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;;; GNU General Public License for more details.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;;; FLORA-SEARCH-AURORA.INVENTORY
|
|
|
|
|
;;;; The menu for inventory selection/management.
|
|
|
|
|
|
|
|
|
|
(in-package :flora-search-aurora.inventory)
|
|
|
|
|
|
2023-07-02 20:47:31 -05:00
|
|
|
|
|
|
|
|
|
;;; ———————————————————————————————————
|
2023-07-03 11:55:09 -05:00
|
|
|
|
;;; Misc. Utils
|
2023-07-02 20:47:31 -05:00
|
|
|
|
;;; ———————————————————————————————————
|
|
|
|
|
(defun subseq-head (length sequence)
|
|
|
|
|
"Get a subsequence of SEQUENCE containing its first LENGTH elements. If LENGTH
|
|
|
|
|
exceeds the size of SEQUENCE, the returned subsequence is equivalent to SEQUENCE."
|
|
|
|
|
(subseq sequence 0 (…:at-most (length sequence) length)))
|
|
|
|
|
|
|
|
|
|
|
2023-07-03 11:55:09 -05:00
|
|
|
|
|
|
|
|
|
;;; ———————————————————————————————————
|
|
|
|
|
;;; Menu-creation! How fun!
|
|
|
|
|
;;; ———————————————————————————————————
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(defun items->menu-plist (item-plists &key (row-width 72))
|
|
|
|
|
"Convert a list of items’ plists (that one might get from OVERWORLD’s map
|
|
|
|
|
:ITEMS) into a pretty and presentable menu-grid of items, for use with
|
|
|
|
|
📋:MENU-STATE(-*)."
|
2023-07-03 11:55:09 -05:00
|
|
|
|
(format *error-output* "ITEMS ~S~%" item-plists)
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(let* ((label-width 7)
|
|
|
|
|
(border-width 2)
|
|
|
|
|
;; Weird bounding, whoops! I’m so clumsy, it’s endearing instead of just annoying! … Right? =w=”
|
|
|
|
|
(column (- 0 label-width border-width))
|
|
|
|
|
(row 0))
|
|
|
|
|
(mapcar (lambda (item)
|
|
|
|
|
(incf column (+ label-width border-width))
|
|
|
|
|
(when (>= column row-width)
|
|
|
|
|
(incf row)
|
|
|
|
|
(setf column 0))
|
2023-07-03 11:55:09 -05:00
|
|
|
|
(append (list :en (subseq-head label-width (or (getf (cdr item) :inv-name-en)
|
|
|
|
|
(getf (cdr item) :name-en)
|
|
|
|
|
(getf (cdr item) :id)))
|
|
|
|
|
:eo (subseq-head label-width (or (getf (cdr item) :inv-name-eo)
|
|
|
|
|
(getf (cdr item) :name-eo)))
|
|
|
|
|
:selected (and (eq row 0) (eq column 0))
|
|
|
|
|
:selection (if (and (eq row 0) (eq column 0)) 100 0)
|
|
|
|
|
:return nil
|
|
|
|
|
:row row)
|
|
|
|
|
(cdr item)))
|
2023-07-02 20:47:31 -05:00
|
|
|
|
item-plists)))
|
|
|
|
|
|
|
|
|
|
|
2023-06-27 21:36:13 -05:00
|
|
|
|
|
|
|
|
|
;;; ———————————————————————————————————
|
|
|
|
|
;;; Inventory loop logic
|
|
|
|
|
;;; ———————————————————————————————————
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(defun inventory-state-update (map inventory-menu)
|
2023-07-03 11:55:09 -05:00
|
|
|
|
"The input-taking/logic-handling component of the inventory state-function.
|
|
|
|
|
Part of INVENTORY-STATE."
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(if (📋:menu-state-update inventory-menu)
|
|
|
|
|
(list :map map :inventory inventory-menu)
|
|
|
|
|
(values nil
|
|
|
|
|
(list :map map))))
|
2023-06-27 21:36:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; ———————————————————————————————————
|
|
|
|
|
;;; Inventory loop drawing
|
|
|
|
|
;;; ———————————————————————————————————
|
2023-07-03 11:55:09 -05:00
|
|
|
|
(defun render-selected-item (matrix items)
|
|
|
|
|
"Draw the title, avatar, and description of the currently-selected item to
|
|
|
|
|
the bottom of the screen."
|
|
|
|
|
(let* ((item (menu:selected-menu-item items))
|
|
|
|
|
(name (list :en (or (getf item :name-en) (getf item :inv-name-en) (getf item :id))
|
|
|
|
|
:eo (or (getf item :name-eo) (getf item :inv-name-eo))))
|
|
|
|
|
(desc (list :en (getf item :desc-en)
|
|
|
|
|
:eo (getf item :desc-eo))))
|
|
|
|
|
(display:render-string-verbatim matrix (str:concat ":" (…:getf-lang name) ": "
|
|
|
|
|
(getf item :avatar))
|
|
|
|
|
'(:x 1 :y 17))
|
|
|
|
|
(display:render-string matrix (…:getf-lang desc)
|
|
|
|
|
'(:x 1 :y 18) :width 70)))
|
|
|
|
|
|
|
|
|
|
|
2023-06-27 21:36:13 -05:00
|
|
|
|
(defun inventory-state-draw (matrix items)
|
2023-07-03 11:55:09 -05:00
|
|
|
|
"The drawing component of the inventory state-function.
|
|
|
|
|
Part of INVENTORY-STATE."
|
|
|
|
|
(📋:menu-state-draw matrix items)
|
|
|
|
|
(render-selected-item matrix items))
|
2023-06-27 21:36:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; ———————————————————————————————————
|
|
|
|
|
;;; Inventory loop
|
|
|
|
|
;;; ———————————————————————————————————
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(defun inventory-state (matrix &key map inventory)
|
2023-06-27 21:36:13 -05:00
|
|
|
|
"A state-function for use with STATE-LOOP."
|
|
|
|
|
(sleep .02)
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(inventory-state-draw matrix inventory)
|
|
|
|
|
(inventory-state-update map inventory))
|
2023-06-27 21:36:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun make-inventory-state (map)
|
|
|
|
|
"Return a state-function for inventory-listing, for use with STATE-LOOP."
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(lambda (matrix &key (map map) (inventory (items->menu-plist (gethash :items map))))
|
2023-06-27 21:36:13 -05:00
|
|
|
|
(apply #'🎒:inventory-state
|
2023-07-02 20:47:31 -05:00
|
|
|
|
(list matrix :map map :inventory inventory))))
|
2023-06-27 21:36:13 -05:00
|
|
|
|
|