most things are working.
This commit is contained in:
@@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
(declare hud)
|
(declare hud)
|
||||||
|
|
||||||
|
(declare get-selected-inventory-item)
|
||||||
|
|
||||||
(def v-shader "attribute vec4 a_position;
|
(def v-shader "attribute vec4 a_position;
|
||||||
attribute vec4 a_color;
|
attribute vec4 a_color;
|
||||||
attribute vec2 a_texCoord0;
|
attribute vec2 a_texCoord0;
|
||||||
@@ -245,14 +247,15 @@ void main ()
|
|||||||
(or (:id interacting-entity) (:id interaction) nil)))
|
(or (:id interacting-entity) (:id interaction) nil)))
|
||||||
((or (when (and interacting-entity (not (:cursor interaction)))
|
((or (when (and interacting-entity (not (:cursor interaction)))
|
||||||
(do (screen! hud :on-start-script)
|
(do (screen! hud :on-start-script)
|
||||||
((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])))
|
((:get-script interacting-entity) (or (get-selected-inventory-item) (get-in entities [:cursor :current])) [x y])))
|
||||||
(when interaction
|
(when interaction
|
||||||
(do (screen! hud :on-start-script)
|
(do (screen! hud :on-start-script)
|
||||||
((:get-script interaction) (or (when (:cursor interaction) :main)
|
((:get-script interaction) (or (when (:cursor interaction) :main)
|
||||||
|
(get-selected-inventory-item)
|
||||||
(get-in entities [:cursor :current]))
|
(get-in entities [:cursor :current]))
|
||||||
[x y])))
|
[x y])))
|
||||||
|
|
||||||
((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
|
((:get-script default-interaction) (or (get-selected-inventory-item) (get-in entities [:cursor :current])) [x y])) entities))
|
||||||
(assoc-in entities [:cursor :down-target] nil)))
|
(assoc-in entities [:cursor :down-target] nil)))
|
||||||
|
|
||||||
|
|
||||||
@@ -876,7 +879,7 @@ void main ()
|
|||||||
(defn update-cursor [screen {{:keys [current override last active was-active]} :cursor :as entities}]
|
(defn update-cursor [screen {{:keys [current override last active was-active]} :cursor :as entities}]
|
||||||
|
|
||||||
(if (= 0.0 (get-in entities [:fade :opacity]))
|
(if (= 0.0 (get-in entities [:fade :opacity]))
|
||||||
(let [new-current (or override current)]
|
(let [new-current (or override (get-selected-inventory-item) current)]
|
||||||
(when-not (and (= new-current
|
(when-not (and (= new-current
|
||||||
last)
|
last)
|
||||||
(= active was-active))
|
(= active was-active))
|
||||||
@@ -1357,7 +1360,7 @@ void main ()
|
|||||||
(screen! hud :on-reactivate :cursor (get-in entities [:cursor :current]))
|
(screen! hud :on-reactivate :cursor (get-in entities [:cursor :current]))
|
||||||
(-> entities
|
(-> entities
|
||||||
(assoc-in [:state :active?] true)
|
(assoc-in [:state :active?] true)
|
||||||
(assoc-in [:cursor :override] nil)))
|
(assoc-in [:cursor :current] :main)))
|
||||||
|
|
||||||
:on-end-safe (fn [screen [entities]]
|
:on-end-safe (fn [screen [entities]]
|
||||||
((actions/get-script entities
|
((actions/get-script entities
|
||||||
@@ -1424,6 +1427,12 @@ void main ()
|
|||||||
(tween/tween [target grow-or-shrink :opacity] screen [target :opacity] opacity-from opacity-to 0.15 :ease tween/ease-in-out-quadratic)))
|
(tween/tween [target grow-or-shrink :opacity] screen [target :opacity] opacity-from opacity-to 0.15 :ease tween/ease-in-out-quadratic)))
|
||||||
entities)))
|
entities)))
|
||||||
|
|
||||||
|
(defn get-selected-inventory-item []
|
||||||
|
(doto
|
||||||
|
(let [[{{:keys [state state-data]} :inv-fsm}] (-> hud :entities deref)]
|
||||||
|
(and (= state :selected)
|
||||||
|
state-data))))
|
||||||
|
|
||||||
(defscreen demo
|
(defscreen demo
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -1509,7 +1518,7 @@ void main ()
|
|||||||
(transition-done? [this screen entities]
|
(transition-done? [this screen entities]
|
||||||
(animation! (get-in entities [:inventory :anim])
|
(animation! (get-in entities [:inventory :anim])
|
||||||
:is-animation-finished
|
:is-animation-finished
|
||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))))
|
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
|
||||||
|
|
||||||
(reify ITransition
|
(reify ITransition
|
||||||
(start-transition [this screen entities]
|
(start-transition [this screen entities]
|
||||||
@@ -1533,7 +1542,7 @@ void main ()
|
|||||||
(transition-done? [this screen entities]
|
(transition-done? [this screen entities]
|
||||||
(animation! (get-in entities [:inventory :anim])
|
(animation! (get-in entities [:inventory :anim])
|
||||||
:is-animation-finished
|
:is-animation-finished
|
||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))))
|
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
|
||||||
|
|
||||||
(reify ITransition
|
(reify ITransition
|
||||||
(start-transition [this screen entities]
|
(start-transition [this screen entities]
|
||||||
@@ -1551,7 +1560,6 @@ void main ()
|
|||||||
(accept-state entities state state-data
|
(accept-state entities state state-data
|
||||||
[(reify ITransition
|
[(reify ITransition
|
||||||
(start-transition [this screen entities]
|
(start-transition [this screen entities]
|
||||||
(screen! scene :on-click-inventory)
|
|
||||||
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
|
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
|
||||||
(transition-done? [this screen entities] true))
|
(transition-done? [this screen entities] true))
|
||||||
(appear-transition state-data :hide :in)
|
(appear-transition state-data :hide :in)
|
||||||
@@ -1601,7 +1609,7 @@ void main ()
|
|||||||
(transition-done? [this screen entities]
|
(transition-done? [this screen entities]
|
||||||
(animation! (get-in entities [:inventory :anim])
|
(animation! (get-in entities [:inventory :anim])
|
||||||
:is-animation-finished
|
:is-animation-finished
|
||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))))
|
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
|
||||||
|
|
||||||
(reify ITransition
|
(reify ITransition
|
||||||
(start-transition [this screen entities]
|
(start-transition [this screen entities]
|
||||||
@@ -1611,19 +1619,40 @@ void main ()
|
|||||||
(transition-done? [this screen entities]
|
(transition-done? [this screen entities]
|
||||||
true))]))
|
true))]))
|
||||||
|
|
||||||
(defmethod transition-hud [:none :aquiring]
|
(defmethod transition-hud [:none :acquire]
|
||||||
|
[screen entities state state-data]
|
||||||
|
(accept-state entities state state-data
|
||||||
|
[(reify ITransition
|
||||||
|
(start-transition [this screen entities]
|
||||||
|
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :open))))
|
||||||
|
(transition-done? [this screen entities]
|
||||||
|
(animation! (get-in entities [:inventory :anim])
|
||||||
|
:is-animation-finished
|
||||||
|
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
|
||||||
|
|
||||||
|
(appear-transition state-data :show :none)
|
||||||
|
(reify ITransition
|
||||||
|
(start-transition [this screen entities]
|
||||||
|
(screen! scene :on-click-inventory)
|
||||||
|
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
|
||||||
|
(transition-done? [this screen entities] true))
|
||||||
|
(appear-transition state-data :hide :in)]))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:acquire :none]
|
||||||
|
[screen entities state state-data]
|
||||||
|
(accept-state entities state state-data [(reify ITransition
|
||||||
|
(start-transition [this screen entities]
|
||||||
|
(-> entities
|
||||||
|
(update-in [:inventory] (fn [i] (actions/start-animation screen i :default)))
|
||||||
|
(dissoc :selected-item)))
|
||||||
|
(transition-done? [this screen entities]
|
||||||
|
true))]))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:selected :acquire]
|
||||||
[screen entities state state-data]
|
[screen entities state state-data]
|
||||||
(accept-state entities state state-data))
|
(accept-state entities state state-data))
|
||||||
|
|
||||||
(defmethod transition-hud [:aquiring :none]
|
(defmethod transition-hud [:aquiring :acquire]
|
||||||
[screen entities state state-data]
|
|
||||||
(accept-state entities state state-data))
|
|
||||||
|
|
||||||
(defmethod transition-hud [:selected :aquiring]
|
|
||||||
[screen entities state state-data]
|
|
||||||
(accept-state entities state state-data))
|
|
||||||
|
|
||||||
(defmethod transition-hud [:aquiring :selected]
|
|
||||||
[screen entities state state-data]
|
[screen entities state state-data]
|
||||||
(accept-state entities state state-data))
|
(accept-state entities state state-data))
|
||||||
|
|
||||||
@@ -1676,11 +1705,13 @@ void main ()
|
|||||||
:baseline 9000
|
:baseline 9000
|
||||||
:opacity 0.8)
|
:opacity 0.8)
|
||||||
:inventory (assoc (utils/get-texture "inventory.png") :x 278 :y 0 :baseline 9000
|
:inventory (assoc (utils/get-texture "inventory.png") :x 278 :y 0 :baseline 9000
|
||||||
:open (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ]))
|
:open (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ]))
|
||||||
|
(animation! :set-play-mode (play-mode :normal)))
|
||||||
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
||||||
:default (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])
|
:opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7])
|
||||||
:closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
|
:closing (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
|
||||||
|
(animation! :set-play-mode (play-mode :normal)))
|
||||||
:anim-start 0
|
:anim-start 0
|
||||||
:mouse-in? (zone/box 278 0 320 42)
|
:mouse-in? (zone/box 278 0 320 42)
|
||||||
:opacity 0.8)
|
:opacity 0.8)
|
||||||
@@ -1735,12 +1766,14 @@ void main ()
|
|||||||
|
|
||||||
:on-give-item
|
:on-give-item
|
||||||
(fn [{:keys [item] :as screen} [ entities]]
|
(fn [{:keys [item] :as screen} [ entities]]
|
||||||
(-> entities
|
(doto
|
||||||
(update-in [:inv-fsm :pending-states] conj [:acquire item])
|
(-> entities
|
||||||
(update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}]
|
(update-in [:inv-fsm :pending-states] conj [:acquire item])
|
||||||
(if (and (= state :selected) (= item state-data))
|
(update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}]
|
||||||
(update-in fsm [:pending-states] conj [:none state-data])
|
(if (and (= state :selected) (= item state-data))
|
||||||
(update-in fsm [:pending-states] conj [state state-data]))))))
|
(update-in fsm [:pending-states] conj [:none state-data])
|
||||||
|
(update-in fsm [:pending-states] conj [state state-data])))))
|
||||||
|
(#(println (get-in % [:inv-fsm :pending-states])))))
|
||||||
|
|
||||||
:on-remove-item
|
:on-remove-item
|
||||||
(fn [{:keys [item] :as screen} [ entities]]
|
(fn [{:keys [item] :as screen} [ entities]]
|
||||||
|
|||||||
Reference in New Issue
Block a user