more good progress with inventory

This commit is contained in:
2016-07-28 19:59:14 -07:00
parent d857ae0511
commit aa081fa2ac
2 changed files with 80 additions and 2 deletions

View File

@@ -541,6 +541,7 @@
(defn remove-item [entities item]
(run-action entities
(begin [this screen entities]
(screen! @(resolve 'advent.screens.scene/hud) :on-remove-item :item item)
(-> entities
(update-in [:state :inventory] #(remove (partial = item) %))
(assoc-in [:cursor :current] :main)))
@@ -582,6 +583,7 @@
(run-action entities
(begin [this screen entities]
(utils/play-sound! screen entities :pickup (constantly 0.3))
(screen! @(resolve 'advent.screens.scene/hud) :on-give-item :item ((:all-items entities) item))
(-> entities
(update-in [:state :inventory] #(conj % item))
(update-in [:state :obtained-items] #(conj % item))

View File

@@ -1483,18 +1483,54 @@ void main ()
(dissoc :selected-item)
(assoc :state :none)))
(defmethod transition-hud [:remove-item :none]
[screen entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :default))
(dissoc :selected-item)
(assoc :state :none)))
(defmethod transition-hud [:opened-inventory :choosing-item]
[{:keys [cursor] :as screen} entities _]
(-> entities
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor cursor))))
:x 300 :y 40 :baseline 9000 :opacity 0.0))
:x 300 :y 40 :baseline 9000 :opacity 0.0
:item cursor))
(assoc-in [:tweens :appear-item]
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :appear-item-y]
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-in-out-quadratic))
(assoc :state :choosing-item)))
(defmethod transition-hud [:none :choosing-item]
[{:keys [cursor] :as screen} entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :open))
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor cursor))))
:x 300 :y 40 :baseline 9000 :opacity 0.0
:item cursor))
(assoc-in [:tweens :appear-item]
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :appear-item-y]
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-in-out-quadratic))
(assoc :state :choosing-item)))
(defmethod transition-hud [:none :give-item]
[{:keys [item] :as screen} entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :opened))
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:x 300 :y 40 :baseline 9000 :opacity 0.0
:item item))
(assoc-in [:tweens :appear-item]
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :appear-item-y]
(tween/tween :appear-item-y screen [:selected-item :y] 40 35 0.5 :ease tween/ease-in-out-quadratic))
(assoc :state :give-item)))
(defmethod transition-hud [:chose-item :returning-item]
[{:keys [cursor] :as screen} entities _]
(screen! scene :on-click-inventory)
@@ -1506,6 +1542,21 @@ void main ()
(update-in [:inventory] (fn [i] (actions/start-animation screen i :closing)))
(assoc :state :returning-item)))
(defmethod transition-hud [:chose-item :remove-item]
[{:keys [cursor] :as screen} entities _]
(-> entities
(assoc-in [:tweens :disappear-item]
(tween/tween :disappear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :disappear-item-y]
(tween/tween :disappear-item-y screen [:selected-item :y] 35 40 0.5 :ease tween/ease-in-out-quadratic))
(update-in [:inventory] (fn [i] (actions/start-animation screen i :closing)))
(assoc :state :remove-item)))
(defmethod transition-hud [:give-item :chose-item]
[screen entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :opened))
(assoc :state :chose-item)))
(defmethod transition-hud [:choosing-item :chose-item]
[screen entities _]
@@ -1548,6 +1599,20 @@ void main ()
(not (get-in entities [:tweens :disappear-item])))
(transition-hud screen entities :none)))
(defmethod process-state :remove-item
[screen entities]
(when
(and (animation! (get-in entities [:inventory :closing])
:is-animation-finished
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
(not (get-in entities [:tweens :disappear-item])))
(transition-hud screen entities :none)))
(defmethod process-state :give-item
[screen entities]
(when-not (get-in entities [:tweens :appear-item])
(transition-hud screen entities :chose-item)))
(defscreen hud
:on-show
(fn [screen entities]
@@ -1625,6 +1690,17 @@ void main ()
(fn [{:keys [^FitViewport viewport width height]} entities]
(.update viewport width height true))
:on-give-item
(fn [screen [ entities]]
(transition-hud screen entities :give-item))
:on-remove-item
(fn [{:keys [item] :as screen} [ entities]]
(println "removing...")
(when (= (:value item) (get-in entities [:selected-item :value]))
(transition-hud screen entities :remove-item)))
:on-return-item
(fn [screen [ entities]]
(if (hud-interactable?)
@@ -1640,7 +1716,7 @@ void main ()
:on-reactivate
(fn [{:keys [cursor] :as screen} [entities]]
(let [selected-item? (and (:value cursor)
(:cursor cursor))]
(:cursor cursor))]
(if selected-item?
(transition-hud screen entities :choosing-item)
(transition-hud screen entities :closing-inventory))))