From 520143e1455c6a3310f615cc66f5d21e5be3255f Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 16 Oct 2016 13:49:11 -0700 Subject: [PATCH] meaningful progress on showing action for mobile. --- desktop/project.clj | 2 +- desktop/src-common/advent/screens/scene.clj | 73 ++++++++++++++------- desktop/src-common/advent/utils.clj | 5 +- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/desktop/project.clj b/desktop/project.clj index fd983606..c8a696bf 100644 --- a/desktop/project.clj +++ b/desktop/project.clj @@ -28,7 +28,7 @@ :source-paths ["src" "src-common" "src-dev"] :jvm-opts ["-Duse-repl=true" "-Dno-steam=true" #_"-Dclojure.compiler.direct-linking=true"] :dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"] - [org.clojure/tools.nrepl "0.2.7"] + [org.clojure/tools.nrepl "0.2.12"] [play-clj-nrepl "0.1.0" :exclusions [play-clj]] [slamhound "1.5.5"] [org.clojure/data.csv "0.1.3"]] diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index e593472d..4df44adb 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -55,7 +55,7 @@ VertexAttributes$Usage] [com.badlogic.gdx.scenes.scene2d Actor Stage])) -(set! *unchecked-math* :warn-on-boxed) +#_(set! *unchecked-math* :warn-on-boxed) (declare hud) @@ -246,6 +246,7 @@ void main () interacting-entity)) (defn left-click [screen entities options] + (println "x y" (:input-x options) (:input-y options)) (let [[x y] (utils/unproject screen options) _ (log/info (str "clicked " x y)) interaction (get-interaction entities x y) @@ -1048,7 +1049,7 @@ void main () (update-fn screen entities) entities)) -(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [parallax ^float multiply-amount ^float hue-amount] :as e }] +(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [parallax ^float multiply-amount ^float hue-amount] :as e :or {parallax 1.0}}] (let [tmp (Vector3.) tmp2 (Vector3.) @@ -1167,7 +1168,7 @@ void main () tr (bitmap-font! font :get-region) _ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear) style (doto (style :label font (color :white)) - (#(-> % .font .getData (.setScale 0.0625)))) + (#(-> % .font .getData (.setScale (* utils/ui-scale 0.0625))))) _ (update! screen :shader shader) rooms {:inside-house (rooms.inside-house/make screen) @@ -1195,6 +1196,7 @@ void main () :current-sounds {:object nil :value []} + :action-icon {} :musics {:object nil :inside-antique (utils/make-music "music/inside-antique.ogg") :town-1 (utils/make-music "music/town-music-1.ogg") @@ -1247,9 +1249,14 @@ void main () :value 0.0} :music-override {:object nil :value nil} - :label (utils/add-actor-to-stage screen - (assoc (label "Sheep" style :set-alignment Align/center) - :x 0 :y 0 :baseline 10000)) + :label (as-> (label "Sheep" style :set-alignment Align/center) l + (if utils/mobile? + (do l (label! l :set-alignment Align/bottomLeft) + l) + (do (label! l :set-alignment Align/center) + l)) + (assoc l :x 0 :y 0 :baseline 10000) + (utils/add-actor-to-stage screen l)) :cursor {:id "cursor" :last nil :override :hourglass @@ -1335,13 +1342,31 @@ void main () last-pos-x (double last-pos-x) last-pos-y (double last-pos-y) - entities (-> entities - (update-in [:label] assoc - :x (unchecked-subtract last-pos-x - cursor-offset-x) - :y (unchecked-add (unchecked-subtract last-pos-y 24 ) - cursor-offset-y)) - (update-in [:label] ensure-on-screen)) + entities (cond-> entities + (not utils/mobile?) (update-in [:label] assoc + :x (unchecked-subtract last-pos-x + cursor-offset-x) + :y (unchecked-add (unchecked-subtract last-pos-y 24 ) + cursor-offset-y)) + utils/mobile? (update-in [:label] + (fn [l] + (let [[x y] (utils/unproject screen options [(.getScreenX (:viewport screen)) (.getScreenHeight (:viewport screen))])] + (assoc l :x (+ 25 x) :y y)))) + + (not utils/mobile?) (update-in [:label] ensure-on-screen)) + + entities (cond-> entities + utils/mobile? (update-in [:action-icon] (fn [ai] + (let [all-items (texture! (texture (pixmap "cursor.png")) :split 18 16) + [x y] (utils/unproject screen options [(.getScreenX (:viewport screen)) (.getScreenHeight (:viewport screen))])] + (try + + (assoc + (texture (aget all-items 0 (.indexOf utils/+all-cursors+ (or (:cursor (first (:last (:cursor entities)))) (first (:last (:cursor entities))))))) + :x x :y y + :baseline 9000) + (catch Exception e nil) + ))))) entities (if (and (@utils/settings :camera-man? true) @@ -1404,7 +1429,8 @@ void main () (if (:parallax e) (render-parallax screen e) (render! screen [e]))) - (render! screen [(:label entities)]) + (render! screen [(:label entities) (:action-icon entities)]) + entities)))) @@ -1521,10 +1547,10 @@ void main () (defn grow-hud [screen entities target up?] (let [grow-or-shrink (if up? :grow :shrink) - scale-from (if up? 1.0 1.1) - scale-to (if up? 1.1 1.0) - opacity-from (if up? 0.8 1.0) - opacity-to (if up? 1.0 0.8)] + scale-from (* utils/ui-scale (if up? 1.0 1.1)) + scale-to (* utils/ui-scale (if up? 1.1 1.0)) + opacity-from (* utils/ui-scale (if up? 0.8 1.0)) + opacity-to (* utils/ui-scale (if up? 1.0 0.8))] (if (and (not (get-in entities [:tweens [target grow-or-shrink :x]])) (not= scale-to (get-in entities [target :scale-y] 1.0))) (-> entities @@ -1834,16 +1860,17 @@ void main () :already-saved? false :close (assoc (utils/get-texture "close.png") - :x 304 :y 224 + :x (- 320 (* utils/ui-scale 16)) :y (- 240 16) :width 16 :height 16 :baseline 9000 :opacity 0.8) :save (assoc (utils/get-texture "save.png") - :x 280 :y 224 - :width 16 :height 16 + :x (- 320 (* 2.5 (* utils/ui-scale 16))) :y (- 240 16) + :width 16 :height 16 :baseline 9000 :opacity 0.8) - :inventory (assoc (utils/get-texture "inventory.png") :x 278 :y 0 :baseline 9000 + :inventory (assoc (utils/get-texture "inventory.png") :x (- 320 (* 21 utils/ui-scale)) :y (* 27 utils/ui-scale ) :baseline 9000 + :origin-x 21 :origin-y 27 :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]) @@ -1958,7 +1985,7 @@ void main () hovered-save? (utils/intersects? (:save entities) [x y])] (screen! scene :hud-active? { :hud-active? (or hovered-close? hovered-inventory? hovered-save?)}))) - #_#_:on-mouse-moved + :on-mouse-moved (fn [screen entities options] (let [[x y] (utils/unproject screen options) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 082494a9..090dde16 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -30,8 +30,8 @@ entity) -(def ui-scale 1.75) -(def mobile? (= 1.75 ui-scale)) +(def ui-scale 1.5) +(def mobile? (= 1.5 ui-scale)) (defn clear-stage [{:keys [^Stage renderer]}] (.clear renderer)) @@ -408,7 +408,6 @@ 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)] - (println object-x object-y object-width object-height) (and (:object e) (< object-x x (+ object-x object-width))