diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index f447f569..af83f64a 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -1353,8 +1353,7 @@ void main () (assoc-in entities [:state :active?] false)) :on-reactivate (fn [screen [entities]] - - (screen! hud :on-reactivate) + (screen! hud :on-reactivate :cursor (get-in entities [:cursor :current])) (-> entities (assoc-in [:state :active?] true) (assoc-in [:cursor :override] nil))) @@ -1448,14 +1447,45 @@ void main () (get-in scene-entities [:state :active?]) (= 0.0 (get-in scene-entities [:fade :opacity]))))) +(defmulti transition-hud (fn [screen entities new-state] [(:state entities) new-state])) +(defmethod transition-hud :default [screen entities new-state] entities) + +(defmethod transition-hud [:none :opening-inventory] + [screen entities _] + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :open)) + (assoc :opening-inventory? true) + (assoc :state :opening-inventory))) + +(defmethod transition-hud [:opening-inventory :opened-inventory] + [screen entities _] + (screen! scene :on-show-inventory) + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :opened)) + (assoc :state :opened-inventory))) + +(defmulti process-state (fn [screen entities] + (:state entities))) + +(defmethod process-state :default [screen entities] entities) + +(defmethod process-state :opening-inventory + [screen entities] + (when + (animation! (get-in entities [:inventory :open]) + :is-animation-finished + (- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start]))) + (transition-hud screen entities :opened-inventory))) + (defscreen hud :on-show (fn [screen entities] (let [screen (assoc screen :total-time 0)] (utils/setup-viewport screen 320 240) - {:already-saved? false - :opening-inventory? false + {:state :none + :already-saved? false + :close (assoc (utils/get-texture "close.png") :x 304 :y 224 :width 16 :height 16 @@ -1496,7 +1526,8 @@ void main () (as-> entities entities (update-in entities [:save] assoc :r 0.75 :g 0.75 :b 0.75) (grow-hud screen entities :save false))) - entities (if (and (= (get-in entities [:inventory :anim]) + entities (or (process-state screen entities) entities) + #_#_entities (if (and (= (get-in entities [:inventory :anim]) (get-in entities [:inventory :closing])) (animation! (get-in entities [:inventory :closing]) :is-animation-finished @@ -1504,7 +1535,7 @@ void main () (-> entities (update-in [:inventory] #(actions/start-animation screen % :default))) entities) - entities (if (and (:opening-inventory? entities) + #_#_entities (if (and (:opening-inventory? entities) (animation! (get-in entities [:inventory :open]) :is-animation-finished (- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))) @@ -1516,6 +1547,7 @@ void main () entities)] #_(label! (:fps entities) :set-text (str (game :fps))) + (render! screen [ (if (and hud-interactable? (not (:already-saved? entities))) (:save entities) @@ -1523,7 +1555,7 @@ void main () (if hud-interactable? (:inventory entities) (assoc (:inventory entities) :opacity 0.5)) - (:selected-item entities) + #_(:selected-item entities) (:close entities)]) entities)) @@ -1535,17 +1567,22 @@ void main () (fn [_ [entities]] (assoc-in entities [:already-saved?] false)) - :on-chose-item - (fn [{:keys [item]} [entities]] - (println utils/+all-cursors+ (.indexOf utils/+all-cursors+ :ball-n-chain) (.indexOf utils/+all-cursors+ (:cursor item) ) (:all-items entities)) - (assoc entities :selected-item - (doto (assoc (texture (aget (get-in entities [:all-items ]) 0 (.indexOf utils/+all-cursors+ (:cursor item)))) - :x 295 :y 40 :baseline 9000 :opacity 1.0) println) - )) :on-reactivate - (fn [screen [entities]] - (update-in entities [:inventory] #(actions/start-animation screen % :closing))) + (fn [{:keys [cursor] :as screen} [entities]] + #_(let [selected-item? (and (:value cursor) + (:cursor cursor))] + (if selected-item? + (do + (-> 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)) + (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)))) + (update-in entities [:inventory] #(actions/start-animation screen % :closing))))) :on-mouse-moved (fn [screen [entities]] @@ -1581,9 +1618,20 @@ void main () nil ((:mouse-in? (:inventory entities)) x y) - (-> entities - (update-in [:inventory] #(actions/start-animation screen % :open)) - (assoc :opening-inventory? true)) + (transition-hud screen entities :opening-inventory) + #_(if (:selected-item entities) + (do + (screen! scene :on-show-inventory) + (-> 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 30 0.5 :ease tween/ease-in-out-quadratic + :finish #(update-in % [:inventory] + (fn [i] (actions/start-animation screen i :closing))))))) + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :open)) + (assoc :opening-inventory? true))) (utils/intersects? (:close entities) [x y])