forked from aaixy/rm-mvmz-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameInputMobile.js
349 lines (298 loc) · 9.36 KB
/
NameInputMobile.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//=============================================================================
// NameInput.js
//=============================================================================
/*:
* @plugindesc 名字输入
* @author wangwang
*
*
* @help
* 帮助的信息
* 用网页输入代替原本的名字输入
*
*
*
*/
function Window_BC() {
this.initialize.apply(this, arguments);
}
(function() {
Scene_Name.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Name.prototype.constructor = Scene_Name;
//初始化
Scene_Name.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
//准备
Scene_Name.prototype.prepare = function(actorId, maxLength) {
this._actorId = actorId;
this._maxLength = maxLength;
};
//创建
Scene_Name.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this._actor = $gameActors.actor(this._actorId);
this.createEditWindow();
this.createBCWindow();
};
//开始
Scene_Name.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);
this._editWindow.refresh();
};
//创建编辑窗口
Scene_Name.prototype.createEditWindow = function() {
this._editWindow = new Window_NameEdit(this._actor, this._maxLength);
this.addWindow(this._editWindow);
};
Scene_Name.prototype.createBCWindow = function() {
var x = this._editWindow.x + this._editWindow.left()
var y = this._editWindow.y + 54
var width = this._editWindow.charWidth() * this._maxLength
var height = this._editWindow.lineHeight()
Graphics._addInput("text",x,y, width,height, this._editWindow.standardFontSize())
Graphics._input.maxLength = this._maxLength
Graphics._input.value = this._actor.name().slice(0, this._maxLength);
this._bcWindow = new Window_BC("保存");
this._bcWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width
this._bcWindow.y = this._editWindow.y +this._editWindow.height
this._bcWindow.setHandler('dianji', this.onInputOk.bind(this));
this.addWindow(this._bcWindow);
this._csWindow = new Window_BC("还原");
this._csWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width - this._bcWindow.width
this._csWindow.y = this._editWindow.y +this._editWindow.height
this._csWindow.setHandler('dianji', this.oncs.bind(this));
this.addWindow(this._csWindow);
};
//输入初始化
Scene_Name.prototype.oncs = function() {
Graphics._input.value = this._actor.name().slice(0, this._maxLength);
};
//当输入确定
Scene_Name.prototype.onInputOk = function() {
var name="" + Graphics._input.value
this._actor.setName(name);
this.popScene();
Graphics._removeInput()
};
//名称编辑窗口
Window_NameEdit.prototype = Object.create(Window_Base.prototype);
Window_NameEdit.prototype.constructor = Window_NameEdit;
//初始化
Window_NameEdit.prototype.initialize = function(actor, maxLength) {
var width = this.windowWidth();
var height = this.windowHeight();
var x = (Graphics.boxWidth - width) / 2;
var y = (Graphics.boxHeight - (height + this.fittingHeight(9) + 8)) / 2;
Window_Base.prototype.initialize.call(this, x, y, width, height);
this._actor = actor;
this._name = actor.name().slice(0, this._maxLength);
this._index = this._name.length;
this._maxLength = maxLength;
this._defaultName = this._name;
this.deactivate();
this.refresh();
ImageManager.loadFace(actor.faceName());
};
//窗口宽
Window_NameEdit.prototype.windowWidth = function() {
return 480;
};
//窗口高
Window_NameEdit.prototype.windowHeight = function() {
return this.fittingHeight(4);
};
//名称
Window_NameEdit.prototype.name = function() {
return this._name;
};
//脸宽
Window_NameEdit.prototype.faceWidth = function() {
return 144;
};
//字符宽
Window_NameEdit.prototype.charWidth = function() {
var text = '我';
return this.textWidth(text);
};
//左
Window_NameEdit.prototype.left = function() {
var nameCenter = (this.contentsWidth() + this.faceWidth()) / 2;
var nameWidth = (this._maxLength + 1) * this.charWidth();
return Math.min(nameCenter - nameWidth / 2, this.contentsWidth() - nameWidth);
};
//刷新
Window_NameEdit.prototype.refresh = function() {
this.contents.clear();
this.drawActorFace(this._actor, 0, 0);
};
//随便写的点击窗口....
Window_BC.prototype = Object.create(Window_Base.prototype);
Window_BC.prototype.constructor = Window_BC;
//初始化
Window_BC.prototype.initialize = function(text) {
var width = 80
var height = this.fittingHeight(1);
Window_Base.prototype.initialize.call(this, 0, 0, width, height);
this._handlers = {};
this._text = '';
this.setText(text)
};
Window_BC.prototype.standardFontSize = function() {
return 16;
};
Window_BC.prototype.lineHeight = function() {
return 20;
};
Window_BC.prototype.standardPadding = function() {
return 16;
};
Window_BC.prototype.textPadding = function() {
return 0;
};
//设置文本
Window_BC.prototype.setText = function(text) {
if (this._text !== text) {
this._text = text;
this.refresh();
}
};
//清除
Window_BC.prototype.clear = function() {
this.setText('');
};
//刷新
Window_BC.prototype.refresh = function() {
this.contents.clear();
this.drawTextEx(this._text, this.textPadding(), 0);
};
Window_BC.prototype.update = function() {
Window_Base.prototype.update.call(this);
this.dianji()
};
Window_BC.prototype.setHandler = function(symbol, method) {
this._handlers[symbol] = method;
};
Window_BC.prototype.isHandled = function(symbol) {
return !!this._handlers[symbol];
};
Window_BC.prototype.callHandler = function(symbol) {
if (this.isHandled(symbol)) {
this._handlers[symbol]();
}
};
Window_BC.prototype.dianji = function() {
if (this.isOpen()) {
if (TouchInput.isTriggered()) {
var x = this.canvasToLocalX(TouchInput.x);
var y = this.canvasToLocalY(TouchInput.y);
if(x >= 0 && y >= 0 && x < this.width && y < this.height){
this.callHandler("dianji")
}
}
}
};
Graphics._createAllElements = function() {
this._createErrorPrinter();
this._createCanvas();
this._createVideo();
this._createUpperCanvas();
this._createRenderer();
this._createFPSMeter();
this._createModeBox();
this._createGameFontLoader();
this._createInput() //修改
};
/**更新所有成分
* @static
* @method _updateAllElements
* @private
*/
Graphics._updateAllElements = function() {
this._updateRealScale();
this._updateErrorPrinter();
this._updateCanvas();
this._updateVideo();
this._updateUpperCanvas();
this._updateRenderer();
this._updateInput(); //添加
this._paintUpperCanvas();
};
//创建输入
Graphics._createInput = function() {
this._input = document.createElement("input");
this._input.id = 'Input';
this._input.type ="text";
this._input.style.imeMode = 'active';
this._input._sx ={};
var sx = this._input._sx;
sx.xs = false;
sx.x= 0;
sx.y=0;
sx.width =100;
sx.height= 20;
sx.fontSize = 18;
//document.body.appendChild(this._input);
};
//添加输入
Graphics._addInput = function(type,x,y,width,height,fontSize) {
this._input.type = type || "text"
var sx = this._input._sx
sx.x= x
sx.y= y
sx.width = width|| 100
sx.height= height|| 20
sx.fontSize = fontSize || 18
this._updateInput()
sx.xs = true
document.body.appendChild(this._input);
this._input.focus();
};
//移除输入
Graphics._removeInput = function() {
this._input.remove()
this._input.value = null
this._input._xs = false
//document.body.appendChild(this._input);
};
//更新输入
Graphics._updateInput =function () {
this._input.style.zIndex = 12;
var sx = this._input._sx
var x = sx.x * this._realScale + (window.innerWidth - this._width * this._realScale) / 2
var y = sx.y * this._realScale + (window.innerHeight - this._height * this._realScale) / 2
var width = sx.width * this._realScale;
var height = sx.height * this._realScale;
var fontSize = sx.fontSize * this._realScale;
this._input.style.position = 'absolute';
this._input.style.margin = 'auto';
this._input.style.top = y + 'px';
this._input.style.left = x + 'px' ;
this._input.style.width = width + 'px';
this._input.style.height = height + 'px';
this._input.style.fontSize = fontSize + 'px';
}
//防止默认
Input._onKeyDown = function(event) {
//如果 需要避免默认 (键值)
if (this._shouldPreventDefault(event.keyCode)) {
if (Graphics && Graphics._input && Graphics._input._sx && Graphics._input._sx.xs){
//允许默认
}else {
//避免默认
event.preventDefault();
}
}
//键值===144
if (event.keyCode === 144) { // Numlock 数字开关
//清除
this.clear();
}
var buttonName = this.keyMapper[event.keyCode];
//如果 键名
if (buttonName) {
//当前状态 键 =true
this._currentState[buttonName] = true;
}
};
})();