Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated jme to latest build. sample13 calls screencontroller now. par…

…sing xml with erb
  • Loading branch information...
commit d4b97ee8ef329c597c0f871ba36885f59f32ba17 1 parent 5a4765f
@jwoertink authored
View
10 assets/Interface/screen.xml → assets/Interface/screen.xml.erb
@@ -3,14 +3,14 @@
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd">
<useControls filename="nifty-default-controls.xml" />
<useStyles filename="nifty-default-styles.xml" />
- <screen id="start">
+ <screen id="start" controller="<%= screen_controller %>">
<!-- required -->
<layer id="background" childLayout="center">
<image filename="assets/Interface/start-background.png"></image>
</layer>
<layer id="foreground" backgroundColor="#0000" childLayout="vertical">
<panel id="panel_top" height="25%" width="75%" align="center" childLayout="center">
- <text text="My Cool Game" font="Interface/Fonts/Default.fnt" width="100%" height="100%" />
+ <text text="<%= player_name %>'s Game" font="Interface/Fonts/Default.fnt" width="100%" height="100%" />
</panel>
<panel id="panel_mid" height="50%" width="75%" align="center" childLayout="center">
<text text="Here goes some text describing the game and the rules and stuff. Incidentally, the text is quite long and needs to wrap at the end of lines. ..."
@@ -18,11 +18,13 @@
</panel>
<panel id="panel_bottom" height="25%" width="75%" align="center" childLayout="horizontal" backgroundColor="#00f8">
<panel id="panel_bottom_left" height="50%" width="50%" valign="center" childLayout="center">
- <control name="button" label="Start" id="StartButton" align="center" valign="center">
+ <control name="button" label="Start" id="StartButton" align="center" valign="center" visibleToMouse="true">
+ <interact onClick="startGame(hud)"/>
</control>
</panel>
<panel id="panel_bottom_right" height="50%" width="50%" valign="center" childLayout="center">
- <control name="button" label="Quit" id="QuitButton" align="center" valign="center">
+ <control name="button" label="Quit" id="QuitButton" align="center" valign="center" visibleToMouse="true">
+ <interact onClick="quitGame()" />
</control>
</panel>
</panel>
View
42 lib/samples/nifty/start_screen_controller.rb
@@ -8,34 +8,52 @@
class StartScreenController < AbstractAppState
include ScreenController
+ field_accessor :initialized
+
+ # Java method not found: com.jme3.app.state.AbstractAppState.initialize()
+ #java_alias :init_with, :initialize
attr_accessor :nifty, :screen, :app
- def initialize(data = "")
-
+ def initialize
+ end
+
+ def init_with(data = {})
+ #init = java_method(:initialize, [com.jme3.app.state.AppStateManager, com.jme3.app.SimpleApplication])
+ #init.call(data[:state_manager], data[:app])
+ @state_manager = data[:state_manager]
+ self.app = data[:app]
+ self.initialized = true
+ return self # mocking a "initialize" method
end
def bind(nifty, screen)
+ puts "\n\n BINDING \n\n"
self.nifty = nifty
self.screen = screen
end
- def on_start_screen
-
- end
-
- def on_end_screen
-
+ def onStartScreen
+ puts "\n\n on_start_screen called: #{initialized}\n\n"
end
- # How do I do this?!
- def app_initialize(state_manager, app)
- super.initialize(state_manager, app)
- self.app = app
+ def onEndScreen
+ puts "\n\n on_end_screen called\n\n"
end
def update(tpf)
+ puts "\n\n UPDATING\n\n"
# jme update loop
end
+ def startGame(next_screen)
+ puts "\n\n Called start for #{next_screen}\n\n"
+ nifty.goto_screen(next_screen)
+ end
+
+ def quitGame()
+ puts "\n\n Called quit\n\n"
+ app.stop
+ end
+
end
View
23 lib/samples/sample13.rb
@@ -6,12 +6,17 @@
java_import "de.lessvoid.nifty.Nifty"
java_import "de.lessvoid.nifty.screen.Screen"
java_import "de.lessvoid.nifty.screen.ScreenController"
+java_import "java.util.logging.Level"
+java_import "java.util.logging.Logger"
+require "samples/nifty/start_screen_controller"
+require 'erb'
+require 'pathname'
class Sample13 < SimpleApplication
-
field_accessor :flyCam
def initialize
+ #Logger.get_logger("").level = Level::WARNING
@game_state = 0
end
@@ -23,13 +28,23 @@ def simpleInitApp
end
def load_start_screen
+ #flyCam.enabled = false
+ flyCam.drag_to_rotate = true
nifty_display = NiftyJmeDisplay.new(asset_manager, input_manager, audio_renderer, gui_view_port)
nifty = nifty_display.nifty
- nifty.from_xml(File.join("assets", "Interface", "screen.xml"), "start")
+ StartScreenController.become_java! # shouldn't return nil, but it does...
+ controller = StartScreenController.new
+ controller.init_with({:state_manager => state_manager, :app => self})
+ screen_controller = controller.get_class.name
+ player_name = "Jeremy"
+ xml_result = ERB.new(IO.read(File.join(PROJECT_ROOT, 'assets', 'Interface', 'screen.xml.erb'))).result(binding)
+ path = File.open(File.join(PROJECT_ROOT, 'assets', 'Interface', "screen-#{Time.now.strftime("%s")}.xml"), 'w+') do |f|
+ f.write(xml_result)
+ f.path
+ end
+ nifty.from_xml(path[path.index("assets/"), path.size], "start", controller)
gui_view_port.add_processor(nifty_display)
- #flyCam.enabled = false
- flyCam.drag_to_rotate = true
end
end
View
15 lib/samples/sample13a.rb
@@ -1,7 +1,6 @@
=begin
Sample using Nifty the "JRuby" way.
=end
-
java_import "com.jme3.app.SimpleApplication"
java_import "com.jme3.niftygui.NiftyJmeDisplay"
java_import "de.lessvoid.nifty.Nifty"
@@ -9,23 +8,25 @@
java_import "de.lessvoid.nifty.builder.LayerBuilder"
java_import "de.lessvoid.nifty.builder.PanelBuilder"
java_import "de.lessvoid.nifty.controls.button.builder.ButtonBuilder"
-java_import "de.lessvoid.nifty.screen.DefaultScreenController"
+#java_import "de.lessvoid.nifty.screen.DefaultScreenController"
+require "#{PROJECT_ROOT}/lib/samples/nifty/start_screen_controller"
-
class Sample13a < SimpleApplication
field_accessor :flyCam
- def simpleInitApp()
+ def simpleInitApp
+ flyCam.setDragToRotate(true)
niftyDisplay = NiftyJmeDisplay.new(assetManager, inputManager, audioRenderer, guiViewPort)
nifty = niftyDisplay.getNifty
guiViewPort.addProcessor(niftyDisplay)
- flyCam.setDragToRotate(true)
nifty.loadStyleFile("nifty-default-styles.xml")
nifty.loadControlFile("nifty-default-controls.xml")
screen_builder = MyScreenBuilder.new("Hello Nifty Screen")
- screen_builder.controller(DefaultScreenController.new)
+ controller = StartScreenController.new
+ controller.init_with({:state_manager => state_manager, :app => self})
+ screen_builder.controller(controller)
screen_builder.layer(MyLayerBuilder.new("Layer_ID"))
nifty.addScreen("Screen_ID", screen_builder.build(nifty))
@@ -65,6 +66,8 @@ def initialize(id, text)
valignCenter
height("5%")
width("15%")
+ visibleToMouse(true)
+ interactOnClick("quitGame")
end
end
View
5 lib/waves.rb
@@ -1,8 +1,11 @@
require 'java'
+require 'jruby/core_ext'
PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
-require File.join(PROJECT_ROOT, 'vendor', 'jme3_2011-08-29.jar')
+$: << File.join(PROJECT_ROOT, "lib")
+
+require File.join("..", 'vendor', 'jme3_2011-10-25.jar')
module Waves
VERSION = "0.0.1"
View
BIN  liblwjgl.jnilib
Binary file not shown
View
BIN  vendor/jme3_2011-08-29.jar → vendor/jme3_2011-10-25.jar
Binary file not shown
View
BIN  vendor/lib/eventbus.jar
Binary file not shown
View
BIN  vendor/lib/jME3-jbullet.jar
Binary file not shown
View
BIN  vendor/lib/jME3-lwjgl-natives.jar
Binary file not shown
View
BIN  vendor/lib/jME3-test.jar
Binary file not shown
View
BIN  vendor/lib/jME3-testdata.jar
Binary file not shown
View
BIN  vendor/lib/lwjgl.jar
Binary file not shown
View
BIN  vendor/lib/nifty-default-controls.jar
Binary file not shown
View
BIN  vendor/lib/nifty-examples.jar
Binary file not shown
View
BIN  vendor/lib/nifty-style-black.jar
Binary file not shown
View
BIN  vendor/lib/nifty.jar
Binary file not shown
View
BIN  vendor/lib/xmlpull-xpp3.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.