-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointClickAdventure.js
More file actions
121 lines (101 loc) · 4.3 KB
/
PointClickAdventure.js
File metadata and controls
121 lines (101 loc) · 4.3 KB
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
/*:
* @plugindesc v1.1 Point-and-Click Menu - Adds a point-and-click dialogue menu for specific objects on the map, similar to traditional adventure games.
* @author Midnight Roach Media
* @help This plugin allows you to click on an object with a special note tag and bring up a dialogue menu with options: Inspect, Talk, Use, Pick-up.
*/
(function() {
var parameters = PluginManager.parameters('PointClickMenu');
// Create a new Window for the point-and-click menu
function Window_PointClickMenu() {
this.initialize.apply(this, arguments);
}
Window_PointClickMenu.prototype = Object.create(Window_Command.prototype);
Window_PointClickMenu.prototype.constructor = Window_PointClickMenu;
Window_PointClickMenu.prototype.initialize = function() {
Window_Command.prototype.initialize.call(this, 0, 0);
this.openness = 0;
this.deactivate();
};
Window_PointClickMenu.prototype.windowWidth = function() {
return 200;
};
Window_PointClickMenu.prototype.windowHeight = function() {
return this.fittingHeight(4);
};
Window_PointClickMenu.prototype.makeCommandList = function() {
this.addCommand('Inspect', 'inspect');
this.addCommand('Talk', 'talk');
this.addCommand('Use', 'use');
this.addCommand('Pick-up', 'pickup');
};
// Extend Scene_Map to handle point-and-click menu
var _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function() {
_Scene_Map_createAllWindows.call(this);
this.createPointClickMenuWindow();
};
Scene_Map.prototype.createPointClickMenuWindow = function() {
this._pointClickMenuWindow = new Window_PointClickMenu();
this._pointClickMenuWindow.setHandler('inspect', this.onInspect.bind(this));
this._pointClickMenuWindow.setHandler('talk', this.onTalk.bind(this));
this._pointClickMenuWindow.setHandler('use', this.onUse.bind(this));
this._pointClickMenuWindow.setHandler('pickup', this.onPickup.bind(this));
this._pointClickMenuWindow.setHandler('cancel', this.onMenuCancel.bind(this));
this.addWindow(this._pointClickMenuWindow);
};
Scene_Map.prototype.onInspect = function() {
console.log("Inspect action selected");
this.closePointClickMenu();
};
Scene_Map.prototype.onTalk = function() {
console.log("Talk action selected");
this.closePointClickMenu();
};
Scene_Map.prototype.onUse = function() {
console.log("Use action selected");
this.closePointClickMenu();
};
Scene_Map.prototype.onPickup = function() {
console.log("Pick-up action selected");
this.closePointClickMenu();
};
Scene_Map.prototype.onMenuCancel = function() {
this.closePointClickMenu();
};
Scene_Map.prototype.closePointClickMenu = function() {
this._pointClickMenuWindow.close();
this._pointClickMenuWindow.deactivate();
};
var _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
if (TouchInput.isTriggered()) {
var x = $gameMap.canvasToMapX(TouchInput.x);
var y = $gameMap.canvasToMapY(TouchInput.y);
var event = $gameMap.eventAt(x, y);
if (this._pointClickMenuWindow.isOpen()) {
if (!this._pointClickMenuWindow.isTouchedInsideFrame()) {
this.onMenuCancel();
}
} else if (event && event.event().meta.PointClickMenu) {
this.openPointClickMenu(TouchInput.x, TouchInput.y);
}
}
};
Scene_Map.prototype.openPointClickMenu = function(x, y) {
this._pointClickMenuWindow.x = x;
this._pointClickMenuWindow.y = y;
this._pointClickMenuWindow.open();
this._pointClickMenuWindow.activate();
};
Window_Base.prototype.isTouchedInsideFrame = function() {
var x = this.canvasToLocalX(TouchInput.x);
var y = this.canvasToLocalY(TouchInput.y);
return x >= 0 && y >= 0 && x < this.width && y < this.height;
};
Game_Map.prototype.eventAt = function(x, y) {
return this.events().find(function(event) {
return event.posNt(x, y);
});
};
})();