From 473f4ea638ee04a119fb2d07166f7159c3ec4e2e Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Thu, 19 Feb 2015 16:09:07 -0800 Subject: [PATCH] fixed inventory and junk. --- desktop/src-common/advent/screens/scene.clj | 114 ++++++++++++-------- desktop/src-common/advent/screens/title.clj | 2 +- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 43830d5c..97806859 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -62,42 +62,34 @@ (defn left-click [screen entities] (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] - (cond - ((:mouse-in? (:inventory entities)) x y) - (click-inventory screen entities) - (utils/intersects? (:close entities) [x y]) - (assoc-in entities [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen)) - %))) + (let [interaction (first (filter #((:mouse-in? %) entities x y) + (get-in entities [:room :interactions]))) + interacting-entity (first (sort-by (comp - :baseline) (filter #(and (:mouse-in? %) + (:get-script %) + ((:mouse-in? %) entities x y)) + (vals (get-in entities [:room :entities]))))) + current-action (get-in entities [:actions :current]) + + ;; TODO - hacky way of resetting queue + entities (if (and current-action (actions/can-skip? current-action screen entities)) + (let [terminated-entities (actions/terminate current-action screen entities)] + (do (put! (actions/get-channel current-action) terminated-entities) + (-> terminated-entities + (assoc-in [:actions :current] nil) + (assoc-in [:actions :started?] false)))) + entities)] - :else - (let [interaction (first (filter #((:mouse-in? %) entities x y) - (get-in entities [:room :interactions]))) - interacting-entity (first (sort-by (comp - :baseline) (filter #(and (:mouse-in? %) - (:get-script %) - ((:mouse-in? %) entities x y)) - (vals (get-in entities [:room :entities]))))) - current-action (get-in entities [:actions :current]) - - ;; TODO - hacky way of resetting queue - entities (if (and current-action (actions/can-skip? current-action screen entities)) - (let [terminated-entities (actions/terminate current-action screen entities)] - (do (put! (actions/get-channel current-action) terminated-entities) - (-> terminated-entities - (assoc-in [:actions :current] nil) - (assoc-in [:actions :started?] false)))) - entities)] - - (if (get-in entities [:actions :script-running?]) - entities - ((or (when interacting-entity - ((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])) - (when interaction - ((:get-script interaction) (or (when (:cursor interaction) :main) - (get-in entities [:cursor :current])) - [x y])) - - ((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities)) - entities)))) + (if (get-in entities [:actions :script-running?]) + entities + ((or (when interacting-entity + ((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])) + (when interaction + ((:get-script interaction) (or (when (:cursor interaction) :main) + (get-in entities [:cursor :current])) + [x y])) + + ((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities)) + entities))) (defn drink-blergh [entities] (actions/walk-straight-to entities :ego [205 45]) @@ -441,8 +433,6 @@ :value 0.0} :music-override {:object nil :value nil} - :close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000) - :cursor {:id "cursor" :current :main :last :main @@ -452,10 +442,7 @@ :fade-in-music (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :ease tween/ease-in-cubic)} :all-items (assoc items/items :object nil) :room (as-> (get rooms (:last-room (get-state))) room - (assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room))))) - :inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000 - :mouse-in? (zone/box 278 0 320 42)) - :fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}] + (assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))}] (music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value])) (utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))])) @@ -513,11 +500,7 @@ (doseq [m (vals (get-in entities [:musics]))] (when m (music! m :set-volume (get-in entities [:volume :value])))) - - - (label! (:fps entities) :set-text (str (game :fps))) (render! screen (sort-by :baseline all-entities)) - (render! screen [(:fps entities)]) entities)) :on-resize (fn [screen entities] @@ -552,6 +535,47 @@ :on-chose-item (fn [{:keys [item]} [entities]] (assoc-in entities [:cursor :current] item)) + :on-show-inventory (fn [screen [entities]] + (click-inventory screen entities)) + :on-close (fn [screen [entities]] + (assoc-in entities [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen)) + %)))) + :on-start-script (fn [{:keys [script]} [entities]] (script entities) entities)) + +(defscreen hud + :on-show + (fn [screen entities] + (let [screen (assoc screen :total-time 0)] + (update! screen :renderer (stage) :camera (orthographic)) + {:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000) + :inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000 + :mouse-in? (zone/box 278 0 320 42)) + :fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)})) + + :on-render + (fn [screen [entities]] + (label! (:fps entities) :set-text (str (game :fps))) + (render! screen [(:fps entities) (:inventory entities) (:close entities)]) + entities) + + :on-resize + (fn [screen entities] + (size! screen 320 240)) + + + + :on-touch-up + (fn [screen [entities]] + (if (= (button-code :left) (:button screen)) + (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] + (cond ((:mouse-in? (:inventory entities)) x y) + (screen! scene :on-show-inventory) + + (utils/intersects? (:close entities) [x y]) + (screen! scene :on-menu) + + :else + nil))))) diff --git a/desktop/src-common/advent/screens/title.clj b/desktop/src-common/advent/screens/title.clj index 93f715ff..c4ee8423 100644 --- a/desktop/src-common/advent/screens/title.clj +++ b/desktop/src-common/advent/screens/title.clj @@ -83,7 +83,7 @@ (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish (fn [entities] (utils/stop-sound (:music entities)) - (set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen) + (set-screen! @(resolve 'advent.core/advent) scene/scene scene/hud dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen ) entities) :ease tween/ease-in-cubic)) (assoc-in [:tweens :fade-out-music]