diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 2e8e1ed8..ddbbd6d2 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -70,7 +70,10 @@ (let [fg-bg-key *fg-bg-key*] (run-action entities (begin [this screen entities] - (update-in entities [fg-bg-key] assoc :script-running? state :last-skip-type (if state :end nil))) + (-> entities + (update-in [fg-bg-key] + assoc :script-running? state :last-skip-type (if state :end nil)) + (assoc-in [:cursor :came-from-inventory?] false))) (continue [this screen entities] entities) diff --git a/desktop/src-common/advent/screens/inventory.clj b/desktop/src-common/advent/screens/inventory.clj index cec613ca..3223e12f 100644 --- a/desktop/src-common/advent/screens/inventory.clj +++ b/desktop/src-common/advent/screens/inventory.clj @@ -21,9 +21,9 @@ (and (:shown? entities) (= 1.0 (:opacity entities)))) -(defn close [screen entities script-started?] +(defn close [screen entities script-started? dragged-out?] (log/info "closing inventory") - (screen! @(resolve 'advent.screens.scene/scene) :on-reactivate :script-started? script-started?) + (screen! @(resolve 'advent.screens.scene/scene) :on-reactivate :script-started? script-started? :came-from-inventory? dragged-out?) (-> entities (assoc-in [:tweens :fade-out] (tween/tween :fade-out screen [:opacity] 1.0 0.0 0.2 :ease tween/ease-out-cubic :finish #(assoc % :shown? false))))) @@ -46,7 +46,7 @@ (cond (and selected-item (mouse-outside-inventory? [x y])) (do (screen! @(resolve 'advent.screens.scene/scene) :on-chose-item :item selected-item) - (close screen entities false)) + (close screen entities false true)) selected-item (-> entities @@ -73,7 +73,7 @@ (log/info "chose inventory item" selected-item) (println selected-item hovered-item dragged?) (cond (not selected-item) - (close screen entities false) + (close screen entities false false) (and (= selected-item hovered-item) dragged?) @@ -81,12 +81,12 @@ (or (not hovered-item) (= selected-item hovered-item)) (do (screen! @(resolve 'advent.screens.scene/scene) :on-chose-item :item selected-item) - (close screen entities false)) + (close screen entities false false)) :else (when-let [interaction-script (or ((or (:scripts selected-item) (constantly nil)) (:value hovered-item)) (actions/get-script entities (actions/talk entities :ego "I'm not sure how those go together.")))] (interaction-script room-entities) - (close screen entities true))))) + (close screen entities true false))))) (defn right-click [screen {:keys [selected-item] :as entities} ] (let [ @@ -98,7 +98,7 @@ ego (get-in room-entities [:room :entities :ego])] (when (and selected-item (= :main current-cursor)) (((:get-script ego) selected-item [0 0]) room-entities) - (close screen entities)))) + (close screen entities true false)))) (defn update-hovered-text [screen {:keys [hovered-text hovered-item selected-item] :as entities}] (cond diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index f3139010..afef37d3 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -249,8 +249,9 @@ void main () (when (and (not (get-in entities [:fg-actions :script-running?])) - (= (get-in entities [:cursor :down-target]) - (or (:id interacting-entity) (:id interaction) nil))) + (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))) (do (screen! hud :on-start-script) ((:get-script interacting-entity) (or (get-selected-inventory-item) (get-in entities [:cursor :current])) [x y]))) @@ -883,7 +884,6 @@ void main () entities)) (defn update-cursor [screen {{:keys [current 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) current)] (when-not (and (= new-current @@ -896,7 +896,6 @@ void main () entities)) - (defn get-looped-animation-point [^Animation animation ^double total-time] (mod total-time (animation! animation :get-animation-duration))) @@ -1367,11 +1366,12 @@ void main () :on-deactivate (fn [screen [entities]] (assoc-in entities [:state :active?] false)) - :on-reactivate (fn [{:keys [script-started?] :as screen} [entities]] + :on-reactivate (fn [{:keys [script-started? came-from-inventory?] :as screen} [entities]] (screen! hud :on-reactivate :cursor (get-in entities [:cursor :current]) :script-started? script-started?) (-> entities (assoc-in [:state :active?] true) - (assoc-in [:cursor :current] :main))) + (assoc-in [:cursor :current] :main) + (assoc-in [:cursor :came-from-inventory?] came-from-inventory?))) :on-end-safe (fn [screen [entities]] ((actions/get-script entities