-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCXJ_Exit.js
296 lines (273 loc) · 10.7 KB
/
CXJ_Exit.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/******************************************************************************
* CXJ_Exit.js *
******************************************************************************
* Exit v1.0.1 *
* By G.A.M. Kertopermono, a.k.a. GaryCXJk *
* License: CC0 1.0 Universal *
* https://creativecommons.org/publicdomain/zero/1.0/ *
******************************************************************************/
var Imported = Imported || {};
Imported.CXJ_Exit = "1.0.1";
/*:
* @target MZ
* @plugindesc MZ v1.0.1 Adds an exit option to desktop versions of the game
* @author G.A.M. Kertopermono
*
* @help
* ============================================================================
* = About =
* ============================================================================
*
* As you all know HTML5 games don't generally need exit buttons. Neither do
* mobile versions, as you can just Back or Home your way out. But with desktop
* that's a whole different thing. You do want to get out without having to
* resort to using CTRL+F4 or something similar.
*
* This plugin adds this option to both the title screen as well as the Game
* End option.
*
* ============================================================================
* = Usage =
* ============================================================================
*
* After you add the plugin, you can set the parameters. They're pretty much
* self-explanatory. "Text - Exit" and "Text - To Desktop" are the text labels
* for each respective button. The first appears in the title screen, the
* latter in the Game End window.
*
* "Add to title" and "Add to Game End" both are boolean values, and determine
* whether or not the new buttons should be added.
*
* On non-desktop browsers the game won't add the exit options. They could be
* made visible, but they don't work, so it's pretty useless to keep them.
*
* ============================================================================
* = Plugin Commands =
* ============================================================================
*
* This plugin contains Plugin Commands. These are as followed:
*
* Exit
* ----
* Exits the game. This can be executed for both desktop and browser-based
* clients, but it would only work on desktop.
*
* ============================================================================
* = Compatibility =
* ============================================================================
*
* This plugin overwrites the functions listed below, but still uses the old
* version, either as the basis for the function or as a fallback. It is
* advised to place this script below other scripts that use these functions.
*
* - Scene_Title.prototype.createCommandWindow
* - Window_TitleCommand.prototype.makeCommandList
* - Scene_GameEnd.prototype.createCommandWindow
* - Window_GameEnd.prototype.makeCommandList
* - Game_Interpreter.prototype.pluginCommand
*
* ============================================================================
* = Changelog =
* ============================================================================
*
* 1.0.1, MZ edition (2022-11-01)
* ------------------------------
*
* * Ported to RPG Maker MZ by McKathlin
*
* 1.0.1 (2015-10-27)
* ------------------
*
* * Added script rename fallback
*
* 1.0.0 (2015-10-26)
* ------------------
*
* * Initial release
*
* ============================================================================
* = License =
* ============================================================================
*
* CC0 1.0 Universal (CC0 1.0)
* Public Domain Dedication
*
* The person who associated a work with this deed has dedicated the work to
* the public domain by waiving all of his or her rights to the work worldwide
* under copyright law, including all related and neighboring rights, to the
* extent allowed by law.
*
* You can copy, modify, distribute and perform the work, even for commercial
* purposes, all without asking permission.
*
* https://creativecommons.org/publicdomain/zero/1.0/
* ============================================================================
*
* @param Text - Exit
* @desc The exit text.
* @default Exit
*
* @param Text - To Desktop
* @desc The exit to desktop text.
* @default To Desktop
*
* @param Add to title
* @type boolean
* @desc Add the exit option to the title screen?
* @default true
*
* @param Add to Game End
* @type boolean
* @desc Add the exit option to the Game End window?
* @default true
*
* @command Exit
* @desc Exit directly to desktop.
*/
(() => {
+function() {
if(Utils.isNwjs()) {
var _pluginName = 'CXJ_Exit';
var _propNames = ['Text - Exit', 'Text - To Desktop', 'Add to title', 'Add to Game End'];
var _defaultParams = {
'Text - Exit' : 'Exit',
'Text - To Desktop' : 'To Desktop',
'Add to title' : 'true',
'Add to Game End' : 'true'
};
var _getParameters = function(pluginName, propNames, defaultParams) {
/* Private function that checks plugin content */
var _checkPluginContent = function(parameters) {
for(var prop in parameters) {
if(parameters.hasOwnProperty(prop)) {
return true;
}
}
return false;
}
var parameters = PluginManager.parameters(pluginName);
if(_checkPluginContent(parameters)) {
return parameters;
}
var currentScript = document.currentScript;
if(currentScript) {
var scriptName = document.currentScript.src;
scriptName = scriptName.substr(scriptName.indexOf('js/plugins/') + 11);
scriptName = scriptName.substr(0, scriptName.lastIndexOf('.js'));
parameters = PluginManager.parameters(scriptName);
}
if(_checkPluginContent(parameters)) {
return parameters;
}
for(var idx = 0; idx < $plugins.length; idx++) {
var plugin = $plugins[idx];
var params = plugin.parameters;
if(plugin.description.indexOf('<' + pluginName + '>') > -1) {
return params;
}
var hasFound = true;
for(var idx = 0; idx < _propNames.length; idx++) {
if(!params.hasOwnProperty(propNames[idx])) {
hasFound = false;
break;
}
}
if(hasFound) {
return params;
}
}
return _defaultParams;
}
var parameters = _getParameters(_pluginName, _propNames, _defaultParams);
TextManager.cxjExit = parameters['Text - Exit'];
TextManager.cxjToDesktop = parameters['Text - To Desktop'];
/*----------------*
*- Title screen -*
*----------------*/
if(parameters['Add to title'].toLowerCase() != 'false') {
+function() {
var oldCreateCommandWindow = Scene_Title.prototype.createCommandWindow;
Scene_Title.prototype.createCommandWindow = function() {
oldCreateCommandWindow.apply(this, arguments);
this._commandWindow.setHandler('exit', this.commandExit.bind(this));
}
// Alias method added for MZ edition
// Expand window height to accommodate additional option
var oldTitleRect = Scene_Title.prototype.commandWindowRect;
Scene_Title.prototype.commandWindowRect = function() {
var rect = oldTitleRect.call(this);
const itemHeight = Window_Selectable.prototype.itemHeight();
var newHeight = rect.height + itemHeight;
var newY = rect.y - Math.round(itemHeight / 2);
return new Rectangle(rect.x, newY, rect.width, newHeight);
}
Scene_Title.prototype.commandExit = function() {
this._commandWindow.close();
this.fadeOutAll();
SceneManager.exit();
}
var oldMakeCommandList = Window_TitleCommand.prototype.makeCommandList;
Window_TitleCommand.prototype.makeCommandList = function() {
oldMakeCommandList.apply(this, arguments);
this.addCommand(TextManager.cxjExit, 'exit');
}
}();
}
/*------------*
*- Game End -*
*------------*/
if(parameters['Add to Game End'].toLowerCase() != 'false') {
+function() {
var oldCreateCommandWindow = Scene_GameEnd.prototype.createCommandWindow;
Scene_GameEnd.prototype.createCommandWindow = function() {
oldCreateCommandWindow.call(this);
this._commandWindow.setHandler('exit', this.commandExit.bind(this));
}
// Alias method added for MZ edition
// Expand window height to accommodate additional option
var oldCommandWindowRect = Scene_GameEnd.prototype.commandWindowRect;
Scene_GameEnd.prototype.commandWindowRect = function() {
var rect = oldCommandWindowRect.call(this);
const itemHeight = Window_Selectable.prototype.itemHeight();
var newHeight = rect.height + itemHeight;
var newY = rect.y - Math.round(itemHeight / 2);
return new Rectangle(rect.x, newY, rect.width, newHeight);
}
Scene_GameEnd.prototype.commandExit = function() {
this._commandWindow.close();
this.fadeOutAll();
SceneManager.exit();
}
var oldMakeCommandList = Window_GameEnd.prototype.makeCommandList;
Window_GameEnd.prototype.makeCommandList = function() {
oldMakeCommandList.call(this);
for(var idx = 0; idx < this._list.length; idx++) {
if(this._list[idx].symbol == 'cancel') {
this._list.splice(idx, 0, {name: TextManager.cxjToDesktop, symbol: 'exit', enabled: true, ext: null});
break;
}
}
}
}();
}
/*------------------*
*- Plugin Command -*
*------------------*/
PluginManager.registerCommand('CXJ_Exit', "Exit", args => {
SceneManager.exit();
});
// MV edition code
/*
+function() {
var oldPluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
oldPluginCommand.call(this, command, args);
if (command === 'Exit') {
SceneManager.exit();
}
};
}();
*/
}
}();
})();