Get INVENTORY (🎒) displaying a list of items!
This commit is contained in:
parent
61eef8110f
commit
0e4f55b4ef
|
@ -18,18 +18,50 @@
|
||||||
|
|
||||||
(in-package :flora-search-aurora.inventory)
|
(in-package :flora-search-aurora.inventory)
|
||||||
|
|
||||||
|
|
||||||
|
;;; ———————————————————————————————————
|
||||||
|
;;; Menu-creation! How fun!
|
||||||
|
;;; ———————————————————————————————————
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
|
||||||
|
(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(-*)."
|
||||||
|
(format *error-output* "ITEMS ~A~%" item-plists)
|
||||||
|
(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))
|
||||||
|
(list :en (subseq-head label-width (or (getf (cdr item) :name-en) (getf (cdr item) :id)))
|
||||||
|
:eo (subseq-head label-width (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))
|
||||||
|
item-plists)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
;;; Inventory loop logic
|
;;; Inventory loop logic
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
(defun inventory-state-update (map)
|
(defun inventory-state-update (map inventory-menu)
|
||||||
(if (and (listen)
|
(if (📋:menu-state-update inventory-menu)
|
||||||
(let ((input (getf (⌨:read-gamefied-char-plist) :semantic)))
|
(list :map map :inventory inventory-menu)
|
||||||
(or (eq input '⌨:🆗)
|
(values nil
|
||||||
(eq input '⌨:❎))))
|
(list :map map))))
|
||||||
(values nil
|
|
||||||
(list :map map))
|
|
||||||
't))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,23 +69,23 @@
|
||||||
;;; Inventory loop drawing
|
;;; Inventory loop drawing
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
(defun inventory-state-draw (matrix items)
|
(defun inventory-state-draw (matrix items)
|
||||||
(✎:render-string matrix (format nil "~A" items) '(:x 0 :y 0)))
|
(📋:menu-state-draw matrix items))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
;;; Inventory loop
|
;;; Inventory loop
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
(defun inventory-state (matrix &key map)
|
(defun inventory-state (matrix &key map inventory)
|
||||||
"A state-function for use with STATE-LOOP."
|
"A state-function for use with STATE-LOOP."
|
||||||
(sleep .02)
|
(sleep .02)
|
||||||
(inventory-state-draw matrix (gethash :items map))
|
(inventory-state-draw matrix inventory)
|
||||||
(inventory-state-update map))
|
(inventory-state-update map inventory))
|
||||||
|
|
||||||
|
|
||||||
(defun make-inventory-state (map)
|
(defun make-inventory-state (map)
|
||||||
"Return a state-function for inventory-listing, for use with STATE-LOOP."
|
"Return a state-function for inventory-listing, for use with STATE-LOOP."
|
||||||
(lambda (matrix &key (map map))
|
(lambda (matrix &key (map map) (inventory (items->menu-plist (gethash :items map))))
|
||||||
(apply #'🎒:inventory-state
|
(apply #'🎒:inventory-state
|
||||||
(list matrix :map map))))
|
(list matrix :map map :inventory inventory))))
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ That is, 0 for non-selected items and 100 for selected items."
|
||||||
"Given a specific ROW, select the next item following the currently-selected
|
"Given a specific ROW, select the next item following the currently-selected
|
||||||
on that same ROW."
|
on that same ROW."
|
||||||
(let* ((selected-n (selected-menu-item-position menu-plist)))
|
(let* ((selected-n (selected-menu-item-position menu-plist)))
|
||||||
(loop for i from (1+ selected-n) upto (length menu-plist)
|
(loop for i from (1+ selected-n) upto (1- (length menu-plist))
|
||||||
do (when (eq (or (getf (nth i menu-plist) :row) 0) row)
|
do (when (eq (or (getf (nth i menu-plist) :row) 0) row)
|
||||||
(return (select-menu-item menu-plist i))))))
|
(return (select-menu-item menu-plist i))))))
|
||||||
|
|
||||||
|
@ -241,6 +241,7 @@ on that same ROW."
|
||||||
(1- (or (getf (nth (selected-menu-item-position menu-plist) menu-plist) :row)
|
(1- (or (getf (nth (selected-menu-item-position menu-plist) menu-plist) :row)
|
||||||
1))))
|
1))))
|
||||||
|
|
||||||
|
|
||||||
(defun select-down-menu-item (menu-plist)
|
(defun select-down-menu-item (menu-plist)
|
||||||
"Select the next item to below the currently-selected item."
|
"Select the next item to below the currently-selected item."
|
||||||
(select-next-item-of-row
|
(select-next-item-of-row
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
(defpackage :flora-search-aurora.menu
|
(defpackage :flora-search-aurora.menu
|
||||||
(:nicknames :fsa.men :menu :📋)
|
(:nicknames :fsa.men :menu :📋)
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
(:export #:menu-state #:make-menu-state
|
(:export #:menu-state #:menu-state-update #:menu-state-draw #:make-menu-state
|
||||||
:label :selection :selected))
|
:label :selection :selected))
|
||||||
|
|
||||||
(defpackage :flora-search-aurora.dialogue
|
(defpackage :flora-search-aurora.dialogue
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
(:nicknames :fsa.o :overworld :🌍)
|
(:nicknames :fsa.o :overworld :🌍)
|
||||||
(:use :cl
|
(:use :cl
|
||||||
:flora-search-aurora.overworld.util)
|
:flora-search-aurora.overworld.util)
|
||||||
(:export #:overworld-state #:make-overworld-state #:overworld-state-draw
|
(:export #:overworld-state #:overworld-state-draw #:make-overworld-state
|
||||||
#:merge-maps
|
#:merge-maps
|
||||||
#:world-coords->screen-coords
|
#:world-coords->screen-coords
|
||||||
#:getf-entity #:getf-entity-data #:removef-entity
|
#:getf-entity #:getf-entity-data #:removef-entity
|
||||||
|
|
Ŝarĝante…
Reference in New Issue