Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package cz.ascaria.zoneofuprising.gui;
  6.  
  7. import cz.ascaria.zoneofuprising.Main;
  8. import cz.ascaria.zoneofuprising.ZoneOfUprisingClient;
  9. import java.util.HashMap;
  10. import java.util.Map;
  11. import java.util.logging.Level;
  12. import tonegod.gui.controls.windows.Window;
  13. import tonegod.gui.core.Screen;
  14.  
  15. /**
  16.  *
  17.  * @author Ascaria Quynn
  18.  */
  19. public class GuiManager {
  20.  
  21.     public HashMap<Class<?extends Layout>, Window[]> layouts;
  22.  
  23.     private ZoneOfUprisingClient game;
  24.     private Screen screen;
  25.  
  26.     public GuiManager(ZoneOfUprisingClient game) {
  27.         this.game = game;
  28.         this.layouts = new HashMap<Class<?extends Layout>, Window[]>();
  29.     }
  30.  
  31.     /**
  32.      * Returns screen for guiNode.
  33.      * @return
  34.      */
  35.     public Screen getScreen() {
  36.         if(null == screen) {
  37.             screen = new Screen(game);
  38.             screen.setUseUIAudio(true);
  39.             screen.setUseCursorEffects(true);
  40.         }
  41.         return screen;
  42.     }
  43.  
  44.     /**
  45.      * Which layout to show.
  46.      * @param layout
  47.      * @return true if layout was shown, false on fail
  48.      */
  49.     public boolean show(Class<?extends Layout> layout) {
  50.         // Create layout if not exist
  51.         if(!layouts.containsKey(layout)) {
  52.             try {
  53.                 Layout instance = layout.newInstance();
  54.                 instance.setGuiManager(this);
  55.                 instance.setScreen(screen);
  56.                 layouts.put(layout, instance.getLayout());
  57.             } catch (Exception ex) {
  58.                 Main.LOG.log(Level.SEVERE, null, ex);
  59.                 return false;
  60.             }
  61.         }
  62.         // Hide all layouts and show specified one
  63.         for(Map.Entry<Class<?extends Layout>, Window[]> entry : layouts.entrySet()) {
  64.             if(layout.equals(entry.getKey())) {
  65.                 for(Window window : entry.getValue()) {
  66.                     window.show();
  67.                     //window.setZOrder(1);
  68.                 }
  69.             } else {
  70.                 for(Window window : entry.getValue()) {
  71.                     window.hide();
  72.                 }
  73.             }
  74.         }
  75.         return true;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement