fairly accurate text positioning.

This commit is contained in:
=
2014-09-08 18:58:51 -07:00
parent dbae4fd0f7
commit 9b4efb8fc7
2 changed files with 22 additions and 21 deletions

View File

@@ -8,7 +8,7 @@
[advent.actions :as actions]
[advent.screens.dialogue :as dialogue])
(: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]]
(let [scale-fn (-> entities :background :scale-fn)
@@ -58,9 +58,14 @@
(defn talk [target-id text]
(fn [screen entities]
(run! dialogue/talking-screen :on-talk :text text
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) 35)
:target-id target-id)
(-> entities
(update-in [target-id :actions] rest)
(assoc-in [target-id :anim] (get-in entities [target-id :talk])))))
(let [target-y (get-in entities [target-id :y])
scale-fn (get-in entities [:background :scale-fn])
scale (scale-fn target-y)
height (* scale 36)]
(run! dialogue/talking-screen :on-talk :text text
: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]))))))

View File

@@ -12,18 +12,13 @@
(defn ensure-on-screen [talk]
(let [margin-width (* 0.05 (game :width))
minimum-x margin-width
maximum-x (- (game :width)
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
)))
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]
@@ -35,9 +30,10 @@
entities)
: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" )
tr (bitmap-font! font :get-region)
scale (or (max scale 0.75) 1)
width (/ (game :width) 1.5)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
@@ -45,14 +41,14 @@
talk (ensure-on-screen talk)]
(label! talk :set-wrap true)
(label! talk :set-width width)
(label! talk :set-font-scale scale)
(label! talk :set-alignment Align/center)
(assoc entities target-id talk)))
:stop-talk
(fn [{:keys [target-id] } [entities]]
(dissoc entities target-id))
:on-resize (fn [screen entities]
(height! screen (game :height))))
(size! screen 1280 960)))