| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import dlangui;
- import config;
- import variables;
- import std.conv;
- import std.stdio;
- import std.array;
- mixin APP_ENTRY_POINT;
- /// entry point for dlangui based application
- extern (C) int UIAppMain(string[] args) {
- // create window
- systemSettings = loadSettingsFromConfigFile("conf/settings.conf");
- oldSettings = systemSettings;
- Window window = Platform.instance.createWindow((systemSettings.windowTitle~" Launcher").to!dstring, null);
- window.backgroundColor = 0xFFFFFF;
- string redResolution = systemSettings.screenWidth.to!string~"x"~systemSettings.screenHeight.to!string;
- writeln(redResolution);
- auto vlayout = new VerticalLayout();
- // put some widgets into background
- static immutable resolutionsAvailable = [
- "1920x1080",
- "1600x900",
- "1366x768",
- "1280x720",
- "1024x576",
- ];
-
- auto makeHandler(int idx) {
- return (Widget rb, bool isChecked) {
- if (isChecked) {
- writeln("selected resolution: ", idx);
- }
- return true;
- };
- }
- int defaultIndex = -1;
- foreach (i, res; resolutionsAvailable) {
- if (res == redResolution) {
- defaultIndex = cast(int)i;
- break;
- }
- }
- for (int i = 0; i < resolutionsAvailable.length; i++) {
- radioButtons[i] = new RadioButton(
- "resolution" ~ i.to!string,
- resolutionsAvailable[i].to!dstring
- );
- vlayout.addChild(radioButtons[i]);
- radioButtons[i].checkChange = makeHandler(i);
-
- if (i == defaultIndex) {
- radioButtons[i].checked = true;
- }
- }
-
- CheckBox fullscreen = new CheckBox();
- fullscreen.text = "Fullscreen".to!dstring;
- fullscreen.checked = systemSettings.defaultFullscreen;
- CheckBox audioState = new CheckBox();
- CheckBox gamepadState = new CheckBox();
- gamepadState.text = "Gamepad".to!dstring;
- gamepadState.checked = systemSettings.gamepadState;
- audioState.text = "Audio".to!dstring;
- audioState.checked = systemSettings.audioState;
- fullscreen.checkChange = (Widget sender, bool isChecked) {
- systemSettings.defaultFullscreen = isChecked;
- writeln("Fullscreen: ", isChecked ? "on" : "off");
- return true;
- };
- gamepadState.checkChange = (Widget sender, bool isChecked) {
- systemSettings.gamepadState = isChecked;
- writeln("gamepad state: ", isChecked ? "on" : "off");
- return true;
- };
- audioState.checkChange = (Widget sender, bool isChecked) {
- systemSettings.audioState = isChecked;
- writeln("Audio state: ", isChecked ? "on" : "off");
- return true;
- };
- Button launchButton = new Button();
- launchButton.text = "Launch!".to!dstring;
- launchButton.click = (Widget sender) {
- string selectedResolution;
- for (int i = 0; i < radioButtons.length; i++) {
- if (radioButtons[i].checked) {
- selectedResolution = resolutionsAvailable[i];
- break;
- }
- }
-
- if (selectedResolution != "") {
- auto parts = selectedResolution.split('x');
- if (parts.length == 2) {
- int newWidth = parts[0].to!int;
- int newHeight = parts[1].to!int;
-
- systemSettings.screenWidth = newWidth;
- systemSettings.screenHeight = newHeight;
-
- saveSettingsToConfigFile("conf/settings.conf");
-
- writeln("resolution:: ", selectedResolution);
- import std.process;
- import std.file;
- std.process.spawnProcess(std.file.getcwd()~"/himmel-engine");
- Platform.instance.closeWindow(window);
- }
- } else {
- writeln("please, select resolution!");
- }
- return true;
- };
- vlayout.addChild(fullscreen);
- vlayout.addChild(audioState);
- vlayout.addChild(gamepadState);
- vlayout.addChild(launchButton);
- // show window
- window.mainWidget = vlayout;
- window.show();
- // run message loop
- return Platform.instance.enterMessageLoop();
- }
|