Refactor and fix interop bugs

This commit is contained in:
oakes
2014-01-11 01:58:08 -05:00
parent ee3fdab2fd
commit d623c580fb
5 changed files with 78 additions and 46 deletions

View File

@@ -19,7 +19,9 @@
OrthogonalTiledMapRenderer] OrthogonalTiledMapRenderer]
[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
ImageButton ImageTextButton Label TextButton TextField])) ImageButton ImageTextButton Label Skin Slider TextButton TextField]
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable
SpriteDrawable TextureRegionDrawable TiledDrawable]))
(defmulti create-entity class) (defmulti create-entity class)

View File

@@ -73,37 +73,39 @@
(execute-fn! on-touch-up :screen-x sx :screen-y sy :pointer p :button b) (execute-fn! on-touch-up :screen-x sx :screen-y sy :pointer p :button b)
false))) false)))
(defn- gesture-detector (defn- gesture-listener
[{:keys [on-fling on-long-press on-pan on-pan-stop on-pinch on-tap on-zoom]} [{:keys [on-fling on-long-press on-pan on-pan-stop on-pinch on-tap on-zoom]}
execute-fn!] execute-fn!]
(let [listener (reify GestureDetector$GestureListener
(reify GestureDetector$GestureListener (fling [this vx vy b]
(fling [this vx vy b] (execute-fn! on-fling :velocity-x vx :velocity-y vy :button b)
(execute-fn! on-fling :velocity-x vx :velocity-y vy :button b) false)
false) (longPress [this x y]
(longPress [this x y] (execute-fn! on-long-press :x x :y y)
(execute-fn! on-long-press :x x :y y) false)
false) (pan [this x y dx dy]
(pan [this x y dx dy] (execute-fn! on-pan :x x :y y :delta-x dx :delta-y dy)
(execute-fn! on-pan :x x :y y :delta-x dx :delta-y dy) false)
false) (panStop [this x y p b]
(panStop [this x y p b] (execute-fn! on-pan-stop :x x :y y :pointer p :button b)
(execute-fn! on-pan-stop :x x :y y :pointer p :button b) false)
false) (pinch [this ip1 ip2 p1 p2]
(pinch [this ip1 ip2 p1 p2] (execute-fn! on-pinch
(execute-fn! on-pinch :initial-pointer-1 ip1 :initial-pointer-2 ip2
:initial-pointer-1 ip1 :initial-pointer-2 ip2 :pointer1 p1 :pointer2 p2)
:pointer1 p1 :pointer2 p2) false)
false) (tap [this x y c b]
(tap [this x y c b] (execute-fn! on-tap :x x :y y :count c :button b)
(execute-fn! on-tap :x x :y y :count c :button b) false)
false) (touchDown [this x y p b]
(touchDown [this x y p b] false)
false) (zoom [this id d]
(zoom [this id d] (execute-fn! on-zoom :initial-distance id :distance d)
(execute-fn! on-zoom :initial-distance id :distance d) false)))
false))]
(proxy [GestureDetector] [listener]))) (defn- gesture-detector
[options execute-fn!]
(proxy [GestureDetector] [(gesture-listener options execute-fn!)]))
(defn- add-input! (defn- add-input!
[^InputProcessor p] [^InputProcessor p]

View File

@@ -9,32 +9,33 @@
; render ; render
(defmacro orthogonal-tiled-map! (defmacro orthogonal-tiled-map!
[{:keys [renderer]} k & options] [screen k & options]
`(utils/call! ^OrthogonalTiledMapRenderer ~renderer ~k ~@options)) `(utils/call! ^OrthogonalTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro isometric-tiled-map! (defmacro isometric-tiled-map!
[{:keys [renderer]} k & options] [screen k & options]
`(utils/call! ^IsometricTiledMapRenderer ~renderer ~k ~@options)) `(utils/call! ^IsometricTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro isometric-staggered-tiled-map! (defmacro isometric-staggered-tiled-map!
[{:keys [renderer]} k & options] [screen k & options]
`(utils/call! ^IsometricStaggeredTiledMapRenderer ~renderer ~k ~@options)) `(utils/call! ^IsometricStaggeredTiledMapRenderer (:renderer ~screen)
~k ~@options))
(defmacro hexagonal-tiled-map! (defmacro hexagonal-tiled-map!
[{:keys [renderer]} k & options] [screen k & options]
`(utils/call! ^HexagonalTiledMapRenderer ~renderer ~k ~@options)) `(utils/call! ^HexagonalTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro stage! (defmacro stage!
[{:keys [renderer]} k & options] [screen k & options]
`(utils/call! ^Stage ~renderer ~k ~@options)) `(utils/call! ^Stage (:renderer ~screen) ~k ~@options))
(defmacro orthographic-camera! (defmacro orthographic-camera!
[{:keys [camera]} k & options] [screen k & options]
`(utils/call! ^OrthographicCamera ~camera ~k ~@options)) `(utils/call! ^OrthographicCamera (:camera ~screen) ~k ~@options))
(defmacro perspective-camera! (defmacro perspective-camera!
[{:keys [camera]} k & options] [screen k & options]
`(utils/call! ^PerspectiveCamera ~camera ~k ~@options)) `(utils/call! ^PerspectiveCamera (:camera ~screen) ~k ~@options))
; global ; global
@@ -84,6 +85,10 @@
[entity k & options] [entity k & options]
`(utils/call! ^Label (:object ~entity) ~k ~@options)) `(utils/call! ^Label (:object ~entity) ~k ~@options))
(defmacro slider!
[entity k & options]
`(utils/call! ^Slider (:object ~entity) ~k ~@options))
(defmacro text-button! (defmacro text-button!
[entity k & options] [entity k & options]
`(utils/call! ^TextButton (:object ~entity) ~k ~@options)) `(utils/call! ^TextButton (:object ~entity) ~k ~@options))

View File

@@ -3,7 +3,7 @@
; rendering ; rendering
(defn render! (defn render!
[{:keys [renderer ^Camera camera]}] [{:keys [renderer ^Camera camera delta-time]}]
(assert renderer) (assert renderer)
(cond (cond
(isa? (type renderer) BatchTiledMapRenderer) (isa? (type renderer) BatchTiledMapRenderer)
@@ -11,7 +11,9 @@
(.setView camera) (.setView camera)
.render) .render)
(isa? (type renderer) Stage) (isa? (type renderer) Stage)
(.draw ^Stage renderer))) (doto ^Stage renderer
(.act delta-time)
.draw)))
(defn tiled-map-layers (defn tiled-map-layers
[{:keys [^BatchTiledMapRenderer renderer]}] [{:keys [^BatchTiledMapRenderer renderer]}]

View File

@@ -7,6 +7,18 @@
(utils/key->class type) "Style.")) (utils/key->class type) "Style."))
~@options)) ~@options))
(defmacro drawable
[type & options]
`(~(symbol (str utils/gdx-package ".scenes.scene2d.utils."
(utils/key->class type) "Drawable."))
~@options))
(defmacro skin
[path & options]
`(utils/calls! ^Skin (Skin. (files! :internal ~path)) ~@options))
; widgets
(defn check-box* (defn check-box*
[^String text arg] [^String text arg]
(CheckBox. text arg)) (CheckBox. text arg))
@@ -42,6 +54,15 @@
[text arg & options] [text arg & options]
`(create-entity (utils/calls! ^Label (label* ~text ~arg) ~@options))) `(create-entity (utils/calls! ^Label (label* ~text ~arg) ~@options)))
(defn slider*
[min max step is-vert? arg]
(Slider. (float min) (float max) (float step) is-vert? arg))
(defmacro slider
[min max step is-vert? arg & options]
`(create-entity
(utils/calls! ^Slider (slider* ~min ~max ~step ~is-vert? ~arg) ~@options)))
(defn text-button* (defn text-button*
[^String text arg] [^String text arg]
(TextButton. text arg)) (TextButton. text arg))