Initial support to Bitmap Fonts
This commit is contained in:
Submodule h2d-libgdx-typinglabel-extension updated: 345ceda938...07e02a73e7
Submodule hyperlap2d-runtime-libgdx updated: c23efeb3a8...81cbcc7fe7
+16
-2
@@ -44,6 +44,7 @@ public class UpdateLabelDataCommand extends EntityModifyRevertibleCommand {
|
||||
Label.LabelStyle prevStyle;
|
||||
boolean prevWrap;
|
||||
boolean prevMono;
|
||||
String prevBitmapFont;
|
||||
|
||||
@Override
|
||||
public void doAction() {
|
||||
@@ -61,22 +62,34 @@ public class UpdateLabelDataCommand extends EntityModifyRevertibleCommand {
|
||||
this.prevText = (String) payload[5];
|
||||
this.prevWrap = labelComponent.wrap;
|
||||
this.prevMono = labelComponent.mono;
|
||||
this.prevBitmapFont = labelComponent.bitmapFont;
|
||||
|
||||
labelComponent.fontName = (String) payload[1];
|
||||
labelComponent.fontSize = (int) payload[2];
|
||||
labelComponent.setAlignment((Integer) payload[3]);
|
||||
labelComponent.setText((String) payload[4]);
|
||||
labelComponent.setStyle(getNewStyle(labelComponent.fontName, labelComponent.fontSize, labelComponent.mono));
|
||||
labelComponent.setWrap((Boolean) payload[6]);
|
||||
labelComponent.mono = (Boolean) payload[7];
|
||||
labelComponent.bitmapFont = (String) payload[8];
|
||||
|
||||
if (labelComponent.bitmapFont != null) {
|
||||
labelComponent.setStyle(getNewStyle(labelComponent.bitmapFont));
|
||||
} else {
|
||||
labelComponent.setStyle(getNewStyle(labelComponent.fontName, labelComponent.fontSize, labelComponent.mono));
|
||||
}
|
||||
|
||||
facade.sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity);
|
||||
}
|
||||
|
||||
private Label.LabelStyle getNewStyle(String fontName) {
|
||||
IResourceRetriever rm = Sandbox.getInstance().getSceneControl().sceneLoader.getRm();
|
||||
return LabelComponentFactory.generateStyle(rm, fontName);
|
||||
}
|
||||
|
||||
private Label.LabelStyle getNewStyle(String fontName, int fontSize, boolean mono) {
|
||||
|
||||
IResourceRetriever rm = Sandbox.getInstance().getSceneControl().sceneLoader.getRm();
|
||||
final boolean hasBitmapFont = rm.getBitmapFont(fontName, fontSize, mono) != null;
|
||||
final boolean hasBitmapFont = rm.getFont(fontName, fontSize, mono) != null;
|
||||
|
||||
if(!hasBitmapFont) {
|
||||
games.rednblack.editor.proxy.ResourceManager resourceManager = facade.retrieveProxy(games.rednblack.editor.proxy.ResourceManager.NAME);
|
||||
@@ -97,6 +110,7 @@ public class UpdateLabelDataCommand extends EntityModifyRevertibleCommand {
|
||||
labelComponent.setStyle(prevStyle);
|
||||
labelComponent.setWrap(prevWrap);
|
||||
labelComponent.mono = prevMono;
|
||||
labelComponent.bitmapFont = prevBitmapFont;
|
||||
|
||||
facade.sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class ProjectManager extends Proxy {
|
||||
public static final String TALOS_VFX_DIR_PATH = "assets/talos-vfx";
|
||||
public static final String SHADER_DIR_PATH = "assets/shaders";
|
||||
public static final String FONTS_DIR_PATH = "assets/freetypefonts";
|
||||
public static final String BITMAP_FONTS_DIR_PATH = "assets/bitmapfonts";
|
||||
|
||||
public ProjectVO currentProjectVO;
|
||||
public ProjectInfoVO currentProjectInfoVO;
|
||||
@@ -445,6 +446,12 @@ public class ProjectManager extends Proxy {
|
||||
if (!currentProjectVO.projectMainExportPath.isEmpty()) {
|
||||
exportFonts(currentProjectVO.projectMainExportPath);
|
||||
}
|
||||
|
||||
exportBitmapFonts(defaultBuildPath);
|
||||
if (!currentProjectVO.projectMainExportPath.isEmpty()) {
|
||||
exportBitmapFonts(currentProjectVO.projectMainExportPath);
|
||||
}
|
||||
|
||||
SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME);
|
||||
sceneDataManager.buildScenes(defaultBuildPath);
|
||||
if (!currentProjectVO.projectMainExportPath.isEmpty()) {
|
||||
@@ -513,6 +520,17 @@ public class ProjectManager extends Proxy {
|
||||
}
|
||||
}
|
||||
|
||||
private void exportBitmapFonts(String targetPath) {
|
||||
String srcPath = currentProjectPath + "/assets";
|
||||
FileHandle origDirectoryHandle = Gdx.files.absolute(srcPath);
|
||||
FileHandle fontsDirectory = origDirectoryHandle.child("bitmapfonts");
|
||||
File fileTarget = new File(targetPath + "/" + fontsDirectory.name());
|
||||
try {
|
||||
FileUtils.copyDirectory(fontsDirectory.file(), fileTarget);
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
private void exportFonts(String targetPath) {
|
||||
String srcPath = currentProjectPath + "/assets";
|
||||
FileHandle origDirectoryHandle = Gdx.files.absolute(srcPath);
|
||||
|
||||
@@ -56,7 +56,8 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
|
||||
private final HashMap<String, SpineDataObject> spineAnimAtlases = new HashMap<>();
|
||||
private final HashMap<String, Array<TextureAtlas.AtlasRegion>> spriteAnimAtlases = new HashMap<>();
|
||||
private final HashMap<FontSizePair, BitmapFont> bitmapFonts = new HashMap<>();
|
||||
private final HashMap<FontSizePair, BitmapFont> fonts = new HashMap<>();
|
||||
private final HashMap<String, BitmapFont> bitmapFonts = new HashMap<>();
|
||||
private final HashMap<String, ShaderProgram> shaderPrograms = new HashMap<>(1);
|
||||
|
||||
private TextureAtlas.AtlasRegion defaultRegion;
|
||||
@@ -183,13 +184,16 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
return spriteAnimAtlases.get(animationName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BitmapFont getBitmapFont(String fontName, int fontSize, boolean mono) {
|
||||
public BitmapFont getFont(String fontName, int fontSize, boolean mono) {
|
||||
FontSizePair pair = new FontSizePair(fontName, fontSize, mono);
|
||||
return bitmapFonts.get(pair);
|
||||
return fonts.get(pair);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitmapFont getBitmapFont(String fontName) {
|
||||
return bitmapFonts.get(fontName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTextureRegion(String regionName) {
|
||||
@@ -206,7 +210,6 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
return projectManager.getCurrentProjectInfoVO();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SceneVO getSceneVO(String name) {
|
||||
SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME);
|
||||
@@ -223,12 +226,26 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
loadCurrentProjectTalosVFXs(projectPath + File.separator + ProjectManager.TALOS_VFX_DIR_PATH);
|
||||
loadCurrentProjectSpineAnimations(projectPath + File.separator + ProjectManager.SPINE_DIR_PATH);
|
||||
loadCurrentProjectSpriteAnimations(projectPath + File.separator + ProjectManager.SPRITE_DIR_PATH);
|
||||
loadCurrentProjectBitmapFonts();
|
||||
loadCurrentProjectBitmapFonts(projectPath + File.separator + ProjectManager.BITMAP_FONTS_DIR_PATH);
|
||||
loadCurrentProjectFonts();
|
||||
loadCurrentProjectShaders(projectPath + File.separator + ProjectManager.SHADER_DIR_PATH);
|
||||
|
||||
removeInvalidResourceReferences();
|
||||
}
|
||||
|
||||
public void loadCurrentProjectBitmapFonts(String path) {
|
||||
bitmapFonts.clear();
|
||||
FileHandle sourceDir = new FileHandle(path);
|
||||
for (FileHandle entry : sourceDir.list()) {
|
||||
File file = entry.file();
|
||||
String filename = file.getName();
|
||||
if (file.isDirectory() || filename.endsWith(".DS_Store")) continue;
|
||||
|
||||
BitmapFont bitmapFont = new BitmapFont(Gdx.files.internal(file.getAbsolutePath()), getTextureRegion(entry.nameWithoutExtension()));
|
||||
bitmapFonts.put(bitmapFont.getData().name, bitmapFont);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCurrentProjectParticles(String path) {
|
||||
particleEffects.clear();
|
||||
FileHandle sourceDir = new FileHandle(path);
|
||||
@@ -370,8 +387,8 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadCurrentProjectBitmapFonts() {
|
||||
bitmapFonts.clear();
|
||||
public void loadCurrentProjectFonts() {
|
||||
fonts.clear();
|
||||
|
||||
ArrayList<FontSizePair> requiredFonts = getProjectRequiredFontsList();
|
||||
for (int i = 0; i < requiredFonts.size(); i++) {
|
||||
@@ -386,7 +403,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
BitmapFont font = generator.generateFont(parameter);
|
||||
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
font.setUseIntegerPositions(false);
|
||||
bitmapFonts.put(pair, font);
|
||||
fonts.put(pair, font);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -456,24 +473,20 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
return expectedFile;
|
||||
}
|
||||
|
||||
public void addBitmapFont(String name, int size, BitmapFont font, boolean mono) {
|
||||
bitmapFonts.put(new FontSizePair(name, size, mono), font);
|
||||
}
|
||||
|
||||
public void flushAllUnusedFonts() {
|
||||
//List of fonts that are required to be in memory
|
||||
ArrayList<FontSizePair> requiredFonts = getProjectRequiredFontsList();
|
||||
ArrayList<FontSizePair> fontsInMemory = new ArrayList<>(bitmapFonts.keySet());
|
||||
ArrayList<FontSizePair> fontsInMemory = new ArrayList<>(fonts.keySet());
|
||||
|
||||
for (FontSizePair font : fontsInMemory) {
|
||||
if (!requiredFonts.contains(font)) {
|
||||
bitmapFonts.remove(font);
|
||||
fonts.remove(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFontLoaded(String shortName, int fontSize, boolean mono) {
|
||||
return bitmapFonts.containsKey(new FontSizePair(shortName, fontSize, mono));
|
||||
return fonts.containsKey(new FontSizePair(shortName, fontSize, mono));
|
||||
}
|
||||
|
||||
public void prepareEmbeddingFont(String fontfamily, int fontSize, boolean mono) {
|
||||
@@ -495,7 +508,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
font.setUseIntegerPositions(false);
|
||||
if (mono)
|
||||
font.setFixedWidthGlyphs(FreeTypeFontGenerator.DEFAULT_CHARS);
|
||||
addBitmapFont(fontfamily, parameter.size, font, mono);
|
||||
fonts.put(new FontSizePair(fontfamily, parameter.size, mono), font);
|
||||
}
|
||||
|
||||
public HashMap<String, SpineDataObject> getProjectSpineAnimationsList() {
|
||||
@@ -514,6 +527,10 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
return talosVFXs;
|
||||
}
|
||||
|
||||
public HashMap<String, BitmapFont> getBitmapFontList() {
|
||||
return bitmapFonts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolutionEntryVO getLoadedResolution() {
|
||||
if(packResolutionName.equals("orig")) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class AssetIOManager {
|
||||
sInstance.assetDescriptors.add(new SpriteAnimationAtlasAsset());
|
||||
sInstance.assetDescriptors.add(new SpriteAnimationSequenceAsset());
|
||||
sInstance.assetDescriptors.add(new ShaderAsset());
|
||||
sInstance.assetDescriptors.add(new BitmapFontAsset());
|
||||
sInstance.assetDescriptors.add(new HyperLap2DInternalLibraryAsset());
|
||||
sInstance.assetDescriptors.add(new HyperLap2DLibraryAsset());
|
||||
sInstance.assetDescriptors.add(new HyperLap2DActionAsset());
|
||||
@@ -50,6 +51,7 @@ public class AssetIOManager {
|
||||
sInstance.dataClassExportMap.put(SpriteAnimationVO.class, AssetsUtils.TYPE_SPRITE_ANIMATION_ATLAS);
|
||||
sInstance.dataClassExportMap.put(ParticleEffectVO.class, AssetsUtils.TYPE_PARTICLE_EFFECT);
|
||||
sInstance.dataClassExportMap.put(TalosVO.class, AssetsUtils.TYPE_TALOS_VFX);
|
||||
sInstance.dataClassExportMap.put(LabelVO.class, AssetsUtils.TYPE_BITMAP_FONT);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@@ -39,12 +39,13 @@ public class AssetsUtils {
|
||||
private AssetsUtils() {
|
||||
fileTypeFilter = new FileTypeFilter(false);
|
||||
|
||||
fileTypeFilter.addRule("All Supported (*.png, *.atlas, *.p, *.json, *.vert, *.frag, *.h2dlib, *.h2daction)", "png", "atlas", "p", "json", "vert", "frag", "h2dlib", "h2daction");
|
||||
fileTypeFilter.addRule("All Supported (*.png, *.atlas, *.p, *.json, *.vert, *.frag, *.fnt, *.h2dlib, *.h2daction)", "png", "atlas", "p", "json", "vert", "frag", "fnt", "h2dlib", "h2daction");
|
||||
fileTypeFilter.addRule("PNG File (*.png)", "png");
|
||||
fileTypeFilter.addRule("Sprite Animation Atlas File (*.atlas)", "atlas");
|
||||
fileTypeFilter.addRule("libGDX/Talos Particle Effect (*.p)", "p");
|
||||
fileTypeFilter.addRule("Spine Animation (*.json)", "json");
|
||||
fileTypeFilter.addRule("Shader (*.vert, *.frag)", "vert", "frag");
|
||||
fileTypeFilter.addRule("BitmapFont (*.fnt)", "fnt");
|
||||
fileTypeFilter.addRule("HyperLap2D Library (*.h2dlib)", "h2dlib");
|
||||
fileTypeFilter.addRule("HyperLap2D Action (*.h2daction)", "h2daction");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package games.rednblack.editor.utils.asset.impl;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.kotcrab.vis.ui.util.dialog.Dialogs;
|
||||
import games.rednblack.editor.proxy.ProjectManager;
|
||||
import games.rednblack.editor.proxy.ResolutionManager;
|
||||
import games.rednblack.editor.renderer.data.LabelVO;
|
||||
import games.rednblack.editor.renderer.data.MainItemVO;
|
||||
import games.rednblack.editor.utils.AssetsUtils;
|
||||
import games.rednblack.editor.utils.asset.Asset;
|
||||
import games.rednblack.editor.view.stage.Sandbox;
|
||||
import games.rednblack.h2d.common.ProgressHandler;
|
||||
import games.rednblack.h2d.common.vo.ExportMapperVO;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BitmapFontAsset extends Asset {
|
||||
@Override
|
||||
protected boolean matchMimeType(FileHandle file) {
|
||||
if (!file.extension().equals("fnt")) return false;
|
||||
|
||||
try {
|
||||
new BitmapFont.BitmapFontData(file, false);
|
||||
return true;
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return AssetsUtils.TYPE_BITMAP_FONT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkExistence(Array<FileHandle> files) {
|
||||
for (FileHandle file : new Array.ArrayIterator<>(files)) {
|
||||
FileHandle fileHandle = new FileHandle(projectManager.getCurrentProjectPath() + File.separator
|
||||
+ ProjectManager.BITMAP_FONTS_DIR_PATH + File.separator + file.nameWithoutExtension() + ".fnt");
|
||||
if (fileHandle.exists())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importAsset(Array<FileHandle> files, ProgressHandler progressHandler, boolean skipRepack) {
|
||||
final String targetPath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.BITMAP_FONTS_DIR_PATH;
|
||||
|
||||
Array<FileHandle> images = new Array<>();
|
||||
for (FileHandle fileHandle : new Array.ArrayIterator<>(files)) {
|
||||
if (!fileHandle.isDirectory() && fileHandle.exists()) {
|
||||
BitmapFont.BitmapFontData font = new BitmapFont.BitmapFontData(fileHandle, false);
|
||||
for (String textureName : font.getImagePaths()) {
|
||||
FileHandle tmp = new FileHandle(textureName);
|
||||
if (!tmp.exists()) {
|
||||
Dialogs.showErrorDialog(Sandbox.getInstance().getUIStage(),
|
||||
"\nAll PNG files needs to have same location as the font file.").padBottom(20).pack();
|
||||
return;
|
||||
}
|
||||
images.add(tmp);
|
||||
}
|
||||
|
||||
String newName = fileHandle.name();
|
||||
File target = new File(targetPath + "/" + newName);
|
||||
try {
|
||||
FileUtils.copyFile(fileHandle.file(), target);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (images.size > 0)
|
||||
projectManager.copyImageFilesForAllResolutionsIntoProject(images, false, progressHandler);
|
||||
|
||||
if (!skipRepack) {
|
||||
ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
|
||||
resolutionManager.rePackProjectImagesForAllResolutionsSync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAsset(int root, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exportAsset(MainItemVO item, ExportMapperVO exportMapperVO, File tmpDir) throws IOException {
|
||||
super.exportAsset(item, exportMapperVO, tmpDir);
|
||||
LabelVO labelVO = (LabelVO) item;
|
||||
if (labelVO.bitmapFont == null) return true;
|
||||
|
||||
File fileSrc = new File(currentProjectPath + ProjectManager.BITMAP_FONTS_DIR_PATH + File.separator + labelVO.bitmapFont + ".fnt");
|
||||
FileUtils.copyFileToDirectory(fileSrc, tmpDir);
|
||||
exportMapperVO.mapper.add(new ExportMapperVO.ExportedAsset(AssetsUtils.TYPE_BITMAP_FONT, fileSrc.getName()));
|
||||
BitmapFont.BitmapFontData bitmapFontData = new BitmapFont.BitmapFontData(new FileHandle(fileSrc), false);
|
||||
for (String textureName : bitmapFontData.imagePaths) {
|
||||
File f = new File(currentProjectPath + ProjectManager.IMAGE_DIR_PATH + File.separator + textureName);
|
||||
FileUtils.copyFileToDirectory(f, tmpDir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class ParticleEffectAsset extends Asset {
|
||||
|
||||
@Override
|
||||
public void importAsset(Array<FileHandle> files, ProgressHandler progressHandler, boolean skipRepack) {
|
||||
final String targetPath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.PARTICLE_DIR_PATH ;
|
||||
final String targetPath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.PARTICLE_DIR_PATH;
|
||||
|
||||
Array<FileHandle> images = new Array<>();
|
||||
for (FileHandle fileHandle : new Array.ArrayIterator<>(files)) {
|
||||
|
||||
+25
-1
@@ -1,5 +1,6 @@
|
||||
package games.rednblack.editor.view.ui.properties.panels;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.kotcrab.vis.ui.widget.VisCheckBox;
|
||||
@@ -30,13 +31,14 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
|
||||
public static final String LABEL_TEXT_CHAR_TYPED = prefix + ".LABEL_TEXT_CHANGED";
|
||||
public static final String LABEL_TEXT_EXPAND_SAVED = prefix + ".LABEL_TEXT_EXPAND_SAVED";
|
||||
public static final String NONE_BITMAP_FONT = "<None>";
|
||||
|
||||
private HashMap<Integer, String> alignMap = new HashMap<>();
|
||||
private Array<String> alignNames = new Array<>();
|
||||
|
||||
private HyperLap2DFacade facade;
|
||||
|
||||
private VisSelectBox<String> fontFamilySelectBox;
|
||||
private VisSelectBox<String> fontFamilySelectBox, bitmapFontSelectBox;
|
||||
private VisSelectBox<String> alignSelectBox;
|
||||
private VisCheckBox boldCheckBox;
|
||||
private VisCheckBox wrapCheckBox;
|
||||
@@ -49,6 +51,7 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
super("Label");
|
||||
facade = HyperLap2DFacade.getInstance();
|
||||
|
||||
bitmapFontSelectBox = StandardWidgetsFactory.createSelectBox(String.class);
|
||||
fontFamilySelectBox = StandardWidgetsFactory.createSelectBox(String.class);
|
||||
alignSelectBox = StandardWidgetsFactory.createSelectBox(String.class);
|
||||
boldCheckBox = StandardWidgetsFactory.createCheckBox();
|
||||
@@ -65,6 +68,10 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
textAreaTable.setSyntax(new TypingLabelSyntax());
|
||||
textArea = textAreaTable.getTextArea();
|
||||
|
||||
mainTable.add(StandardWidgetsFactory.createLabel("Bitmap Font", Align.right)).padRight(5).width(90).left();
|
||||
mainTable.add(bitmapFontSelectBox).width(90).padRight(5);
|
||||
mainTable.row().padTop(5);
|
||||
|
||||
mainTable.add(StandardWidgetsFactory.createLabel("Font Family", Align.right)).padRight(5).width(90).left();
|
||||
mainTable.add(fontFamilySelectBox).width(90).padRight(5);
|
||||
mainTable.row().padTop(5);
|
||||
@@ -94,6 +101,10 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
setAlignList();
|
||||
}
|
||||
|
||||
public String getBitmapFont() {
|
||||
return bitmapFontSelectBox.getSelected();
|
||||
}
|
||||
|
||||
public String getFontFamily() {
|
||||
return fontFamilySelectBox.getSelected();
|
||||
}
|
||||
@@ -180,6 +191,18 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
fontFamilySelectBox.setSelected(name);
|
||||
}
|
||||
|
||||
public void setBitmapFontList(HashMap<String, BitmapFont> fontFamilies) {
|
||||
Array<String> tmp = new Array<>();
|
||||
tmp.add(NONE_BITMAP_FONT);
|
||||
for (String name : fontFamilies.keySet())
|
||||
tmp.add(name);
|
||||
bitmapFontSelectBox.setItems(tmp);
|
||||
}
|
||||
|
||||
public void setBitmapFontFamily(String name) {
|
||||
bitmapFontSelectBox.setSelected(name);
|
||||
}
|
||||
|
||||
public void setStyle(boolean bold, boolean italic) {
|
||||
boldCheckBox.setChecked(bold);
|
||||
italicCheckBox.setChecked(italic);
|
||||
@@ -200,6 +223,7 @@ public class UILabelItemProperties extends UIItemCollapsibleProperties {
|
||||
|
||||
private void setListeners() {
|
||||
final String eventName = getUpdateEventName();
|
||||
bitmapFontSelectBox.addListener(new SelectBoxChangeListener(eventName));
|
||||
fontFamilySelectBox.addListener(new SelectBoxChangeListener(eventName));
|
||||
alignSelectBox.addListener(new SelectBoxChangeListener(eventName));
|
||||
boldCheckBox.addListener(new CheckBoxChangeListener(eventName));
|
||||
|
||||
+7
-1
@@ -2,6 +2,7 @@ package games.rednblack.editor.view.ui.properties.panels;
|
||||
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.proxy.FontManager;
|
||||
import games.rednblack.editor.proxy.ResourceManager;
|
||||
import games.rednblack.editor.renderer.components.label.LabelComponent;
|
||||
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
|
||||
import games.rednblack.editor.view.ui.properties.UIItemPropertiesMediator;
|
||||
@@ -17,6 +18,7 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator<UILa
|
||||
private String prevText = null;
|
||||
|
||||
private FontManager fontManager;
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public UILabelItemPropertiesMediator() {
|
||||
super(NAME, new UILabelItemProperties());
|
||||
@@ -26,8 +28,10 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator<UILa
|
||||
public void onRegister() {
|
||||
facade = HyperLap2DFacade.getInstance();
|
||||
fontManager = facade.retrieveProxy(FontManager.NAME);
|
||||
resourceManager = facade.retrieveProxy(ResourceManager.NAME);
|
||||
lockUpdates = true;
|
||||
viewComponent.setFontFamilyList(fontManager.getFontNamesFromMap());
|
||||
viewComponent.setBitmapFontList(resourceManager.getBitmapFontList());
|
||||
lockUpdates = false;
|
||||
}
|
||||
|
||||
@@ -71,6 +75,7 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator<UILa
|
||||
viewComponent.setText(labelComponent.text.toString().replace("\\n", "\n"));
|
||||
viewComponent.setWrap(labelComponent.wrap);
|
||||
viewComponent.setMono(labelComponent.mono);
|
||||
viewComponent.setBitmapFontFamily(labelComponent.bitmapFont != null ? labelComponent.bitmapFont : UILabelItemProperties.NONE_BITMAP_FONT);
|
||||
|
||||
if(prevText == null) this.prevText = viewComponent.getText();
|
||||
}
|
||||
@@ -79,7 +84,7 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator<UILa
|
||||
protected void translateViewToItemData() {
|
||||
final String newText = viewComponent.getText();
|
||||
|
||||
Object[] payload = new Object[8];
|
||||
Object[] payload = new Object[9];
|
||||
payload[0] = observableReference;
|
||||
payload[1] = viewComponent.getFontFamily();
|
||||
payload[2] = viewComponent.getFontSize();
|
||||
@@ -88,6 +93,7 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator<UILa
|
||||
payload[5] = prevText;
|
||||
payload[6] = viewComponent.isWrap();
|
||||
payload[7] = viewComponent.isMono();
|
||||
payload[8] = viewComponent.getBitmapFont().equals(UILabelItemProperties.NONE_BITMAP_FONT) ? null : viewComponent.getBitmapFont();
|
||||
sendNotification(MsgAPI.ACTION_UPDATE_LABEL_DATA, payload);
|
||||
|
||||
this.prevText = newText;
|
||||
|
||||
+4
@@ -2,6 +2,7 @@ package games.rednblack.editor.view.ui.properties.panels;
|
||||
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.proxy.FontManager;
|
||||
import games.rednblack.editor.proxy.ResourceManager;
|
||||
import games.rednblack.editor.view.stage.tools.TextTool;
|
||||
import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator;
|
||||
|
||||
@@ -14,6 +15,7 @@ public class UITextToolPropertiesMediator extends UIAbstractPropertiesMediator<T
|
||||
public static final String NAME = TAG;
|
||||
|
||||
private FontManager fontManager;
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public UITextToolPropertiesMediator() {
|
||||
super(NAME, new UITextToolProperties());
|
||||
@@ -23,7 +25,9 @@ public class UITextToolPropertiesMediator extends UIAbstractPropertiesMediator<T
|
||||
public void onRegister() {
|
||||
facade = HyperLap2DFacade.getInstance();
|
||||
fontManager = facade.retrieveProxy(FontManager.NAME);
|
||||
resourceManager = facade.retrieveProxy(ResourceManager.NAME);
|
||||
viewComponent.setFontFamilyList(fontManager.getFontNamesFromMap());
|
||||
viewComponent.setBitmapFontList(resourceManager.getBitmapFontList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user