Thursday, July 25, 2013

PlayN / tripleplay - Simple Progressbar

Since there is no default progressbar widget in the tripleplay gui framework, I've build my  own one. Feel free to use, improvements are appreciated. I use it for the visualization of creature's lifeenergy in my game. 

 
package de.creaturewars.client.gui;

import tripleplay.ui.Background;
import tripleplay.ui.SizableGroup;
import tripleplay.ui.Style;
import tripleplay.ui.layout.AxisLayout;

/**
 * 
 * @author Paul Weibert
 * 
 */
public class ProgressBar extends SizableGroup {

 private final int BAR_COLOR = 0xff379aff;
 private final int EMPTY_COLOR = 0xff000000;
 private float maxValue = 100;
 private float value = 0;
 private SizableGroup bar;
 private float barHeight = 10;

 public ProgressBar(float width, float height) {
  super(AxisLayout.horizontal());
  this.preferredSize.update(width, height);
  this.addStyles(Style.HALIGN.left);
  this.bar = new SizableGroup(AxisLayout.horizontal());
  this.addStyles(Style.BACKGROUND.is(Background.solid(EMPTY_COLOR)));
  this.bar.setStyles(Style.BACKGROUND.is(Background.solid(BAR_COLOR)));
  this.bar.addStyles(Style.HALIGN.left);

  add(bar);
 }

 public void setValue(float value) {
  this.value = value;
  dataChanged();
 }

 public void setMaxValue(float maxValue) {
  this.maxValue = maxValue;
  dataChanged();
 }

 private void dataChanged() {
  float w = this.preferredSize.get().width();
  float qoutient = w / maxValue;
  float barWidth = qoutient * value;
  final float maxWidth = this.preferredSize.get().width();
  
  
  if(barWidth > maxWidth){
   barWidth = maxWidth;
  }
  
  bar.preferredSize.update(barWidth, barHeight);
 }

 public void setBarHeight(float barHeight) {
  this.barHeight = barHeight;
 }

}

Tuesday, April 9, 2013

PlayN and eclipse - flash build issue

In my previous post I have described how to set up eclipse for gamedevelopment with PlayN and import the PlayN showcases. The Html and Java versions worked fine and  I tried to run the flash version (Run As -> Maven install) which failed with the following output: 
 [INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building PlayN Showcase Flash 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ playn-showcase-flash ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) @ playn-showcase-flash ---
[INFO] Configured Artifact: com.adobe.flex:flex-sdk:4.1.0.16076_mpl:zip
[INFO] Unpacking /home/paul/.m2/repository/com/adobe/flex/flex-sdk/4.1.0.16076_mpl/flex-sdk-4.1.0.16076_mpl.zip to
  /home/paul/development/playn-samples/showcase/flash/target/flex4sdk
   with includes null and excludes:null
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (default) @ playn-showcase-flash ---
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.359s
[INFO] Finished at: Mon Apr 08 08:13:27 CEST 2013
[INFO] Final Memory: 10M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (default) on project playn-showcase-flash: An Ant BuildException has occured: /home/paul/development/playn-samples/showcase/flash/target/flex4sdk/bin not found. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
My System Information:
  • OS: Ubuntu 12.04 LTS 32bit
  • Eclipse Indigo

 Resolving The Errors

We look at the first error Message,
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (default) on project playn-showcase-flash: An Ant BuildException has occured: /home/paul/development/playn-samples/showcase/flash/target/flex4sdk/bin not found.
When browsing to the mentioned folder /home/paul/development/playn-samples/showcase/flash/target/flex4sdk it turns out that this folder is empty. Something must have gone wrong during unpacking or copying. An upper message tells us where we can find the right flex4sdk :
[INFO] Unpacking /home/paul/.m2/repository/com/adobe/flex/flex-sdk/4.1.0.16076_mpl/flex-sdk-4.1.0.16076_mpl.zip to
  /home/paul/development/playn-samples/showcase/flash/target/flex4sdk
   with includes null and excludes:null
We  browse to /home/paul/.m2/repository/com/adobe/flex/flex-sdk/4.1.0.16076_mpl/ unpack the flex-sdk-4.1.0.16076_mpl.zip and copy its content to the home/paul/development/playn-samples/showcase/flash/target/flex4sdk (You can also create a symlink).

