This commit is contained in:
2014-12-16 07:59:27 -08:00

View File

@@ -39,7 +39,9 @@
scale (or (min (max scale 0.75) 1) 1)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
talk (assoc (label text (style :label font (color :white))) :y (* 4 y))]
talk (assoc (label text (style :label font (if (= :ego target-id)
(color :white)
(color :yellow)))) :y (* 4 y))]
(label! talk :set-font-scale scale)
(label! talk :set-alignment Align/center)
(assoc entities target-id (-> talk
@@ -54,6 +56,14 @@
:on-resize (fn [screen entities]
(size! screen 1280 960)))
(def choice-height 30)
(defn intersects? [e [x y]]
(and (:object e)
(< (:x e) x (+ (:x e) (.getWidth (:object e))))
(< (:y e) y (+ (:y e) (:height e)))))
(defscreen choice-screen
:on-show
(fn [screen entities]
@@ -71,27 +81,29 @@
tr (bitmap-font! font :get-region)
scale 1
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
choice-count (count choices)]
(-> entities
(into (for [[[text] i] (map vector choices (range))]
[i (assoc (label text (style :label font (color :white))) :x 30 :y (* 30 i))]))
(assoc :state {:object nil :callback callback :choices choices}))))
[i (assoc (label text (style :label font (color :white))) :height 30 :x 30 :y (+ 30 (* choice-height (- choice-count i 1))) :index i)]))
(assoc :state {:object nil :callback callback :choices choices :font font}))))
:on-touch-up (fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(when (seq entities)
(when (< y (* 30 (dec (count entities))))
((get-in entities [:state :callback]) (int (/ y 30)))
(when-let [choice (first (filter #(intersects? % [x y]) (vals entities)))]
((get-in entities [:state :callback]) (:index choice))
{}))))
:on-mouse-moved (fn [screen [entities]]
(when (seq entities)
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
font (bitmap-font "ego/font.fnt" )]
(doseq [index (range (dec (count entities)))]
(if (< (* index 30) y (* (inc index) 30))
(label! (entities index) :set-style (style :label font (color :yellow)))
(label! (entities index) :set-style (style :label font (color :white))))))))
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
choice-count (dec (count entities))]
(doseq [e (vals entities)
:when (:object e)]
(if (intersects? e [x y])
(label! e :set-style (style :label (get-in entities [:state :font]) (color :yellow)))
(label! e :set-style (style :label (get-in entities [:state :font]) (color :white))))))))
:on-resize (fn [screen entities]
(size! screen 1280 960)))