-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpceth2_msg.c
255 lines (227 loc) · 4.83 KB
/
pceth2_msg.c
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
/*
* pceth2 - メッセージ関連
*
* (c)2005 てとら★ぽっと
*
* 2005/05/08 main.cから分離
* 2005/05/27 getNum仕様変更に対応
* 2005/06/15 名前置換文字を追加(これで全部だといいけど→抜けてたっていうかコピペでミス
* !!、!?の禁則処理を修正。手動禁則目的の\nのみの改行は回避
* 2005/06/16 禁則処理対象に)を追加。命令直前の\nも改行対象に
* 2005/06/25 名前置換処理をコンバータ側に移動
*/
#include <string.h>
#include <piece.h>
#include "zurapce/zurapce.h"
#include "common.h"
#include "pceth2_msg.h"
#include "pceth2_sys.h"
#include "pceth2_str.h"
#include "pceth2_sel.h"
//=============================================================================
// 文字描画
//=============================================================================
/*
* 行頭ならTRUEを返す
*/
BOOL pceth2_isLineTop()
{
int x;
FontFuchi_GetPos(&x, NULL);
return (x <= MSG_X_MIN);
}
/*
* ページ先頭ならTRUEを返す
*/
BOOL pceth2_isPageTop()
{
int y;
FontFuchi_GetPos(NULL, &y);
return (pceth2_isLineTop() && (y <= MSG_Y_MIN));
}
/*
* ページ先頭に移動する
*/
void pceth2_setPageTop()
{
while (!pceth2_isPageTop()) {
pceth2_putCR();
}
}
/*
* メッセージをクリア、バッファもクリア
*/
void pceth2_clearMessage(void)
{
Ldirect_VBuffClear(0, 0, DISP_X, DISP_Y);
*play.msg = '\0';
play.msglen = 0;
}
/*
* メッセージを復帰
*/
void pceth2_comeBackMessage(void)
{
Ldirect_VBuffClear(0, 0, DISP_X, DISP_Y);
FontFuchi_SetPos(MSG_X_MIN, MSG_Y_MIN);
FontFuchi_PutStr(play.msg);
if (play.gameMode == GM_SELECT) { // 選択中なら矢印描画
pceth2_drawSelArrow();
} else if (play.gameMode == GM_MAPSELECT) {
pceth2_drawMapSelArrow();
}
msgView = 1;
wait = 0;
Ldirect_Update();
}
/*
* 2バイト文字を描いて、メッセージバッファにも入れる
*/
void pceth2_putKanji(const char *str)
{
FontFuchi_GetPos(&keyWaitX, &keyWaitY);
keyWaitX += FONT_W + 1;
keyWaitY += 5;
FontFuchi_Printf("%c%c", *str, *(str + 1));
Ldirect_VBuffView(TRUE);
*(play.msg + play.msglen++) = *str;
*(play.msg + play.msglen++) = *(str + 1);
*(play.msg + play.msglen) = '\0';
}
/*
* 改行して、メッセージバッファにも入れる
*/
void pceth2_putCR(void)
{
FontFuchi_PutStr("\n");
*(play.msg + play.msglen++) = '\n';
*(play.msg + play.msglen) = '\0';
}
/*
* メッセージ制御処理
*/
int pceth2_procControl(SCRIPT_DATA *s)
{
s->p++; // <
switch (*(s->data + s->p++))
{
case 'S': // オート制御
case 'F':
{
speed = pceth2_getNum(s);
s->p++; // >
return 1;
}
break;
case 'W': // ウェイト
{
wait = pceth2_getNum(s);
s->p++; // >
play.gameMode = GM_TIMEWAIT;
}
break;
}
return 0;
}
/*
* エスケープシーケンス処理
*/
int pceth2_procEscape(SCRIPT_DATA *s)
{
static const char * const lfWords[] = {" ", "「", "『", "("};
int i;
s->p++;
switch (*(s->data + s->p++)) // 絶対に1個進めるのでここで++しとく
{
case 'k': // キー待ち
{
// 次が\nなら改ページにより連続でキー待ちになる可能性があるので先に改行しておく
if (!strncmp(s->data + s->p, "\\n", 2)) {
s->p += 2;
if (!pceth2_isLineTop()) { // 行頭でなければ改行する
pceth2_putCR();
if (pceth2_isPageTop()) {
play.gameMode = GM_KEYWAIT;
Ldirect_Update();
return 0;
}
}
}
if (!pceth2_isPageTop()) {
play.gameMode = GM_KEYWAIT;
Ldirect_Update();
return 0;
}
}
break;
case 'n': // 改行
{
if (!pceth2_isPageTop()) { // 行頭でなければ改行する
if (pceth2_isKanji(s)) { // 命令直前なら改行
for (i = 0; i < array_size(lfWords); i++) { // 手動禁則処理の改行は無視したい
if (!strncmp(s->data + s->p, lfWords[i], 2)) {
pceth2_putCR();
if (pceth2_isPageTop()) {
play.gameMode = GM_KEYWAIT;
Ldirect_Update();
return 0;
}
break;
}
}
}
}
}
break;
case 'p': // キー待ちページ送り
{
s->p += 4; // ページ管理IDを飛ばす
if (!pceth2_isPageTop()) { // ページ先頭でなければキー待ち改ページ
pceth2_setPageTop();
play.gameMode = GM_KEYWAIT;
Ldirect_Update();
return 0;
}
}
break;
}
return 1;
}
/*
* 禁則処理(行う必要がある場合1を返す)
*/
int pceth2_jpnHyphenation(const char *str)
{
static const char * const hypWords[] = {"。", "、", "」", "』", ")"};
int i, x;
FontFuchi_GetPos(&x, NULL);
if (x > MSG_X_MAX - (FONT_W + 1)) {
for (i = 0; i < array_size(hypWords); i++) {
if (!strncmp(str, hypWords[i], 2)) {
return 1;
}
}
}
return 0;
}
/*
* P/ECE版独特の改行処理
*/
int pceth2_lineFeed(const char *str)
{
static const char * const start_word[] = {" ", "「", "『"};
static const char * const end_word[] = {"。", "」", "』"};
int i, j;
if (play.msglen >= 2 && !pceth2_isLineTop()) {
for (i = 0; i < array_size(start_word); i++) {
if (!strncmp(str, start_word[i], 2)) {
for (j = 0; j < array_size(start_word); j++) {
if (!strncmp(play.msg + play.msglen - 2, end_word[j], 2)) {
return 1;
}
}
}
}
}
return 0;
}