From bbaaa91575043ab465cd22897adcd0717d629c66 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 12 Sep 2019 09:06:25 -0400 Subject: [PATCH] Fixed black styles on game reload (Android) --- .../AssetsAnnotationProcessor.java | 4 +- core/src/io/anuke/mindustry/core/UI.java | 2 + core/src/io/anuke/mindustry/ui/Styles.java | 542 +++++++++--------- 3 files changed, 278 insertions(+), 270 deletions(-) diff --git a/annotations/src/main/java/io/anuke/annotations/AssetsAnnotationProcessor.java b/annotations/src/main/java/io/anuke/annotations/AssetsAnnotationProcessor.java index e61c769f2c..9dc159405d 100644 --- a/annotations/src/main/java/io/anuke/annotations/AssetsAnnotationProcessor.java +++ b/annotations/src/main/java/io/anuke/annotations/AssetsAnnotationProcessor.java @@ -55,6 +55,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{ TypeSpec.Builder type = TypeSpec.classBuilder("Tex").addModifiers(Modifier.PUBLIC); TypeSpec.Builder ictype = TypeSpec.classBuilder("Icon").addModifiers(Modifier.PUBLIC); MethodSpec.Builder load = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC); + MethodSpec.Builder loadStyles = MethodSpec.methodBuilder("loadStyles").addModifiers(Modifier.PUBLIC, Modifier.STATIC); MethodSpec.Builder icload = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC); String resources = path + "/assets-raw/sprites/ui"; Files.walk(Paths.get(resources)).forEach(p -> { @@ -98,7 +99,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{ t.getEnclosedElements().stream().filter(e -> e.getKind() == ElementKind.FIELD).forEach(field -> { String fname = field.getSimpleName().toString(); if(fname.startsWith("default")){ - load.addStatement("io.anuke.arc.Core.scene.addStyle(" + field.asType().toString() + ".class, io.anuke.mindustry.ui.Styles." + fname + ")"); + loadStyles.addStatement("io.anuke.arc.Core.scene.addStyle(" + field.asType().toString() + ".class, io.anuke.mindustry.ui.Styles." + fname + ")"); } }); } @@ -107,6 +108,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{ JavaFile.builder(packageName, ictype.build()).build().writeTo(Utils.filer); type.addMethod(load.build()); + type.addMethod(loadStyles.build()); JavaFile.builder(packageName, type.build()).build().writeTo(Utils.filer); } diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index cc30b3cbe9..13b2eaa25e 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -91,6 +91,8 @@ public class UI implements ApplicationListener, Loadable{ Tex.load(); Icon.load(); + Styles.load(); + Tex.loadStyles(); Dialog.setShowAction(() -> sequence(alpha(0f), fadeIn(0.1f))); Dialog.setHideAction(() -> sequence(fadeOut(0.1f))); diff --git a/core/src/io/anuke/mindustry/ui/Styles.java b/core/src/io/anuke/mindustry/ui/Styles.java index 47731d0fe9..cd9af651ad 100644 --- a/core/src/io/anuke/mindustry/ui/Styles.java +++ b/core/src/io/anuke/mindustry/ui/Styles.java @@ -23,281 +23,285 @@ import static io.anuke.mindustry.gen.Tex.*; @StyleDefaults public class Styles{ - public static Drawable - black = whiteui.tint(0f, 0f, 0f, 1f), - black9 = whiteui.tint(0f, 0f, 0f, 0.9f), - black8 = whiteui.tint(0f, 0f, 0f, 0.8f), - black6 = whiteui.tint(0f, 0f, 0f, 0.6f), - black3 = whiteui.tint(0f, 0f, 0f, 0.3f), - none = whiteui.tint(0f, 0f, 0f, 0f), - flatDown = createFlatDown(), - flatOver = whiteui.tint(Color.valueOf("454545")); + public static Drawable black, black9, black8, black6, black3, none, flatDown, flatOver; + public static ButtonStyle defaultb, waveb; + public static TextButtonStyle defaultt, squaret, nodet, cleart, discordt, infot, clearPartialt, clearTogglet, clearToggleMenut, togglet; + public static ImageButtonStyle defaulti, nodei, righti, emptyi, emptytogglei, selecti, cleari, clearFulli, clearPartiali, clearPartial2i, clearTogglei, clearTransi, clearToggleTransi, clearTogglePartiali; + public static ScrollPaneStyle defaultPane, horizontalPane; + public static KeybindDialogStyle defaultKeybindDialog; + public static SliderStyle defaultSlider, vSlider; + public static LabelStyle defaultLabel, outlineLabel; + public static TextFieldStyle defaultField, areaField; + public static CheckBoxStyle defaultCheck; + public static DialogStyle defaultDialog, fullDialog; - public static ButtonStyle - defaultb = new ButtonStyle(){{ - down = buttonDown; - up = button; - over = buttonOver; - disabled = buttonDisabled; - }}, - waveb = new ButtonStyle(){{ - up = buttonEdge4; - over = buttonEdgeOver4; - disabled = buttonEdge4; - }}; + public static void load(){ + black = whiteui.tint(0f, 0f, 0f, 1f); + black9 = whiteui.tint(0f, 0f, 0f, 0.9f); + black8 = whiteui.tint(0f, 0f, 0f, 0.8f); + black6 = whiteui.tint(0f, 0f, 0f, 0.6f); + black3 = whiteui.tint(0f, 0f, 0f, 0.3f); + none = whiteui.tint(0f, 0f, 0f, 0f); + flatDown = createFlatDown(); + flatOver = whiteui.tint(Color.valueOf("454545")); - public static TextButtonStyle - defaultt = new TextButtonStyle(){{ - over = buttonOver; - disabled = buttonDisabled; - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - down = buttonDown; - up = button; - }}, - squaret = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - over = buttonSquareOver; - disabled = buttonDisabled; - down = buttonSquareDown; - up = buttonSquare; - }}, - nodet = new TextButtonStyle(){{ - disabled = button; - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - up = buttonOver; - over = buttonDown; - }}, - cleart = new TextButtonStyle(){{ - over = flatOver; - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - down = flatOver; - up = black; - }}, - discordt = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - up = discordBanner; - }}, - infot = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - up = infoBanner; - }}, - clearPartialt = new TextButtonStyle(){{ - down = whiteui; - up = pane; - over = flatDown; - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - }}, - clearTogglet = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - checked = flatDown; - down = flatDown; - up = black; - over = flatOver; - disabled = black; - disabledFontColor = Color.gray; - }}, - clearToggleMenut = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - checked = flatDown; - down = flatDown; - up = clear; - over = flatOver; - disabled = black; - disabledFontColor = Color.gray; - }}, - togglet = new TextButtonStyle(){{ - font = Fonts.def; - fontColor = Color.white; - checked = buttonDown; - down = buttonDown; - up = button; - over = buttonOver; - disabled = buttonDisabled; - disabledFontColor = Color.gray; - }}; + defaultb = new ButtonStyle(){{ + down = buttonDown; + up = button; + over = buttonOver; + disabled = buttonDisabled; + }}; + + waveb = new ButtonStyle(){{ + up = buttonEdge4; + over = buttonEdgeOver4; + disabled = buttonEdge4; + }}; - public static ImageButtonStyle - defaulti = new ImageButtonStyle(){{ - down = buttonDown; - up = button; - over = buttonOver; - imageDisabledColor = Color.gray; - imageUpColor = Color.white; - disabled = buttonDisabled; - }}, - nodei = new ImageButtonStyle(){{ - up = buttonOver; - over = buttonDown; - }}, - righti = new ImageButtonStyle(){{ - over = buttonRightOver; - down = buttonRightDown; - up = buttonRight; - }}, - emptyi = new ImageButtonStyle(){{ - imageDownColor = Pal.accent; - imageUpColor = Color.white; - }}, - emptytogglei = new ImageButtonStyle(){{ - imageCheckedColor = Color.white; - imageDownColor = Color.white; - imageUpColor = Color.gray; - }}, - selecti = new ImageButtonStyle(){{ - checked = buttonSelect; - up = none; - }}, - cleari = new ImageButtonStyle(){{ - down = flatOver; - up = black; - over = flatOver; - }}, - clearFulli = new ImageButtonStyle(){{ - down = whiteui; - up = pane; - over = flatDown; - }}, - clearPartiali = new ImageButtonStyle(){{ - down = flatDown; - up = none; - over = flatOver; - }}, - clearPartial2i = new ImageButtonStyle(){{ - down = whiteui; - up = pane; - over = flatDown; - }}, - clearTogglei = new ImageButtonStyle(){{ - down = flatDown; - checked = flatDown; - up = black; - over = flatOver; - }}, - clearTransi = new ImageButtonStyle(){{ - down = flatDown; - up = black6; - over = flatOver; - }}, - clearToggleTransi = new ImageButtonStyle(){{ - down = flatDown; - checked = flatDown; - up = black6; - over = flatOver; - }}, - clearTogglePartiali = new ImageButtonStyle(){{ - down = flatDown; - checked = flatDown; - up = none; - over = flatOver; - }}; + defaultt = new TextButtonStyle(){{ + over = buttonOver; + disabled = buttonDisabled; + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + down = buttonDown; + up = button; + }}; + squaret = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + over = buttonSquareOver; + disabled = buttonDisabled; + down = buttonSquareDown; + up = buttonSquare; + }}; + nodet = new TextButtonStyle(){{ + disabled = button; + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + up = buttonOver; + over = buttonDown; + }}; + cleart = new TextButtonStyle(){{ + over = flatOver; + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + down = flatOver; + up = black; + }}; + discordt = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + up = discordBanner; + }}; + infot = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + up = infoBanner; + }}; + clearPartialt = new TextButtonStyle(){{ + down = whiteui; + up = pane; + over = flatDown; + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + }}; + clearTogglet = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + checked = flatDown; + down = flatDown; + up = black; + over = flatOver; + disabled = black; + disabledFontColor = Color.gray; + }}; + clearToggleMenut = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + checked = flatDown; + down = flatDown; + up = clear; + over = flatOver; + disabled = black; + disabledFontColor = Color.gray; + }}; + togglet = new TextButtonStyle(){{ + font = Fonts.def; + fontColor = Color.white; + checked = buttonDown; + down = buttonDown; + up = button; + over = buttonOver; + disabled = buttonDisabled; + disabledFontColor = Color.gray; + }}; - public static ScrollPaneStyle - defaultPane = new ScrollPaneStyle(){{ - vScroll = scroll; - vScrollKnob = scrollKnobVerticalBlack; - }}, - horizontalPane = new ScrollPaneStyle(){{ - vScroll = scroll; - vScrollKnob = scrollKnobVerticalBlack; - hScroll = scrollHorizontal; - hScrollKnob = scrollKnobHorizontalBlack; - }}; - - public static KeybindDialogStyle - defaultKeybindDialog = new KeybindDialogStyle(){{ - keyColor = Pal.accent; - keyNameColor = Color.white; - controllerColor = Color.lightGray; - }}; - - public static SliderStyle - defaultSlider = new SliderStyle(){{ - background = slider; - knob = sliderKnob; - knobOver = sliderKnobOver; - knobDown = sliderKnobDown; - }}, - vSlider = new SliderStyle(){{ - background = sliderVertical; - knob = sliderKnob; - knobOver = sliderKnobOver; - knobDown = sliderKnobDown; - }}; - - public static LabelStyle - defaultLabel = new LabelStyle(){{ - font = Fonts.def; - fontColor = Color.white; - }}, - outlineLabel = new LabelStyle(){{ - font = Fonts.outline; - fontColor = Color.white; - }}; - - public static TextFieldStyle - defaultField = new TextFieldStyle(){{ - font = Fonts.chat; - fontColor = Color.white; - disabledFontColor = Color.gray; - disabledBackground = underlineDisabled; - selection = Tex.selection; - background = underline; - invalidBackground = underlineRed; - cursor = Tex.cursor; - messageFont = Fonts.def; - messageFontColor = Color.gray; - }}, - areaField = new TextFieldStyle(){{ - font = Fonts.chat; - fontColor = Color.white; - disabledFontColor = Color.gray; - selection = Tex.selection; - background = underline; - cursor = Tex.cursor; - messageFont = Fonts.def; - messageFontColor = Color.gray; - }}; + defaulti = new ImageButtonStyle(){{ + down = buttonDown; + up = button; + over = buttonOver; + imageDisabledColor = Color.gray; + imageUpColor = Color.white; + disabled = buttonDisabled; + }}; + nodei = new ImageButtonStyle(){{ + up = buttonOver; + over = buttonDown; + }}; + righti = new ImageButtonStyle(){{ + over = buttonRightOver; + down = buttonRightDown; + up = buttonRight; + }}; + emptyi = new ImageButtonStyle(){{ + imageDownColor = Pal.accent; + imageUpColor = Color.white; + }}; + emptytogglei = new ImageButtonStyle(){{ + imageCheckedColor = Color.white; + imageDownColor = Color.white; + imageUpColor = Color.gray; + }}; + selecti = new ImageButtonStyle(){{ + checked = buttonSelect; + up = none; + }}; + cleari = new ImageButtonStyle(){{ + down = flatOver; + up = black; + over = flatOver; + }}; + clearFulli = new ImageButtonStyle(){{ + down = whiteui; + up = pane; + over = flatDown; + }}; + clearPartiali = new ImageButtonStyle(){{ + down = flatDown; + up = none; + over = flatOver; + }}; + clearPartial2i = new ImageButtonStyle(){{ + down = whiteui; + up = pane; + over = flatDown; + }}; + clearTogglei = new ImageButtonStyle(){{ + down = flatDown; + checked = flatDown; + up = black; + over = flatOver; + }}; + clearTransi = new ImageButtonStyle(){{ + down = flatDown; + up = black6; + over = flatOver; + }}; + clearToggleTransi = new ImageButtonStyle(){{ + down = flatDown; + checked = flatDown; + up = black6; + over = flatOver; + }}; + clearTogglePartiali = new ImageButtonStyle(){{ + down = flatDown; + checked = flatDown; + up = none; + over = flatOver; + }}; - public static CheckBoxStyle - defaultCheck = new CheckBoxStyle(){{ - checkboxOn = checkOn; - checkboxOff = checkOff; - checkboxOnOver = checkOnOver; - checkboxOver = checkOver; - checkboxOnDisabled = checkOnDisabled; - checkboxOffDisabled = checkDisabled; - font = Fonts.def; - fontColor = Color.white; - disabledFontColor = Color.gray; - }}; + defaultPane = new ScrollPaneStyle(){{ + vScroll = scroll; + vScrollKnob = scrollKnobVerticalBlack; + }}; + horizontalPane = new ScrollPaneStyle(){{ + vScroll = scroll; + vScrollKnob = scrollKnobVerticalBlack; + hScroll = scrollHorizontal; + hScrollKnob = scrollKnobHorizontalBlack; + }}; - public static DialogStyle - defaultDialog = new DialogStyle(){{ - stageBackground = black9; - titleFont = Fonts.def; - background = windowEmpty; - titleFontColor = Pal.accent; - }}, - fullDialog = new DialogStyle(){{ - stageBackground = black; - titleFont = Fonts.def; - background = windowEmpty; - titleFontColor = Pal.accent; - }}; + defaultKeybindDialog = new KeybindDialogStyle(){{ + keyColor = Pal.accent; + keyNameColor = Color.white; + controllerColor = Color.lightGray; + }}; + + defaultSlider = new SliderStyle(){{ + background = slider; + knob = sliderKnob; + knobOver = sliderKnobOver; + knobDown = sliderKnobDown; + }}; + vSlider = new SliderStyle(){{ + background = sliderVertical; + knob = sliderKnob; + knobOver = sliderKnobOver; + knobDown = sliderKnobDown; + }}; + + defaultLabel = new LabelStyle(){{ + font = Fonts.def; + fontColor = Color.white; + }}; + outlineLabel = new LabelStyle(){{ + font = Fonts.outline; + fontColor = Color.white; + }}; + + defaultField = new TextFieldStyle(){{ + font = Fonts.chat; + fontColor = Color.white; + disabledFontColor = Color.gray; + disabledBackground = underlineDisabled; + selection = Tex.selection; + background = underline; + invalidBackground = underlineRed; + cursor = Tex.cursor; + messageFont = Fonts.def; + messageFontColor = Color.gray; + }}; + areaField = new TextFieldStyle(){{ + font = Fonts.chat; + fontColor = Color.white; + disabledFontColor = Color.gray; + selection = Tex.selection; + background = underline; + cursor = Tex.cursor; + messageFont = Fonts.def; + messageFontColor = Color.gray; + }}; + + defaultCheck = new CheckBoxStyle(){{ + checkboxOn = checkOn; + checkboxOff = checkOff; + checkboxOnOver = checkOnOver; + checkboxOver = checkOver; + checkboxOnDisabled = checkOnDisabled; + checkboxOffDisabled = checkDisabled; + font = Fonts.def; + fontColor = Color.white; + disabledFontColor = Color.gray; + }}; + + defaultDialog = new DialogStyle(){{ + stageBackground = black9; + titleFont = Fonts.def; + background = windowEmpty; + titleFontColor = Pal.accent; + }}; + fullDialog = new DialogStyle(){{ + stageBackground = black; + titleFont = Fonts.def; + background = windowEmpty; + titleFontColor = Pal.accent; + }}; + } private static Drawable createFlatDown(){ AtlasRegion region = Core.atlas.find("flat-down-base");