-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbentelk_FullScreenOptions.js
99 lines (85 loc) · 3.7 KB
/
bentelk_FullScreenOptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*:
* @plugindesc Adds a "Full Screen" option to the Options window
* @author Ben Hendel-Doying
*
* @help That's it! (It's actually a surprising amount of work, but you don't have to
* worry about that :P)
*/
(function() {
// built-in method for detecting full-screen is whack; this fixes that:
Graphics._isFullScreen = function() {
return !!(
(document.fullScreenElement && document.fullScreenElement !== null) ||
document.mozFullScreen ||
document.webkitFullscreenElement ||
document.msFullscreenElement
);
};
// add "Full Screen" option to options menu
Object.defineProperty(ConfigManager, 'fullscreen', {
get: function() {
return Graphics._isFullScreen();
},
set: function(value) {
if(value)
Graphics._requestFullScreen();
else
Graphics._cancelFullScreen();
},
configurable: true
});
let originalWindowOptionsInitialize = Window_Options.prototype.initialize;
Window_Options.prototype.initialize = function()
{
originalWindowOptionsInitialize.call(this);
// when the call is made to go fullscreen, or leave fullscreen, it isn't made instantly: SOME environments
// give us a Promise to work with; some apparently don't?? so we use event listeners instead. we attach them
// here (stupid browser prefixes...), and unattach them in Window_Options.close (below).
document.body.addEventListener('fullscreenchange', () => { this.fullScreenChangeHandler(); });
document.body.addEventListener('mozfullscreenchange', () => { this.fullScreenChangeHandler(); });
document.body.addEventListener('webkitfullscreenchange', () => { this.fullScreenChangeHandler(); });
document.body.addEventListener('msfullscreenchange', () => { this.fullScreenChangeHandler(); });
};
Window_Options.prototype.fullScreenChangeHandler = function() {
// redraw all the items (done in response to a fullscreen change, so that we can correctly update the ON/OFF
// label for fullscreenedness
let topIndex = this.topIndex();
for (let i = 0; i < this.maxPageItems(); i++) {
let index = topIndex + i;
if (index < this.maxItems()) {
this.redrawItem(index);
}
}
};
Window_Options.prototype.close = function()
{
Window_Base.prototype.close.call(this);
// remove all the full screen event listeners when we leave
document.body.removeEventListener('fullscreenchange');
document.body.removeEventListener('mozfullscreenchange');
document.body.removeEventListener('webkitfullscreenchange');
document.body.removeEventListener('msfullscreenchange');
};
let originalMakeData = ConfigManager.makeData;
ConfigManager.makeData = function() {
let config = originalMakeData.call(this);
config.fullscreen = this.fullscreen;
return config;
};
let originalApplyData = ConfigManager.applyData;
ConfigManager.applyData = function(config) {
originalApplyData.call(this, config);
this.fullscreen = this.readFullscreen(config, 'fullscreen');
};
// default value of true
ConfigManager.readFullscreen = function(config, name) {
return config.hasOwnProperty(name) ? !!config[name] : true;
};
let originalMakeCommandList = Window_Options.prototype.makeCommandList;
Window_Options.prototype.makeCommandList = function() {
this.addCommand('Full Screen', 'fullscreen');
originalMakeCommandList.call(this);
};
if(ConfigManager.fullscreen)
Graphics._requestFullScreen();
})();