-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathMrTS_MapSelection.js
388 lines (352 loc) · 11.5 KB
/
MrTS_MapSelection.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
//=============================================================================
// MrTS_MapSelection.js
//=============================================================================
/*:
* @plugindesc Allows to travel to different maps from a single scene.
* @author Mr. Trivel
*
* @param Map Select Text
* @desc Map Select Text
* Default: Map Select
* @default Map Select
*
* @param Help Text
* @desc Text at the bottom window.
* @default Select a challenge for your fated heroes to struggle in.
*
* @param Max Items
* @desc Max items in a list before having to scroll.
* Default: 10
* @default 10
*
* @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.1
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* MapSelection Start - Enters Map Selection Scene
* MapSelection Add [ID] - Adds selection to the menu
* MapSelection Remove [ID] - Removes selection from the menu
*
* Examples:
* MapSelection Start
* MapSelection Add 4
* MapSelection Remove 5
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Map List Structure
* --------------------------------------------------------------------------------
* mapList in an array of objects.
* Each object start with { and ends with }
* Each object has ID and Name properties.
* {
* ID: 1,
* Name: "Some Name"
* }
* ID is used for plugin commands listed above.
* Name is what will be seen on the command window ingame.
* Now, the object may have one of three groups of other properties.
* Group 1 - Sublist properties:
* Sublist: [],
* Background: "BackgroundName"
*
* Group 2 - Map teleport properties:
* MapID: 3,
* X: 5,
* Y: 20
*
* Group 3 - Execute common event properties:
* CE_ID: 2
*
* So if Object is Group 1 type, when you click on it, you'll get it's list,
* meanwhile if Object is Group 2 type, when you click on it, you'll be teleported
* to it's map, if Object is Group 3 type, when you click on it, you'll get Common
* Event executed defined by CE_ID.
*
* To edit the map list, open up this plugin in your favorite text editor and
* scroll down to "EDIT MAP LIST HERE". Make sure to check the example there, too.
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Image Info
* --------------------------------------------------------------------------------
* All backgrounds go into img\system folder.
*
* Default Background file: img\system\mapSelect.png
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.1 - List allows excuting Common Events.
* 1.0 - Release
*/
(function() {
//--------------------------------------------------------------------------------
// EDIT MAP LIST HERE v
//--------------------------------------------------------------------------------
var mapList = [
{
ID: 1,
Name: "Black Moon Guild",
Background: "blackness",
Sublist: [
{
ID: 2,
Name: "Floor 1",
MapID: 5,
X: 10,
Y: 17
},
{
ID: 3,
Name: "Floor 2",
MapID: 5,
X: 5,
Y: 8
}
]
},
{
ID: 4,
Name: "Forest of Graves",
Background: "Meadow",
Sublist: [
{
ID: 5,
Name: "Entrance",
MapID: 2,
X: 18,
Y: 38
},
{
ID: 6,
Name: "Heart of the Forest",
MapID: 2,
X: 25,
Y: 18
}
]
},
{
ID: 7,
Name: "Call the Events!",
CE_ID: 1
}
];
//--------------------------------------------------------------------------------
// EDIT MAP LIST THERE ^
//--------------------------------------------------------------------------------
var parameters = PluginManager.parameters('MrTS_MapSelection');
var paramMapSelectText = String(parameters['Map Select Text'] || "Choose Destination");
var paramHelpText = String(parameters['Help Text'] || "Select a challenge for your fated heroes to struggle in.");
var paramMaxItems = Number(parameters['Max Items'] || 10);
//--------------------------------------------------------------------------
// 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() === "mapselection") {
switch (args[0].toUpperCase())
{
case 'START':
{
SceneManager.push(Scene_MapSelect);
} break;
case 'ADD':
{
$gameSystem.addMapSelection(Number(args[1]));
} break;
case 'REMOVE':
{
$gameSystem.removeMapSelection(Number(args[1]));
} break;
}
}
};
//--------------------------------------------------------------------------
// Game_System
Game_System.prototype.addMapSelection = function(id) {
if (!this._mapSelections) this._mapSelections = [];
this._mapSelections.push(id);
};
Game_System.prototype.removeMapSelection = function(id) {
if (!this._mapSelections) this._mapSelections = [];
this._mapSelections.splice(this._mapSelections.indexOf(id), 1);
};
Game_System.prototype.getMapSelections = function() {
if (!this._mapSelections) this._mapSelections = [];
return this._mapSelections;
};
//--------------------------------------------------------------------------
// Scene_MapSelect
//
// Map selection scene.
function Scene_MapSelect() {
this.initialize.apply(this, arguments);
};
Scene_MapSelect.prototype = Object.create(Scene_MenuBase.prototype);
Scene_MapSelect.prototype.constructor = Scene_MapSelect;
Scene_MapSelect.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_MapSelect.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createTopWindow();
this.createListWindow();
this.createBottomWindow();
this._stack = [];
};
Scene_MapSelect.prototype.createBackground = function() {
this._backgroundSprite = new Sprite();
this._backgroundSprite.bitmap = ImageManager.loadSystem('mapSelect');
this.addChild(this._backgroundSprite);
};
Scene_MapSelect.prototype.createTopWindow = function() {
this._topWindow = new Window_MapSelect_Message(paramMapSelectText, 40);
this.addWindow(this._topWindow);
};
Scene_MapSelect.prototype.createListWindow = function() {
this._listWindow = new Window_MapSelect_List();
this._listWindow.setHandler('ok', this.listOkay.bind(this));
this._listWindow.setHandler('cancel', this.listCancel.bind(this));
this.addWindow(this._listWindow);
this._listWindow.setObject(mapList);
this._listWindow.select(0);
this._listWindow.activate();
};
Scene_MapSelect.prototype.createBottomWindow = function() {
this._bottomWindow = new Window_MapSelect_Message(paramHelpText, Graphics.boxHeight - 100);
this.addWindow(this._bottomWindow);
};
Scene_MapSelect.prototype.listOkay = function() {
var item = this._listWindow.item(this._listWindow.index());
if (item.Sublist)
{
this._stack.push([this._listWindow._object, this._listWindow.index()]);
this._backgroundSprite.bitmap = ImageManager.loadSystem(item.Background);
this._listWindow.select(0);
this._listWindow.setObject(item);
this._listWindow.refresh();
this._listWindow.activate()
}
else if (item.CE_ID)
{
this.popScene();
$gameTemp.reserveCommonEvent(item.CE_ID);
}
else
{
this.popScene();
$gamePlayer.reserveTransfer(item.MapID, item.X, item.Y, 2, 0);
}
};
Scene_MapSelect.prototype.listCancel = function() {
if (this._stack.length > 0)
{
this._listWindow.setObject(this._stack[this._stack.length-1][0]);
if (this._stack[this._stack.length-1][0].Bitmap)
this._backgroundSprite.bitmap = ImageManager.loadSystem(this._stack[this._stack.length-1][0].Background);
else
this._backgroundSprite.bitmap = ImageManager.loadSystem('mapSelect');
this._listWindow.refresh();
this._listWindow.select(this._stack[this._stack.length-1][1]);
this._listWindow.activate();
this._stack.splice(this._stack.length-1, 1);
}
else
{
this.popScene();
}
};
//--------------------------------------------------------------------------
// Window_MapSelect_Message
//
// Window with top text.
function Window_MapSelect_Message() {
this.initialize.apply(this, arguments);
};
Window_MapSelect_Message.prototype = Object.create(Window_Base.prototype);
Window_MapSelect_Message.prototype.constructor = Window_MapSelect_Message;
Window_MapSelect_Message.prototype.initialize = function(message, y) {
this._message = message;
Window_Base.prototype.initialize.call(this, 0, y, 200, 40);
var ww = this.textWidth(message) + this.standardPadding()*2;
var wh = this.fittingHeight(1);
var wx = Graphics.boxWidth/2 - ww/2;
this.x = wx;
this.width = ww;
this.height = wh;
this.refresh();
};
Window_MapSelect_Message.prototype.refresh = function() {
this.createContents();
this.drawText(this._message, 0, 0, this.contentsWidth(), 'center');
};
//--------------------------------------------------------------------------
// Window_MapSelect_List
//
// Let's player to choose a map.
function Window_MapSelect_List() {
this.initialize.apply(this, arguments);
};
Window_MapSelect_List.prototype = Object.create(Window_Selectable.prototype);
Window_MapSelect_List.prototype.constructor = Window_MapSelect_List;
Window_MapSelect_List.prototype.initialize = function() {
Window_Selectable.prototype.initialize.call(this, 60, 120, 350, 200);
};
Window_MapSelect_List.prototype.setObject = function(obj) {
this._object = obj;
this.resize();
this.refresh();
};
Window_MapSelect_List.prototype.resize = function() {
var length = 0;
var array = this._object.Sublist ? this._object.Sublist : this._object;
for (var i = 0; i < array.length; i++) {
if ($gameSystem.getMapSelections().contains(array[i].ID)) length++;
}
this.height = this.fittingHeight(Math.min(length, paramMaxItems));
this.createContents();
};
Window_MapSelect_List.prototype.maxItems = function() {
if (!this._object) return 0;
var length = 0;
var array = this._object.Sublist ? this._object.Sublist : this._object;
for (var i = 0; i < array.length; i++) {
if ($gameSystem.getMapSelections().contains(array[i].ID)) length++;
}
return length;
};
Window_MapSelect_List.prototype.item = function(index) {
var pos = -1;
var array = this._object.Sublist ? this._object.Sublist : this._object;
for (var i = 0; i < array.length; i++) {
if ($gameSystem.getMapSelections().contains(array[i].ID))
{
pos++;
if (pos === index) return array[i];
}
}
return null;
};
Window_MapSelect_List.prototype.drawItem = function(index) {
var item = this.item(index);
if (item)
{
var rect = this.itemRectForText(index);
this.drawText(item.Name, rect.x, rect.y);
}
};
})();