forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_MapNodesTravel.js
478 lines (436 loc) · 14.2 KB
/
MrTS_MapNodesTravel.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//=============================================================================
// MrTS_MapNodesTravel.js
//=============================================================================
/*:
* @plugindesc Allows to travel to different maps through node selection.
* @author Mr. Trivel
*
* @param Cursor Offset
* @desc Offset for Cursor image. X Y
* Default: 0 -48
* @default 0 -48
*
* @param Info Offset
* @desc Offset for Info image. X Y
* Default: -88 -118
* @default -88 -118
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial and non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.0
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Setting up nodes
* --------------------------------------------------------------------------------
* Open up this plugin in your favorite text editor and scroll down to the part
* where it says EDIT MAP NODES HERE - follow the structure there.
* "keyName": {
* picture: "pictureName",
* xMenu: number,
* yMenu: number,
* mapID: number,
* mapX: number,
* mapY: number
* },
*
* "keyName" - key name of node that will be used to lock/unlock it - single word.
* picture - picture name to show above the node
* xMenu - X position in meun
* yMenu - Y position in menu
* mapID - map ID to teleport to
* mapX - map X to teleport to
* mapY - map Y to teleport to
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* MapNode Enter - Enters MapNode scene
*
* MapNode Show [KEYNAME] - Adds node on the map
* MapNode Hide [KEYNAME] - Removes node from the map
*
* MapNode Lock [KEYNAME] - Locks node on the map
* MapNode Unlock [KEYNAME] - Unlocks node on the map
*
* Examples:
* MapNode Enter
*
* MapNode Show Forest
* MapNode Hide Forest
*
* MapNode Lock Graveyard
* Mapnode Unlock StoneFarm
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Pictures
* --------------------------------------------------------------------------------
* All pictures go into img\system folder.
* Default pictures:
* img\system\mapNodeCursor.png
* img\system\mapNodeBackground.png
* img\system\mapNodeLocked.png
* img\system\mapNodeUnlocked.png
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
*/
(function() {
var mapNodeList = {
//--------------------------------------------------------------------------------
// EDIT MAP NODES HERE v
//--------------------------------------------------------------------------------
"forest": {
picture: "forestNode",
xMenu: 182,
yMenu: 302,
mapId: 2,
mapX: 24,
mapY: 20
},
"advGuild": {
picture: "guildNode",
xMenu: 702,
yMenu: 192,
mapId: 5,
mapX: 10,
mapY: 17
},
"node1": {
picture: "node",
xMenu: 1117,
yMenu: 204,
mapId: 2,
mapX: 24,
mapY: 20
},
"node2": {
picture: "node",
xMenu: 458,
yMenu: 624,
mapId: 2,
mapX: 24,
mapY: 20
},
"node3": {
picture: "node",
xMenu: 991,
yMenu: 557,
mapId: 2,
mapX: 24,
mapY: 20
},
"node4": {
picture: "node",
xMenu: 168,
yMenu: 672,
mapId: 2,
mapX: 24,
mapY: 20
},
"node5": {
picture: "node",
xMenu: 912,
yMenu: 312,
mapId: 2,
mapX: 24,
mapY: 20
}
//--------------------------------------------------------------------------------
// EDIT MAP NODES THERE ^
//--------------------------------------------------------------------------------
}
var parameters = PluginManager.parameters('MrTS_MapNodesTravel');
var paramCursorOffset = String(parameters['Cursor Offset'] || "0 -48");
var paramCursorOffsetData = paramCursorOffset.split(' ');
paramCursorOffsetData[0] = Number(paramCursorOffsetData[0]);
paramCursorOffsetData[1] = Number(paramCursorOffsetData[1]);
var paramInfoOffset = String(parameters['Info Offset'] || "-88 -118");
var paramInfoOffsetData = paramInfoOffset.split(' ');
paramInfoOffsetData[0] = Number(paramInfoOffsetData[0]);
paramInfoOffsetData[1] = Number(paramInfoOffsetData[1]);
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "mapnode") {
switch (args[0].toUpperCase())
{
case 'ENTER':
{
SceneManager.push(Scene_MapNodes);
} break;
case 'SHOW':
{
$gameSystem.showMapNode(args[1]);
} break;
case 'HIDE':
{
$gameSystem.hideMapNode(args[1]);
} break;
case 'LOCK':
{
$gameSystem.lockMapNode(args[1]);
} break;
case 'UNLOCK':
{
$gameSystem.unlockMapNode(args[1]);
} break;
}
}
};
//--------------------------------------------------------------------------
// Game_System
//
_Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this._nodesShown = [];
this._nodesLocked = [];
};
Game_System.prototype.showMapNode = function(keyname) {
if (!mapNodeList[keyname]) {
console.warn(keyname + " doesn't exist in mapNodeList!");
return;
}
if (!this.mapNodeShown(keyname)) this._nodesShown.push(keyname);
};
Game_System.prototype.hideMapNode = function(keyname) {
if (this.mapNodeShown(keyname))
this._nodesShown.splice(this._nodesShown.indexOf(keyname), 1);
};
Game_System.prototype.lockMapNode = function(keyname) {
if (!mapNodeList[keyname]) {
console.warn(keyname + " doesn't exist in mapNodeList!");
return;
}
if (!this.mapNodeLocked(keyname)) this._nodesLocked.push(keyname);
};
Game_System.prototype.unlockMapNode = function(keyname) {
if (this.mapNodeLocked(keyname))
this._nodesLocked.splice(this._nodesLocked.indexOf(keyname), 1);
};
Game_System.prototype.mapNodeShown = function(keyname) {
return this._nodesShown.contains(keyname);
};
Game_System.prototype.mapNodeLocked = function(keyname) {
return this._nodesLocked.contains(keyname);
};
Game_System.prototype.getMapNodesShown = function() {
return this._nodesShown;
};
//--------------------------------------------------------------------------
// Scene_MapNodes
//
// Map Nodes scene. For travelling.
function Scene_MapNodes() {
this.initialize.apply(this, arguments);
};
Scene_MapNodes.prototype = Object.create(Scene_Base.prototype);
Scene_MapNodes.prototype.constructor = Scene_MapNodes;
Scene_MapNodes.prototype.initialize = function() {
Scene_Base.prototype.initialize.call(this);
};
Scene_MapNodes.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this.createBackground();
this.createWindowLayer();
this.createSelectionWindow();
};
Scene_MapNodes.prototype.createBackground = function() {
this._backgroundImage = new Sprite();
this._backgroundImage.bitmap = ImageManager.loadSystem("mapNodeBackground");
this.addChild(this._backgroundImage);
};
Scene_MapNodes.prototype.createSelectionWindow = function() {
this._selectWindow = new Window_MapNodes();
this._selectWindow.setHandler('ok', this.selectOk.bind(this));
this._selectWindow.setHandler('cancel', this.popScene.bind(this));
this._selectWindow.select(0);
this._selectWindow.activate();
this.addWindow(this._selectWindow);
};
Scene_MapNodes.prototype.selectOk = function() {
var node = mapNodeList[$gameSystem.getMapNodesShown()[this._selectWindow.index()]];
console.log(node);
$gamePlayer.reserveTransfer(node.mapId, node.mapX, node.mapY, 2, 0);
this.popScene();
};
//--------------------------------------------------------------------------
// Window_MapNodes
//
// Shows all nodes and allows travelling between them.
function Window_MapNodes() {
this.initialize.apply(this, arguments);
};
Window_MapNodes.prototype = Object.create(Window_Selectable.prototype);
Window_MapNodes.prototype.constructor = Window_MapNodes;
Window_MapNodes.prototype.initialize = function() {
var sp = this.standardPadding();
this._nodes = [];
this._cursor = new Sprite();
this._info = new Sprite();
this._cursor.bitmap = ImageManager.loadSystem("mapNodeCursor");
this._nodeLockedBitmap = ImageManager.loadSystem("mapNodeLocked");
this._nodeUnlockedBitmap = ImageManager.loadSystem("mapNodeUnlocked");
Window_Selectable.prototype.initialize.call(this, -sp, -sp, Graphics.boxWidth+sp, Graphics.boxHeight+sp);
var nodes = $gameSystem.getMapNodesShown();
for (var i = 0; i < this.maxItems(); i++) {
var node = mapNodeList[nodes[i]];
var tmpSpr = new Sprite();
tmpSpr.bitmap = $gameSystem.mapNodeLocked(nodes[i]) ? this._nodeLockedBitmap : this._nodeUnlockedBitmap;
tmpSpr.x = node.xMenu;
tmpSpr.y = node.yMenu;
this._nodes.push(tmpSpr);
this.addChild(tmpSpr);
}
var rect = this.itemRect(0);
this._cursor.x = rect.x;
this._cursor.y = rect.y;
var node = mapNodeList[nodes[0]];
this._info.bitmap = ImageManager.loadSystem(node.picture);
this._info.x = node.xMenu + paramInfoOffsetData[0];
this._info.y = node.yMenu + paramInfoOffsetData[1];
this.addChild(this._cursor);
this.addChild(this._info);
this.opacity = 0;
this.refresh();
};
Window_MapNodes.prototype.maxItems = function() {
return $gameSystem.getMapNodesShown().length;
};
Window_MapNodes.prototype.updateCursor = function() {
this.setCursorRect(0, 0, 0, 0);
};
Window_MapNodes.prototype.itemRect = function(index) {
var rect = new Rectangle;
var nodes = $gameSystem.getMapNodesShown();
var node = mapNodeList[nodes[index]];
if ($gameSystem.mapNodeLocked(nodes[index]) && this._nodeLockedBitmap.isReady())
{
rect.x = node.xMenu;
rect.y = node.yMenu;
rect.width = this._nodeLockedBitmap.width;
rect.height = this._nodeLockedBitmap.height;
}
else if (!$gameSystem.mapNodeLocked(nodes[index]) && this._nodeUnlockedBitmap.isReady())
{
rect.x = node.xMenu;
rect.y = node.yMenu;
rect.width = this._nodeUnlockedBitmap.width;
rect.height = this._nodeUnlockedBitmap.height;
}
else
{
rect.x = node.xMenu;
rect.y = node.yMenu;
rect.width = 48;
rect.height = 48;
}
rect.x -= this.standardPadding();
rect.y -= this.standardPadding();
return rect;
};
Window_MapNodes.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
var node = mapNodeList[$gameSystem.getMapNodesShown()[this.index()]];
var tX = node.xMenu + paramCursorOffsetData[0];
var tY = node.yMenu + paramCursorOffsetData[1];
var dX = tX - this._cursor.x;
var dY = tY - this._cursor.y;
this._cursor.x += dX * 0.08;
this._cursor.y += dY * 0.08;
};
Window_MapNodes.prototype.updateInfoSprite = function() {
var nodes = $gameSystem.getMapNodesShown();
var node = mapNodeList[nodes[this.index()]];
this._info.x = node.xMenu + paramInfoOffsetData[0];
this._info.y = node.yMenu + paramInfoOffsetData[1];
this._info.bitmap = ImageManager.loadSystem(node.picture);
};
Window_MapNodes.prototype.cursorDown = function(wrap) {
var lowerWithY = [];
var index = this.index();
for (var i = 0; i < this._nodes.length; i++) {
if (this._nodes[i].y > this._nodes[index].y)
lowerWithY.push(i);
}
var cs = this._nodes;
var df = this.distance;
lowerWithY.sort(function(a, b) {
return df(cs[index].x, cs[index].y, cs[a].x, cs[a].y) - df(cs[index].x, cs[index].y, cs[b].x, cs[b].y)
});
if (lowerWithY.length > 0) this.select(lowerWithY[0]);
this.updateInfoSprite();
};
Window_MapNodes.prototype.cursorUp = function(wrap) {
var higherWithY = [];
var index = this.index();
for (var i = 0; i < this._nodes.length; i++) {
if (this._nodes[i].y < this._nodes[index].y)
higherWithY.push(i);
}
var cs = this._nodes;
var df = this.distance;
higherWithY.sort(function(a, b) {
return df(cs[index].x, cs[index].y, cs[a].x, cs[a].y) - df(cs[index].x, cs[index].y, cs[b].x, cs[b].y)
});
if (higherWithY.length > 0) this.select(higherWithY[0]);
this.updateInfoSprite();
};
Window_MapNodes.prototype.cursorRight = function(wrap) {
var higherWithX = [];
var index = this.index();
for (var i = 0; i < this._nodes.length; i++) {
if (this._nodes[i].x > this._nodes[index].x)
higherWithX.push(i);
}
var cs = this._nodes;
var df = this.distance;
higherWithX.sort(function(a, b) {
return df(cs[index].x, cs[index].y, cs[a].x, cs[a].y) - df(cs[index].x, cs[index].y, cs[b].x, cs[b].y)
});
if (higherWithX.length > 0) this.select(higherWithX[0]);
this.updateInfoSprite();
};
Window_MapNodes.prototype.cursorLeft = function(wrap) {
var lowerWithX = [];
var index = this.index();
for (var i = 0; i < this._nodes.length; i++) {
if (this._nodes[i].x < this._nodes[index].x)
lowerWithX.push(i);
}
var cs = this._nodes;
var df = this.distance;
lowerWithX.sort(function(a, b) {
return df(cs[index].x, cs[index].y, cs[a].x, cs[a].y) - df(cs[index].x, cs[index].y, cs[b].x, cs[b].y)
});
if (lowerWithX.length > 0) this.select(lowerWithX[0]);
this.updateInfoSprite();
};
Window_MapNodes.prototype.distance = function(x1, y1, x2, y2) {
var a = x1 - x2;
var b = y1 - y2;
return Math.abs(a) + Math.abs(b);
};
Window_MapNodes.prototype.isCurrentItemEnabled = function() {
return !$gameSystem.mapNodeLocked($gameSystem.getMapNodesShown()[this.index()]);
};
Window_MapNodes.prototype.onTouch = function(triggered) {
Window_Selectable.prototype.onTouch.call(this, triggered);
this.updateInfoSprite();
};
})();