Skip to content

Commit e57179c

Browse files
Add fullscreen toggle and launch options (#397)
1 parent a511bbb commit e57179c

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/GlobalVariables.as

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ package
108108
public var air_useWebsockets:Boolean = false;
109109
public var air_saveWindowPosition:Boolean = false;
110110
public var air_saveWindowSize:Boolean = false;
111+
public var air_useFullScreen:Boolean = false;
111112

112113
public var air_windowProperties:Object;
113114
public var file_replay_cache:FileCache = new FileCache("replays/cache.json", 1);
@@ -140,6 +141,7 @@ package
140141
air_useWebsockets = LocalOptions.getVariable("use_websockets", false);
141142
air_saveWindowPosition = LocalOptions.getVariable("save_window_position", false);
142143
air_saveWindowSize = LocalOptions.getVariable("save_window_size", false);
144+
air_useFullScreen = LocalOptions.getVariable("save_usefullscreen", false);
143145

144146
air_windowProperties = LocalOptions.getVariable("window_properties", {"x": 0, "y": 0, "width": 0, "height": 0});
145147

@@ -693,6 +695,16 @@ package
693695
}
694696
}
695697

698+
public function isFullScreen():Boolean
699+
{
700+
if (gameMain.stage)
701+
{
702+
return gameMain.stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE;
703+
}
704+
705+
return false;
706+
}
707+
696708
public function unlockTokenById(type:String, id:String):void
697709
{
698710
try

src/Main.as

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ package
166166
window.width = Math.max(100, _gvars.air_windowProperties.width + WINDOW_WIDTH_EXTRA);
167167
window.height = Math.max(100, _gvars.air_windowProperties.height + WINDOW_HEIGHT_EXTRA);
168168
}
169+
if (_gvars.air_useFullScreen)
170+
{
171+
_gvars.toggleFullScreen();
172+
}
169173
ignoreWindowChanges = false;
170174

171175
//- Load Menu Music

src/popups/settings/SettingsTabMisc.as

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package popups.settings
1919
import flash.net.navigateToURL;
2020
import flash.system.Capabilities;
2121
import menu.MainMenu;
22+
import flash.events.KeyboardEvent;
23+
import flash.ui.Keyboard;
2224

2325
public class SettingsTabMisc extends SettingsTabBase
2426
{
@@ -55,6 +57,8 @@ package popups.settings
5557
private var windowPositionSet:BoxButton;
5658
private var windowPositionReset:BoxButton;
5759
private var windowSavePositionCheck:BoxCheck;
60+
private var windowFullscreen:BoxCheck;
61+
private var windowSaveFullscreen:BoxCheck;
5862

5963
public function SettingsTabMisc(settingsWindow:SettingsWindow):void
6064
{
@@ -71,6 +75,8 @@ package popups.settings
7175
Main.window.addEventListener(NativeWindowBoundsEvent.MOVE, e_windowPropertyChange);
7276
Main.window.addEventListener(NativeWindowBoundsEvent.RESIZE, e_windowPropertyChange);
7377

78+
container.stage.addEventListener(KeyboardEvent.KEY_DOWN, e_onKeyDownMenu, true, int.MAX_VALUE - 10, true);
79+
7480
container.graphics.lineStyle(1, 0xFFFFFF, 0.35);
7581
container.graphics.moveTo(295, 15);
7682
container.graphics.lineTo(295, 405);
@@ -211,13 +217,21 @@ package popups.settings
211217
windowSavePositionCheck = new BoxCheck(container, xOff + 3, yOff + 3, clickHandler);
212218
yOff += 30;
213219

220+
new Text(container, xOff + 23, yOff, _lang.string("air_options_fullscreen"));
221+
windowFullscreen = new BoxCheck(container, xOff + 3, yOff + 3, clickHandler);
222+
223+
new Text(container, xOff + 133, yOff, _lang.string("air_options_launch_fullscreen"));
224+
windowSaveFullscreen = new BoxCheck(container, xOff + 113, yOff + 3, clickHandler);
225+
yOff += 30;
226+
214227
setTextMaxWidth(245);
215228
}
216229

217230
override public function closeTab():void
218231
{
219232
Main.window.removeEventListener(NativeWindowBoundsEvent.MOVE, e_windowPropertyChange);
220233
Main.window.removeEventListener(NativeWindowBoundsEvent.RESIZE, e_windowPropertyChange);
234+
container.stage.removeEventListener(KeyboardEvent.KEY_DOWN, e_onKeyDownMenu);
221235
}
222236

223237
override public function setValues():void
@@ -243,6 +257,8 @@ package popups.settings
243257

244258
windowSavePositionCheck.checked = _gvars.air_saveWindowPosition;
245259
windowSaveSizeCheck.checked = _gvars.air_saveWindowSize;
260+
windowSaveFullscreen.checked = _gvars.air_useFullScreen;
261+
windowFullscreen.checked = _gvars.isFullScreen();
246262
}
247263

