updates on leaving inventory screen.
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
||||||
InputMultiplexer InputProcessor Net Preferences Screen]))
|
InputMultiplexer InputProcessor Net Preferences Screen]))
|
||||||
|
|
||||||
|
(defn interactable? [entities]
|
||||||
|
(and (:shown? entities) (= 1.0 (:opacity entities))))
|
||||||
|
|
||||||
|
|
||||||
(defn close [screen entities script-started?]
|
(defn close [screen entities script-started?]
|
||||||
(log/info "closing inventory")
|
(log/info "closing inventory")
|
||||||
@@ -30,17 +33,29 @@
|
|||||||
selected-entity (first (filter #((:box %) x y) (vals (:items entities))))]
|
selected-entity (first (filter #((:box %) x y) (vals (:items entities))))]
|
||||||
(assoc entities :selected-item (:item selected-entity))))
|
(assoc entities :selected-item (:item selected-entity))))
|
||||||
|
|
||||||
|
(defn mouse-outside-inventory? [[x y]]
|
||||||
|
(or (< x 80)
|
||||||
|
(> x 1200)
|
||||||
|
(< y 80)
|
||||||
|
(> y 880)))
|
||||||
|
|
||||||
(defn mouse-drag [screen [{:keys [selected-item] :as entities}]]
|
(defn mouse-drag [screen [{:keys [selected-item] :as entities}]]
|
||||||
(let [[x y] (utils/unproject screen)
|
(when (interactable? entities)
|
||||||
hovered-entity (first (filter #((:box %) x y) (vals (:items entities))))
|
(let [[x y] (utils/unproject screen)
|
||||||
]
|
hovered-entity (first (filter #((:box %) x y) (vals (:items entities))))]
|
||||||
(if selected-item
|
(cond
|
||||||
(-> entities
|
(and selected-item (mouse-outside-inventory? [x y]))
|
||||||
(assoc-in [:items selected-item :x] (- x 32))
|
(do (screen! @(resolve 'advent.screens.scene/scene) :on-chose-item :item selected-item)
|
||||||
(assoc-in [:items selected-item :y] (- y 32))
|
(close screen entities false))
|
||||||
(assoc :dragged? true)
|
|
||||||
(assoc :hovered-item (:item hovered-entity)))
|
selected-item
|
||||||
(assoc entities :hovered-item (:item hovered-entity) :dragged? true))))
|
(-> entities
|
||||||
|
(assoc-in [:items selected-item :x] (- x 32))
|
||||||
|
(assoc-in [:items selected-item :y] (- y 32))
|
||||||
|
(assoc :dragged? true)
|
||||||
|
(assoc :hovered-item (:item hovered-entity)))
|
||||||
|
:else
|
||||||
|
(assoc entities :hovered-item (:item hovered-entity) :dragged? true)))))
|
||||||
|
|
||||||
|
|
||||||
(defn mouse-move [screen [entities]]
|
(defn mouse-move [screen [entities]]
|
||||||
@@ -119,10 +134,9 @@
|
|||||||
:hovered-text hovered-text}))
|
:hovered-text hovered-text}))
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
|
(fn [{:keys [^FitViewport viewport] :as screen} [{:keys [shown? tweens] :as entities}]]
|
||||||
(.apply viewport)
|
(.apply viewport)
|
||||||
(let [
|
(let [entities (utils/apply-tweens screen entities tweens)
|
||||||
entities (utils/apply-tweens screen entities (:tweens entities))
|
|
||||||
opacity (get-in entities [:opacity])
|
opacity (get-in entities [:opacity])
|
||||||
entities (-> entities
|
entities (-> entities
|
||||||
(assoc-in [:overlay :opacity] opacity)
|
(assoc-in [:overlay :opacity] opacity)
|
||||||
@@ -134,7 +148,7 @@
|
|||||||
|
|
||||||
items items))))]
|
items items))))]
|
||||||
|
|
||||||
(when (:shown? entities)
|
(when shown?
|
||||||
(doto (:hovered-text entities)
|
(doto (:hovered-text entities)
|
||||||
(label! :set-color (color 1 1 1 opacity)))
|
(label! :set-color (color 1 1 1 opacity)))
|
||||||
(render! screen [(:fade entities) (:overlay entities)])
|
(render! screen [(:fade entities) (:overlay entities)])
|
||||||
@@ -146,9 +160,7 @@
|
|||||||
|
|
||||||
:show-screen (fn [{items :items :as screen} [entities]]
|
:show-screen (fn [{items :items :as screen} [entities]]
|
||||||
(log/info "showing inventory")
|
(log/info "showing inventory")
|
||||||
(if (:shown? entities)
|
(when-not (:shown? entities)
|
||||||
entities
|
|
||||||
|
|
||||||
(-> entities
|
(-> entities
|
||||||
(assoc :shown? true
|
(assoc :shown? true
|
||||||
:opacity 0.0
|
:opacity 0.0
|
||||||
@@ -165,13 +177,13 @@
|
|||||||
padding (/ item-width 2)
|
padding (/ item-width 2)
|
||||||
padding (* 4 padding)]]
|
padding (* 4 padding)]]
|
||||||
[item (assoc (texture (aget (:all-items entities) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
|
[item (assoc (texture (aget (:all-items entities) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
|
||||||
:x x :y y
|
:x x :y y
|
||||||
:scale-x 4
|
:scale-x 4
|
||||||
:scale-y 4
|
:scale-y 4
|
||||||
:origin-x 0
|
:origin-x 0
|
||||||
:origin-y 0
|
:origin-y 0
|
||||||
:item item
|
:item item
|
||||||
:box (zone/box (- offset-x padding) (- offset-y padding) (+ offset-x item-width padding padding) (+ offset-y item-width padding padding)))])))
|
:box (zone/box (- offset-x padding) (- offset-y padding) (+ offset-x item-width padding padding) (+ offset-y item-width padding padding)))])))
|
||||||
(assoc-in [:tweens :fade-in] (tween/tween :fade-in screen [:opacity] 0.0 1.0 0.2 :ease tween/ease-out-cubic)))))
|
(assoc-in [:tweens :fade-in] (tween/tween :fade-in screen [:opacity] 0.0 1.0 0.2 :ease tween/ease-out-cubic)))))
|
||||||
|
|
||||||
:on-mouse-moved mouse-move
|
:on-mouse-moved mouse-move
|
||||||
@@ -179,7 +191,7 @@
|
|||||||
:on-touch-down mouse-down
|
:on-touch-down mouse-down
|
||||||
|
|
||||||
:on-touch-up (fn [screen [entities]]
|
:on-touch-up (fn [screen [entities]]
|
||||||
(when (and (:shown? entities) (= 1.0 (:opacity entities)))
|
(when (interactable? entities)
|
||||||
(if (= (button-code :left) (:button screen))
|
(if (= (button-code :left) (:button screen))
|
||||||
(left-click screen entities)
|
(left-click screen entities)
|
||||||
(right-click screen entities))))
|
(right-click screen entities))))
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
(or factor 1.0)))
|
(or factor 1.0)))
|
||||||
|
|
||||||
(defn cursor [filename which]
|
(defn cursor [filename which]
|
||||||
(let [scale 2
|
(let [scale 4
|
||||||
base-cursor (pixmap filename)
|
base-cursor (pixmap filename)
|
||||||
target-width (* 16 scale)
|
target-width (* 16 scale)
|
||||||
target-height (* 16 scale)
|
target-height (* 16 scale)
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
(pixmap! resized :draw-pixmap base-cursor (* index 18) 0 16 16
|
(pixmap! resized :draw-pixmap base-cursor (* index 18) 0 16 16
|
||||||
0 0 target-width target-height)
|
0 0 target-width target-height)
|
||||||
|
|
||||||
(graphics! :new-cursor resized 0 0)))
|
(graphics! :new-cursor resized 0 0 )))
|
||||||
|
|
||||||
(defn get-texture [path]
|
(defn get-texture [path]
|
||||||
(let [atlas-name (str/replace path #".png" "")
|
(let [atlas-name (str/replace path #".png" "")
|
||||||
|
|||||||
Reference in New Issue
Block a user