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] :on-touch-up (fn [screen entities options]
(println "touched up!")
(let [[x y] (utils/unproject screen options)] (let [[x y] (utils/unproject screen options)]
(when (seq (get-in entities [:state :choices])) (when (seq (get-in entities [:state :choices]))
(when-let [choice (first (filter #(utils/intersects? % [x y]) (get-in entities [:state :labels])))] (when-let [choice (first (filter #(utils/intersects? % [x y]) (get-in entities [:state :labels])))]

View File

@@ -275,7 +275,9 @@ void main ()
[x y]))) [x y])))
((:get-script default-interaction) (get-script-selector entities) [x y])) entities)) ((: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}] (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)] (let [entities (assoc-in entities [:cursor :depressed?] false)]
@@ -1071,6 +1073,7 @@ void main ()
(let [tmp (Vector3.) (let [tmp (Vector3.)
tmp2 (Vector3.) tmp2 (Vector3.)
original-combined (.cpy (.combined camera))
parallax-view (Matrix4.) parallax-view (Matrix4.)
parallax-combined (Matrix4.) parallax-combined (Matrix4.)
p (float parallax)] p (float parallax)]
@@ -1106,7 +1109,7 @@ void main ()
(- (* 240 p 0.5) (- (* 240 p 0.5)
(/ 120 (.zoom camera))))) screen batch) (/ 120 (.zoom camera))))) screen batch)
(.setColor batch (color 1 1 1 1)) (.setColor batch (color 1 1 1 1))
))) (.set (.combined camera) original-combined))))
(def nighttime-times #{:night :sunrise}) (def nighttime-times #{:night :sunrise})
(defn get-rendered [entities {:keys [time ^double y ^double offset-y night-profile] :or {night-profile :default} :as e}] (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 :on-pan
(fn [screen entities {:keys [input-x input-y delta-x delta-y]}] (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))) (let [ideal-x (+ (get-in entities [:cam :x]) (- (/ delta-x 4)))
ideal-y (+ (get-in entities [:cam :y]) (/ delta-y 4))] ideal-y (+ (get-in entities [:cam :y]) (/ delta-y 4))]
(-> entities (-> entities
@@ -1363,10 +1367,10 @@ void main ()
entities entities
))) )))
#_#_:on-scrolled :on-scrolled
(fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} entities options] (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 :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] (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))] (filter identity))]
(utils/stop-music snd))) (utils/stop-music snd)))
#_#_:on-mouse-moved :on-mouse-moved
mouse-moved mouse-moved
:on-touch-dragged :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)) (tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-linear))
move-tween (condp = in-or-out move-tween (condp = in-or-out
:far-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 :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 :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 :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 (-> entities
(assoc :selected-item (assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item)))) (assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:x 300 :y (condp = in-or-out :origin-x 8
:in :origin-y 0
35 :scale-x utils/ui-scale
:out :scale-y utils/ui-scale
30 :x (- 320 (* utils/ui-scale 12))
:none :y (* utils/ui-scale (condp = in-or-out
35 :in
:far-out 35
35) :baseline 9000 :opacity (if (= :hide hide-or-show) 1.0 0.0) :out
:item item)) 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] fade-tween)
(assoc-in [:tweens :appear-item-y] move-tween)))) (assoc-in [:tweens :appear-item-y] move-tween))))
(transition-done? [this screen entities] (transition-done? [this screen entities]
@@ -1897,17 +1906,22 @@ void main ()
:already-saved? false :already-saved? false
:close (assoc (utils/get-texture "close.png") :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 :width 16 :height 16
:scale-x utils/ui-scale :scale-y utils/ui-scale
:baseline 9000 :baseline 9000
:opacity 0.8) :opacity 0.8)
:save (assoc (utils/get-texture "save.png") :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 :width 16 :height 16
:baseline 9000 :baseline 9000
:opacity 0.8) :opacity 0.8)
:inventory (assoc (utils/get-texture "inventory.png") :x (- 320 (* 21 utils/ui-scale)) :y (* 27 utils/ui-scale ) :baseline 9000 :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 :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 ])) :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))) (animation! :set-play-mode (play-mode :normal)))
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :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]) :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))) (animation! :set-play-mode (play-mode :normal)))
:anim-start 0 :anim-start 0
:mouse-in? (zone/box 278 0 320 42)
:opacity 0.8) :opacity 0.8)
:all-items (texture! (texture (pixmap "cursor.png")) :split 18 16) :all-items (texture! (texture (pixmap "cursor.png")) :split 18 16)
#_#_:fps (->> (assoc (label "" (color :white) ) :x 5 :baseline 0 :opacity 0.1) #_#_:fps (->> (assoc (label "" (color :white) ) :x 5 :baseline 0 :opacity 0.1)
@@ -2017,16 +2030,17 @@ void main ()
:on-touch-down :on-touch-down
(fn [screen entities options] (fn [screen entities options]
(let [[x y] (utils/unproject screen 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-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])] hovered-save? (utils/intersects? (:save entities) [x y])]
(screen! scene :hud-active? { :hud-active? (or hovered-close? hovered-inventory? hovered-save?)}))) (screen! scene :hud-active? { :hud-active? (or hovered-close? hovered-inventory? hovered-save?)})))
:on-mouse-moved :on-mouse-moved
(fn [screen entities options] (fn [screen entities options]
(let [[x y] (utils/unproject screen 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-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])] hovered-save? (utils/intersects? (:save entities) [x y])]
(cond (and hovered-inventory? (hud-interactable?)) (cond (and hovered-inventory? (hud-interactable?))
@@ -2063,7 +2077,7 @@ void main ()
nil nil
((:mouse-in? (:inventory entities)) x y) (utils/intersects? (:inventory entities) [x y])
(if (= :selected (get-in entities [:inv-fsm :state])) (if (= :selected (get-in entities [:inv-fsm :state]))
(update-in entities [:inv-fsm :pending-states] conj [:none (get-in entities [:inv-fsm :state-data])]) (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] :flask-with-contents [8 8]
:trophy [8 8] :trophy [8 8]
:ladder [8 8] :ladder [8 8]
:stick :stick [8 8]
:cat-toy :cat-toy [8 8]
:balloon [3 3] :balloon [3 3]
:frog-legs [8 8] :frog-legs [8 8]
:teddy [8 8] :teddy [8 8]
@@ -406,10 +406,12 @@
(defn intersects? [e [x y]] (defn intersects? [e [x y]]
(when (:object e) (when (:object e)
(let [object-x (or (:x e) (when (actor? e ) (.getX ^Actor (:object e))) 0) (let [object-width (* (:scale-x e 1.0) (or (:width e) (when (actor? e ) (.getWidth ^Actor (:object e))) 0))
object-y (or (:y e) (when (actor? e ) (.getY ^Actor (:object e))) 0) object-height (* (:scale-y e 1.0) (or (:height e) (when (actor? e ) (.getHeight ^Actor (:object e))) 0))
object-width (or (:width e) (when (actor? e ) (.getWidth ^Actor (:object e))) 0) origin-x (* (:scale-x e 1.0) (:origin-x e 0))
object-height (or (:height e) (when (actor? e ) (.getHeight ^Actor (:object 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) (and (:object e)
(< object-x x (+ object-x object-width)) (< object-x x (+ object-x object-width))
@@ -449,8 +451,8 @@
[x y]))) [x y])))
(defn contains-point? [x1 y1 width height x y] (defn contains-point? [x1 y1 width height x y]
(and (< x1 x (+ x1 width)) (and (<= x1 x (+ x1 width))
(< y1 y (+ y1 height)))) (<= y1 y (+ y1 height))))
(defn is-unstoppable-script-running [screen entities] (defn is-unstoppable-script-running [screen entities]
(let [current-action (get-in entities [:fg-actions :current]) (let [current-action (get-in entities [:fg-actions :current])