Added locale deskapp
This commit is contained in:
parent
fabf63607b
commit
a67ac250ce
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,7 +3,8 @@
|
|||
#
|
||||
|
||||
# Ignore project resources
|
||||
main-gdxapp-desktop/warpcore.xml
|
||||
gdxapp4d-boot-desktop/warpcore.xml
|
||||
gdxapp4d-boot-desktop/etc
|
||||
|
||||
# Ignore maven resources
|
||||
target
|
||||
|
|
|
@ -2,7 +2,9 @@ package love.distributedrebirth.gdxapp4d.vrgem4;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -37,11 +39,26 @@ public class VrGem4LocaleServiceImpl implements VrGem4LocaleService {
|
|||
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
|
||||
void open() {
|
||||
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()) {
|
||||
try {
|
||||
properties.loadFromXML(new FileInputStream(propFile));
|
||||
|
@ -59,8 +76,8 @@ public class VrGem4LocaleServiceImpl implements VrGem4LocaleService {
|
|||
|
||||
@Override
|
||||
public void setTextLocaleI18n(String isoCode) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
properties.put(LocaleKey.TEXT_LOCALE.name(), isoCode);
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
|
|||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
|
||||
import love.distributedrebirth.gdxapp4d.vrsys5.apps.BasicConsoleDeskApp;
|
||||
import love.distributedrebirth.gdxapp4d.vrsys5.apps.ImGuiDeskApp;
|
||||
import love.distributedrebirth.gdxapp4d.vrsys5.apps.SettingLocaleDeskApp;
|
||||
|
||||
@Component
|
||||
public class VrSys5Component {
|
||||
|
@ -27,10 +28,12 @@ public class VrSys5Component {
|
|||
|
||||
private final DeskAppLauncher basicLauncher;
|
||||
private final DeskAppLauncher imguiLauncher;
|
||||
private final DeskAppLauncher localeLauncher;
|
||||
|
||||
public VrSys5Component() {
|
||||
basicLauncher = new DeskAppLauncher(DeskAppMenuSection.SYSTEM, "Basic Console", () -> new BasicConsoleDeskApp());
|
||||
imguiLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "ImGui Demo", () -> new ImGuiDeskApp());
|
||||
localeLauncher = new DeskAppLauncher(DeskAppMenuSection.SYSTEM, "Locale", () -> new SettingLocaleDeskApp(localeService));
|
||||
}
|
||||
|
||||
@Activate
|
||||
|
@ -38,6 +41,7 @@ public class VrSys5Component {
|
|||
log.debug(this, SystemGdxLog.ACTIVATE);
|
||||
deskAppService.installDeskApp(basicLauncher);
|
||||
deskAppService.installDeskApp(imguiLauncher);
|
||||
deskAppService.installDeskApp(localeLauncher);
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
|
@ -45,5 +49,6 @@ public class VrSys5Component {
|
|||
log.debug(this, SystemGdxLog.DEACTIVATE);
|
||||
deskAppService.removeDeskApp(basicLauncher);
|
||||
deskAppService.removeDeskApp(imguiLauncher);
|
||||
deskAppService.removeDeskApp(localeLauncher);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue