oakes / play-clj

A Clojure game library
The Unlicense
940 stars 72 forks source link

Missing Method In Dialog #71

Closed Yoshiyuka closed 9 years ago

Yoshiyuka commented 9 years ago

I have one more issue I'm interpreting as being a bug. According to the libgdx documentation on the Dialog class, the text method has a version which accepts a Label type such that text(Label label). However, if I try to call text on a dialog through (dialog! popup :text content) where content is an entity returned by (label "text" (skin "uiskin.json")) I'm presented with an exception claiming that it can't find the proper version of text to call based on the given argument:

dialog-issue.core=> java.lang.IllegalArgumentException: No matching method found
: text for class com.badlogic.gdx.scenes.scene2d.ui.Dialog
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:80)
        at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
        at dialog_issue.core$eval2245$fn__2265.invoke(core.clj:256)
        at clojure.lang.Var.invoke(Var.java:383)
        at play_clj.core$defscreen_STAR_$execute_fn_BANG___886$fn__889.invoke(core.clj:83)
        at clojure.lang.AFn.applyToHelper(AFn.java:152)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.lang.AFunction$1.doInvoke(AFunction.java:29)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at dialog_issue.core$eval2331$fn__2332.invoke(core.clj:44)
        at play_clj.core$defscreen_STAR_$execute_fn_BANG___886.doInvoke(core.clj:85)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at play_clj.core$defscreen_STAR_$fn__912.invoke(core.clj:113)
        at clojure.lang.AFn.applyToHelper(AFn.java:152)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.core$apply.invoke(core.clj:626)
        at play_clj.core$set_screen_BANG_$run_fn_BANG___943.doInvoke(core.clj:517)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at play_clj.core$set_screen_BANG_$reify__951.show(core.clj:522)
        at com.badlogic.gdx.Game.setScreen(Game.java:61)
        at play_clj.core.proxy$com.badlogic.gdx.Game$ff19274a.setScreen(UnknownSource)
        at play_clj.core$set_screen_BANG_.doInvoke(core.clj:518)
        at clojure.lang.RestFn.invoke(RestFn.java:423)
        at dialog_issue.core$eval2335$fn__2336.invoke(form-init7519133605842818004.clj:1)
        at clojure.lang.AFn.run(AFn.java:22)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication.executeRunnables(LwjglApplication.java:240)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:193)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

The offending code:

:on-show
  (fn [screen entities]
    (let [popup (dialog "Test Dialog" (skin "uiskin.json"))
          content (label "Test Label" (skin "uiskin.json"))]
    (update! screen :renderer (stage))
    (dialog! popup :button "Close")
    (dialog! popup :text content)
    popup))

I've gotten around this error by directly instantiating a Label class such that:

(ns dialog-issue.core
  (:require [play-clj.core :refer :all]
                 [play-clj.ui :refer :all])
  (:import [com.badlogic.gdx.scenes.scene2d.ui Label]))

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (let [popup (dialog "Test Dialog" (skin "uiskin.json"))
          content (Label. "Test Label" (skin "uiskin.json"))]
    (update! screen :renderer (stage))
    (dialog! popup :button "Close")
    (dialog! popup :text content)
    popup))
)

This also has given me the ability to directly manipulate the properties of the label prior to it being added to the dialog's content table. For instance, setting word wrap to true: (label! content :set-wrap true)

Thank you for the very quick response to the previous issues!

oakes commented 9 years ago

This is because (label "Test Label" (skin "uiskin.json")) doesn't actually return a Label, it returns as LabelEntity. You can fix this by pulling the underlying Java object out of the entity like this:

(dialog! popup :text (:object content))