fixes: ui scale of inventory,save,close. intersects.

This commit is contained in:
Bryce Covert
2016-12-07 22:23:54 -08:00
parent c81614c5ef
commit 7c905309d8
3 changed files with 51 additions and 36 deletions

View File

@@ -190,7 +190,6 @@
))))))
:on-touch-up (fn [screen entities options]
(println "touched up!")
(let [[x y] (utils/unproject screen options)]
(when (seq (get-in entities [:state :choices]))
(when-let [choice (first (filter #(utils/intersects? % [x y]) (get-in entities [:state :labels])))]

View File

@@ -275,7 +275,9 @@ void main ()
[x y])))
((:get-script default-interaction) (get-script-selector entities) [x y])) entities))
(assoc-in entities [:cursor :down-target] nil)))
(cond-> entities
true (assoc-in [:cursor :down-target] nil)
utils/mobile? (assoc-in [:cursor :last-pos] [0 0]))))
(defn handle-touch-up [{:keys [^FitViewport viewport] :as screen} entities {:keys [input-x input-y] :as options}]
(let [entities (assoc-in entities [:cursor :depressed?] false)]
@@ -1071,6 +1073,7 @@ void main ()
(let [tmp (Vector3.)
tmp2 (Vector3.)
original-combined (.cpy (.combined camera))
parallax-view (Matrix4.)
parallax-combined (Matrix4.)
p (float parallax)]
@@ -1106,7 +1109,7 @@ void main ()
(- (* 240 p 0.5)
(/ 120 (.zoom camera))))) screen batch)
(.setColor batch (color 1 1 1 1))
)))
(.set (.combined camera) original-combined))))
(def nighttime-times #{:night :sunrise})
(defn get-rendered [entities {:keys [time ^double y ^double offset-y night-profile] :or {night-profile :default} :as e}]
@@ -1318,7 +1321,8 @@ void main ()
:on-pan
(fn [screen entities {:keys [input-x input-y delta-x delta-y]}]
(when (get-in entities [:state :active?])
(when (and utils/mobile?
(get-in entities [:state :active?]))
(let [ideal-x (+ (get-in entities [:cam :x]) (- (/ delta-x 4)))
ideal-y (+ (get-in entities [:cam :y]) (/ delta-y 4))]
(-> entities
@@ -1363,10 +1367,10 @@ void main ()
entities
)))
#_#_:on-scrolled
:on-scrolled
(fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} entities options]
(update-in entities [:cam :zoom] #(* % (+ 1 (/ (double (:amount options)) 100.0 )))))
(update-in entities [:cam :zoom] #(* % (+ 1 (/ (double (:amount options)) 10.0 )))))
:on-render
(fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} {{:keys [last-pos ] [cursor-offset-x cursor-offset-y] :offset} :cursor :keys [tweens] :as entities} options]
@@ -1492,7 +1496,7 @@ void main ()
(filter identity))]
(utils/stop-music snd)))
#_#_:on-mouse-moved
:on-mouse-moved
mouse-moved
:on-touch-dragged
@@ -1652,28 +1656,33 @@ void main ()
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-linear))
move-tween (condp = in-or-out
:far-out
(tween/tween :appear-item-y screen [:selected-item :y] 35 40 0.5 :ease tween/ease-linear)
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 40) 0.5 :ease tween/ease-linear)
:out
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-linear)
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 30) (* utils/ui-scale 35) 0.5 :ease tween/ease-linear)
:in
(tween/tween :appear-item-y screen [:selected-item :y] 35 30 0.5 :ease tween/ease-linear)
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 30) 0.5 :ease tween/ease-linear)
:none
(tween/tween :appear-item-y screen [:selected-item :y] 35 35 0.5 :ease tween/ease-linear))]
(tween/tween :appear-item-y screen [:selected-item :y] (* utils/ui-scale 35) (* utils/ui-scale 35) 0.5 :ease tween/ease-linear))]
(-> entities
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:x 300 :y (condp = in-or-out
:in
35
:out
30
:none
35
:far-out
35) :baseline 9000 :opacity (if (= :hide hide-or-show) 1.0 0.0)
:item item))
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:origin-x 8
:origin-y 0
:scale-x utils/ui-scale
:scale-y utils/ui-scale
:x (- 320 (* utils/ui-scale 12))
:y (* utils/ui-scale (condp = in-or-out
:in
35
:out
30
:none
35
:far-out
35)) :baseline 9000 :opacity (if (= :hide hide-or-show) 1.0 0.0)
:item item))
(assoc-in [:tweens :appear-item] fade-tween)
(assoc-in [:tweens :appear-item-y] move-tween))))
(transition-done? [this screen entities]
@@ -1897,17 +1906,22 @@ void main ()
:already-saved? false
:close (assoc (utils/get-texture "close.png")
:x (- 320 (* utils/ui-scale 16)) :y (- 240 16)
:x 320 :y 240
:origin-x 16 :origin-y 16
:width 16 :height 16
:scale-x utils/ui-scale :scale-y utils/ui-scale
:baseline 9000
:opacity 0.8)
:save (assoc (utils/get-texture "save.png")
:x (- 320 (* 2.5 (* utils/ui-scale 16))) :y (- 240 16)
:x (- 320 (* utils/ui-scale 16) 4) :y 240
:origin-x 16 :origin-y 16
:width 16 :height 16
:baseline 9000
:opacity 0.8)
:inventory (assoc (utils/get-texture "inventory.png") :x (- 320 (* 21 utils/ui-scale)) :y (* 27 utils/ui-scale ) :baseline 9000
:width 42 :height 56
:origin-x 21 :origin-y 27
:scale-x utils/ui-scale :scale-y utils/ui-scale
: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])
@@ -1917,7 +1931,6 @@ void main ()
: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
:mouse-in? (zone/box 278 0 320 42)
:opacity 0.8)
:all-items (texture! (texture (pixmap "cursor.png")) :split 18 16)
#_#_:fps (->> (assoc (label "" (color :white) ) :x 5 :baseline 0 :opacity 0.1)
@@ -2017,16 +2030,17 @@ void main ()
:on-touch-down
(fn [screen entities options]
(let [[x y] (utils/unproject screen options)
hovered-inventory? ((:mouse-in? (:inventory entities)) x y)
hovered-inventory? (utils/intersects? (:inventory entities) [x y])
hovered-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])]
(screen! scene :hud-active? { :hud-active? (or hovered-close? hovered-inventory? hovered-save?)})))
:on-mouse-moved
(fn [screen entities options]
(let [[x y] (utils/unproject screen options)
hovered-inventory? ((:mouse-in? (:inventory entities)) x y)
hovered-inventory? (utils/intersects? (:inventory entities) [x y])
hovered-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])]
(cond (and hovered-inventory? (hud-interactable?))
@@ -2063,7 +2077,7 @@ void main ()
nil
((:mouse-in? (:inventory entities)) x y)
(utils/intersects? (:inventory entities) [x y])
(if (= :selected (get-in entities [:inv-fsm :state]))
(update-in entities [:inv-fsm :pending-states] conj [:none (get-in entities [:inv-fsm :state-data])])

View File

@@ -65,8 +65,8 @@
:flask-with-contents [8 8]
:trophy [8 8]
:ladder [8 8]
:stick
:cat-toy
:stick [8 8]
:cat-toy [8 8]
:balloon [3 3]
:frog-legs [8 8]
:teddy [8 8]
@@ -406,10 +406,12 @@
(defn intersects? [e [x y]]
(when (:object e)
(let [object-x (or (:x e) (when (actor? e ) (.getX ^Actor (:object e))) 0)
object-y (or (:y e) (when (actor? e ) (.getY ^Actor (:object e))) 0)
object-width (or (:width e) (when (actor? e ) (.getWidth ^Actor (:object e))) 0)
object-height (or (:height e) (when (actor? e ) (.getHeight ^Actor (:object e))) 0)]
(let [object-width (* (:scale-x e 1.0) (or (:width e) (when (actor? e ) (.getWidth ^Actor (:object e))) 0))
object-height (* (:scale-y e 1.0) (or (:height e) (when (actor? e ) (.getHeight ^Actor (:object e))) 0))
origin-x (* (:scale-x e 1.0) (:origin-x e 0))
origin-y (* (:scale-y e 1.0) (:origin-y e 0))
object-x (- (or (:x e) (when (actor? e ) (.getX ^Actor (:object e))) 0) origin-x)
object-y (- (or (:y e) (when (actor? e ) (.getY ^Actor (:object e))) 0) origin-y)]
(and (:object e)
(< object-x x (+ object-x object-width))
@@ -449,8 +451,8 @@
[x y])))
(defn contains-point? [x1 y1 width height x y]
(and (< x1 x (+ x1 width))
(< y1 y (+ y1 height))))
(and (<= x1 x (+ x1 width))
(<= y1 y (+ y1 height))))
(defn is-unstoppable-script-running [screen entities]
(let [current-action (get-in entities [:fg-actions :current])