Skip to content

Commit f49127f

Browse files
committed
Added tags to UI styles to increase the ui.json readability.
1 parent 9ffa3e2 commit f49127f

File tree

4 files changed

+109
-21
lines changed

4 files changed

+109
-21
lines changed

adventure-editor/src/main/resources/projectTmpl/android/assets/ui/ui.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22

3-
com.badlogic.gdx.graphics.g2d.BitmapFont: {
3+
BitmapFont: {
44
default: {file: fonts/Roboto-Regular.ttf, size: 17},
55
debug: {file: fonts/Roboto-Regular.ttf, size: 14},
66
big-font: {file: fonts/PaytoneOne.ttf, size: 35},
@@ -13,7 +13,7 @@ com.badlogic.gdx.graphics.g2d.BitmapFont: {
1313
},
1414

1515

16-
com.badlogic.gdx.graphics.Color: {
16+
Color: {
1717
white: { a: 1, b: 1, g: 1, r: 1 },
1818
black: { a: 1, b: 0, g: 0, r: 0 },
1919
dark-grey: { a: 1, b: 0.25, g: 0.25, r: 0.25 },
@@ -25,7 +25,7 @@ com.badlogic.gdx.graphics.Color: {
2525
yellow: { r: 1, g: 1, b: 0.13, a: 1 }
2626
},
2727

28-
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
28+
TintedDrawable: {
2929
black: { name: white_pixel, color: { r: 0, g: 0, b: 0, a: 1.0 } },
3030
black08: { name: white_pixel, color: { r: 0, g: 0, b: 0, a: 0.8 } },
3131
white: { name: white_pixel, color: white },
@@ -62,7 +62,7 @@ com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
6262
dialog-down-over: {name:dialog_down, color: white-trans},
6363
},
6464

65-
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
65+
ButtonStyle: {
6666
inventory: {up:inventory},
6767
delete_game: {up:delete, over: delete-over},
6868
menu: {up:menu-up, over: menu, down: menu},
@@ -82,7 +82,7 @@ com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
8282
},
8383

8484

85-
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
85+
TextButtonStyle: {
8686
default: {
8787
font: debug,
8888
up: grey,
@@ -122,39 +122,39 @@ com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
122122
},
123123

124124

125-
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
125+
LabelStyle: {
126126
default: { font: default, fontColor: white},
127127
debug: { font: debug, fontColor: white},
128128
title: { font: big-font, fontColor: white},
129129
ui-dialog: { font: message-font, fontColor: white},
130130
},
131131

132132

133-
com.bladecoder.engine.ui.MenuScreen$MenuScreenStyle: {
133+
MenuScreenStyle: {
134134
default: {textButtonStyle: menu, showTitle: true, titleStyle: title}
135135
},
136136

137137

138-
com.bladecoder.engine.ui.LoadSaveScreen$LoadSaveScreenStyle: {
138+
LoadSaveScreenStyle: {
139139
default: {textButtonStyle: menu}
140140
},
141141

142142

143-
com.bladecoder.engine.ui.CreditsScreen$CreditScreenStyle: {
143+
CreditScreenStyle: {
144144
default: {
145145
titleFont: credits-title, font: credits
146146
}
147147
},
148148

149-
com.bladecoder.engine.ui.InventoryUI$InventoryUIStyle: {
149+
InventoryUIStyle: {
150150
default: {background: black08, itemBackground: dark-grey}
151151
},
152152

153-
com.bladecoder.engine.ui.DialogUI$DialogUIStyle: {
153+
DialogUIStyle: {
154154
default: {background: black08, textButtonStyle: {font: dialog-font, fontColor: white, overFontColor: light-grey}}
155155
},
156156

157-
com.bladecoder.engine.ui.TextManagerUI$TextManagerUIStyle: {
157+
TextManagerUIStyle: {
158158
default: {
159159
rectBackground: rect,
160160
talkBackground: white,
@@ -166,7 +166,7 @@ com.bladecoder.engine.ui.TextManagerUI$TextManagerUIStyle: {
166166
},
167167

168168

169-
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
169+
TextFieldStyle: {
170170
default: {
171171
selection: grey,
172172
background: dark-grey,
@@ -182,7 +182,7 @@ com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
182182
},
183183

184184

185-
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
185+
ScrollPaneStyle: {
186186
default: {
187187
vScroll: dark-grey, vScrollKnob: grey, hScrollKnob: dark-grey, hScroll: dark-grey, corner: white
188188
},
@@ -194,7 +194,7 @@ com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
194194
}
195195
},
196196

197-
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
197+
ListStyle: {
198198
default: {
199199
fontColorUnselected: text-dark,
200200
selection: dark-grey,
@@ -211,7 +211,7 @@ com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
211211
},
212212

213213

214-
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
214+
SelectBoxStyle: {
215215
default: {
216216
background: dark-grey,
217217
backgroundOver: grey,
@@ -223,11 +223,11 @@ com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
223223
},
224224
},
225225

226-
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
226+
WindowStyle: {
227227
default: { titleFont: big-font, background: black08, titleFontColor: white },
228228
},
229229

230-
com.bladecoder.engine.ui.retro.VerbUI$VerbUIStyle: {
230+
VerbUIStyle: {
231231
default: { verbButtonStyle: {font:message-font, fontColor: yellow, up: dark-grey, overFontColor: white}, inventoryButtonStyle: {up: dark-grey, over: grey}, infoLineLabelStyle: {font: default}, upArrow: inv_up, downArrow: inv_down},
232232
}
233233
}

adventure-editor/src/main/resources/versions.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Autogenerated by build.gradle
2-
#Wed Sep 21 11:46:59 CEST 2016
2+
#Fri Sep 23 14:20:48 CEST 2016
33
roboVMVersion=2.2.0
44
gwtVersion=2.6.0
55
libgdxVersion=1.9.4

blade-engine/src/com/bladecoder/engine/ui/BladeSkin.java

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.bladecoder.engine.ui;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
36
import com.badlogic.gdx.Gdx;
47
import com.badlogic.gdx.files.FileHandle;
58
import com.badlogic.gdx.graphics.Color;
@@ -8,13 +11,37 @@
811
import com.badlogic.gdx.graphics.g2d.TextureRegion;
912
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
1013
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
14+
import com.badlogic.gdx.scenes.scene2d.ui.Button;
15+
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
16+
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
17+
import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
18+
import com.badlogic.gdx.scenes.scene2d.ui.Label;
19+
import com.badlogic.gdx.scenes.scene2d.ui.List;
20+
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
21+
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
22+
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
1123
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
24+
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
25+
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane;
26+
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
27+
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
28+
import com.badlogic.gdx.scenes.scene2d.ui.TextTooltip;
29+
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
30+
import com.badlogic.gdx.scenes.scene2d.ui.Tree;
31+
import com.badlogic.gdx.scenes.scene2d.ui.Window;
32+
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
33+
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
34+
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
35+
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
36+
import com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable;
1237
import com.badlogic.gdx.utils.Json;
1338
import com.badlogic.gdx.utils.Json.ReadOnlySerializer;
14-
import com.bladecoder.engine.util.DPIUtils;
15-
import com.bladecoder.engine.util.FileUtils;
1639
import com.badlogic.gdx.utils.JsonValue;
1740
import com.badlogic.gdx.utils.SerializationException;
41+
import com.badlogic.gdx.utils.reflect.ClassReflection;
42+
import com.badlogic.gdx.utils.reflect.ReflectionException;
43+
import com.bladecoder.engine.util.DPIUtils;
44+
import com.bladecoder.engine.util.FileUtils;
1845

1946
/**
2047
* Custom Skin class to add TTF font support
@@ -41,6 +68,37 @@ protected Json getJsonLoader(final FileHandle skinFile) {
4168
Json json = super.getJsonLoader(skinFile);
4269

4370
final Skin skin = this;
71+
72+
json.setSerializer(Skin.class, new ReadOnlySerializer<Skin>() {
73+
public Skin read (Json json, JsonValue typeToValueMap, @SuppressWarnings("rawtypes") Class ignored) {
74+
for (JsonValue valueMap = typeToValueMap.child; valueMap != null; valueMap = valueMap.next) {
75+
try {
76+
Class<?> type = json.getClass(valueMap.name());
77+
if (type == null) type = ClassReflection.forName(valueMap.name());
78+
readNamedObjects(json, type, valueMap);
79+
} catch (ReflectionException ex) {
80+
throw new SerializationException(ex);
81+
}
82+
}
83+
return skin;
84+
}
85+
86+
private void readNamedObjects (Json json, Class<?> type, JsonValue valueMap) {
87+
Class<?> addType = type == TintedDrawable.class ? Drawable.class : type;
88+
for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) {
89+
Object object = json.readValue(type, valueEntry);
90+
if (object == null) continue;
91+
try {
92+
add(valueEntry.name, object, addType);
93+
if (addType != Drawable.class && ClassReflection.isAssignableFrom(Drawable.class, addType))
94+
add(valueEntry.name, object, Drawable.class);
95+
} catch (Exception ex) {
96+
throw new SerializationException(
97+
"Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name, ex);
98+
}
99+
}
100+
}
101+
});
44102

45103
json.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() {
46104
public BitmapFont read(Json json, JsonValue jsonData, @SuppressWarnings("rawtypes") Class type) {
@@ -112,7 +170,28 @@ else if (size != -1) // TODO set size in points (dpi
112170
return font;
113171
}
114172
});
173+
174+
for (Class<?> cls : TAGGED_STYLES){
175+
json.addClassTag(cls.getSimpleName(), cls);
176+
}
115177

116178
return json;
117179
}
180+
181+
private static final Class<?>[] AUTO_TAGGED_STYLES = {
182+
BitmapFont.class, Color.class, TintedDrawable.class,
183+
NinePatchDrawable.class, SpriteDrawable.class, TextureRegionDrawable.class, TiledDrawable.class,
184+
Button.ButtonStyle.class, CheckBox.CheckBoxStyle.class, ImageButton.ImageButtonStyle.class,
185+
ImageTextButton.ImageTextButtonStyle.class, Label.LabelStyle.class, List.ListStyle.class,
186+
ProgressBar.ProgressBarStyle.class, ScrollPane.ScrollPaneStyle.class, SelectBox.SelectBoxStyle.class,
187+
Slider.SliderStyle.class, SplitPane.SplitPaneStyle.class, TextButton.TextButtonStyle.class,
188+
TextField.TextFieldStyle.class, TextTooltip.TextTooltipStyle.class, Touchpad.TouchpadStyle.class,
189+
Tree.TreeStyle.class, Window.WindowStyle.class
190+
};
191+
192+
private final static ArrayList<Class<?>> TAGGED_STYLES = new ArrayList<Class<?>>(Arrays.asList(AUTO_TAGGED_STYLES));
193+
194+
public static final void addStyleTag(Class<?> tag) {
195+
TAGGED_STYLES.add(tag);
196+
}
118197
}

blade-engine/src/com/bladecoder/engine/ui/UI.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.bladecoder.engine.assets.EngineAssetManager;
2626
import com.bladecoder.engine.model.World;
2727
import com.bladecoder.engine.ui.defaults.DefaultSceneScreen;
28+
import com.bladecoder.engine.ui.retro.VerbUI;
2829
import com.bladecoder.engine.util.Config;
2930
import com.bladecoder.engine.util.EngineLogger;
3031
import com.bladecoder.engine.util.RectangleRenderer;
@@ -156,6 +157,14 @@ public void render() {
156157
}
157158

158159
private void loadAssets() {
160+
BladeSkin.addStyleTag(VerbUI.VerbUIStyle.class);
161+
BladeSkin.addStyleTag(TextManagerUI.TextManagerUIStyle.class);
162+
BladeSkin.addStyleTag(DialogUI.DialogUIStyle.class);
163+
BladeSkin.addStyleTag(InventoryUI.InventoryUIStyle.class);
164+
BladeSkin.addStyleTag(CreditsScreen.CreditScreenStyle.class);
165+
BladeSkin.addStyleTag(LoadSaveScreen.LoadSaveScreenStyle.class);
166+
BladeSkin.addStyleTag(MenuScreen.MenuScreenStyle.class);
167+
159168
FileHandle skinFile = EngineAssetManager.getInstance().getAsset(SKIN_FILENAME);
160169
TextureAtlas atlas = new TextureAtlas(EngineAssetManager.getInstance().getResAsset(
161170
SKIN_FILENAME.substring(0,SKIN_FILENAME.lastIndexOf('.')) + ".atlas"));

0 commit comments

Comments
 (0)