Some duplication, but it's a nice experience.

This commit is contained in:
Bryce Covert
2017-02-09 22:13:14 -08:00
parent 592a609129
commit a4edcf1277
2 changed files with 94 additions and 66 deletions

View File

@@ -295,8 +295,9 @@
:on-render :on-render
(fn [{:keys [camera ^FitViewport viewport] :as screen} entities options] (fn [{:keys [camera ^FitViewport viewport] :as screen} entities options]
(.apply viewport) (.apply viewport)
(render! screen [(:label entities) (:action-icon entities)]) (let [entities (utils/apply-tweens screen entities (:tweens entities))]
entities) (render! screen [(:label entities) (or (:action-icon entities) (:item-icon entities) )])
entities))
:on-hover-start :on-hover-start
(fn [screen {:keys [all-icons] :as entities} {:keys [hover-text x y scene-viewport cursor ]}] (fn [screen {:keys [all-icons] :as entities} {:keys [hover-text x y scene-viewport cursor ]}]
@@ -329,6 +330,47 @@
true (update-in [:label] ensure-on-screen)))) true (update-in [:label] ensure-on-screen))))
:on-select-item
(fn [screen {:keys [all-icons] :as entities} {:keys [selected-item upright? in-or-out hide-or-show notify]}]
(let [fade-tween (if (= :hide hide-or-show)
(tween/tween :appear-item screen [:item-icon :opacity] 1.0 0.0 0.5 :ease tween/ease-linear :finish (fn [entities] (reset! notify true) (dissoc entities :item-icon)))
(tween/tween :appear-item screen [:item-icon :opacity] 0.0 1.0 0.5 :ease tween/ease-linear :finish (fn [entities] (reset! notify true) entities)))
move-tween (condp = in-or-out
:far-out
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 45) 0.5 :ease tween/ease-linear)
:out
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 35) (* utils/ui-scale 4 40) 0.5 :ease tween/ease-linear)
:in
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 35) 0.5 :ease tween/ease-linear)
:none
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 40) 0.5 :ease tween/ease-linear))]
(-> entities
(assoc :item-icon
(assoc (texture (aget all-icons 0 (.indexOf utils/+all-cursors+ (:cursor selected-item))))
:origin-x 8
:origin-y 0
:scale-x (* 4 utils/ui-scale)
:scale-y (* 4 utils/ui-scale)
:x (* utils/ui-scale 4 (condp = in-or-out
:in
40
:out
35
:none
40
:far-out
40))
:y 0
:baseline 9000
:opacity (if (= :hide hide-or-show) 1.0 0.0)
:item selected-item))
(assoc-in [:tweens :appear-item] fade-tween)
(assoc-in [:tweens :appear-item-y] move-tween))))
#_#_:on-update-camera #_#_:on-update-camera
(fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [scene-viewport scene-camera]}] (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [scene-viewport scene-camera]}]
(reduce-kv (fn [entities id e] (reduce-kv (fn [entities id e]

View File

@@ -1534,15 +1534,17 @@
(assoc-in [:inv-fsm :transition-steps] transitions))) (assoc-in [:inv-fsm :transition-steps] transitions)))
(defn appear-transition [item hide-or-show in-or-out] (defn appear-transition [item hide-or-show in-or-out]
(let [notify (atom false)]
(reify ITransition (reify ITransition
(start-transition [this screen entities] (start-transition [this screen entities]
(let [upright? (= 0.0 (get-in entities [:inventory :angle] 0.0))
fade-tween (if (= :hide hide-or-show)
(tween/tween :appear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-linear)
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-linear))
move-tween (if upright? (let [upright? (= 0.0 (get-in entities [:inventory :angle] 0.0))]
(condp = in-or-out (if upright?
(let [fade-tween (if (= :hide hide-or-show)
(tween/tween :appear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-linear :finish (fn [e] (reset! notify true) e))
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-linear :finish (fn [e] (reset! notify true) e)))
move-tween (condp = in-or-out
:far-out :far-out
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 40) 0.5 :ease tween/ease-linear) (tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 40) 0.5 :ease tween/ease-linear)
:out :out
@@ -1552,19 +1554,7 @@
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 30) 0.5 :ease tween/ease-linear) (tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 30) 0.5 :ease tween/ease-linear)
:none :none
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 35) 0.5 :ease tween/ease-linear)) (tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 35) 0.5 :ease tween/ease-linear))]
(condp = in-or-out
:far-out
(tween/tween :appear-item-y screen [:selected-item :x] (* utils/ui-scale 40) (* utils/ui-scale 45) 0.5 :ease tween/ease-linear)
:out
(tween/tween :appear-item-y screen [:selected-item :x] (* utils/ui-scale 35) (* utils/ui-scale 40) 0.5 :ease tween/ease-linear)
:in
(tween/tween :appear-item-y screen [:selected-item :x] (* utils/ui-scale 40) (* utils/ui-scale 35) 0.5 :ease tween/ease-linear)
:none
(tween/tween :appear-item-y screen [:selected-item :x] (* utils/ui-scale 40) (* utils/ui-scale 40) 0.5 :ease tween/ease-linear)))]
(-> entities (-> entities
(assoc :selected-item (assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item)))) (assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
@@ -1572,19 +1562,8 @@
:origin-y 0 :origin-y 0
:scale-x utils/ui-scale :scale-x utils/ui-scale
:scale-y utils/ui-scale :scale-y utils/ui-scale
:x (if upright? :x (* utils/ui-scale 12)
(* utils/ui-scale 12) :y (* utils/ui-scale (condp = in-or-out
(* utils/ui-scale (condp = in-or-out
:in
40
:out
35
:none
40
:far-out
40)))
:y (if upright?
(* utils/ui-scale (condp = in-or-out
:in :in
35 35
:out :out
@@ -1593,16 +1572,23 @@
35 35
:far-out :far-out
35)) 35))
0)
:baseline 9000 :baseline 9000
:opacity (if (= :hide hide-or-show) 1.0 0.0) :opacity (if (= :hide hide-or-show) 1.0 0.0)
:item item)) :item item))
(assoc-in [:tweens :appear-item] fade-tween) (assoc-in [:tweens :appear-item] fade-tween)
(assoc-in [:tweens :appear-item-y] move-tween)))) (assoc-in [:tweens :appear-item-y] move-tween)))
(do
(screen! tooltip-screen :on-select-item {:in-or-out in-or-out
:selected-item item
:hide-or-show hide-or-show
:upright? upright?
:notify notify})
entities))
))
(transition-done? [this screen entities] (transition-done? [this screen entities]
(not (get-in entities [:tweens :appear-item]))))) @notify))))
(defmethod transition-hud [:none :open] (defmethod transition-hud [:none :open]
[screen entities state state-data] [screen entities state state-data]