parent
							
								
									3cad5ad202
								
							
						
					
					
						commit
						990c3de5ca
					
				@ -0,0 +1,11 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Horizontal align sides | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public enum AlignX | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						LEFT, CENTER, RIGHT; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,11 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Vertical align sides | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public enum AlignY | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						TOP, CENTER, BOTTOM; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,82 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui.components.layout; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.control.AppAccess; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.AlignX; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.LayoutComponent; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.Component; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.proxy.RectBound; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Holder with same-sized columns, aligned to left or right | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class HorizontalFixedFlowLayout extends LayoutComponent { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private int col = 0; | 
				
			||||||
 | 
						private Num colWidth; | 
				
			||||||
 | 
						private AlignX align; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @param app app access | 
				
			||||||
 | 
						 * @param context context | 
				
			||||||
 | 
						 * @param elementWidth width of all elements | 
				
			||||||
 | 
						 * @param align component align. Legal values are LEFT and RIGHT. | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public HorizontalFixedFlowLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) { | 
				
			||||||
 | 
							super(app, context); | 
				
			||||||
 | 
							this.colWidth = elementWidth; | 
				
			||||||
 | 
							this.align = align; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							if (align != AlignX.LEFT && align != AlignX.RIGHT) { | 
				
			||||||
 | 
								throw new IllegalArgumentException("Can align only left or right."); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * make a new holder.<br> | 
				
			||||||
 | 
						 * Context must be assigned before rendering. | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param app app access | 
				
			||||||
 | 
						 * @param elementWidth width of all elements | 
				
			||||||
 | 
						 * @param align component align. Legal values are LEFT and RIGHT. | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public HorizontalFixedFlowLayout(AppAccess app, Num elementWidth, AlignX align) { | 
				
			||||||
 | 
							this(app, null, elementWidth, align); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Add an item | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param elem | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public void add(final Component elem) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (elem == null) return; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final Rect r; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							switch (align) { | 
				
			||||||
 | 
								case LEFT: | 
				
			||||||
 | 
									r = leftEdge().growRight(colWidth).moveX(colWidth.mul(col++)); | 
				
			||||||
 | 
									break; | 
				
			||||||
 | 
								case RIGHT: | 
				
			||||||
 | 
									r = rightEdge().growLeft(colWidth).moveX(colWidth.mul(-(col++))); | 
				
			||||||
 | 
									break; | 
				
			||||||
 | 
								default: | 
				
			||||||
 | 
									throw new IllegalArgumentException("Bad align."); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							elem.setRect(r); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							attach(elem); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,82 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui.components.layout; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.control.AppAccess; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.AlignY; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.LayoutComponent; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.Component; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.proxy.RectBound; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Holder with same-sized rows, aligned to top or bottom | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class VerticalFixedFlowLayout extends LayoutComponent { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private int row = 0; | 
				
			||||||
 | 
						private Num rowHeight; | 
				
			||||||
 | 
						private AlignY align; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @param app app access | 
				
			||||||
 | 
						 * @param context context | 
				
			||||||
 | 
						 * @param elementHeight height of all elements | 
				
			||||||
 | 
						 * @param align component align. Legal values are TOP and BOTTOM. | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public VerticalFixedFlowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) { | 
				
			||||||
 | 
							super(app, context); | 
				
			||||||
 | 
							this.rowHeight = elementHeight; | 
				
			||||||
 | 
							this.align = align; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							if (align != AlignY.TOP && align != AlignY.BOTTOM) { | 
				
			||||||
 | 
								throw new IllegalArgumentException("Can align only to top or bottom."); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * make a new holder.<br> | 
				
			||||||
 | 
						 * Context must be assigned before rendering. | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param app app access | 
				
			||||||
 | 
						 * @param elementHeight height of all elements | 
				
			||||||
 | 
						 * @param align component align. Legal values are TOP and BOTTOM. | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public VerticalFixedFlowLayout(AppAccess app, Num elementHeight, AlignY align) { | 
				
			||||||
 | 
							this(app, null, elementHeight, align); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Add an item | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param elem | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public void add(final Component elem) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (elem == null) return; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final Rect r; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							switch (align) { | 
				
			||||||
 | 
								case TOP: | 
				
			||||||
 | 
									r = topEdge().growDown(rowHeight).moveY(rowHeight.mul(row++)); | 
				
			||||||
 | 
									break; | 
				
			||||||
 | 
								case BOTTOM: | 
				
			||||||
 | 
									r = bottomEdge().growUp(rowHeight).moveY(rowHeight.mul(-(row++))); | 
				
			||||||
 | 
									break; | 
				
			||||||
 | 
								default: | 
				
			||||||
 | 
									throw new IllegalArgumentException("Bad align."); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							elem.setRect(r); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							attach(elem); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,46 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.screens.main_menu; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.gui.AlignX; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.AlignY; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.layout.VerticalFixedFlowLayout; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.components.painters.TextPainter; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.screens.Screen; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.screens.ScreenLayer; | 
				
			||||||
 | 
					import mightypork.gamecore.render.fonts.GLFont; | 
				
			||||||
 | 
					import mightypork.rogue.Res; | 
				
			||||||
 | 
					import mightypork.utils.math.color.RGB; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MenuLayer extends ScreenLayer { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public MenuLayer(Screen screen) { | 
				
			||||||
 | 
							super(screen); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							init(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void init() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							Rect menuBox = root.shrink(root.height().min(root.width()).mul(0.1));		 | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							Num lineHeight = menuBox.height().min(menuBox.width()).mul(0.13); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							VerticalFixedFlowLayout layout = new VerticalFixedFlowLayout(root, menuBox, lineHeight, AlignY.TOP); | 
				
			||||||
 | 
							root.add(layout); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							GLFont f = Res.getFont("press_start"); | 
				
			||||||
 | 
							layout.add(new TextPainter(f, AlignX.CENTER, RGB.WHITE, "Hello!")); | 
				
			||||||
 | 
							layout.add(new TextPainter(f, AlignX.CENTER, RGB.CYAN, "Woof Woof")); | 
				
			||||||
 | 
							layout.add(new TextPainter(f, AlignX.CENTER, RGB.PURPLE, "MooooOOoOO")); | 
				
			||||||
 | 
							layout.add(new TextPainter(f, AlignX.CENTER, RGB.GREEN, "Bye!")); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public int getPriority() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return 2; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,23 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.screens.main_menu; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.control.AppAccess; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.screens.LayeredScreen; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class ScreenMainMenu extends LayeredScreen { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public ScreenMainMenu(AppAccess app) { | 
				
			||||||
 | 
							super(app); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							addLayer(new MenuLayer(this)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public String getName() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return "rogue.menu"; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue