forked from biud436/MV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RS_ScreenOrientation.js
213 lines (188 loc) · 6.99 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
/*:
* @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;
}
}
};
})();