-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_ScreenOrientation.js
221 lines (196 loc) Β· 7.38 KB
/
RS_ScreenOrientation.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
//================================================================
// RS_ScreenOrientation.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2017 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc <RS_ScreenOrientation>
* @author biud436
*
* @param Image
* @desc Prevent deletion.
* @default btn_fullscr
* @require 1
* @dir img/pictures
* @type file
*
* @param default orientation
* @type select
* @desc landscape, portrait
* @default landscape
* @option landscape
* @option portrait
*
* @help
* =============================================================================
* Test Devices
* =============================================================================
* Android Chrome (64.0.3282.137) - Supported
* iOS Safari (iPhone8) - Not Supported
* =============================================================================
* How to setup an image
* =============================================================================
* Download an image from
* https://github.com/biud436/MV/blob/master/docs/images/btn_fullscr.png
* and then place it in your img/pictures folder.
* =============================================================================
* Version Log
* =============================================================================
* 2017.02.16 (v1.0.0) - First Release
* 2018.03.01 (v1.0.1) :
* - Changed the image and works.
* - Added the feature that can automatically hide the image when changing the screen orientation is to a landscape.
* - Fixed the bug that causes when restarting the game.
*/
/*:ko
* @plugindesc <RS_ScreenOrientation>
* @author biud436
*
* @param Image
* @text μ΄λ―Έμ§
* @desc Prevent deletion.
* @default btn_fullscr
* @require 1
* @dir img/pictures
* @type file
*
* @param default orientation
* @text κΈ°λ³Έ νλ©΄ λ°©ν₯
* @type select
* @desc κΈ°λ³Έ νλ©΄ λ°©ν₯μ μ€μ ν©λλ€.
* @default landscape
* @option landscape (κ°λ‘)
* @value landscape
* @option portrait (μΈλ‘)
* @value portrait
*
* @help
*
* νλ¬κ·ΈμΈ μλλ‘μ΄λ ν¬λ‘¬ μΉ λΈλΌμ°μ μ μ©μ
λλ€. (νμ μΆκ°ν μνκ° μλ λ)
*
* νλ©΄ λ°©ν₯ λ³κ²½μ λν κΆνμ λ³΄ν΅ λ²νΌμ λλ₯΄λ κ²κ³Ό κ°μ μ€μ μνΈ μμ©μ΄ μμ λμλ§
* μ»μ μ μμ΅λλ€.
*
* κ·Έλμ μ 체 νλ©΄ λ³κ²½ λ²νΌμ λλ¬μΌλ§ νλ©΄ λ°©ν₯μ λ³κ²½λκ² λ§λ€ μ λ°μ μμμ΅λλ€.
*
* =============================================================================
* ν
μ€νΈ κΈ°κΈ°
* =============================================================================
*
* Android Chrome (64.0.3282.137) - ν¬λ‘¬ λΈλΌμ°μ μμλ§ μ§μν©λλ€.
* iOS Safari (iPhone8) - μ¬ν리λ μ΄ κΈ°λ₯μ μ§μνμ§ μμ΅λλ€.
*
* =============================================================================
* μ΄λ―Έμ§ μ€μ λ°©λ²
* =============================================================================
*
* μ΄λ―Έμ§λ₯Ό λ€μ λ§ν¬μμ λ€μ΄λ‘λ λ°μ ν img/pictures ν΄λμ μΆκ°νμΈμ.
*
* λ§ν¬ - https://github.com/biud436/MV/blob/master/docs/images/btn_fullscr.png
*
* =============================================================================
* λ³λ μ¬ν
* =============================================================================
* 2017.02.16 (v1.0.0) - First Release
* 2018.03.01 (v1.0.1) :
* - Changed the image and works.
* - Added the feature that can automatically hide the image when changing the screen orientation is to a landscape.
* - Fixed the bug that causes when restarting the game.
*/
var Imported = Imported || {};
Imported.ScreenOrientation = true;
(function () {
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_ScreenOrientation>');
});
parameters = (parameters.length > 0) && parameters[0].parameters;
var tempEvent;
//============================================================================
// Graphics
//============================================================================
Graphics._convertScreenOrientation = function (event) {
Graphics._requestFullScreen();
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
if(orientation) {
orientation.lock(parameters["default orientation"]).then(null, function(error) {});
}
if(event) event.preventDefault();
};
//============================================================================
// Scene_Title
//============================================================================
var alias_Scene_Title_create = Scene_Title.prototype.create;
Scene_Title.prototype.create = function () {
alias_Scene_Title_create.call(this);
if(Utils.isMobileDevice()) {
var userAgent = window.navigator.userAgent || "";
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
// A Safari Mobile is not supported in ScreenOrientation API.
} else if(userAgent.match(/Chrome/i) || userAgent.match(/Chromium/i) || userAgent.match(/Firefox/i)) {
this.createFullscreenImage();
}
}
};
Scene_Title.prototype.createFullscreenImage = function () {
var div, path, filePath, img, imgName;
var target_div = document.querySelector("#div_fullscr");
if(target_div) document.body.removeChild(target_div);
div = document.createElement("div");
div.id = "div_fullscr";
imgName = parameters["Image"] + ".png";
if (Utils.RPGMAKER_VERSION >= "1.6.0" && Utils.isNwjs()) {
path = require('path');
var base, root;
base = path.dirname(process.mainModule.filename);
root = path.join(base, "img", "pictures");
filePath = path.join(root, imgName);
} else {
filePath = "img/pictures/" + imgName;
}
img = new Image();
img.id = "btn_fullscr";
img.src = filePath;
img.hidden = true;
img.width = 96;
img.height = 96;
img.addEventListener("click", function (e) {
Graphics._convertScreenOrientation(e);
}, false);
img.addEventListener("touchend", function (e) {
Graphics._convertScreenOrientation(e);
}, false);
div.appendChild(img);
div.style.zIndex = 98;
Graphics._centerElement(div);
document.body.appendChild(div);
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
if(orientation) {
window.addEventListener("orientationchange", Scene_Title.prototype.onorientationchange.bind(this), false);
if (!orientation.type.match(/(?:landscape)/)) {
img.hidden = false;
}
}
this.on('removed', function () {
var target_div = document.querySelector("#div_fullscr");
if(target_div) document.body.removeChild(target_div);
}, this);
};
Scene_Title.prototype.onorientationchange = function () {
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
if(!orientation) return;
if (orientation.type.match(/(?:landscape)/)) {
var target_div = document.querySelector("#div_fullscr");
if(target_div) {
target_div.hidden = true;
}
} else {
var target_div = document.querySelector("#div_fullscr");
if(target_div) {
target_div.hidden = false;
}
}
};
})();