Refactor and add groups
This commit is contained in:
@@ -70,9 +70,9 @@
|
|||||||
(defmacro animation
|
(defmacro animation
|
||||||
[duration textures & args]
|
[duration textures & args]
|
||||||
`(Animation. ~duration
|
`(Animation. ~duration
|
||||||
(u/gdx-into-array (map :object ~textures))
|
(u/convert-array (map :object ~textures))
|
||||||
(u/gdx-static-field :graphics :g2d :Animation
|
(u/static-field-upper :graphics :g2d :Animation
|
||||||
~(or (first args) :normal))))
|
~(or (first args) :normal))))
|
||||||
|
|
||||||
(defn animation->texture
|
(defn animation->texture
|
||||||
([{:keys [total-time]} ^Animation animation]
|
([{:keys [total-time]} ^Animation animation]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
(defmacro color
|
(defmacro color
|
||||||
[& args]
|
[& args]
|
||||||
`~(if (keyword? (first args))
|
`~(if (keyword? (first args))
|
||||||
`(Color. ^Color (u/gdx-static-field :graphics :Color ~(first args)))
|
`(Color. ^Color (u/static-field-upper :graphics :Color ~(first args)))
|
||||||
`(Color. ~@args)))
|
`(Color. ~@args)))
|
||||||
|
|
||||||
; interop
|
; interop
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
|
|
||||||
(defmacro key-code
|
(defmacro key-code
|
||||||
[key]
|
[key]
|
||||||
`~(symbol (str u/gdx-package ".Input$Keys/" (u/key->static-field key))))
|
`~(symbol (str u/main-package ".Input$Keys/" (u/key->static-field key true))))
|
||||||
|
|
||||||
(defmacro is-pressed?
|
(defmacro is-pressed?
|
||||||
[key]
|
[key]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
[com.badlogic.gdx.scenes.scene2d Actor Stage]
|
[com.badlogic.gdx.scenes.scene2d Actor Stage]
|
||||||
[com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog
|
[com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog
|
||||||
HorizontalGroup Image ImageButton ImageTextButton Label Skin Slider
|
HorizontalGroup Image ImageButton ImageTextButton Label Skin Slider
|
||||||
TextButton TextField VerticalGroup WidgetGroup]
|
Table TextButton TextField VerticalGroup WidgetGroup]
|
||||||
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener
|
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener
|
||||||
ChangeListener ClickListener DragListener FocusListener
|
ChangeListener ClickListener DragListener FocusListener
|
||||||
NinePatchDrawable SpriteDrawable TextureRegionDrawable
|
NinePatchDrawable SpriteDrawable TextureRegionDrawable
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
(defmacro drawable
|
(defmacro drawable
|
||||||
[type & options]
|
[type & options]
|
||||||
`(~(symbol (str u/gdx-package ".scenes.scene2d.u."
|
`(~(symbol (str u/main-package ".scenes.scene2d.u."
|
||||||
(u/key->class type) "Drawable."))
|
(u/key->class type) "Drawable."))
|
||||||
~@options))
|
~@options))
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
(defmacro style
|
(defmacro style
|
||||||
[type & options]
|
[type & options]
|
||||||
`(~(symbol (str u/gdx-package ".scenes.scene2d.ui."
|
`(~(symbol (str u/main-package ".scenes.scene2d.ui."
|
||||||
(u/key->class type) "$"
|
(u/key->class type) "$"
|
||||||
(u/key->class type) "Style."))
|
(u/key->class type) "Style."))
|
||||||
~@options))
|
~@options))
|
||||||
@@ -119,30 +119,43 @@
|
|||||||
|
|
||||||
; groups
|
; groups
|
||||||
|
|
||||||
(defn add-children
|
(defmulti add-to-group! #(-> % first :object type) :default WidgetGroup)
|
||||||
[^WidgetGroup group children]
|
|
||||||
(doseq [{:keys [object]} children]
|
|
||||||
(assert (isa? (type object) Actor))
|
|
||||||
(.addActor group ^Actor object))
|
|
||||||
group)
|
|
||||||
|
|
||||||
(defn horizontal*
|
(defmethod add-to-group! WidgetGroup
|
||||||
[children]
|
[[{:keys [^WidgetGroup object]} children]]
|
||||||
(add-children (HorizontalGroup.) children))
|
(doseq [child children]
|
||||||
|
(.addActor object ^Actor (:object child))))
|
||||||
|
|
||||||
|
(defmethod add-to-group! Table
|
||||||
|
[[{:keys [^Table object]} children]]
|
||||||
|
(doseq [child children]
|
||||||
|
(.add object ^Actor (:object child))))
|
||||||
|
|
||||||
|
(defn add!
|
||||||
|
[group children]
|
||||||
|
(add-to-group! [group children])
|
||||||
|
group)
|
||||||
|
|
||||||
(defmacro horizontal
|
(defmacro horizontal
|
||||||
[children & options]
|
[children & options]
|
||||||
`(u/create-entity (u/calls! ^HorizontalGroup (horizontal* ~children)
|
`(-> (u/calls! ^HorizontalGroup (HorizontalGroup.) ~@options)
|
||||||
~@options)))
|
(doto (.setFillParent true))
|
||||||
|
u/create-entity
|
||||||
(defn vertical*
|
(add! ~children)))
|
||||||
[children]
|
|
||||||
(add-children (VerticalGroup.) children))
|
|
||||||
|
|
||||||
(defmacro vertical
|
(defmacro vertical
|
||||||
[children & options]
|
[children & options]
|
||||||
`(u/create-entity (u/calls! ^VerticalGroup (vertical* ~children)
|
`(-> (u/calls! ^VerticalGroup (VerticalGroup.) ~@options)
|
||||||
~@options)))
|
(doto (.setFillParent true))
|
||||||
|
u/create-entity
|
||||||
|
(add! ~children)))
|
||||||
|
|
||||||
|
(defmacro table
|
||||||
|
[children & options]
|
||||||
|
`(-> (u/calls! ^Table (Table.) ~@options)
|
||||||
|
(doto (.setFillParent true))
|
||||||
|
u/create-entity
|
||||||
|
(add! ~children)))
|
||||||
|
|
||||||
; listeners
|
; listeners
|
||||||
|
|
||||||
@@ -266,3 +279,15 @@
|
|||||||
(defmacro dialog!
|
(defmacro dialog!
|
||||||
[entity k & options]
|
[entity k & options]
|
||||||
`(u/call! ^Dialog (:object ~entity) ~k ~@options))
|
`(u/call! ^Dialog (:object ~entity) ~k ~@options))
|
||||||
|
|
||||||
|
(defmacro horizontal!
|
||||||
|
[entity k & options]
|
||||||
|
`(u/call! ^HorizontalGroup (:object ~entity) ~k ~@options))
|
||||||
|
|
||||||
|
(defmacro vertical!
|
||||||
|
[entity k & options]
|
||||||
|
`(u/call! ^VerticalGroup (:object ~entity) ~k ~@options))
|
||||||
|
|
||||||
|
(defmacro table!
|
||||||
|
[entity k & options]
|
||||||
|
`(u/call! ^Table (:object ~entity) ~k ~@options))
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
[com.badlogic.gdx.utils Array]
|
[com.badlogic.gdx.utils Array]
|
||||||
[com.badlogic.gdx.scenes.scene2d Actor]))
|
[com.badlogic.gdx.scenes.scene2d Actor]))
|
||||||
|
|
||||||
(def ^:const gdx-package "com.badlogic.gdx")
|
(def ^:const main-package "com.badlogic.gdx")
|
||||||
|
|
||||||
(defn ^:private split-key
|
(defn ^:private split-key
|
||||||
[key]
|
[key]
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
(defn ^:private join-keys
|
(defn ^:private join-keys
|
||||||
[keys]
|
[keys]
|
||||||
(->> keys (map name) (s/join ".") (str gdx-package ".")))
|
(->> keys (map name) (s/join ".") (str main-package ".")))
|
||||||
|
|
||||||
(defn key->static-field
|
(defn key->static-field
|
||||||
[key]
|
[key upper?]
|
||||||
(->> (split-key key)
|
(->> (split-key key)
|
||||||
(map s/upper-case)
|
(map (if upper? s/upper-case s/lower-case))
|
||||||
(s/join "_")
|
(s/join "_")
|
||||||
symbol))
|
symbol))
|
||||||
|
|
||||||
@@ -38,17 +38,21 @@
|
|||||||
(str ".")
|
(str ".")
|
||||||
symbol)))
|
symbol)))
|
||||||
|
|
||||||
(defn gdx-static-field*
|
(defn ^:private static-field
|
||||||
[args]
|
[args upper?]
|
||||||
(->> (key->static-field (last args))
|
(->> (key->static-field (last args) upper?)
|
||||||
(str (join-keys (butlast args)) "/")
|
(str (join-keys (butlast args)) "/")
|
||||||
symbol))
|
symbol))
|
||||||
|
|
||||||
(defmacro gdx-static-field
|
(defmacro static-field-lower
|
||||||
[& args]
|
[& args]
|
||||||
`~(gdx-static-field* args))
|
`~(static-field args false))
|
||||||
|
|
||||||
(defn gdx-into-array
|
(defmacro static-field-upper
|
||||||
|
[& args]
|
||||||
|
`~(static-field args true))
|
||||||
|
|
||||||
|
(defn convert-array
|
||||||
[a]
|
[a]
|
||||||
(Array. true (into-array a) 1 (count a)))
|
(Array. true (into-array a) 1 (count a)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user