Added locale deskapp

This commit is contained in:
Willem Cazander 2022-03-26 23:42:48 +01:00
parent fabf63607b
commit a67ac250ce
4 changed files with 78 additions and 4 deletions

3
.gitignore vendored
View file

@ -3,7 +3,8 @@
# #
# Ignore project resources # Ignore project resources
main-gdxapp-desktop/warpcore.xml gdxapp4d-boot-desktop/warpcore.xml
gdxapp4d-boot-desktop/etc
# Ignore maven resources # Ignore maven resources
target target

View file

@ -2,7 +2,9 @@ package love.distributedrebirth.gdxapp4d.vrgem4;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
@ -37,11 +39,26 @@ public class VrGem4LocaleServiceImpl implements VrGem4LocaleService {
properties = new Properties(); properties = new Properties();
} }
private void save() {
File propFile = new File(warpBase.getWarpshipHome(), "etc/locale.xml");
try {
properties.storeToXML(new FileOutputStream(propFile), "Locales", StandardCharsets.UTF_8);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Activate @Activate
void open() { void open() {
log.debug(this, SystemGdxLog.ACTIVATE); log.debug(this, SystemGdxLog.ACTIVATE);
File propFile = new File(warpBase.getWarpshipHome(), "etc/locale.properties"); File etcFile = new File(warpBase.getWarpshipHome(), "etc");
if (!etcFile.exists()) {
etcFile.mkdir();
}
File propFile = new File(warpBase.getWarpshipHome(), "etc/locale.xml");
if (propFile.exists()) { if (propFile.exists()) {
try { try {
properties.loadFromXML(new FileInputStream(propFile)); properties.loadFromXML(new FileInputStream(propFile));
@ -59,8 +76,8 @@ public class VrGem4LocaleServiceImpl implements VrGem4LocaleService {
@Override @Override
public void setTextLocaleI18n(String isoCode) { public void setTextLocaleI18n(String isoCode) {
// TODO Auto-generated method stub properties.put(LocaleKey.TEXT_LOCALE.name(), isoCode);
save();
} }
@Override @Override

View file

@ -12,6 +12,7 @@ import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
import love.distributedrebirth.gdxapp4d.vrsys5.apps.BasicConsoleDeskApp; import love.distributedrebirth.gdxapp4d.vrsys5.apps.BasicConsoleDeskApp;
import love.distributedrebirth.gdxapp4d.vrsys5.apps.ImGuiDeskApp; import love.distributedrebirth.gdxapp4d.vrsys5.apps.ImGuiDeskApp;
import love.distributedrebirth.gdxapp4d.vrsys5.apps.SettingLocaleDeskApp;
@Component @Component
public class VrSys5Component { public class VrSys5Component {
@ -27,10 +28,12 @@ public class VrSys5Component {
private final DeskAppLauncher basicLauncher; private final DeskAppLauncher basicLauncher;
private final DeskAppLauncher imguiLauncher; private final DeskAppLauncher imguiLauncher;
private final DeskAppLauncher localeLauncher;
public VrSys5Component() { public VrSys5Component() {
basicLauncher = new DeskAppLauncher(DeskAppMenuSection.SYSTEM, "Basic Console", () -> new BasicConsoleDeskApp()); basicLauncher = new DeskAppLauncher(DeskAppMenuSection.SYSTEM, "Basic Console", () -> new BasicConsoleDeskApp());
imguiLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "ImGui Demo", () -> new ImGuiDeskApp()); imguiLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "ImGui Demo", () -> new ImGuiDeskApp());
localeLauncher = new DeskAppLauncher(DeskAppMenuSection.SYSTEM, "Locale", () -> new SettingLocaleDeskApp(localeService));
} }
@Activate @Activate
@ -38,6 +41,7 @@ public class VrSys5Component {
log.debug(this, SystemGdxLog.ACTIVATE); log.debug(this, SystemGdxLog.ACTIVATE);
deskAppService.installDeskApp(basicLauncher); deskAppService.installDeskApp(basicLauncher);
deskAppService.installDeskApp(imguiLauncher); deskAppService.installDeskApp(imguiLauncher);
deskAppService.installDeskApp(localeLauncher);
} }
@Deactivate @Deactivate
@ -45,5 +49,6 @@ public class VrSys5Component {
log.debug(this, SystemGdxLog.DEACTIVATE); log.debug(this, SystemGdxLog.DEACTIVATE);
deskAppService.removeDeskApp(basicLauncher); deskAppService.removeDeskApp(basicLauncher);
deskAppService.removeDeskApp(imguiLauncher); deskAppService.removeDeskApp(imguiLauncher);
deskAppService.removeDeskApp(localeLauncher);
} }
} }

View file

@ -0,0 +1,51 @@
package love.distributedrebirth.gdxapp4d.vrsys5.apps;
import java.util.ArrayList;
import java.util.List;
import imgui.ImGui;
import imgui.type.ImInt;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4LocaleService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class SettingLocaleDeskApp extends AbstractDeskApp implements DeskAppRenderer {
private final VrGem4LocaleService localeService;
private ImInt selectedLocale = new ImInt();
private String[] localeItems;
public SettingLocaleDeskApp(VrGem4LocaleService localeService) {
this.localeService = localeService;
}
public void create() {
getContours().setTitle("Locale Settings");
getContours().registrateContour(DeskAppContourSection.MAIN, this);
List<String> bases = new ArrayList<>();
bases.add("en");
bases.add("hiero");
localeItems = new String[bases.size()];
localeItems = bases.toArray(localeItems);
int selected = bases.indexOf(localeService.getTextLocaleI18n());
if (selected != -1) {
selectedLocale.set(selected);
}
}
@Override
public void render() {
ImGui.text("Select the locale to use;");
boolean changedLoc = ImGui.combo("TextLocale", selectedLocale, localeItems);
if (changedLoc) {
String newLoc = localeItems[selectedLocale.get()];
localeService.setTextLocaleI18n(newLoc);
}
}
}