diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index d1f55f5c..db8d5b15 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/resources/cursor_light.png b/desktop/resources/cursor_light.png index 9b627dbd..af5bd3ba 100644 Binary files a/desktop/resources/cursor_light.png and b/desktop/resources/cursor_light.png differ diff --git a/desktop/src-common/advent/screens/rooms.clj b/desktop/src-common/advent/screens/rooms.clj index 683cfc36..0a0048d8 100644 --- a/desktop/src-common/advent/screens/rooms.clj +++ b/desktop/src-common/advent/screens/rooms.clj @@ -6,7 +6,7 @@ [com.badlogic.gdx.scenes.scene2d Actor Stage] [java.lang Object])) -(defn make-entity [id entity] +(defn make-entity [id {:keys [scripts script only-script] :as entity}] (merge entity {:id id :mouse-in? (fn [entities x y] @@ -22,24 +22,41 @@ ((zone/box entity-x entity-y (+ entity-x (* width (or scale-x 1))) (+ entity-y (* height (or scale-y 1)))) x y)))} - (when (or (:scripts entity) (:script entity)) + (when (or script scripts only-script) {:get-script (fn [cursor [x y]] - (if (= :main cursor) - (:script entity) - (when-let [scripts (:scripts entity)] - (or (scripts (:value cursor)) (scripts :default)))))}))) + (cond only-script + only-script + + (= :main cursor) + script + + scripts + (or (scripts (:value cursor)) (scripts :default)) + + :else + nil) + )}))) (defn make [& {:keys [collision interactions entities] :as params}] - (let [interactions-as-list (for [[id spec] interactions] + (let [interactions-as-list (for [[id {:keys [script scripts only-script box] :as spec}] interactions] (merge spec - (when (:box spec) + (when box {:mouse-in? (fn [_ x y] - ((apply zone/box (:box spec)) x y))}) - {:get-script (fn [cursor [x y]] - (if (= :main cursor) - (:script spec) - (when-let [scripts (:scripts spec)] - (or (scripts (:value cursor)) (scripts :default))))) - :id id})) + ((apply zone/box box) x y))}) + (when (or script scripts only-script) + {:get-script (fn [cursor [x y]] + (cond only-script + only-script + + (= :main cursor) + script + + scripts + (or (scripts (:value cursor)) (scripts :default)) + + :else + nil) + )}) + {:id id})) entities (into {} (for [[id entity] entities] [id (make-entity id entity)]))] (merge params {:collision (advent.pathfind/map-from-resource collision) diff --git a/desktop/src-common/advent/screens/rooms/common.clj b/desktop/src-common/advent/screens/rooms/common.clj index 908c6e06..0f11c4b9 100644 --- a/desktop/src-common/advent/screens/rooms/common.clj +++ b/desktop/src-common/advent/screens/rooms/common.clj @@ -66,6 +66,7 @@ disappear-left {1 [:disappear 0.7]} } :night-profile :sprite + :cursor :talk :origin-x 0 :origin-y 0 :talk-color (color 0.95 0.3 1.0 1.0) diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index bf21f803..260db83e 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -629,7 +629,7 @@ :cauldron-sound {:object nil :sound (utils/load-sound "outsidehouse/cauldron.ogg")} :interactions {:door {:box [250 100 281 160] - :script + :only-script (actions/get-script entities (actions/walk-to entities :ego [257 90] :face :right :skip-type :end) @@ -660,21 +660,21 @@ :cursor :right} :right-dir {:box [220 141 320 204] - :script (actions/get-script + :only-script (actions/get-script entities (actions/walk-to entities :ego [244 150] :skip-type :end) (actions/transition-background entities :behind-house [122 140]) (actions/walk-to entities :ego [172 122])) :cursor :right} :up-dir {:box [105 180 203 240] - :script (actions/get-script + :only-script (actions/get-script entities (actions/walk-to entities :ego [137 204] :skip-type :end) (actions/transition-background entities :cat-tree [223 -51]) (actions/walk-straight-to entities :ego [200 10])) :cursor :up} :left-dir {:box [0 40 40 140] - :script (actions/get-script + :only-script (actions/get-script entities (walk-to-castle entities)) :cursor :left}} @@ -697,6 +697,7 @@ [:stand 1] sheep-1 [:stand 2] sheep-2 [:stand 3] sheep-3 + :cursor :hand :origin-y 3 :origin-x 6 :scale-x (scaler [38 160]) @@ -785,7 +786,7 @@ :outside-particles (common/make-outside-particles) - :magic (assoc (doto (particle-effect "particles/magic") ) + :magic (assoc (particle-effect "particles/magic") :x 153 :y 105 :baseline 238) @@ -796,19 +797,20 @@ :anim-sound-frames {door {1 [:door-sound 0.1]}} ) :lamb (assoc (utils/get-texture "outsidehouse/lamb.png") - :x 10 :y 163 :baseline 77 - :right {:stand (animation 0.1 [lamb-stand]) - :walk lamb-walk} - - :left {:stand (utils/flip (animation 0.1 [lamb-stand])) - :walk (utils/flip lamb-walk)} - :scale-x (scaler [10 163]) - :scale-y (scaler [10 163]) - :script (actions/get-script entities - (actions/talk entities :ego "Aww, it's a newborn lamb!")) - :scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) - :grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) - :sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))}) + :cursor :look + :x 10 :y 163 :baseline 77 + :right {:stand (animation 0.1 [lamb-stand]) + :walk lamb-walk} + + :left {:stand (utils/flip (animation 0.1 [lamb-stand])) + :walk (utils/flip lamb-walk)} + :scale-x (scaler [10 163]) + :scale-y (scaler [10 163]) + :script (actions/get-script entities + (actions/talk entities :ego "Aww, it's a newborn lamb!")) + :scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) + :grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) + :sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))}) :butterfly (assoc (animation->texture screen butterfly-stand) :x 161 :y 218 @@ -823,6 +825,7 @@ a (catmull-rom-spline! ^CatmullRomSpline (:path entity) :value-at v pos-f)] (assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))} :cauldron (rooms/make-entity :cauldron (assoc (animation->texture screen cauldron) + :cursor :look :x 139 :y 73 :baseline 167 :anim cauldron :anim-start 0 @@ -832,6 +835,7 @@ :scripts put-something-in-cauldron)) :charcoal (rooms/make-entity :charcoal (assoc (animation->texture screen charcoal) + :cursor :hand :anim charcoal :anim-start 0 :night-profile :none @@ -854,6 +858,7 @@ :wizard "Good job, Tick."))}})) :note (rooms/make-entity :note (assoc (utils/get-texture "outsidehouse/note.png") :x 277 :y 74 :baseline 160 + :cursor :hand :night-profile :none :script (actions/get-script entities (actions/walk-to entities :ego [280 80] :face :right) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index e5cf8dd4..6b0b70fb 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -221,7 +221,8 @@ void main () (get-in entities [:room :interactions]))) ) (defn get-interacting-entity [entities x y] - (let [interactable-entities (if (= (doto (get-selected-inventory-item) (#(log/info "clicked with " %)) ) :main) + (let [interactable-entities (if (= (doto (get-selected-inventory-item) + (#(log/info "clicked with " %)) ) :main) (vals (dissoc (get-in entities [:room :entities]) :ego)) (vals (get-in entities [:room :entities]))) interacting-entity (first (sort-by (comp - :baseline) @@ -248,13 +249,13 @@ void main () (or (= (get-in entities [:cursor :down-target]) (or (:id interacting-entity) (:id interaction) nil)) (get-in entities [:cursor :came-from-inventory?]))) - ((or (when (and interacting-entity (not (:cursor interaction))) + ((or (when (and (not (:override-cursor interaction)) + interacting-entity) (do (screen! hud :on-start-script {}) ((:get-script interacting-entity) (get-script-selector entities) [x y]))) (when interaction (do (screen! hud :on-start-script {}) - ((:get-script interaction) (or (when (:cursor interaction) :main) - (get-script-selector entities)) + ((:get-script interaction) (get-script-selector entities) [x y]))) ((:get-script default-interaction) (get-script-selector entities) [x y])) entities)) @@ -878,17 +879,35 @@ void main () entities) entities)) -(defn update-cursor [screen {{:keys [override last active was-active]} :cursor :as entities}] - (if (= 0.0 (get-in entities [:fade :opacity])) - (let [new-current (or override (get-selected-inventory-item) :main)] - (when-not (and (= new-current - last) - (= active was-active)) - (let [image-path (if active "cursor_light.png" "cursor.png")] - (graphics! :set-cursor (utils/cursor image-path (or (:cursor new-current) new-current))))) - (update-in entities [:cursor ] assoc :last new-current - :was-active active)) - entities)) +(defn translate-depressed [cursor depressed?] + (if depressed? + (get {:hand :hand-depressed + :talk :talk-depressed + :look :look-depressed} cursor cursor) + cursor)) + +(defn update-cursor [{:keys [total-time] :as screen} {{:keys [override last depressed? time-changed] :or {time-changed 0}} :cursor :as entities}] +(let [new-current (or override (get-selected-inventory-item) :main) + time-changed (double time-changed) + total-time (double total-time)] + (cond + (not= 0.0 (get-in entities [:fade :opacity])) + entities + + (< (unchecked-subtract total-time time-changed) 0.15) + entities + + (= [new-current depressed?] last) + entities + + :else + (do + (graphics! :set-cursor (utils/cursor "cursor.png" (translate-depressed (or (:cursor new-current) new-current) + depressed?))) + (update-in entities [:cursor ] assoc + :last [new-current depressed?] + :time-changed total-time)) + ))) (defn get-looped-animation-point ^double [^Animation animation ^double total-time] @@ -1236,7 +1255,7 @@ void main () :on-resume (fn [screen {{:keys [current override last active was-active]} :cursor :as entities} options] (let [current (or override (get-selected-inventory-item) :main) - image-path (if active "cursor_light.png" "cursor.png")] + image-path "cursor.png"] (graphics! :set-cursor (utils/cursor image-path (or (:cursor current) current)))) (doseq [[k [start time fn]] (get-in entities [:room :timers])] (add-timer! screen k start time))) @@ -1337,7 +1356,7 @@ void main () (set! (. camera zoom) (:zoom (:cam entities))) (set! (.. camera position x) (:x (:cam entities) 160.0)) (set! (.. camera position y) (:y (:cam entities) 120.0))) - (let [#_#_entities (utils/update-override screen entities options) + (let [entities (utils/update-override screen entities options) entities (play-key-sounds screen entities) entities (update-current-sound-vols! entities) entities (remove-ended-sounds screen entities)] @@ -1371,6 +1390,7 @@ void main () (when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport) (.getScreenWidth viewport) (.getScreenHeight viewport) input-x input-y) + ; TODO: override cursor when started in black (when (and (= (button-code :left) (:button options)) (get-in entities [:state :active?]) @@ -1379,22 +1399,31 @@ void main () (let [[x y] (utils/unproject screen options) interaction (get-interaction entities x y) interacting-entity (get-interacting-entity entities x y)] - (assoc-in entities [:cursor :down-target] (or (:id interacting-entity ) (:id interaction) nil)))))) + (-> entities + (assoc-in [:cursor :depressed?] true) + (assoc-in [:cursor :down-target] (or (:id interacting-entity ) (:id interaction) nil))))))) :on-touch-up (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [input-x input-y] :as options}] - - (when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport) - (.getScreenWidth viewport) (.getScreenHeight viewport) - input-x input-y) - (if (= (button-code :right) - (:button options)) - (do - (screen! hud :on-return-item {})) - (when (and (get-in entities [:state :active?]) - (or (not (get-in entities [:state :hud-active?])) - (get-in entities [:fg-actions :script-running?])) - (= 0.0 (get-in entities [:fade :opacity]))) - (left-click screen entities options))))) + (let [entities (assoc-in entities [:cursor :depressed?] false)] + (cond + (not (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport) + (.getScreenWidth viewport) (.getScreenHeight viewport) + input-x input-y)) + entities + + (= (button-code :right) + (:button options)) + (do (screen! hud :on-return-item {}) + entities) + + (and (get-in entities [:state :active?]) + (or (not (get-in entities [:state :hud-active?])) + (get-in entities [:fg-actions :script-running?])) + (= 0.0 (get-in entities [:fade :opacity]))) + (left-click screen entities options) + + :else + entities))) :on-deactivate (fn [screen entities options] (assoc-in entities [:state :active?] false)) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 10ca8ab9..9ea40f06 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -45,13 +45,13 @@ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (log/info (:input-x screen) (:input-y screen) "->" x y))) -(def ^:const +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune]) +(def ^:const +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune :hand :hand-depressed :talk :talk-depressed :look :look-depressed]) (def settings (atom {:music-volume 50.0 :sound-volume 75.0 :fullscreen true})) -(def selected-save (atom nil)) +(defonce selected-save (atom nil)) (defn current-music-volume [& [^double factor]] (-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2) @@ -271,8 +271,7 @@ (assoc entity :x (vector-2! v :x) :y (vector-2! v :y))))))) (defn path-point [speed screen entities entity] - (* (- (:total-time screen) (:path-start-time entity 0.0)) speed) - ) + (* (- (:total-time screen) (:path-start-time entity 0.0)) speed)) (defn update-path-location [speed screen entities entity] (if (:path entity) @@ -291,10 +290,10 @@ (filter #(and (:mouse-in? %) ((:mouse-in? %) entities x y) (not= "ego" (:id %)) - (:script %)) + (:get-script %)) (vals (get-in entities [:room :entities]))) (filter #(and ((:mouse-in? %) entities x y) - (:script %)) + (:get-script %)) (get-in entities [:room :interactions]))))) (defn hovering-ego [entities [x y]] @@ -388,7 +387,8 @@ (.getScreenWidth viewport) (.getScreenHeight viewport) (first raw-pos) (last raw-pos))) hovering-ego (hovering-ego entities last-pos) - current (get-in entities [:cursor :current])] + current (get-in entities [:cursor :current]) + selected-inventory-item (@(resolve 'advent.screens.scene/get-selected-inventory-item))] (cond out-of-bounds @@ -397,35 +397,27 @@ (not (get-in entities [:state :active?])) (-> entities - (assoc-in [:cursor :override] nil) - (assoc-in [:cursor :active] false)) + (assoc-in [:cursor :override] nil)) (is-unstoppable-script-running screen entities) (-> entities - (assoc-in [:cursor :override] :hourglass) - (assoc-in [:cursor :active] false)) + (assoc-in [:cursor :override] :hourglass)) (get-in entities [:state :hud-active?]) (-> entities - (assoc-in [:cursor :override] nil) - (assoc-in [:cursor :active] false)) + (assoc-in [:cursor :override] nil)) - (and hovering-ego (not @(resolve 'advent.screens.scene/get-selected-inventory-item))) - (-> entities - (assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main))) - (assoc-in [:cursor :active] true)) + (and mouse-override (:only-script mouse-override)) + (assoc-in entities [:cursor :override] (:cursor mouse-override)) + + selected-inventory-item + (assoc-in entities [:cursor :override] selected-inventory-item) mouse-override - (-> entities - (assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main))) - (assoc-in [:cursor :active] true)) - - + (assoc-in entities [:cursor :override] (:cursor mouse-override)) :else - (-> entities - (assoc-in [:cursor :override] nil) - (assoc-in [:cursor :active] false))))) + (assoc-in entities [:cursor :override] :main)))) (def default-night-merge {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 1.0 :hue-amount 1.0}) (def default-night-merge-sprite {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 0.3 :hue-amount 0.4})