We run the flash target again Run As->maven install on playn-showcase-flash. The previous message disappear. But the build still fails with the following output:
...
[INFO]
[INFO] --- gwt-maven-plugin:2.5.0:compile (default) @ playn-showcase-flash ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.534s
[INFO] Finished at: Mon Apr 08 08:30:57 CEST 2013
[INFO] Final Memory: 13M/173M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0:compile (default) on project playn-showcase-flash: GWT Module org.jbox2d.GwtBox2D not found in project sources or resources. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
 The GWT Compiler tells us that the Module org.jbox2d.GwtBox2D is missing. This module should be located in the jbox-sources.jar. We take a look at the Maven Dependencies:
A playn-jbox-xx.jar is actually listed but this jar contains only binaries, but the GWT Compiler need the source files. We must add an maven dependency for the sourcefile archive.

Later I found out that this wasn't the last missing maven dependency, to resolve all missing dependencies i had to add the following dependencies to my playn-showcase-flash/pom.xml:
         <dependency>
            <groupId>com.googlecode.playn</groupId>
            <artifactId>playn-html</artifactId>
            <version>1.6</version>
            <classifier>sources</classifier>
        </dependency>

        <dependency>
            <groupId>com.googlecode.playn</groupId>
            <artifactId>playn-jbox2d</artifactId>
            <version>${playn.version}</version>
            <classifier>sources</classifier>
        </dependency>

        <dependency>
            <groupId>com.threerings</groupId>
            <artifactId>tripleplay</artifactId>
            <version>${playn.version}</version>
            <classifier>sources</classifier>
        </dependency>
        <dependency>
            <groupId>com.googlecode.playn</groupId>
            <artifactId>playn-flash</artifactId>
            <version>${playn.version}</version>
            <classifier>sources</classifier>
        </dependency>
Now all dependencies should be complete. But running (Run As-> Maven install) the flash target results in an other Build Failure. Which seems to be more serious:

[INFO] --- gwt-maven-plugin:2.5.0:compile (default) @ playn-showcase-flash ---
[INFO] Compiling module playn.showcase.ShowcaseFlash
[INFO]    Validating units:
[INFO]       Ignored 1 unit with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO]    Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
[INFO]       Rebinding com.google.gwt.useragent.client.UserAgentAsserter
[INFO]          Checking rule <replace-with class='com.google.gwt.user.client.FlashUserAgentProperty'/>
[INFO]             [WARN] Unknown type 'com.google.gwt.user.client.UserAgentAsserter.UserAgentProperty' specified in deferred binding rule
[INFO]    Computing all possible rebind results for 'com.google.gwt.user.client.DocumentModeAsserter'
[INFO]       Rebinding com.google.gwt.user.client.DocumentModeAsserter
[INFO]          Checking rule <replace-with class='com.google.gwt.user.client.FlashUserAgentProperty'/>
[INFO]             [WARN] Unknown type 'com.google.gwt.user.client.UserAgentAsserter.UserAgentProperty' specified in deferred binding rule
[INFO]    Computing all possible rebind results for 'playn.showcase.flash.ShowcaseFlash'
[INFO]       Rebinding playn.showcase.flash.ShowcaseFlash
[INFO]          Checking rule <replace-with class='com.google.gwt.user.client.FlashUserAgentProperty'/>
[INFO]             [WARN] Unknown type 'com.google.gwt.user.client.UserAgentAsserter.UserAgentProperty' specified in deferred binding rule
[INFO] [ERROR] Unexpected internal compiler error
[INFO] java.lang.NoClassDefFoundError: com/google/gwt/dev/jjs/impl/TypeLinker
[INFO]     at com.google.gwt.dev.jas.JavaToActionScriptCompiler.precompile(JavaToActionScriptCompiler.java:530)
[INFO]     at com.google.gwt.dev.jas.JasCompiler.precompile(JasCompiler.java:41)
[INFO]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:278)
[INFO]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
[INFO]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
[INFO]     at com.google.gwt.dev.Compiler.run(Compiler.java:232)
[INFO]     at com.google.gwt.dev.Compiler.run(Compiler.java:198)
[INFO]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
[INFO]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
[INFO]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
[INFO]     at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[INFO] Caused by: java.lang.ClassNotFoundException: com.google.gwt.dev.jjs.impl.TypeLinker
[INFO]     at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
[INFO]     at java.security.AccessController.doPrivileged(Native Method)
[INFO]     at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
[INFO]     at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
[INFO]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
[INFO]     at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
[INFO]     ... 11 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE


The line Caused by: java.lang.ClassNotFoundException: com.google.gwt.dev.jjs.impl.TypeLinker
tells us that the class TypeLinker is missing. After spending several time googling I found out that this problem won't be easy to fix since the flash target of PlayN 1.6 is not compatible to gwt 2.5 which is curiously  used by PlayN 1.6. Another curious thing is that the PlayN Developers seem to know about this problem:

I found the following comment on http://code.google.com/p/playn/wiki/PlatformStatus:

"Using Flash currently requires some fiddling because the GWT plugin that translates Java to ActionScript has fallen out of date with GWT. Thus one has to roll back to an older version of GWT (pre-2.4) to use the Flash backend. "
Because of this message I spent a whole day trying to switch back to gwt 2.3 without success.  It's quite hard because the flash target depends on artifacts witch seem to depend on gwt2.5. No matter what gwt version you include there are still some classes missing.


 Notes

  • I've decided to post this article even though I didn't find a solution, with the hope the first part may be still useful for somebody.
  • Leave your comments if you have any ideas on how this problem can be solved
  • If flash support is essential for your project you should try PlayN 1.4 is seems to be the last version which supports the flash target

Sunday, April 7, 2013

Getting started with Eclipse and PlayN - run playn showcases

This article mentions how to set up eclipse for the work with the crossplatform game framework PlayN and also how to import and run the showcases.  
I decided to write this article since the Getting Started guide on http://code.google.com/p/playn/wiki/GettingStarted  is pretty short and some points were not quite clear to me as I was trying to set up Eclipse with PlayN. So I hope this guide will be helpful for you.

Some Information about my System :
  • OS: Ubuntu 12.04 LTS
  • Java: Open JDK 1.6
  • Eclipse Indigo

What is not covered in this article?  

Above all I was interested in the java, flash and html 5 functionality of PlayN. So I didn't test the ios and android targets. I your main interest lies in the mobile targets maybe this may be the wrong place for you. 

Set Up Maven Plugin

  •  First of all you need to install the Maven Plugin:  therefore click on Help -> Install New Software and type "maven" , the screen should look like this:
  • Select the item as shown in the picture, agree to install unsigned content if you'll be asked 

Another plugin you need is the native-dependency-plugin, to install it do the following:
  • In Eclipse click on: Help->Install New Software->Add (upper right corner)
  • The add "http://mavennatives.googlecode.com/svn/eclipse-update/" as new update site
  •  
  • Select the new Site, and the plugin to install  
  • install the plugin (accept to install unsigned content) 
  • Now we are done with the maven installation

 

Download and import the PlayN showcases

To download the showcases you need to install git. 
When the git installation was successful, we can checkout the showcases
  • Open a terminal (should also work on windows similarly) and cd to your eclipse workspace you want the showcases to be in
  • type : "git clone https://code.google.com/p/playn-samples"
If the download completed successfully there should be a directory named "playn-samples" and we can now import the samples in eclipse: 
  • In eclipse: click on File->Import.. 
  • Choose "Existing Maven Projects" and click on next
  • In the next screen click on "Browse" and browse to the previously mentioned "playn-samples" folder, select the subfolder "showcase" then on "ok" and on "Next" (later you can also try other samples from the "playn-samples" folder the same way)

  •  After this you see a summary of the required maven-plugins and eclipse tells you that one of them is missing (I wasn't able to find a way to resolve it). So we just click on "Finish".


  •  If all went right you should now see a bunch of new projects named "playn-showcase-x" 

Run the showcases

  • To run the showcases right click on playn-showcase->Run As -> maven install, As result the following should appear:

If you want to run the html version of the showcase
  • Previously make sure that the port 8080 is not already being used.
  • right click on playn-showcase-html->Run As -> maven install
  • Open a browser and type http://localhost:8080, now you should see the same menu and be able to play the samples

Notes

  • I haven't tried the android and ios targets
  • The flash target is not compiling (I will update the post when I have figured out what the problem is)
  • If you want to change the default port for the html target, just change the jetty-plugin configuration in pom.xml of the xx-html project to this: 
             
                org.mortbay.jetty
                jetty-maven-plugin
                8.0.0.v20110901
                
                    
                        ${project.basedir}/target/${project.artifactId}-${project.version}
                    
                    
                        
                            8181
                        
                    
                

                
                    
                        test-html
                        integration-test
                        
                            run-exploded