167 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			167 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package electrosphere.renderer.ui;
 | |
| 
 | |
| import electrosphere.controls.ControlHandler;
 | |
| import electrosphere.engine.Globals;
 | |
| import electrosphere.renderer.ui.elements.Button;
 | |
| import electrosphere.renderer.ui.elements.Label;
 | |
| import electrosphere.renderer.ui.elements.Window;
 | |
| import electrosphere.renderer.ui.elementtypes.ClickableElement;
 | |
| import electrosphere.renderer.ui.elementtypes.DrawableElement;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author amaterasu
 | |
|  */
 | |
| public class WidgetUtils {
 | |
|     
 | |
|     
 | |
|     // public static TextBox createTextBox(int positionX, int positionY, int width, int height, int cols, int rows, String text, boolean render){
 | |
|     //     TextBox rVal = new TextBox(-width/2, positionY, width, height, rows, cols, text, render, false);
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
|     // public static TextBox createVerticallyAlignedTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
 | |
|     //     TextBox rVal = new TextBox(-width/2, windowTop, width, height, rows, cols, text, render, false);
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
|     // public static TextBox createVerticallyAlignedMinSizeTextBox(int charWidth, int charHeight, int windowTop, int cols, int rows, String text, boolean render){
 | |
|     //     TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
|     // public static TextBox createVerticallyAlignedMinSizeTextBoxFromCharCount(int charWidth, int charHeight, int windowTop, String text, boolean render){
 | |
|     //     int cols = text.length();
 | |
|     //     int rows = 1;
 | |
|     //     TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
 | |
|     //     rVal.setVisible(true);
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
|     
 | |
|     
 | |
|     
 | |
|     // public static TextBox createVerticallyAlignedEditableTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
 | |
|     //     TextBox rVal = new TextBox(-(int)(width/2.5), windowTop, width, height, rows, cols, text, render, true);
 | |
|     //     rVal.setVisible(true);
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
|     // public static LayoutSchemeListScrollable createListTEST(){
 | |
|     //     LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(200, 200, 500, 500, true);
 | |
|     //     rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
 | |
|     //     rVal.addWidget(WidgetUtils.createTextBox(100, 100, 500, 500, 3, 10, "TEST", true));
 | |
|     //     // Globals.widgetManager.registerWidget(rVal);
 | |
|     //     return rVal;
 | |
|     // }
 | |
|     
 | |
| //     public static DrawableElement createWindowTEST(){
 | |
| //         Window rVal = new Window(0, 0, 1920, 1080);
 | |
| // //        //panel 1
 | |
| // //        ImagePanel imagePanel = new ImagePanel();
 | |
| // //        imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
 | |
| // //        imagePanel.setPositionX(100);
 | |
| // //        imagePanel.setPositionY(100);
 | |
| // //        imagePanel.setVisible(true);
 | |
| // //        rVal.addWidget(imagePanel);
 | |
| // //        //panel 2
 | |
| // //        imagePanel = new ImagePanel();
 | |
| // //        imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
 | |
| // //        imagePanel.setVisible(true);
 | |
| // //        rVal.addWidget(imagePanel);
 | |
| // //        rVal.setVisible(true);
 | |
| // //        //window top
 | |
| // //        imagePanel = new ImagePanel();
 | |
| // //        imagePanel.setTexture(Globals.assetManager.fetchTexture("Textures/ui/WindowBorder.png"));
 | |
| // //        imagePanel.setWidth(100);
 | |
| // //        imagePanel.setHeight(50);
 | |
| // //        imagePanel.setPositionX(200);
 | |
| // //        imagePanel.setPositionY(50);
 | |
| // //        imagePanel.setVisible(true);
 | |
| // //        rVal.addWidget(imagePanel);
 | |
| // //        TextInput textInput = new TextInput();
 | |
| // //        textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
 | |
| // //        textInput.setPositionX(0);
 | |
| // //        textInput.setPositionY(0);
 | |
| // //        textInput.setWidth(500);
 | |
| // //        textInput.setHeight(500);
 | |
| // //        textInput.setFontWidth(10);
 | |
| // //        textInput.setFontHeight(27);
 | |
| // //        textInput.setVisible(true);
 | |
| // //        rVal.addWidget(textInput);
 | |
|         
 | |
|         
 | |
| // //        BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A');
 | |
| // //        rVal.addWidget(characterDisp);
 | |
|         
 | |
| //         Label label = new Label(100,100,1);
 | |
| //         label.setText("TESTING");
 | |
| //         rVal.addChild(label);
 | |
|         
 | |
| // //        TextInput textInput2 = new TextInput();
 | |
| // //        textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
 | |
| // //        textInput2.setPositionX(500);
 | |
| // //        textInput2.setPositionY(0);
 | |
| // //        textInput2.setWidth(500);
 | |
| // //        textInput2.setHeight(500);
 | |
| // //        textInput2.setFontWidth(20);
 | |
| // //        textInput2.setFontHeight(40);
 | |
| // //        textInput2.setVisible(true);
 | |
| // //        rVal.addWidget(textInput2);
 | |
|         
 | |
| //         rVal.setVisible(true);
 | |
| //         // Globals.widgetManager.registerWidget(rVal);
 | |
| //         return rVal;
 | |
| //     }
 | |
|     
 | |
|     public static DrawableElement createInGameMainMenuButton(){
 | |
|         int width = (int)(Globals.WINDOW_WIDTH * 0.05);
 | |
|         int height = (int)(Globals.WINDOW_HEIGHT * 0.05);
 | |
|         int x = Globals.WINDOW_WIDTH - width;
 | |
|         int y = Globals.WINDOW_HEIGHT - height;
 | |
| //        Window rVal = new Window(x, 10, 100, 20);
 | |
|         Window rVal = new Window(x,y,width,height,true);
 | |
| //        Window rVal = new Window(100,100,100,100);
 | |
| //        System.out.println(x + " " + y + " " + width + " " + height);
 | |
| //        LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(x, y, width, height, true);
 | |
| ////        rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
 | |
| //        rVal.addWidget(WidgetUtils.createTextBox(0, 0, width, height, 1, 4, "MENU", true));
 | |
| //        Widget rVal = WidgetUtils.createTextBox(x, y, width, height, 4, 1, "MENU", true);
 | |
| 
 | |
|         //the actual "menu" label
 | |
|         Label menuLabel = new Label(0.3f);
 | |
|         menuLabel.setText("Menu");
 | |
|         menuLabel.setVisible(true);
 | |
|         rVal.addChild(menuLabel);
 | |
|         
 | |
|         //label telling player what key they have their menu bound to
 | |
|         Label keyCodeLabel = new Label(0.3f);
 | |
|         keyCodeLabel.setText(ControlHandler.convertKeycodeToName(Globals.controlHandler.getControl(ControlHandler.DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue()));
 | |
|         keyCodeLabel.setVisible(true);
 | |
|         rVal.addChild(keyCodeLabel);
 | |
|         
 | |
|         rVal.setVisible(false);
 | |
| //        Globals.inGameUI.add(rVal);
 | |
|         // Globals.widgetManager.registerWidget(rVal);
 | |
|         return rVal;
 | |
|     }
 | |
| 
 | |
|     public static Button createLabelButton(String label, int posX, int posY, float fontSize, ClickableElement.ClickEventCallback callback){
 | |
|         Button rVal = new Button();
 | |
|         Label buttonLabel = new Label(fontSize);
 | |
|         rVal.setPositionX(posX);
 | |
|         rVal.setPositionY(posY);
 | |
|         buttonLabel.setText(label);
 | |
|         rVal.addChild(buttonLabel);
 | |
|         rVal.setOnClick(callback);
 | |
|         return rVal;
 | |
|     }
 | |
|     
 | |
|     
 | |
| }
 |