more progress on ui scaling.

This commit is contained in:
Bryce Covert
2016-10-15 17:41:03 -07:00
parent 2f831bb4b2
commit 85945b7fa6
3 changed files with 78 additions and 48 deletions

View File

@@ -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]}]