-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindow_Command.js
153 lines (127 loc) · 3.93 KB
/
Window_Command.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
//-----------------------------------------------------------------------------
// Window_Command
//
// The superclass of windows for selecting a command.
function Window_Command() {
this.initialize.apply(this, arguments);
}
Window_Command.prototype = Object.create(Window_Selectable.prototype);
Window_Command.prototype.constructor = Window_Command;
Window_Command.prototype.initialize = function(x, y) {
this.clearCommandList();
this.makeCommandList();
var width = this.windowWidth();
var height = this.windowHeight();
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this.refresh();
this.select(0);
this.activate();
};
Window_Command.prototype.windowWidth = function() {
return 240;
};
Window_Command.prototype.windowHeight = function() {
return this.fittingHeight(this.numVisibleRows());
};
Window_Command.prototype.numVisibleRows = function() {
return Math.ceil(this.maxItems() / this.maxCols());
};
Window_Command.prototype.maxItems = function() {
return this._list.length;
};
Window_Command.prototype.clearCommandList = function() {
this._list = [];
};
Window_Command.prototype.makeCommandList = function() {
};
Window_Command.prototype.addCommand = function(name, symbol, enabled, ext) {
if (enabled === undefined) {
enabled = true;
}
if (ext === undefined) {
ext = null;
}
this._list.push({ name: name, symbol: symbol, enabled: enabled, ext: ext});
};
Window_Command.prototype.commandName = function(index) {
return this._list[index].name;
};
Window_Command.prototype.commandSymbol = function(index) {
return this._list[index].symbol;
};
Window_Command.prototype.isCommandEnabled = function(index) {
return this._list[index].enabled;
};
Window_Command.prototype.currentData = function() {
return this.index() >= 0 ? this._list[this.index()] : null;
};
Window_Command.prototype.isCurrentItemEnabled = function() {
return this.currentData() ? this.currentData().enabled : false;
};
Window_Command.prototype.currentSymbol = function() {
return this.currentData() ? this.currentData().symbol : null;
};
Window_Command.prototype.currentExt = function() {
return this.currentData() ? this.currentData().ext : null;
};
Window_Command.prototype.findSymbol = function(symbol) {
for (var i = 0; i < this._list.length; i++) {
if (this._list[i].symbol === symbol) {
return i;
}
}
return -1;
};
Window_Command.prototype.selectSymbol = function(symbol) {
var index = this.findSymbol(symbol);
if (index >= 0) {
this.select(index);
} else {
this.select(0);
}
};
Window_Command.prototype.findExt = function(ext) {
for (var i = 0; i < this._list.length; i++) {
if (this._list[i].ext === ext) {
return i;
}
}
return -1;
};
Window_Command.prototype.selectExt = function(ext) {
var index = this.findExt(ext);
if (index >= 0) {
this.select(index);
} else {
this.select(0);
}
};
Window_Command.prototype.drawItem = function(index) {
var rect = this.itemRectForText(index);
var align = this.itemTextAlign();
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);
};
Window_Command.prototype.itemTextAlign = function() {
return 'left';
};
Window_Command.prototype.isOkEnabled = function() {
return true;
};
Window_Command.prototype.callOkHandler = function() {
var symbol = this.currentSymbol();
if (this.isHandled(symbol)) {
this.callHandler(symbol);
} else if (this.isHandled('ok')) {
Window_Selectable.prototype.callOkHandler.call(this);
} else {
this.activate();
}
};
Window_Command.prototype.refresh = function() {
this.clearCommandList();
this.makeCommandList();
this.createContents();
Window_Selectable.prototype.refresh.call(this);
};