From 4d98c939a0f51e34fafd6d2b2fdfb3d375fe9463 Mon Sep 17 00:00:00 2001 From: Jonah Bauer Date: Thu, 13 Jan 2022 19:26:26 +0100 Subject: [PATCH] refactoring --- .../wizard/client/libgdx/screens/ConnectScreen.java | 2 +- .../wizard/client/libgdx/screens/CreateGameScreen.java | 8 ++++---- .../wizard/client/libgdx/screens/LobbyScreen.java | 4 ++-- .../wizard/client/libgdx/screens/MenuScreen.java | 10 ++++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java index b85afbe..abbb130 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java @@ -37,7 +37,7 @@ public class ConnectScreen extends MenuScreen { game.storage.uri = uriString; game.getClient().execute(Menu.class, (s, c) -> s.connect(c, uri)); } catch (URISyntaxException e) { - uriField.setStyle(skin.get("error", TextField.TextFieldStyle.class)); + uriField.setStyle(getTextFieldErrorStyle()); } sfxClick(); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java index e5f70c0..f6021ef 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java @@ -139,14 +139,14 @@ public class CreateGameScreen extends MenuScreen { String sessionName = this.sessionName.getText(); if (sessionName.isBlank()) { log.warn("Please choose a session name."); - this.sessionName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); + this.sessionName.setStyle(getTextFieldErrorStyle()); error = true; } String playerName = this.playerName.getText(); if (playerName.isBlank()) { log.warn("Please choose a name."); - this.playerName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); + this.playerName.setStyle(getTextFieldErrorStyle()); error = true; } @@ -155,7 +155,7 @@ public class CreateGameScreen extends MenuScreen { timeout = Long.parseLong(this.timeOut.getText()); } catch (NumberFormatException e) { log.warn("Please choose a valid timeout."); - this.timeOut.setStyle(skin.get("error", TextField.TextFieldStyle.class)); + this.timeOut.setStyle(getTextFieldErrorStyle()); error = true; } @@ -165,7 +165,7 @@ public class CreateGameScreen extends MenuScreen { config = Configuration.values()[selected]; } catch (ArrayIndexOutOfBoundsException e) { log.warn("Please select a valid configuration."); - this.configurations.setStyle(skin.get("error", SelectBox.SelectBoxStyle.class)); + this.configurations.setStyle(getSelectBoxErrorStyle()); error = true; } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java index be6eb70..26ef380 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java @@ -197,13 +197,13 @@ public class LobbyScreen extends MenuScreen { String playerName = this.playerName.getText(); if (playerName.isBlank()) { log.warn("Please choose a player name"); - this.playerName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); + this.playerName.setStyle(getTextFieldErrorStyle()); error = true; } if (selectedSession == null) { log.warn("Please select a session."); - this.sessionListContainer.setStyle(skin.get("error", ScrollPane.ScrollPaneStyle.class)); + this.sessionListContainer.setStyle(getScrollPaneErrorStyle()); error = true; } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java index d8f5037..da0eadb 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java @@ -1,8 +1,7 @@ package eu.jonahbauer.wizard.client.libgdx.screens; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; -import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.Layout; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; @@ -14,6 +13,13 @@ public abstract class MenuScreen extends WizardScreen { @Getter(value = AccessLevel.PROTECTED, lazy = true) private final HorizontalGroup buttonGroup = createButtonGroup(); + @Getter(value = AccessLevel.PROTECTED, lazy = true) + private final TextField.TextFieldStyle textFieldErrorStyle = skin.get("error", TextField.TextFieldStyle.class); + @Getter(value = AccessLevel.PROTECTED, lazy = true) + private final ScrollPane.ScrollPaneStyle scrollPaneErrorStyle = skin.get("error", ScrollPane.ScrollPaneStyle.class); + @Getter(value = AccessLevel.PROTECTED, lazy = true) + private final SelectBox.SelectBoxStyle selectBoxErrorStyle = skin.get("error", SelectBox.SelectBoxStyle.class); + public MenuScreen(WizardGame game) { super(game); }