Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 15th, 2012  |  syntax: None  |  size: 5.50 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package game.states;
  2.  
  3. import game.core.InGameState;
  4. import game.gui.niftyinput.CustomSlickInputSystem;
  5. import game.gui.screens.ShowQuestObjectiveStateStartScreen;
  6.  
  7. import java.util.Vector;
  8.  
  9. import org.newdawn.slick.GameContainer;
  10. import org.newdawn.slick.Graphics;
  11. import org.newdawn.slick.Input;
  12. import org.newdawn.slick.SlickException;
  13. import org.newdawn.slick.state.StateBasedGame;
  14. import org.newdawn.slick.state.transition.FadeInTransition;
  15. import org.newdawn.slick.state.transition.FadeOutTransition;
  16.  
  17. import de.lessvoid.nifty.Nifty;
  18. import de.lessvoid.nifty.builder.ElementBuilder;
  19. import de.lessvoid.nifty.builder.PanelBuilder;
  20. import de.lessvoid.nifty.builder.TextBuilder;
  21. import de.lessvoid.nifty.controls.ScrollPanel;
  22. import de.lessvoid.nifty.controls.ScrollPanel.AutoScroll;
  23. import de.lessvoid.nifty.controls.scrollpanel.builder.ScrollPanelBuilder;
  24. import de.lessvoid.nifty.elements.Element;
  25. import de.lessvoid.nifty.screen.Screen;
  26. import de.lessvoid.nifty.slick2d.NiftyOverlayBasicGameState;
  27. import de.lessvoid.nifty.slick2d.loaders.SlickAddLoaderLocation;
  28. import de.lessvoid.nifty.slick2d.loaders.SlickRenderFontLoaders;
  29. import de.lessvoid.nifty.slick2d.render.font.loader.DefaultSlickRenderFontLoader;
  30.  
  31. /**
  32.  * @author Michel Montenegro
  33.  */
  34. public class ShowQuestObjectiveState extends NiftyOverlayBasicGameState{
  35.  
  36.         public static final int ID = 3;
  37.         public ShowQuestObjectiveState() {
  38.  
  39.         }
  40.  
  41.  
  42.         @Override
  43.         public int getID() {
  44.                 return ID;
  45.         }
  46.  
  47.         @Override
  48.         protected void enterState(GameContainer container, StateBasedGame sbGame)
  49.                         throws SlickException {
  50.  
  51.         }
  52.  
  53.         @Override
  54.         protected void initGameAndGUI(GameContainer container, StateBasedGame sbGame)
  55.                         throws SlickException {
  56.                 initNifty(container, sbGame, new CustomSlickInputSystem());
  57.                
  58.         }
  59.  
  60.         @Override
  61.         protected void leaveState(GameContainer arg0, StateBasedGame arg1)
  62.                         throws SlickException {
  63.  
  64.         }
  65.  
  66.        
  67.        
  68.         private static Element createMapItemPopup(Nifty nifty, Screen screen, Element parent)
  69.         {
  70.             Element scrollPanel = createScrollPanel( nifty, screen, parent );
  71.             Element scrollContainer = scrollPanel.findElementByName( "#nifty-scrollpanel-child-root" );
  72.             Vector<ElementBuilder> list = new Vector<ElementBuilder>();
  73.             list.add( createHeader("------" ) );
  74.             list.add( createHeader( "Actions" ) );
  75.             list.add( createHeader( "--------" ) );
  76.  
  77.             createVerticalPanel( nifty, screen, scrollContainer, list );
  78.             scrollContainer.layoutElements();
  79.             parent.getNiftyControl(ScrollPanel.class).setUp( 0, 20, 0, 20*10, AutoScroll.OFF ); // basically 20px for clicking on the scrollbar buttons and 200px when you press below or above the scrollhandle (and when the scrollbar someday supports the page up/down keys...)
  80.             return parent;
  81.         }
  82.        
  83.         private static Element createScrollPanel( Nifty nifty, Screen screen, Element parent )
  84.         {
  85.             ScrollPanelBuilder scrollBuilder = new ScrollPanelBuilder( "scrollpanel" );
  86.             scrollBuilder.width( "100%" );
  87.             scrollBuilder.height( "100%" );
  88.             scrollBuilder.set( "vertical", "true" );
  89.             scrollBuilder.set( "horizontal", "false" );
  90.             return scrollBuilder.build( nifty, screen, parent );
  91.         }
  92.        
  93.         private static TextBuilder createHeader( String text )
  94.         {
  95.             TextBuilder textBuilder = new TextBuilder();
  96.             textBuilder.width( 500 + "px" );
  97.             textBuilder.height( 20 + "px" );
  98.             textBuilder.font( "resources/fonts/console.fnt" );
  99.             textBuilder.textHAlignLeft();
  100.             textBuilder.text(text);
  101.             return textBuilder;
  102.         }
  103.         private static Element createVerticalPanel( Nifty nifty, Screen screen, Element parent, Vector<ElementBuilder> list )
  104.         {
  105.             PanelBuilder panelBuilder = new PanelBuilder();
  106.             panelBuilder.x( "0px" );
  107.             panelBuilder.y( "0px" );
  108.             panelBuilder.width( 20 + "px" );
  109.             panelBuilder.height( 20 * list.size() + "px" );
  110.             panelBuilder.alignLeft();
  111.             panelBuilder.valignTop();
  112.             panelBuilder.set( "childLayout", "vertical" );
  113.             panelBuilder.style("nifty-panel");
  114.            
  115.             Element panel = panelBuilder.build( nifty, screen, parent );
  116.             for( int i = 0; i < list.size(); i++ ){
  117.                 list.get( i ).build( nifty, screen, panel);
  118.             }  
  119.             return panel;
  120.         }
  121.        
  122.        
  123.         @Override
  124.         protected void prepareNifty(Nifty nifty, StateBasedGame sbGame) {
  125.                 ShowQuestObjectiveStateStartScreen.getInstance().createScreen(nifty);
  126.                
  127.                 SlickRenderFontLoaders.getInstance().addLoader(new DefaultSlickRenderFontLoader(), SlickAddLoaderLocation.first);
  128.                 Element sp = getNifty().getCurrentScreen().findElementByName("scrollPanel");
  129.             createMapItemPopup(getNifty(),getNifty().getCurrentScreen(), sp);
  130.         }
  131.        
  132.         @Override
  133.         protected void renderGame(GameContainer container, StateBasedGame sbg,
  134.                         Graphics graphics) throws SlickException {
  135.  
  136.         }
  137.  
  138.         @Override
  139.         protected void updateGame(GameContainer container, StateBasedGame sbGame,
  140.                         int delta) throws SlickException {
  141.                 if (container.getInput().isKeyPressed(Input.KEY_ESCAPE)) {
  142.                         sbGame.enterState(InGameState.ID, new FadeOutTransition(),      new FadeInTransition());
  143.                 }
  144.         }
  145.  
  146.         @Override
  147.         public void mousePressed(int button, int x, int y) {
  148.                 super.mousePressed(button, x, y);
  149.         }
  150.  
  151.         @Override
  152.         public void mouseReleased(int button, int x, int y) {
  153.                 super.mouseReleased(button, x, y);
  154.         }
  155.  
  156.         @Override
  157.         public void mouseMoved(int oldx, int oldy, int newx, int newy) {
  158.                 super.mouseMoved(oldx, oldy, newx, newy);
  159.         }
  160.  
  161.         @Override
  162.         public void keyPressed(final int key, final char c) {
  163.  
  164.         }
  165.  
  166.         @Override
  167.         public void keyReleased(final int key, final char c) {
  168.  
  169.         }
  170. }
clone this paste RAW Paste Data