mirror of
				https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
				synced 2025-10-31 21:59:03 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			407 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Groovy
		
	
	
	
	
	
			
		
		
	
	
			407 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Groovy
		
	
	
	
	
	
| // Styling of Lemur components
 | |
| // For documentation, see:
 | |
| // https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
 | |
| 
 | |
| import com.jme3.math.ColorRGBA
 | |
| import com.jme3.texture.Texture
 | |
| import com.simsilica.lemur.*
 | |
| import com.simsilica.lemur.component.QuadBackgroundComponent
 | |
| import com.simsilica.lemur.Button
 | |
| import com.simsilica.lemur.Button.ButtonAction
 | |
| import com.simsilica.lemur.Command
 | |
| import com.simsilica.lemur.HAlignment
 | |
| import com.simsilica.lemur.Insets3f
 | |
| import com.simsilica.lemur.component.QuadBackgroundComponent
 | |
| import com.simsilica.lemur.component.TbtQuadBackgroundComponent
 | |
| import pp.monopoly.client.MonopolyApp
 | |
| import pp.monopoly.game.server.Player
 | |
| 
 | |
| def bgColor = color(1, 1, 1, 1)
 | |
| def buttonEnabledColor = color(0, 0, 0, 1)
 | |
| def buttonDisabledColor = color(0.8, 0.9, 1, 0.2)
 | |
| def buttonBgColor = color(1, 1, 1, 1)
 | |
| def sliderColor = color(0.6, 0.8, 0.8, 1)
 | |
| def sliderBgColor = color(0.5, 0.75, 0.75, 1)
 | |
| def gradientColor = color(0.5, 0.75, 0.85, 0.5)
 | |
| def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1)
 | |
| def solidWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 1))
 | |
| def greyBackground = new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
 | |
| def lightGreyBackground = new QuadBackgroundComponent(new ColorRGBA(0.4f, 0.4f, 0.4f, 1.0f));
 | |
| def lightGrey = color(0.6, 0.6, 0.6, 1.0)
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| def gradient = TbtQuadBackgroundComponent.create(
 | |
|         texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png",
 | |
|                 generateMips: false),
 | |
|         1, 1, 1, 126, 126,
 | |
|         1f, false)
 | |
| 
 | |
| def doubleGradient = new QuadBackgroundComponent(gradientColor)
 | |
| doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
 | |
|         generateMips: false)
 | |
| //doubleGradient.color = color(0, 0, 0, 1)
 | |
| 
 | |
| def orangeBorder = TbtQuadBackgroundComponent.create(
 | |
|         texture(name: "/com/simsilica/lemur/icons/border.png", // Replace with an appropriate texture if needed
 | |
|                 generateMips: false),
 | |
|         1, 1, 1, 126, 126,
 | |
|         1f, false)
 | |
| orangeBorder.color = color(1, 0.5, 0, 1) // Orange color
 | |
| 
 | |
| 
 | |
| def createCustomBackground(app) {
 | |
|     // Load the texture from the assets
 | |
|     Texture texture = app.getAssetManager().loadTexture("Pictures/kontobg.png")
 | |
| 
 | |
|     // Create the TbtQuadBackgroundComponent
 | |
|     def backgroundCustom = TbtQuadBackgroundComponent.create(
 | |
|             texture,          // The texture to use
 | |
|             1, 1, 1,          // Insets for the 9-patch behavior
 | |
|             126, 126,         // The size of the texture
 | |
|             1f,               // The scale factor
 | |
|             false             // No tiling
 | |
|     )
 | |
| 
 | |
|     return backgroundCustom
 | |
| }
 | |
| 
 | |
| selector("pp") {
 | |
|     font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt")
 | |
| }
 | |
| 
 | |
| selector("label", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     color = buttonEnabledColor
 | |
| }
 | |
| 
 | |
| selector("label-Bold", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     font = font("Interface/Fonts/Metropolis/Metropolis-Bold-32.fnt")
 | |
|     fontSize = 30
 | |
|     color = buttonEnabledColor
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| 
 | |
| }
 | |
| 
 | |
