more progress on ui scaling.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
[com.badlogic.gdx.utils Align]
|
[com.badlogic.gdx.utils Align]
|
||||||
[com.badlogic.gdx.math Vector3 Vector2 Matrix4]
|
[com.badlogic.gdx.math Vector3 Vector2 Matrix4]
|
||||||
[com.badlogic.gdx Screen]
|
[com.badlogic.gdx Screen]
|
||||||
|
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable ]
|
||||||
[play_clj.entities NinePatchEntity]))
|
[play_clj.entities NinePatchEntity]))
|
||||||
|
|
||||||
(defn ensure-on-screen [talk]
|
(defn ensure-on-screen [talk]
|
||||||
@@ -59,8 +60,8 @@
|
|||||||
_ (nine-patch! p :set-padding 25 25 5 15)
|
_ (nine-patch! p :set-padding 25 25 5 15)
|
||||||
|
|
||||||
tr (bitmap-font! font :get-region)
|
tr (bitmap-font! font :get-region)
|
||||||
scale (/ scale 2)
|
scale (* scale (/ utils/ui-scale 2))
|
||||||
scale (or (min (max scale 0.2) 0.25) 0.25)
|
scale (or (min (max scale (/ utils/ui-scale 5) 0.4) (/ utils/ui-scale 4)) (/ utils/ui-scale 4))
|
||||||
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||||
style (style :label font color)
|
style (style :label font color)
|
||||||
[source-x source-y] [x y]
|
[source-x source-y] [x y]
|
||||||
@@ -71,7 +72,7 @@
|
|||||||
(assoc :source-x source-x :source-y source-y)
|
(assoc :source-x source-x :source-y source-y)
|
||||||
(doto
|
(doto
|
||||||
(label! :set-wrap true)
|
(label! :set-wrap true)
|
||||||
(#(label! % :set-width (min 700 (+ 50 (label! % :get-width))))))
|
(#(label! % :set-width (min (* (+ 1 (* 0.5 (- utils/ui-scale 1))) 700) (+ 50 (label! % :get-width))))))
|
||||||
(#(utils/add-actor-to-stage screen %)))
|
(#(utils/add-actor-to-stage screen %)))
|
||||||
x (- x (/ (label! talk :get-width) 2))
|
x (- x (/ (label! talk :get-width) 2))
|
||||||
talk (assoc talk :x x :y y :id id)
|
talk (assoc talk :x x :y y :id id)
|
||||||
@@ -114,7 +115,7 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
(defn style-label [e font mouse-pos]
|
(defn style-label [e font mouse-pos]
|
||||||
(label! e :set-style (style :label font (get-color e mouse-pos)))
|
(table! (:label e) :set-style (style :label font (get-color e mouse-pos)))
|
||||||
e)
|
e)
|
||||||
|
|
||||||
(defscreen choice-screen
|
(defscreen choice-screen
|
||||||
@@ -132,54 +133,72 @@
|
|||||||
:choices []
|
:choices []
|
||||||
:last-pos [0 0]
|
:last-pos [0 0]
|
||||||
:font font
|
:font font
|
||||||
:np (assoc p
|
:bg p
|
||||||
:x 5 :y 5 :width 1270)}}))
|
}}))
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
|
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
|
||||||
(.apply viewport)
|
(.apply viewport)
|
||||||
(when (seq (get-in entities [:state :choices]))
|
(let [entities (update-in entities [:state :bg]
|
||||||
(render! screen [(get-in entities [:state :np])])
|
(fn [bg]
|
||||||
(render! screen (vals entities)))
|
(assoc bg :x 0 :y 0 :width 1280 :height (get-in entities [:state :table :height] 0))
|
||||||
|
))]
|
||||||
|
(when (seq (get-in entities [:state :choices]))
|
||||||
|
(render! screen [(get-in entities [:state :bg])])
|
||||||
|
(render! screen [(get-in entities [:state :table])])
|
||||||
|
#_(render! screen (vals entities))))
|
||||||
entities)
|
entities)
|
||||||
|
|
||||||
:on-present-choices
|
:on-present-choices
|
||||||
(fn [screen entities {:keys [choices callback]}]
|
(fn [screen entities {:keys [choices callback]}]
|
||||||
(let [choice-count (count choices)
|
(let [choice-count (count choices)
|
||||||
font (get-in entities [:state :font])]
|
font (get-in entities [:state :font])
|
||||||
|
labels (vec (->> (for [[[text] i] (map vector choices (range))]
|
||||||
|
(assoc
|
||||||
|
(label text (style :label font (color 0.6 1.0 1.0 1.0)) :set-wrap true :set-alignment Align/bottomLeft
|
||||||
|
:set-font-scale (* utils/ui-scale 0.25)
|
||||||
|
:set-width 1240)
|
||||||
|
|
||||||
|
:index i
|
||||||
|
:width 1240))
|
||||||
|
(map (fn [l] (assoc (table [[ l :width 1240]])
|
||||||
|
:label l
|
||||||
|
:index (:index l))))))]
|
||||||
(-> entities
|
(-> entities
|
||||||
(into (for [[[text] i] (map vector choices (range))
|
|
||||||
:let [e (label text (style :label font (color 0.6 1.0 1.0 1.0)) :set-alignment Align/bottomLeft)
|
|
||||||
e (assoc e :height choice-height :x 30 :y (+ 25 (* choice-height (- choice-count i 1))) :index i)
|
|
||||||
e (style-label e font (get-in entities [:state :last-pos]))]]
|
|
||||||
[i (doto e
|
|
||||||
(label! :set-x (:x e))
|
|
||||||
(label! :set-y (:y e))
|
|
||||||
(label! :set-height (:height e))
|
|
||||||
(label! :set-font-scale 0.25)
|
|
||||||
(#(utils/add-actor-to-stage screen %)))]))
|
|
||||||
(assoc-in [:state :choices] choices)
|
(assoc-in [:state :choices] choices)
|
||||||
(assoc-in [:state :callback] callback)
|
(assoc-in [:state :callback] callback)
|
||||||
(assoc-in [:state :np :height] (* choice-height (inc choice-count))))))
|
(assoc-in [:state :labels] labels)
|
||||||
|
(assoc-in [:state :table]
|
||||||
|
(doto (-> labels
|
||||||
|
(vertical :align Align/bottomLeft :pad 20 :space 24)
|
||||||
|
|
||||||
|
(#(utils/add-actor-to-stage screen %))
|
||||||
|
(assoc :x 0 :y 0 :width 1240)
|
||||||
|
(#(assoc % :height (vertical! % :get-pref-height)))
|
||||||
|
))))))
|
||||||
|
|
||||||
:on-touch-up (fn [screen entities options]
|
:on-touch-up (fn [screen entities options]
|
||||||
(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]) (vals entities)))]
|
(when-let [choice (first (filter #(utils/intersects? % [x y]) (get-in entities [:state :labels])))]
|
||||||
(utils/clear-stage screen)
|
(utils/clear-stage screen)
|
||||||
((get-in entities [:state :callback]) (:index choice))
|
((get-in entities [:state :callback]) (:index choice))
|
||||||
(-> entities
|
(-> entities
|
||||||
(assoc-in [:state :callback] nil)
|
(assoc-in [:state :callback] nil)
|
||||||
(assoc-in [:state :choices] [])
|
(assoc-in [:state :choices] [])
|
||||||
(select-keys [:state]))))))
|
(assoc-in [:state :labels] [])
|
||||||
|
(assoc-in [:state :table] nil)
|
||||||
|
(select-keys [:state]))))))
|
||||||
|
|
||||||
:on-mouse-moved (fn [screen entities options]
|
:on-mouse-moved (fn [screen entities options]
|
||||||
(let [[x y] (utils/unproject screen options)
|
(let [[x y] (utils/unproject screen options)
|
||||||
entities (assoc-in entities [:state :last-pos] [x y])
|
entities (assoc-in entities [:state :last-pos] [x y])
|
||||||
choice-count (dec (count entities))]
|
choice-count (dec (count entities))]
|
||||||
(doseq [e (vals entities)
|
(when-let [table (get-in entities [:state :table])]
|
||||||
:when (:object e)]
|
(doseq [e (get-in entities [:state :labels])]
|
||||||
(style-label e (get-in entities [:state :font]) [x y]))
|
|
||||||
|
(style-label e (get-in entities [:state :font]) [x y])))
|
||||||
entities))
|
entities))
|
||||||
|
|
||||||
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
|
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
(defn button-style []
|
(defn button-style []
|
||||||
(let [^TextButton$TextButtonStyle style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
|
(let [^TextButton$TextButtonStyle style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
|
||||||
tx (-> style .font .getRegion .getTexture)]
|
tx (-> style .font .getRegion .getTexture)]
|
||||||
(-> style .font .getData (.setScale 0.5))
|
(-> style .font .getData (.setScale 1.0))
|
||||||
|
|
||||||
(call! ^Texture tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
(call! ^Texture tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||||
style))
|
style))
|
||||||
@@ -161,7 +161,7 @@
|
|||||||
(defn make-checkbox
|
(defn make-checkbox
|
||||||
([msg checked & rest]
|
([msg checked & rest]
|
||||||
(let [s (skin! (skin "ui/ui.json") :get CheckBox$CheckBoxStyle)]
|
(let [s (skin! (skin "ui/ui.json") :get CheckBox$CheckBoxStyle)]
|
||||||
(-> s .font .getData (.setScale 0.25))
|
(-> s .font .getData (.setScale 0.5))
|
||||||
(doto (merge (check-box msg s)
|
(doto (merge (check-box msg s)
|
||||||
(apply hash-map rest))
|
(apply hash-map rest))
|
||||||
(set-checkbox-state checked)
|
(set-checkbox-state checked)
|
||||||
@@ -178,7 +178,7 @@
|
|||||||
bg (drawable :nine-patch ^NinePatch (:object p))
|
bg (drawable :nine-patch ^NinePatch (:object p))
|
||||||
style (style :label font (or col (color 1.0 0.3 0.3 1.0)))
|
style (style :label font (or col (color 1.0 0.3 0.3 1.0)))
|
||||||
#_#__ (set! (.background style) bg)]
|
#_#__ (set! (.background style) bg)]
|
||||||
(-> style .font .getData (.setScale 0.25))
|
(-> style .font .getData (.setScale 0.5))
|
||||||
(-> msg
|
(-> msg
|
||||||
(label style)
|
(label style)
|
||||||
(assoc :x 0 :y 0 :height 40 :origin-x 0 :origin-y 0 :z 8)
|
(assoc :x 0 :y 0 :height 40 :origin-x 0 :origin-y 0 :z 8)
|
||||||
@@ -207,30 +207,30 @@
|
|||||||
(table)
|
(table)
|
||||||
(doto (table! :set-background (NinePatchDrawable. (skin! (skin "ui/ui.json") :get-patch "ui-bg" ))))
|
(doto (table! :set-background (NinePatchDrawable. (skin! (skin "ui/ui.json") :get-patch "ui-bg" ))))
|
||||||
(assoc
|
(assoc
|
||||||
:y 32 :width 504 :height 335
|
:y 32 :width (* utils/ui-scale 504) :height (* utils/ui-scale 335)
|
||||||
:x (- (/ 1280 2) (/ 504 2))
|
:x (- (/ 1280 2) (/ (* utils/ui-scale 504) 2))
|
||||||
:z 8
|
:z 8
|
||||||
:opacity 1.0)))
|
:opacity 1.0)))
|
||||||
|
|
||||||
(defn main-menu [screen]
|
(defn main-menu [screen]
|
||||||
(let [start-playing-label (quest-label)
|
(let [start-playing-label (quest-label)
|
||||||
is-starting? (= "Begin Quest" start-playing-label)]
|
is-starting? (= "Begin Quest" start-playing-label)]
|
||||||
(make-table [[(make-button start-playing-label :key :continue-or-start) :height 56 :pad-bottom 4 :width 250]
|
(make-table [[(make-button start-playing-label :key :continue-or-start) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)]
|
||||||
:row
|
:row
|
||||||
[(doto (make-button "Load" :key :load)
|
[(doto (make-button "Load" :key :load)
|
||||||
(text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height 56 :pad-bottom 4 :width 250]
|
(text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)]
|
||||||
:row
|
:row
|
||||||
[(doto (make-button "Chapters" :key :chapters)
|
[(doto (make-button "Chapters" :key :chapters)
|
||||||
(text-button! :set-disabled (not (->> (utils/get-chapters)
|
(text-button! :set-disabled (not (->> (utils/get-chapters)
|
||||||
(vals)
|
(vals)
|
||||||
(filter identity)
|
(filter identity)
|
||||||
seq)))) :height 56 :pad-bottom 4 :width 250]
|
seq)))) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)]
|
||||||
|
|
||||||
:row
|
:row
|
||||||
[(make-button "Settings" :key :settings) :height 56 :pad-bottom 4 :width 250]
|
[(make-button "Settings" :key :settings) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)]
|
||||||
|
|
||||||
:row
|
:row
|
||||||
[(make-button "End Quest" :key :end-quest) :height 56 :width 250]
|
[(make-button "End Quest" :key :end-quest) :height (* utils/ui-scale 56) :width (* utils/ui-scale 250)]
|
||||||
])))
|
])))
|
||||||
|
|
||||||
(defn chapters-menu []
|
(defn chapters-menu []
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
(.addListener ^Actor object listener))
|
(.addListener ^Actor object listener))
|
||||||
entity)
|
entity)
|
||||||
|
|
||||||
|
|
||||||
|
(def ui-scale 1.75)
|
||||||
|
(def mobile? (= 1.75 ui-scale))
|
||||||
|
|
||||||
(defn clear-stage [{:keys [^Stage renderer]}]
|
(defn clear-stage [{:keys [^Stage renderer]}]
|
||||||
(.clear renderer))
|
(.clear renderer))
|
||||||
|
|
||||||
@@ -399,9 +403,16 @@
|
|||||||
(vals tweens)))
|
(vals tweens)))
|
||||||
|
|
||||||
(defn intersects? [e [x y]]
|
(defn intersects? [e [x y]]
|
||||||
(and (:object e)
|
(when (:object e)
|
||||||
(< (:x e) x (+ (:x e) (or (:width e) (when (actor? e) (.getWidth ^Actor (:object e))))))
|
(let [object-x (or (:x e) (when (actor? e ) (.getX ^Actor (:object e))) 0)
|
||||||
(< (:y e) y (+ (:y e) (or (:height e) (when (actor? e) (.getHeight ^Actor (:object e))))))))
|
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))
|
||||||
|
(< object-y y (+ object-y object-height))))))
|
||||||
|
|
||||||
(defn get-current-music [entities]
|
(defn get-current-music [entities]
|
||||||
(let [time (get-in entities [:state :time])
|
(let [time (get-in entities [:state :time])
|
||||||
|
|||||||
Reference in New Issue
Block a user