diff --git a/desktop/project.clj b/desktop/project.clj index d0f7ad95..2c63d3b0 100644 --- a/desktop/project.clj +++ b/desktop/project.clj @@ -26,7 +26,7 @@ :profiles { :dev { :source-paths ["src" "src-common" "src-dev"] - :jvm-opts ["-Duse-repl=true" "-Dno-steam=true"] + :jvm-opts ["-Duse-repl=true" "-Dno-steam=true" "-Dclojure.compiler.direct-linking=true"] :dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"] [org.clojure/tools.nrepl "0.2.7"] [play-clj-nrepl "0.1.0" :exclusions [play-clj]] diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index af83f64a..3b97c71d 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -1343,7 +1343,8 @@ void main () input-x input-y) (if (= (button-code :right) (:button screen)) - (assoc-in entities [:cursor :current] :main) + (do + (screen! hud :on-return-item)) (when (and (get-in entities [:state :active?]) (not (get-in entities [:state :hud-active?])) (= 0.0 (get-in entities [:fade :opacity]))) @@ -1369,7 +1370,7 @@ void main () (screen! hud :on-chose-item :item item) (assoc-in entities [:cursor :current] item)) - :on-show-inventory (fn [screen [entities]] + :on-click-inventory (fn [screen [entities]] (click-inventory screen entities)) :on-save (fn [screen [entities]] (when-not (get-in entities [:fg-actions :script-running?]) @@ -1453,17 +1454,65 @@ void main () (defmethod transition-hud [:none :opening-inventory] [screen entities _] (-> entities - (update-in [:inventory] #(actions/start-animation screen % :open)) - (assoc :opening-inventory? true) + (update-in [:inventory] #(actions/start-animation screen % :open)) (assoc :state :opening-inventory))) (defmethod transition-hud [:opening-inventory :opened-inventory] [screen entities _] - (screen! scene :on-show-inventory) + (screen! scene :on-click-inventory) (-> entities (update-in [:inventory] #(actions/start-animation screen % :opened)) (assoc :state :opened-inventory))) +(defmethod transition-hud [:opened-inventory :closing-inventory] + [screen entities _] + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :closing)) + (assoc :state :closing-inventory))) + +(defmethod transition-hud [:closing-inventory :none] + [screen entities _] + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :default)) + (assoc :state :none))) + +(defmethod transition-hud [:returning-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)) + (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 [:chose-item :returning-item] + [{:keys [cursor] :as screen} entities _] + (screen! scene :on-click-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)) + (update-in [:inventory] (fn [i] (actions/start-animation screen i :closing))) + (assoc :state :returning-item))) + + +(defmethod transition-hud [:choosing-item :chose-item] + [screen entities _] + (-> entities + (update-in [:inventory] #(actions/start-animation screen % :opened)) + (assoc :state :chose-item))) + (defmulti process-state (fn [screen entities] (:state entities))) @@ -1477,6 +1526,28 @@ void main () (- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start]))) (transition-hud screen entities :opened-inventory))) +(defmethod process-state :closing-inventory + [screen entities] + (when + (animation! (get-in entities [:inventory :closing]) + :is-animation-finished + (- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start]))) + (transition-hud screen entities :none))) + +(defmethod process-state :choosing-item + [screen entities] + (when-not (get-in entities [:tweens :appear-item]) + (transition-hud screen entities :chose-item))) + +(defmethod process-state :returning-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))) + (defscreen hud :on-show (fn [screen entities] @@ -1501,7 +1572,7 @@ void main () :anim (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :default (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7]) - :closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [9 10 11 12 0]) + :closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0]) :anim-start 0 :mouse-in? (zone/box 278 0 320 42) :opacity 0.8) @@ -1520,31 +1591,22 @@ void main () (as-> entities entities (update-in entities [:inventory] assoc :r 0.75 :g 0.75 :b 0.75) (grow-hud screen entities :inventory false))) + entities (if (:selected-item entities) + (if hud-interactable? + (as-> entities entities + (update-in entities [:selected-item] assoc :r 1.0 :g 1.0 :b 1.0 )) + (as-> entities entities + (update-in entities [:selected-item] assoc :r 0.75 :g 0.75 :b 0.75) + (grow-hud screen entities :selected-item false))) + entities) entities (if (and hud-interactable? (not (:already-saved? entities))) (as-> entities entities (update-in entities [:save] assoc :r 1.0 :g 1.0 :b 1.0 )) (as-> entities entities (update-in entities [:save] assoc :r 0.75 :g 0.75 :b 0.75) (grow-hud screen entities :save false))) - 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 - (- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))) - (-> entities - (update-in [:inventory] #(actions/start-animation screen % :default))) - 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])))) - (do - (screen! scene :on-show-inventory) - (-> entities - (assoc :opening-inventory? false) - (assoc-in [:inventory :anim] (get-in entities [:inventory :opened])))) - entities)] + + entities (or (process-state screen entities) entities)] #_(label! (:fps entities) :set-text (str (game :fps))) @@ -1555,7 +1617,7 @@ void main () (if hud-interactable? (:inventory entities) (assoc (:inventory entities) :opacity 0.5)) - #_(:selected-item entities) + (:selected-item entities) (:close entities)]) entities)) @@ -1563,6 +1625,13 @@ void main () (fn [{:keys [^FitViewport viewport width height]} entities] (.update viewport width height true)) + :on-return-item + (fn [screen [ entities]] + (if (hud-interactable?) + + (transition-hud screen entities :returning-item))) + + :on-start-script (fn [_ [entities]] (assoc-in entities [:already-saved?] false)) @@ -1570,19 +1639,11 @@ void main () :on-reactivate (fn [{:keys [cursor] :as screen} [entities]] - #_(let [selected-item? (and (:value cursor) + (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))))) + (transition-hud screen entities :choosing-item) + (transition-hud screen entities :closing-inventory)))) :on-mouse-moved (fn [screen [entities]] @@ -1592,7 +1653,11 @@ void main () hovered-save? (utils/intersects? (:save entities) [x y])] (screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?)) (cond (and hovered-inventory? (hud-interactable?)) - (grow-hud screen entities :inventory true) + (as-> entities entities + (grow-hud screen entities :inventory true) + (if (:selected-item entities) + (grow-hud screen entities :selected-item true) + entities)) hovered-close? (grow-hud screen entities :close true) @@ -1603,6 +1668,9 @@ void main () :else (let [entities (update-in entities [:tweens] dissoc :inventory-grow-x :inventory-grow-y) entities (grow-hud screen entities :inventory false) + entities (if (:selected-item entities) + (grow-hud screen entities :selected-item false) + entities) entities (grow-hud screen entities :close false) entities (grow-hud screen entities :save false)] entities @@ -1617,22 +1685,12 @@ void main () (not (hud-interactable?)) nil + ((:mouse-in? (:inventory entities)) x y) - (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))) + (if (:selected-item entities) + (transition-hud screen entities :returning-item) + (transition-hud screen entities :opening-inventory)) (utils/intersects? (:close entities) [x y]) (screen! scene :on-menu)