| selector("label-toolbar", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     font = font("Interface/Fonts/Metropolis/Metropolis-Bold-32.fnt")
 | |
|     fontSize = 25
 | |
|     color = new ColorRGBA(ColorRGBA.White)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| 
 | |
| }
 | |
| selector("label-Text", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     fontSize = 25
 | |
|     color = buttonEnabledColor
 | |
| }
 | |
| 
 | |
| selector("label-account", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     fontSize = 25
 | |
|     color = new ColorRGBA(ColorRGBA.White)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| }
 | |
| 
 | |
| selector("card-label", "pp") {
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     color = ColorRGBA.Black
 | |
| }
 | |
| 
 | |
| selector("header", "pp") {
 | |
|     font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     color = color(1, 0.5, 0, 1)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| }
 | |
| 
 | |
| selector("container", "pp") {
 | |
|     background = solidWhiteBackground.clone()
 | |
|     background.setColor(bgColor)
 | |
| }
 | |
| 
 | |
| selector("toolbar") {
 | |
|     background = gradient.clone()
 | |
|     background.setColor(bgColor)
 | |
|     //color = (new ColorRGBA(0.4157f, 0.4235f, 0.4392f, 1.0f))
 | |
| 
 | |
| }
 | |
| selector("slider", "pp") {
 | |
|     background = gradient.clone()
 | |
|     background.setColor(bgColor)
 | |
| }
 | |
| 
 | |
| def pressedCommand = new Command<Button>() {
 | |
|     void execute(Button source) {
 | |
|         if (source.isPressed())
 | |
|             source.move(1, -1, 0)
 | |
|         else
 | |
|             source.move(-1, 1, 0)
 | |
|     }
 | |
| }
 | |
| 
 | |
| def enabledCommand = new Command<Button>() {
 | |
|     void execute(Button source) {
 | |
|         if (source.isEnabled())
 | |
|             source.setColor(buttonEnabledColor)
 | |
|         else
 | |
|             source.setColor(buttonDisabledColor)
 | |
|     }
 | |
| }
 | |
| 
 | |
| def repeatCommand = new Command<Button>() {
 | |
|     private long startTime
 | |
|     private long lastClick
 | |
| 
 | |
|     void execute(Button source) {
 | |
|         // Only do the repeating click while the mouse is
 | |
|         // over the button (and pressed of course)
 | |
|         if (source.isPressed() && source.isHighlightOn()) {
 | |
|             long elapsedTime = System.currentTimeMillis() - startTime
 | |
|             // After half a second pause, click 8 times a second
 | |
|             if (elapsedTime > 500 && elapsedTime > lastClick + 125) {
 | |
|                 source.click()
 | |
| 
 | |
|                 // Try to quantize the last click time to prevent drift
 | |
|                 lastClick = ((elapsedTime - 500) / 125) * 125 + 500
 | |
|             }
 | |
|         }
 | |
|         else {
 | |
|             startTime = System.currentTimeMillis()
 | |
|             lastClick = 0
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| def stdButtonCommands = [
 | |
|         (ButtonAction.Down)    : [pressedCommand],
 | |
|         (ButtonAction.Up)      : [pressedCommand],
 | |
|         (ButtonAction.Enabled) : [enabledCommand],
 | |
|         (ButtonAction.Disabled): [enabledCommand]
 | |
| ]
 | |
| 
 | |
| def sliderButtonCommands = [
 | |
|         (ButtonAction.Hover): [repeatCommand]
 | |
| ]
 | |
| 
 | |
| selector("title", "pp") {
 | |
|     color = color(0.8, 0.9, 1, 0.85f)
 | |
|     highlightColor = color(1, 0.8, 1, 0.85f)
 | |
|     shadowColor = color(0, 0, 0, 0.75f)
 | |
|     shadowOffset = vec3(2, -2, -1)
 | |
|     background = new QuadBackgroundComponent(color(0.5, 0.75, 0.85, 1))
 | |
|     background.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
 | |
|             generateMips: false)
 | |
|     insets = new Insets3f(2, 2, 2, 2)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| 
 | |
|     buttonCommands = stdButtonCommands
 | |
| }
 | |
| 
 | |
| 
 | |
| selector("button", "pp") {
 | |
|     def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Orange border
 | |
|     def innerBackground = new QuadBackgroundComponent(buttonBgColor) // Inner button background
 | |
| 
 | |
|     // Apply the outer border as the main background
 | |
|     background = outerBackground
 | |
| 
 | |
|     // Use insets to create a margin/padding effect for the inner background
 | |
|     insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
|     buttonCommands = stdButtonCommands
 | |
| }
 | |
| 
 | |
| selector("slider", "pp") {
 | |
|     insets = new Insets3f(1, 3, 1, 2)
 | |
| }
 | |
| 
 | |
| selector("slider", "button", "pp") {
 | |
|     background = doubleGradient.clone()
 | |
|     //background.setColor(sliderBgColor)
 | |
|     insets = new Insets3f(0, 0, 0, 0)
 | |
| }
 | |
| 
 | |
| selector("slider.thumb.button", "pp") {
 | |
|     text = "[]"
 | |
|     color = sliderColor
 | |
| }
 | |
| 
 | |
| selector("slider.left.button", "pp") {
 | |
|     text = "-"
 | |
|     background = doubleGradient.clone()
 | |
|     //background.setColor(sliderBgColor)
 | |
|     background.setMargin(5, 0)
 | |
|     color = sliderColor
 | |
| 
 | |
|     buttonCommands = sliderButtonCommands
 | |
| }
 | |
| 
 | |
| selector("slider.right.button", "pp") {
 | |
|     text = "+"
 | |
|     background = doubleGradient.clone()
 | |
|     //background.setColor(sliderBgColor)
 | |
|     background.setMargin(4, 0)
 | |
|     color = sliderColor
 | |
| 
 | |
|     buttonCommands = sliderButtonCommands
 | |
| }
 | |
| 
 | |
| selector("slider.up.button", "pp") {
 | |
|     buttonCommands = sliderButtonCommands
 | |
| }
 | |
| 
 | |
| selector("slider.down.button", "pp") {
 | |
|     buttonCommands = sliderButtonCommands
 | |
| }
 | |
| 
 | |
| selector("checkbox", "pp") {
 | |
|     color = buttonEnabledColor
 | |
|     fontSize = 20
 | |
| }
 | |
| 
 | |
| selector("rollup", "pp") {
 | |
|     background = gradient.clone()
 | |
|     background.setColor(bgColor)
 | |
| }
 | |
| 
 | |
| selector("tabbedPanel", "pp") {
 | |
|     activationColor = buttonEnabledColor
 | |
| }
 | |
| 
 | |
| selector("tabbedPanel.container", "pp") {
 | |
|     background = null
 | |
| }
 | |
| 
 | |
| selector("tab.button", "pp") {
 | |
|     background = solidWhiteBackground.clone()
 | |
|     background.setColor(bgColor)
 | |
|     color = tabbuttonEnabledColor
 | |
|     insets = new Insets3f(4, 2, 0, 2)
 | |
| 
 | |
|     buttonCommands = stdButtonCommands
 | |
| }
 | |
| selector("settings-title", "pp") {
 | |
|     def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Grey inner border
 | |
|     def innerBackground = new QuadBackgroundComponent(buttonBgColor) // White outer border background
 | |
| 
 | |
|     background = outerBackground
 | |
|     fontSize = 40
 | |
|     insets = new Insets3f(3, 3, 3, 3)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
|  }
 | |
| selector("warning-title", "pp") {
 | |
|     def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Grey inner border
 | |
|     def innerBackground = new QuadBackgroundComponent(buttonBgColor) // White outer border background
 | |
|     font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
 | |
|     background = outerBackground
 | |
|     fontSize = 40
 | |
|     insets = new Insets3f(3, 3, 3, 3)
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
| }
 | |
| 
 | |
| selector("menu-button", "pp") {
 | |
|     fontSize = 40 // Set font size
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
|     buttonCommands = stdButtonCommands
 | |
| }
 | |
| 
 | |
| // Style for Selector text
 | |
| selector("selector.item.label") {
 | |
|     color = color(0, 0, 0, 1)  // Black text
 | |
|     fontSize = 16  // Optional: Adjust the text size if needed
 | |
|     textHAlignment = HAlignment.Left  // Optional: Align text to the left
 | |
|     insets = new Insets3f(2, 2, 2, 2)  // Optional: Add padding around text
 | |
| }
 | |
| // Style the popup container background
 | |
| selector("selector.popup") {
 | |
|     background = new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.8f))  // Translucent white background
 | |
|     insets = new Insets3f(5, 5, 5, 5)  // Padding inside the popup container
 | |
| }
 | |
| 
 | |
| // Style the text of dropdown options
 | |
| selector("selector.item.label") {
 | |
|     color = color(0, 0, 0, 1)  // Black text
 | |
|     fontSize = 16  // Optional: Adjust font size
 | |
|     textHAlignment = HAlignment.Left  // Align text to the left
 | |
|     insets = new Insets3f(2, 5, 2, 5)  // Add padding for each option
 | |
| }
 | |
| 
 | |
| // Style the hover state of dropdown options
 | |
| selector("selector.item.label", "hover") {
 | |
|     color = color(1, 1, 1, 1)  // White text when hovered
 | |
|     background = new QuadBackgroundComponent(new ColorRGBA(0.2f, 0.6f, 1.0f, 0.9f))  // Highlighted background
 | |
| }
 | |
| 
 | |
| def enabledCommandToolbar = new Command<Button>() {
 | |
|     MonopolyApp app // Pass the app instance to access player details
 | |
| 
 | |
|     void execute(Button source) {
 | |
|         // Get the current player's color
 | |
|         Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
 | |
|         ColorRGBA playerColor = Player.getColor(currentPlayer.getId()).getColor();
 | |
| 
 | |
|         if (source.isEnabled()) {
 | |
|             source.setColor(ColorRGBA.White);
 | |
|             def playerBackground = new QuadBackgroundComponent(playerColor); // Use player's color
 | |
|             source.setBackground(playerBackground);
 | |
|         } else {
 | |
|             source.setColor(ColorRGBA.White);
 | |
|             def grayBackground = new QuadBackgroundComponent(ColorRGBA.Gray); // Use gray when disabled
 | |
|             source.setBackground(grayBackground);
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| def stdButtonCommandsToolbar = [
 | |
|         (ButtonAction.Down)    : [pressedCommand],
 | |
|         (ButtonAction.Up)      : [pressedCommand],
 | |
|         (ButtonAction.Enabled) : [enabledCommandToolbar],
 | |
|         (ButtonAction.Disabled): [enabledCommandToolbar]
 | |
| ]
 | |
| 
 | |
| selector("button-toolbar", "pp") {
 | |
|     def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Orange border
 | |
|     def innerBackground = new QuadBackgroundComponent(buttonBgColor) // Inner button background
 | |
| 
 | |
|     // Apply the outer border as the main background
 | |
|     background = outerBackground
 | |
| 
 | |
|     // Use insets to create a margin/padding effect for the inner background
 | |
|     insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
 | |
|     textHAlignment = HAlignment.Center
 | |
|     textVAlignment = VAlignment.Center
 | |
|     buttonCommands = stdButtonCommandsToolbar
 | |
| }
 | |
| 
 | |
| 
 | |
| selector("button-toolbar2", "pp") { playerColor ->
 | |
|     def validColor = playerColor ?: new ColorRGBA(0, 0, 0, 0) // Vollständig transparent
 | |
|     def playerGradientBackground = new QuadBackgroundComponent(validColor)
 | |
| 
 | |
|     // Kein Hintergrundbild, komplett transparent
 | |
|     playerGradientBackground.setColor(new ColorRGBA(0, 0, 0, 0)) // RGBA (Rot, Grün, Blau, Alpha)
 | |
| 
 | |
|     background = playerGradientBackground.clone() // Setze den Hintergrund
 | |
|     insets = new Insets3f(3, 3, 3, 3) // Optional: Ränder
 | |
|     textHAlignment = HAlignment.Center // Text-Zentrierung
 | |
|     textVAlignment = VAlignment.Center // Text-Zentrierung
 | |
|     
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 |