fairly accurate text positioning.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
[advent.actions :as actions]
|
[advent.actions :as actions]
|
||||||
[advent.screens.dialogue :as dialogue])
|
[advent.screens.dialogue :as dialogue])
|
||||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||||
[com.badlogic.gdx.graphics.g2d TextureRegion] ))
|
[com.badlogic.gdx.graphics.g2d TextureRegion]))
|
||||||
|
|
||||||
(defn jump-to [screen entities entity [x y]]
|
(defn jump-to [screen entities entity [x y]]
|
||||||
(let [scale-fn (-> entities :background :scale-fn)
|
(let [scale-fn (-> entities :background :scale-fn)
|
||||||
@@ -58,9 +58,14 @@
|
|||||||
|
|
||||||
(defn talk [target-id text]
|
(defn talk [target-id text]
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(run! dialogue/talking-screen :on-talk :text text
|
(let [target-y (get-in entities [target-id :y])
|
||||||
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) 35)
|
scale-fn (get-in entities [:background :scale-fn])
|
||||||
:target-id target-id)
|
scale (scale-fn target-y)
|
||||||
(-> entities
|
height (* scale 36)]
|
||||||
(update-in [target-id :actions] rest)
|
(run! dialogue/talking-screen :on-talk :text text
|
||||||
(assoc-in [target-id :anim] (get-in entities [target-id :talk])))))
|
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
|
||||||
|
:target-id target-id
|
||||||
|
:scale scale)
|
||||||
|
(-> entities
|
||||||
|
(update-in [target-id :actions] rest)
|
||||||
|
(assoc-in [target-id :anim] (get-in entities [target-id :talk]))))))
|
||||||
|
|||||||
@@ -12,18 +12,13 @@
|
|||||||
(defn ensure-on-screen [talk]
|
(defn ensure-on-screen [talk]
|
||||||
(let [margin-width (* 0.05 (game :width))
|
(let [margin-width (* 0.05 (game :width))
|
||||||
minimum-x margin-width
|
minimum-x margin-width
|
||||||
maximum-x (- (game :width)
|
maximum-x (- (game :width) margin-width)
|
||||||
margin-width)
|
|
||||||
label-width (label! talk :get-width)
|
label-width (label! talk :get-width)
|
||||||
label-right (+ (:x talk) label-width)
|
label-right (+ (:x talk) label-width)]
|
||||||
]
|
(cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
|
||||||
(cond (> label-right maximum-x)
|
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
|
||||||
(assoc talk :x (- maximum-x label-width))
|
:else talk)))
|
||||||
(< (:x talk) minimum-x)
|
|
||||||
(assoc talk :x minimum-x)
|
|
||||||
:else
|
|
||||||
talk
|
|
||||||
)))
|
|
||||||
(defscreen talking-screen
|
(defscreen talking-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -35,9 +30,10 @@
|
|||||||
entities)
|
entities)
|
||||||
|
|
||||||
:on-talk
|
:on-talk
|
||||||
(fn [{:keys [create-talk target-id text x y]} [entities]]
|
(fn [{:keys [create-talk target-id text x y scale]} [entities]]
|
||||||
(let [font (bitmap-font "ego/font.fnt" )
|
(let [font (bitmap-font "ego/font.fnt" )
|
||||||
tr (bitmap-font! font :get-region)
|
tr (bitmap-font! font :get-region)
|
||||||
|
scale (or (max scale 0.75) 1)
|
||||||
width (/ (game :width) 1.5)
|
width (/ (game :width) 1.5)
|
||||||
tx (.getTexture tr)
|
tx (.getTexture tr)
|
||||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||||
@@ -45,14 +41,14 @@
|
|||||||
talk (ensure-on-screen talk)]
|
talk (ensure-on-screen talk)]
|
||||||
(label! talk :set-wrap true)
|
(label! talk :set-wrap true)
|
||||||
(label! talk :set-width width)
|
(label! talk :set-width width)
|
||||||
|
(label! talk :set-font-scale scale)
|
||||||
(label! talk :set-alignment Align/center)
|
(label! talk :set-alignment Align/center)
|
||||||
(assoc entities target-id talk)))
|
(assoc entities target-id talk)))
|
||||||
|
|
||||||
:stop-talk
|
:stop-talk
|
||||||
(fn [{:keys [target-id] } [entities]]
|
(fn [{:keys [target-id] } [entities]]
|
||||||
(dissoc entities target-id))
|
(dissoc entities target-id))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:on-resize (fn [screen entities]
|
:on-resize (fn [screen entities]
|
||||||
(height! screen (game :height))))
|
(size! screen 1280 960)))
|
||||||
|
|||||||
Reference in New Issue
Block a user