font positioning is better.
This commit is contained in:
@@ -6,8 +6,24 @@
|
||||
[clojure.pprint]
|
||||
[advent.pathfind])
|
||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion]))
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion]
|
||||
[com.badlogic.gdx.scenes.scene2d.utils Align]))
|
||||
|
||||
(defn ensure-on-screen [talk]
|
||||
(let [margin-width (* 0.05 (game :width))
|
||||
minimum-x margin-width
|
||||
maximum-x (- (game :width)
|
||||
margin-width)
|
||||
label-width (label! talk :get-width)
|
||||
label-right (+ (:x talk) label-width)
|
||||
]
|
||||
(cond (> label-right maximum-x)
|
||||
(assoc talk :x (- maximum-x label-width))
|
||||
(< (:x talk) minimum-x)
|
||||
(assoc talk :x minimum-x)
|
||||
:else
|
||||
talk
|
||||
)))
|
||||
(defscreen talking-screen
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
@@ -20,12 +36,16 @@
|
||||
|
||||
:on-talk
|
||||
(fn [{:keys [create-talk target-id text x y]} [entities]]
|
||||
(let [font (bitmap-font "mainfont.fnt" )
|
||||
(let [font (bitmap-font "ego/font.fnt" )
|
||||
tr (bitmap-font! font :get-region)
|
||||
width (/ (game :width) 1.5)
|
||||
tx (.getTexture tr)
|
||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||
talk (assoc (label text (style :label font (color :white)) ) :x (* 4 x) :y (* 4 y))]
|
||||
(label! talk :set-font-scale 1)
|
||||
talk (assoc (label text (style :label font (color :white))) :x (- (* 4 x) (/ width 2)) :y (* 4 y))
|
||||
talk (ensure-on-screen talk)]
|
||||
(label! talk :set-wrap true)
|
||||
(label! talk :set-width width)
|
||||
(label! talk :set-alignment Align/center)
|
||||
(assoc entities target-id talk)))
|
||||
|
||||
:stop-talk
|
||||
|
||||
Reference in New Issue
Block a user