248264
override public function clickHandler(e:MouseEvent):void
@@ -332,12 +348,14 @@ package popups.settings
332348
_gvars.air_windowProperties["x"] = windowXBox.validate(Math.round((Capabilities.screenResolutionX - Main.window.width) * 0.5));
333349
_gvars.air_windowProperties["y"] = windowYBox.validate(Math.round((Capabilities.screenResolutionY - Main.window.height) * 0.5));
334350
e_windowSetUpdate();
351+
windowFullscreen.checked = _gvars.isFullScreen();
335352
}
336353
else if (e.target == windowPositionReset)
337354
{
338355
_gvars.air_windowProperties["x"] = Math.round((Capabilities.screenResolutionX - Main.window.width) * 0.5);
339356
_gvars.air_windowProperties["y"] = Math.round((Capabilities.screenResolutionY - Main.window.height) * 0.5);
340357
e_windowSetUpdate();
358+
windowFullscreen.checked = _gvars.isFullScreen();
341359
}
342360

343361
// Window Size
@@ -354,12 +372,25 @@ package popups.settings
354372
_gvars.air_windowProperties["width"] = windowWidthBox.validate(Main.GAME_WIDTH);
355373
_gvars.air_windowProperties["height"] = windowHeightBox.validate(Main.GAME_HEIGHT);
356374
e_windowSetUpdate();
375+
windowFullscreen.checked = _gvars.isFullScreen();
357376
}
358377
else if (e.target == windowSizeReset)
359378
{
360379
_gvars.air_windowProperties["width"] = Main.GAME_WIDTH;
361380
_gvars.air_windowProperties["height"] = Main.GAME_HEIGHT;
362381
e_windowSetUpdate();
382+
windowFullscreen.checked = _gvars.isFullScreen();
383+
}
384+
else if (e.target == windowSaveFullscreen)
385+
{
386+
e.target.checked = !e.target.checked;
387+
_gvars.air_useFullScreen = !_gvars.air_useFullScreen;
388+
LocalOptions.setVariable("save_usefullscreen", _gvars.air_useFullScreen);
389+
}
390+
else if (e.target == windowFullscreen)
391+
{
392+
_gvars.toggleFullScreen();
393+
windowFullscreen.checked = _gvars.isFullScreen();
363394
}
364395
}
365396

@@ -372,6 +403,23 @@ package popups.settings
372403
}
373404
}
374405

406+
public function e_onKeyDownMenu(e:KeyboardEvent):void
407+
{
408+
var keyCode:int = e.keyCode;
409+
410+
if (keyCode == Keyboard.ESCAPE)
411+
{
412+
windowFullscreen.checked = false; //ESC exits fullscreen
413+
return;
414+
}
415+
416+
if (e.ctrlKey && keyCode == Keyboard.S)
417+
{
418+
windowFullscreen.checked = false; //CTRL+S also exits fullscreen
419+
return;
420+
}
421+
}
422+
375423
private function e_windowPropertyChange(e:Event):void
376424
{
377425
windowWidthBox.text = _gvars.air_windowProperties["width"];

0 commit comments

Comments
 (0)