progress on making dialogue appearance better.
This commit is contained in:
@@ -250,11 +250,20 @@
|
||||
(let [_ (swap! initial-time #(or % (:total-time screen)))
|
||||
target-y (get-in entities [:room :entities target-id :y])
|
||||
target-x (get-in entities [:room :entities target-id :x])
|
||||
width (or (get-in entities [:room :entities target-id :width])
|
||||
(.getRegionWidth (get-in entities [:room :entities target-id :object])))
|
||||
origin-x (get-in entities [:room :entities target-id :origin-x])
|
||||
target-x (if (nil? origin-x) (+ target-x (/ width 2)) target-x )
|
||||
height (or (get-in entities [:room :entities target-id :height])
|
||||
(.getRegionHeight (get-in entities [:room :entities target-id :object])))
|
||||
scaled (get-in entities [:room :entities target-id :scaled])
|
||||
scale-fn (get-in entities [:room :scale-fn])
|
||||
scale (scale-fn [target-x target-y])
|
||||
height (* scale 36)]
|
||||
scale (if scaled
|
||||
(scale-fn [target-x target-y])
|
||||
1)
|
||||
height (* scale height)]
|
||||
(screen! dialogue/talking-screen :on-talk :text text
|
||||
:x (get-in entities [:room :entities target-id :x]) :y (+ (get-in entities [:room :entities target-id :y]) height)
|
||||
:x target-x :y (+ (get-in entities [:room :entities target-id :y]) height)
|
||||
:color (get-in entities [:room :entities target-id :talk-color])
|
||||
|
||||
:target-id target-id
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[play-clj.utils :refer :all]
|
||||
[play-clj.g2d :refer :all]
|
||||
[clojure.pprint]
|
||||
[clojure.set :as set]
|
||||
[advent.pathfind]
|
||||
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]
|
||||
#_[advent.screens.scene :as scene])
|
||||
@@ -35,12 +36,18 @@
|
||||
:on-talk
|
||||
(fn [{:keys [create-talk target-id color text x y scale]} [entities]]
|
||||
(let [font (bitmap-font "ego/font.fnt" )
|
||||
p (nine-patch {:region (:object (texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
|
||||
_ (nine-patch! p :set-padding 25 25 5 15)
|
||||
|
||||
bg (drawable :nine-patch (:object p))
|
||||
_ (bitmap-font! font :set-markup-enabled true)
|
||||
tr (bitmap-font! font :get-region)
|
||||
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)) :y (* 4 y))]
|
||||
style (style :label font color)
|
||||
#__ #_(set! (.background style) bg)
|
||||
talk (assoc (label text style) :y (* 4 y) )]
|
||||
(label! talk :set-font-scale scale)
|
||||
(label! talk :set-alignment Align/center)
|
||||
(assoc entities target-id (-> talk
|
||||
@@ -63,46 +70,72 @@
|
||||
(< (:x e) x (+ (:x e) (.getWidth (:object e))))
|
||||
(< (:y e) y (+ (:y e) (:height e)))))
|
||||
|
||||
(defn get-color [e mouse-pos]
|
||||
(if (intersects? e mouse-pos)
|
||||
(color :yellow)
|
||||
(color 0.6 1.0 1.0 1.0)
|
||||
))
|
||||
|
||||
(defn style-label [e font mouse-pos]
|
||||
(label! e :set-style (style :label font (get-color e mouse-pos)))
|
||||
e)
|
||||
|
||||
(defscreen choice-screen
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
(update! screen :renderer (stage) :camera (orthographic))
|
||||
{})
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(render! screen (vals entities))
|
||||
entities)
|
||||
|
||||
:on-present-choices
|
||||
(fn [{:keys [choices callback]} [entities]]
|
||||
(let [font (bitmap-font "ego/font.fnt" )
|
||||
tr (bitmap-font! font :get-region)
|
||||
scale 1
|
||||
tx (.getTexture tr)
|
||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||
choice-count (count choices)]
|
||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
|
||||
{:state {:object nil
|
||||
:callback nil
|
||||
:choices []
|
||||
:last-pos [0 0]
|
||||
:font font
|
||||
:np (assoc (nine-patch {:region (:object (texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
|
||||
:x 5 :y 5 :width 1270)}}))
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(when (seq (get-in entities [:state :choices]))
|
||||
(render! screen [(get-in entities [:state :np])])
|
||||
(render! screen (vals entities)))
|
||||
entities)
|
||||
|
||||
:on-present-choices
|
||||
(fn [{:keys [choices callback]} [entities]]
|
||||
(let [choice-count (count choices)
|
||||
font (get-in entities [:state :font])]
|
||||
(-> entities
|
||||
(into (for [[[text] i] (map vector choices (range))]
|
||||
[i (assoc (label text (style :label font (color 0.6 1.0 1.0 1.0))) :height 30 :x 30 :y (+ 30 (* choice-height (- choice-count i 1))) :index i)]))
|
||||
(assoc :state {:object nil :callback callback :choices choices :font font}))))
|
||||
(into (for [[[text] i] (map vector choices (range))
|
||||
:let [e (label text (style :label font (color 0.6 1.0 1.0 1.0)))
|
||||
e (assoc e :height 30 :x 30 :y (+ 30 (* choice-height (- choice-count i 1))) :index i)
|
||||
e (style-label e font (get-in entities [:state :last-pos]))]]
|
||||
[i e]))
|
||||
(assoc-in [:state :choices] choices)
|
||||
(assoc-in [:state :callback] callback)
|
||||
(assoc-in [:state :np :height] (* 30 (inc choice-count))))))
|
||||
|
||||
: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 (seq (get-in entities [:state :choices]))
|
||||
(when-let [choice (first (filter #(intersects? % [x y]) (vals entities)))]
|
||||
((get-in entities [:state :callback]) (:index choice))
|
||||
{}))))
|
||||
(-> entities
|
||||
(assoc-in [:state :callback] nil)
|
||||
(assoc-in [:state :choices] [])
|
||||
(select-keys [:state]))))))
|
||||
|
||||
:on-mouse-moved (fn [screen [entities]]
|
||||
(when (seq entities)
|
||||
(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 0.6 1.0 1.0 1.0))))))))
|
||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
||||
entities (assoc-in entities [:state :last-pos] [x y])
|
||||
choice-count (dec (count entities))]
|
||||
(doseq [e (vals entities)
|
||||
:when (:object e)]
|
||||
(style-label e (get-in entities [:state :font]) [x y]))
|
||||
entities))
|
||||
|
||||
:on-resize (fn [screen entities]
|
||||
(size! screen 1280 960)))
|
||||
|
||||
Reference in New Issue
Block a user