more progress on ui scaling.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
[com.badlogic.gdx.utils Align]
|
||||
[com.badlogic.gdx.math Vector3 Vector2 Matrix4]
|
||||
[com.badlogic.gdx Screen]
|
||||
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable ]
|
||||
[play_clj.entities NinePatchEntity]))
|
||||
|
||||
(defn ensure-on-screen [talk]
|
||||
@@ -59,8 +60,8 @@
|
||||
_ (nine-patch! p :set-padding 25 25 5 15)
|
||||
|
||||
tr (bitmap-font! font :get-region)
|
||||
scale (/ scale 2)
|
||||
scale (or (min (max scale 0.2) 0.25) 0.25)
|
||||
scale (* scale (/ utils/ui-scale 2))
|
||||
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)
|
||||
style (style :label font color)
|
||||
[source-x source-y] [x y]
|
||||
@@ -71,7 +72,7 @@
|
||||
(assoc :source-x source-x :source-y source-y)
|
||||
(doto
|
||||
(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 %)))
|
||||
x (- x (/ (label! talk :get-width) 2))
|
||||
talk (assoc talk :x x :y y :id id)
|
||||
@@ -114,7 +115,7 @@
|
||||
))
|
||||
|
||||
(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)
|
||||
|
||||
(defscreen choice-screen
|
||||
@@ -132,54 +133,72 @@
|
||||
:choices []
|
||||
:last-pos [0 0]
|
||||
:font font
|
||||
:np (assoc p
|
||||
:x 5 :y 5 :width 1270)}}))
|
||||
:bg p
|
||||
}}))
|
||||
|
||||
:on-render
|
||||
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
|
||||
(.apply viewport)
|
||||
(when (seq (get-in entities [:state :choices]))
|
||||
(render! screen [(get-in entities [:state :np])])
|
||||
(render! screen (vals entities)))
|
||||
(let [entities (update-in entities [:state :bg]
|
||||
(fn [bg]
|
||||
(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)
|
||||
|
||||
:on-present-choices
|
||||
(fn [screen entities {:keys [choices callback]}]
|
||||
(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
|
||||
(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 :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]
|
||||
(let [[x y] (utils/unproject screen options)]
|
||||
(when (seq (get-in entities [:state :choices]))
|
||||
(when-let [choice (first (filter #(utils/intersects? % [x y]) (vals entities)))]
|
||||
(utils/clear-stage screen)
|
||||
((get-in entities [:state :callback]) (:index choice))
|
||||
(-> entities
|
||||
(assoc-in [:state :callback] nil)
|
||||
(assoc-in [:state :choices] [])
|
||||
(select-keys [:state]))))))
|
||||
(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])))]
|
||||
(utils/clear-stage screen)
|
||||
((get-in entities [:state :callback]) (:index choice))
|
||||
(-> entities
|
||||
(assoc-in [:state :callback] nil)
|
||||
(assoc-in [:state :choices] [])
|
||||
(assoc-in [:state :labels] [])
|
||||
(assoc-in [:state :table] nil)
|
||||
(select-keys [:state]))))))
|
||||
|
||||
:on-mouse-moved (fn [screen entities options]
|
||||
(let [[x y] (utils/unproject screen options)
|
||||
entities (assoc-in entities [:state :last-pos] [x y])
|
||||
choice-count (dec (count entities))]
|
||||
(doseq [e (vals entities)
|
||||
:when (:object e)]
|
||||
(style-label e (get-in entities [:state :font]) [x y]))
|
||||
entities (assoc-in entities [:state :last-pos] [x y])
|
||||
choice-count (dec (count entities))]
|
||||
(when-let [table (get-in entities [:state :table])]
|
||||
(doseq [e (get-in entities [:state :labels])]
|
||||
|
||||
(style-label e (get-in entities [:state :font]) [x y])))
|
||||
entities))
|
||||
|
||||
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
(defn button-style []
|
||||
(let [^TextButton$TextButtonStyle style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
|
||||
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)
|
||||
style))
|
||||
@@ -161,7 +161,7 @@
|
||||
(defn make-checkbox
|
||||
([msg checked & rest]
|
||||
(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)
|
||||
(apply hash-map rest))
|
||||
(set-checkbox-state checked)
|
||||
@@ -178,7 +178,7 @@
|
||||
bg (drawable :nine-patch ^NinePatch (:object p))
|
||||
style (style :label font (or col (color 1.0 0.3 0.3 1.0)))
|
||||
#_#__ (set! (.background style) bg)]
|
||||
(-> style .font .getData (.setScale 0.25))
|
||||
(-> style .font .getData (.setScale 0.5))
|
||||
(-> msg
|
||||
(label style)
|
||||
(assoc :x 0 :y 0 :height 40 :origin-x 0 :origin-y 0 :z 8)
|
||||
@@ -207,30 +207,30 @@
|
||||
(table)
|
||||
(doto (table! :set-background (NinePatchDrawable. (skin! (skin "ui/ui.json") :get-patch "ui-bg" ))))
|
||||
(assoc
|
||||
:y 32 :width 504 :height 335
|
||||
:x (- (/ 1280 2) (/ 504 2))
|
||||
:y 32 :width (* utils/ui-scale 504) :height (* utils/ui-scale 335)
|
||||
:x (- (/ 1280 2) (/ (* utils/ui-scale 504) 2))
|
||||
:z 8
|
||||
:opacity 1.0)))
|
||||
|
||||
(defn main-menu [screen]
|
||||
(let [start-playing-label (quest-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
|
||||
[(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
|
||||
[(doto (make-button "Chapters" :key :chapters)
|
||||
(text-button! :set-disabled (not (->> (utils/get-chapters)
|
||||
(vals)
|
||||
(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
|
||||
[(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
|
||||
[(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 []
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
(.addListener ^Actor object listener))
|
||||
entity)
|
||||
|
||||
|
||||
(def ui-scale 1.75)
|
||||
(def mobile? (= 1.75 ui-scale))
|
||||
|
||||
(defn clear-stage [{:keys [^Stage renderer]}]
|
||||
(.clear renderer))
|
||||
|
||||
@@ -399,9 +403,16 @@
|
||||
(vals tweens)))
|
||||
|
||||
(defn intersects? [e [x y]]
|
||||
(and (:object e)
|
||||
(< (:x e) x (+ (:x e) (or (:width e) (when (actor? e) (.getWidth ^Actor (:object e))))))
|
||||
(< (:y e) y (+ (:y e) (or (:height e) (when (actor? e) (.getHeight ^Actor (:object e))))))))
|
||||
(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)]
|
||||
(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]
|
||||
(let [time (get-in entities [:state :time])
|
||||
|
||||
Reference in New Issue
Block a user