From 9b4efb8fc791567bfb23055d98adc33dd2a12033 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 8 Sep 2014 18:58:51 -0700 Subject: [PATCH] fairly accurate text positioning. --- desktop/src-common/advent/actions.clj | 19 +++++++++------ .../src-common/advent/screens/dialogue.clj | 24 ++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 3e318110..9fc83ec8 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -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])))))) diff --git a/desktop/src-common/advent/screens/dialogue.clj b/desktop/src-common/advent/screens/dialogue.clj index 1079ea42..dcdd69ef 100644 --- a/desktop/src-common/advent/screens/dialogue.clj +++ b/desktop/src-common/advent/screens/dialogue.clj @@ -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)))