Mercurial > otakunoraifu
annotate scn2k/scn2k_text.cc @ 38:658272d883ed
* Support (more or less) button style selects (fuuko's ones)
* Strip text objects from strings (may support object text objects later)
author | thib |
---|---|
date | Tue, 17 Mar 2009 20:35:08 +0000 |
parents | 4d7486cb20a9 |
children | de29c4d2d043 |
rev | line source |
---|---|
0 | 1 /* |
2 TODO: | |
3 日付のラベルが画面切り替え時に欠けるのを修正 | |
4 画像効果 : 人間の入れ換わりなど | |
5 kcursor の操作を WidText クラスに任せる | |
6 WidText クラスには新たに以下の操作を加える | |
7 ・ウェイト終了後、クリアなしに新たなテキストを追加、新たにstart-waitする | |
8 ・文字の描画 (Start) と Wait(カーソル表示待ち)の分離。 | |
9 Start すると文字を描画開始する。クリックで全描画。 | |
10 Flush するとバッファ内の文字をすべて描画する | |
11 Wait すると全描画後、クリックされるまでカーソルを表示するまで待つ | |
12 TextImpl 側の状態としては Wait のみを持つ (PREPAREに戻るのを待つ) | |
13 ただし、Skip の権利はどっちがもつ?(現状は?) | |
14 | |
15 GrpObj: NextObj と GrpObj を分離。CreateObj は現状通り、Visible=1 時に行う。 | |
16 それぞれ num=0 (screen) の枝leaf として実装。delete時は親のdeleteのみを | |
17 行い、子はGrpObjの実体だけを削除する | |
18 Visible 後のhide は実際に hide とする | |
19 ExecReservedCmd() はなくせるはず。Delete() もなくなる。 | |
20 カノギ:ReBlit() がうまくいかないせいで名前ウィンドウが消えた時の背景がなくなる | |
21 | |
22 くら:回想表示 | |
23 SEL画像効果 | |
24 DONE: | |
25 ともよのテキストウィンドウ実装、ボタン実装 | |
26 shake の画像効果 | |
27 オブジェクト内のテキスト色の実装 | |
28 画像効果の改善 | |
29 */ | |
30 | |
31 /* | |
32 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno | |
33 * All rights reserved. | |
34 * | |
35 * Redistribution and use in source and binary forms, with or without | |
36 * modification, are permitted provided that the following conditions | |
37 * are met: | |
38 * 1. Redistributions of source code must retain the above copyright | |
39 * notice, this list of conditions and the following disclaimer. | |
40 * 2. Redistributions in binary form must reproduce the above copyright | |
41 * notice, this list of conditions and the following disclaimer in the | |
42 * documentation and/or other materials provided with the distribution. | |
43 * 3. The name of the author may not be used to endorse or promote products | |
44 * derived from this software without specific prior written permission. | |
45 * | |
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
56 */ | |
57 | |
58 #include"window/event.h" | |
59 #include"window/picture.h" | |
60 #include"window/widget.h" | |
61 #include"system/file.h" | |
62 #include"system/system_config.h" | |
63 #include"scn2k.h" | |
64 | |
65 #include<string> | |
66 using namespace std; | |
67 | |
68 // kanji conv : デバッグ表示用 | |
69 void kconv(const unsigned char* src, unsigned char* dest); | |
70 void kconv_rev(const unsigned char* src, unsigned char* dest); | |
71 string kconv(const string& s); | |
72 string kconv_rev(const string& s); | |
73 // render.cc | |
74 void DSurfaceFillA(Surface* src, const Rect& rect, int r, int g, int b, int a); // テキストウィンドウ背景の設定 | |
75 void DSurfaceMove(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect); // コピー | |
76 | |
77 /**************************************************************:: | |
78 ** | |
79 ** TextImpl(interface) | |
80 */ | |
81 struct TimerAtom { | |
82 int from; | |
83 int to; | |
84 unsigned int start_time; | |
85 unsigned int total_time; | |
86 }; | |
87 | |
88 struct TextWindow { | |
89 /* @@@ : SetWindowColor での surface 再設定に注意 */ | |
90 WidText* wid; | |
91 bool name_visible; | |
92 WidLabel* name; | |
93 PicContainer* name_container; | |
94 PicBase* face; | |
95 PicBase* face_pics[8]; | |
96 TextWindow(PicContainer& parent, Event::Container& event, int window_no, const AyuSysConfig& config, void* callback); | |
97 ~TextWindow() { | |
98 if (name_container) delete name_container; | |
99 int i; for (i=0; i<8; i++) { | |
100 if (face_pics[i]) delete face_pics[i]; | |
101 } | |
102 if (wid) delete wid; | |
103 } | |
104 Rect WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config); | |
105 void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, const AyuSysConfig& config, void* callback); | |
106 void show(void) { | |
107 wid->show(); | |
108 if (name_container && name_visible) name_container->show(); | |
109 if (face) face->show(); | |
110 } | |
111 void hide(void) { | |
112 wid->hide(); | |
113 if (name_container) name_container->hide(); | |
114 if (face) face->hide(); | |
115 } | |
116 void ShowFace(const char* path) { | |
117 if (!face) return; | |
118 face->SetSurface( path, 0,0); | |
119 } | |
120 void ResetFace(void) { | |
121 if (!face) return; | |
122 face->SetSurface( (Surface*)0, 0,0); | |
123 } | |
124 void StartText(const TextStream& _stream) { | |
125 wid->Clear(); | |
126 wid->stream = _stream; | |
127 if (name_container) { | |
128 char namestr[1024]; | |
129 namestr[0] = 0; | |
130 wid->stream.RemoveName(namestr, 1024); | |
131 if (namestr[0] == 0) { | |
132 name_container->hide(); | |
133 } else { | |
134 if (name) { | |
135 name_container->show_all(); | |
136 name->SetText(namestr); | |
137 } | |
138 } | |
139 } | |
140 wid->Start(); | |
141 } | |
142 void SetName(const char* n) { | |
143 if (name_container && name) { | |
144 if (n[0]) { | |
145 name_container->show(); | |
146 name->SetText(n); | |
147 name_visible = true; | |
148 } else { | |
149 name_container->hide(); | |
150 name_visible = false; | |
151 } | |
152 } | |
153 } | |
154 }; | |
155 | |
156 class TextImpl { | |
157 private: | |
158 public: | |
159 TextWindow* text; | |
160 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2, WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5, WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7, | |
161 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12, | |
162 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512, | |
163 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12), | |
164 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15), BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17), | |
165 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK) | |
166 } Status; | |
167 Status status, status_saved, status_mask; | |
168 private: | |
169 std::string ruby_text; | |
170 bool ruby_text_flag; | |
171 unsigned int wait_time; | |
172 unsigned int old_time; | |
173 unsigned int base_time; | |
174 int text_window_number; | |
175 bool text_parsing; | |
176 TextStream text_stream; | |
177 SkipMode skip_mode; | |
178 int save_selectcount; | |
179 | |
180 std::map<int, TimerAtom> timer_var; | |
181 std::vector<WidTextButton*> selects; | |
182 std::vector<int> sel_backlog_pos; | |
183 string replace_name[26]; | |
184 string replace_name2[26]; | |
185 PicContainer* sel_widget; | |
186 PicWidget* backlog_widget; | |
187 | |
188 vector<BacklogItem>& backlog; | |
189 BacklogItem& backlog_item; | |
190 BacklogItem cur_backlog_item; | |
191 BacklogItem drawn_backlog_item; | |
192 | |
193 public: | |
194 PicContainer& parent; | |
195 Event::Container& event; | |
196 AyuSysConfig& config; | |
197 private: | |
198 TextWindow* widgets[32]; | |
199 WidTimeCursor* kcursor; | |
200 Surface* sel_bg1; | |
201 Surface* sel_bg2; | |
202 Rect sel_bg_rect; | |
203 | |
204 void SetCursor(int num); | |
205 VarInfo wait_savedvar[2]; | |
206 | |
207 public: | |
208 void AddText(const char* str); | |
209 | |
210 static void PressFuncSkip(void* pointer, WidButton* from); | |
211 static void PressFuncLoad(void* pointer, WidButton* from); | |
212 static void PressFuncSave(void* pointer, WidButton* from); | |
213 static void PressFuncBacklog(void* pointer, WidButton* from); | |
214 static void PressFuncBacklogFwd(void* pointer, WidButton* from); | |
215 private: | |
216 static void PressFuncButton(void* pointer, WidButton* from); | |
217 static bool PressFunc(int x, int y, void* pointer); | |
218 | |
219 public: | |
220 TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item); | |
221 ~TextImpl(); | |
222 void InitWindow(void); | |
223 void SetWindowColor(int r, int g, int b, int a, bool is_transparent); | |
224 void SetTextSpeed(int new_speed); | |
225 void SetTextWait(int new_wait); | |
226 void CreateSelect(Cmd& cmd); | |
227 void Exec(Cmd& cmd); | |
228 bool Wait(unsigned int current_time, Cmd& cmd); | |
229 void hide(void); | |
230 void show(void) { show(text_window_number); } | |
231 void show(int num); | |
232 void DrawBacklog(BacklogItem& item, Cmd& cmd); | |
233 void Save(std::string& str, bool select_save); | |
234 void Load(const char* str); | |
235 void SetSkipMode(SkipMode _mode); | |
236 void CreateSelBG(void); | |
237 }; | |
238 | |
239 /**************************************************************:: | |
240 ** | |
241 ** TextImpl(implementation) | |
242 */ | |
243 TextImpl::TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& _config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item) : | |
244 text(0),status(TextImpl::NORMAL), status_saved(TextImpl::NORMAL), status_mask(TextImpl::NORMAL), ruby_text_flag(false), | |
245 old_time(0), base_time(0), text_window_number(0), text_parsing(false), skip_mode(SKIP_NO), save_selectcount(0), sel_widget(0), | |
246 backlog_widget(0), backlog(parent_backlog), backlog_item(parent_backlog_item), parent(_parent), event(_event), config(_config), | |
247 kcursor(0), sel_bg1(0), sel_bg2(0), sel_bg_rect(0,0,0,0) { | |
248 int i; | |
249 for (i=0; i<32; i++) { | |
250 widgets[i] = 0; | |
251 } | |
252 text_stream.kanji_type = TextStream::sjis; | |
253 event.RegisterGlobalPressFunc(&PressFunc, (void*)this); | |
254 } | |
255 | |
256 TextImpl::~TextImpl() { | |
257 if (sel_widget) delete sel_widget; | |
258 int i; | |
259 for (i=0; i<32; i++) { | |
260 if (widgets[i]) delete widgets[i]; | |
261 } | |
262 if (backlog_widget) delete backlog_widget; | |
263 if (sel_bg1) parent.Root().DeleteSurface(sel_bg1); | |
264 if (sel_bg2) parent.Root().DeleteSurface(sel_bg2); | |
265 event.DeleteGlobalPressFunc(&PressFunc, (void*)this); | |
266 } | |
267 | |
268 bool TextImpl::PressFunc(int x, int y, void* pointer) { | |
269 TextImpl* t = (TextImpl*)pointer; | |
270 if (t->status == WAIT_CLICK) { | |
271 t->status = WAIT_ABORT; | |
272 } else if (t->status == WAIT_CLICK_MOUSEPOS) { | |
273 t->status = WAIT_CLICK_MOUSEPOSEND_L; | |
274 } else if (t->status_mask & CLEARSCR_WAIT_MASK) { | |
275 t->status_mask = Status(t->status_mask & (~CLEARSCR_WAIT_MASK)); | |
276 if (t->text) t->text->show(); | |
277 if (t->kcursor) { | |
278 if (t->status == WAIT_TEXT) t->kcursor->show(); | |
279 } | |
280 if (t->sel_widget) t->sel_widget->show(); | |
281 if (t->backlog_widget) t->backlog_widget->show(); | |
282 } else if (t->status_mask & BACKLOG_WAIT_MASK) { | |
283 t->status_mask = Status(t->status_mask | BACKLOG_MASK_KOE); | |
284 } else if ( (t->skip_mode & SKIP_TEXT) && (!(t->skip_mode & SKIP_IN_MENU)) ) { | |
285 if (t->status == WAIT_SELECT_INBOX) ; | |
286 else if (t->status == WAIT_SELECT_OUTBOX) ; | |
287 else if (t->status == WAIT_SELECT_VALUE) ; | |
288 else t->status_mask = Status(t->status_mask | SKIPEND_MASK); | |
289 } | |
290 return true; // event not deleted | |
291 } | |
292 void TextImpl::PressFuncButton(void* pointer, WidButton* from) { | |
293 TextImpl* t = (TextImpl*)pointer; | |
294 if (t->status != WAIT_SELECT_INBOX && t->status != WAIT_SELECT_OUTBOX) return; | |
295 vector<WidTextButton*>::iterator it; | |
296 int sel = 0; | |
297 for (it=t->selects.begin(); it != t->selects.end(); it++, sel++) { | |
298 if (from == *it) break; | |
299 } | |
300 if (it == t->selects.end()) { | |
301 fprintf(stderr,"TextImpl::PressFuncButton: Cannot find select widget\n"); | |
302 return; | |
303 } | |
304 t->status = Status(WAIT_SELECT_VALUE + sel); | |
305 return; | |
306 } | |
307 | |
308 void TextImpl::SetSkipMode(SkipMode _mode) { | |
309 if ( (skip_mode & SKIP_IN_MENU) && (_mode & SKIP_IN_MENU) == 0) { | |
310 if (status_mask & BACKLOG_WAIT_MASK) { // backlog mode から復帰 | |
311 status_mask = Status(status_mask & (~(BACKLOG_MASK|BACKLOG_MASK_FWD|BACKLOG_MASK_KOE|BACKLOG_WAIT_MASK))); | |
312 text->wid->Clear(); | |
313 if (status == WAIT_TEXT && text != 0) { | |
314 text->StartText(text_stream); | |
315 text->ShowFace(backlog_item.face.c_str()); | |
316 text->wid->Flush(); | |
317 if (kcursor) kcursor->show(); | |
318 } | |
319 drawn_backlog_item.Clear(); | |
320 } | |
321 if (text) text->wid->activate(); | |
322 if (sel_widget) { | |
323 sel_widget->show(); | |
324 if (kcursor) kcursor->hide(); | |
325 } | |
326 if (backlog_widget) backlog_widget->show(); | |
327 if (status_mask & STATSAVE_MASK) { | |
328 status_mask = Status(status_mask & (~STATSAVE_MASK)); | |
329 status = status_saved; | |
330 } | |
331 } else if ( (skip_mode & SKIP_IN_MENU) == 0 && (_mode & SKIP_IN_MENU) ) { | |
332 if (text) text->wid->deactivate(); | |
333 if (sel_widget) sel_widget->hide(); | |
334 if (backlog_widget) backlog_widget->hide(); | |
335 } | |
336 skip_mode = _mode; | |
337 } | |
338 | |
339 /* hash_map が欲しい……*/ | |
340 #include<map> | |
341 #include<list> | |
342 struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う | |
343 map<string, int> facetonum; | |
344 typedef pair<string,int> Node; | |
345 typedef list<Node> List; | |
346 List container; | |
347 int id_max; | |
348 static int size_max; | |
349 SaveFaceHash() : id_max(0) { | |
350 } | |
351 void NewNode(string face, int face_id) { | |
352 facetonum[face] = face_id; | |
353 container.push_front(Node(face, face_id)); | |
354 if (container.size() > size_max) { | |
355 Node remove = container.back(); | |
356 container.pop_back(); | |
357 facetonum.erase(remove.first); | |
358 } | |
359 } | |
360 int Add(string face) { | |
361 int id; int ret = -1; | |
362 int i; List::iterator it; | |
363 if (face.empty()) return -1; | |
364 if (facetonum.find(face) == facetonum.end()) { | |
365 id = ++id_max; | |
366 NewNode(face, id); | |
367 ret = -1; | |
368 } else { | |
369 id = facetonum[face]; | |
370 for (i=0, it=container.begin(); it != container.end(); i++, it++) { | |
371 if (it->second == id) { | |
372 ret = i; | |
373 Node n = *it; | |
374 container.erase(it); | |
375 container.push_front(n); | |
376 break; | |
377 } | |
378 } | |
379 } | |
380 return ret; | |
381 } | |
382 string Get(int num) { | |
383 if (num < 0) return ""; | |
384 List::iterator it = container.begin(); | |
385 for (; it != container.end(); it++) { | |
386 if (num == 0) return it->first; | |
387 num--; | |
388 } | |
389 return ""; | |
390 } | |
391 }; | |
392 int SaveFaceHash::size_max = 20; | |
393 | |
394 void TextImpl::Save(string& str, bool rollback_save) { | |
395 char buf[1024]; | |
396 str = "\n"; | |
397 str += "[TextImpl Window]\n"; | |
398 sprintf(buf, "TextImplWindow=%d\n",text_window_number); | |
399 str += buf; | |
400 if (rollback_save) { | |
401 ++save_selectcount; | |
402 BacklogItem save_item; | |
403 save_item.SetSavepos(save_selectcount); | |
404 backlog.push_back(save_item); | |
405 } | |
406 sprintf(buf, "SaveSelectCount=%d\n",save_selectcount); | |
407 | |
408 str += buf; | |
409 int i; | |
410 for (i=0; i<26; i++) { | |
411 if (replace_name2[i].empty()) continue; | |
412 sprintf(buf, "RName.%c=%s\n",i+'A',replace_name2[i].c_str()); | |
413 str += buf; | |
414 } | |
415 int cnt = 0; | |
416 vector<BacklogItem>::iterator it; | |
417 it = backlog.begin(); | |
418 if (!rollback_save) { | |
419 SaveFaceHash face_log; | |
420 do { | |
421 int cur_scn = -1; int cur_pos = -1; | |
422 sprintf(buf, "Backlog.%d=",++cnt); | |
423 str += buf; | |
424 for (; it != backlog.end(); it++) { | |
425 buf[0] = 0; int buflen = 0; | |
426 if (it->scn == -1) continue; | |
427 if (it->pos == -1 && it->scn != 0) continue; | |
428 | |
429 buf[buflen++] = ';'; | |
430 if (it->scn == 0 && it->pos == -1) { | |
431 buflen += snprintf(buf+buflen, 1000-buflen, "\"%s\".", it->text.Save().c_str()); | |
432 } else { | |
433 if (cur_scn != -1 && cur_scn != it->scn) break; // scn change | |
434 if (cur_pos != -1 && cur_pos/5000 != it->pos/5000) break; // pos exceeded | |
435 if (!it->text.container.empty()) { | |
436 buflen += snprintf(buf+buflen, 1000-buflen, "\"%s\"", it->text.Save().c_str()); | |
437 } | |
438 if (cur_scn == -1) { // scene change | |
439 buflen += snprintf(buf+buflen, 1000-buflen, ":%d:%d",it->scn,it->pos); | |
440 cur_scn = it->scn; | |
441 } else { | |
442 buflen += snprintf(buf+buflen, 1000-buflen, "%d",it->pos); | |
443 } | |
444 cur_pos = it->pos; | |
445 } | |
446 if (it->koe != -1) | |
447 buflen += snprintf(buf+buflen, 1000-buflen, ",%d",it->koe); | |
448 if (!it->face.empty()) { | |
449 if (it->koe == -1) buf[buflen++] = ','; | |
450 int face_num = face_log.Add(it->face); | |
451 if (face_num >= 0 && face_num < 20) | |
452 buflen += snprintf(buf+buflen, 1000-buflen, ",%c", 'A'+face_num); | |
453 else | |
454 buflen += snprintf(buf+buflen, 1000-buflen, ",\"%s\"", it->face.c_str()); | |
455 } | |
456 buf[buflen++] = '\0'; | |
457 if (buflen >= 1000) { // 万が一、バックログ1アイテムの大きさが 1000byte を越えるとき | |
458 fprintf(stderr,"Fatal : Cannot save backlog crrectly; Please send bug report to the author.\n"); | |
459 } else str += buf; | |
460 } | |
461 str += "\n"; | |
462 } while(it != backlog.end()); | |
463 } | |
464 return; | |
465 } | |
466 void TextImpl::Load(const char* str) { | |
467 if (text) text->wid->Clear(); | |
468 hide(); | |
469 text_window_number = 0; | |
470 save_selectcount = 0; | |
471 if (sel_widget) { | |
472 selects.clear(); | |
473 sel_backlog_pos.clear(); | |
474 delete sel_widget; | |
475 sel_widget = 0; | |
476 } | |
477 if (backlog_widget) { | |
478 delete backlog_widget; | |
479 backlog_widget = 0; | |
480 } | |
481 status = NORMAL; | |
482 status_mask = NORMAL; | |
483 status_saved = NORMAL; | |
484 text_parsing = false; | |
485 text_stream.Clear(); | |
486 // backlog.clear(); | |
487 vector<BacklogItem> new_backlog; | |
488 backlog_item.Clear(); | |
489 cur_backlog_item.Clear(); | |
490 drawn_backlog_item.Clear(); | |
491 | |
492 str = strstr(str, "\n[TextImpl Window]\n"); | |
493 | |
494 if (str) { | |
495 SaveFaceHash face_log; | |
496 str += strlen("\n[TextImpl Window]\n"); | |
497 const char* strend = str; | |
498 do { | |
499 str = strend; | |
500 | |
501 strend = strchr(str, '\n'); | |
502 if (strend == 0) strend = str + strlen(str); | |
503 else strend++; | |
504 | |
505 if (str[0] == '[') break; // next section | |
506 if (strncmp(str, "TextImplWindow=",15) == 0) { | |
507 str += 15; | |
508 sscanf(str, "%d", &text_window_number); | |
509 } else if (strncmp(str, "SaveSelectCount=",16) == 0) { | |
510 str += 16; | |
511 sscanf(str, "%d", &save_selectcount); | |
512 } else if (strncmp(str, "RName.", 6) == 0) { | |
513 int n = str[6]-'A'; | |
514 if (n >= 0 && n < 26 && str[7] == '=') { | |
515 const char* s = strchr(str, '\n'); | |
516 int len = -1; | |
517 if (s) len = s-(str+8); | |
518 if (len > 0) { | |
519 replace_name2[n].assign(str+8, len); | |
520 } | |
521 } | |
522 } else if (strncmp(str, "Backlog.", 8) == 0) { | |
523 int cur_scn = -1; | |
524 int n = -1; | |
525 sscanf(str+8, "%d", &n); /* not used */ | |
526 const char* next_str = strchr(str, ';'); | |
527 while(next_str != 0 && next_str < strend) { | |
528 str = next_str + 1; | |
529 next_str = strchr(str, ';'); | |
530 if (next_str == 0) next_str = strend; | |
531 | |
532 BacklogItem item; | |
533 if (str[0] == '"') { | |
534 const char* send = strchr(str+1, '"'); | |
535 if (send == 0 || send > next_str) continue; | |
536 string tmp_str; tmp_str.assign(str+1, send-str-1); | |
537 item.DeleteTextPos(); | |
538 item.text.Load(tmp_str); | |
539 str = send + 1; | |
540 } | |
541 if (str[0] == '.') { | |
542 item.DeleteTextPos(); | |
543 str++; | |
544 } else if (str[0] == ':') { | |
545 sscanf(str, ":%d:%d", &item.scn, &item.pos); | |
546 cur_scn = item.scn; | |
547 | |
548 } else { | |
549 item.scn = cur_scn; | |
550 sscanf(str, "%d", &item.pos); | |
551 } | |
552 str = strchr(str, ','); | |
553 if (str == 0 || str > next_str) goto backlog_store; | |
554 str++; | |
555 if (str[0] == ';' || str[0] == ',') | |
556 item.koe = -1; | |
557 else | |
558 sscanf(str, "%d", &item.koe); | |
559 str = strchr(str, ','); | |
560 if (str == 0 || str > next_str) goto backlog_store; | |
561 str++; | |
562 if (*str == '"') { | |
563 const char* send = strchr(str+1, '"'); | |
564 if (send) { | |
565 item.face.assign(str+1, send-str-1); | |
566 } | |
567 } else if (*str >= 'A' && *str <= 'Z') { | |
568 item.face = face_log.Get(*str - 'A'); | |
569 } | |
570 face_log.Add(item.face); | |
571 backlog_store: | |
572 new_backlog.push_back(item); | |
573 } | |
574 } | |
575 } while (*strend != 0); | |
576 } | |
577 if (new_backlog.empty() && (!backlog.empty())) { // empty なら save_selectcount まで backlog を巻き戻す | |
578 vector<BacklogItem>::iterator it = backlog.end(); | |
579 do { | |
580 it--; | |
581 if (it->scn == BacklogItem::SaveSelect && it->pos == save_selectcount) { | |
582 // Save 位置を見つけたらそれ以降を erase | |
583 backlog.erase(it, backlog.end()); | |
584 break; | |
585 } | |
586 } while(it != backlog.begin()); | |
587 --save_selectcount; | |
588 } else { | |
589 backlog.swap(new_backlog); | |
590 } | |
591 // backlog.clear(); | |
592 return; | |
593 } | |
594 | |
595 void TextImpl::hide(void) { | |
596 if (text) text->hide(); | |
597 if (kcursor) kcursor->hide(); | |
598 text = 0; | |
599 } | |
600 void TextImpl::show(int num) { | |
601 if (num != text_window_number) { | |
602 hide(); | |
603 if (num >= 0 && num < 32 && widgets[num] != 0) { | |
604 text_window_number = num; | |
605 } | |
606 } | |
607 text = widgets[text_window_number]; | |
608 text->show(); | |
609 if (kcursor) { | |
610 int kx, ky, d; | |
611 char key[1024]; | |
612 sprintf(key, "#WINDOW.%03d.KEYCUR_MOD", text_window_number); | |
613 config.GetParam(key, 3, &d, &kx, &ky); | |
614 // 正しくない気がする | |
615 kx += text->wid->Pic()->PosX(); | |
616 ky += text->wid->Pic()->PosY(); | |
617 // 微妙に下にする | |
618 ky += 8; | |
619 kcursor->Pic()->Move(kx, ky); | |
620 } | |
621 } | |
622 void TextImpl::DrawBacklog(BacklogItem& item, Cmd& cmd) { | |
18 | 623 show(); |
0 | 624 text->wid->deactivate(); |
625 status_mask = Status(status_mask | BACKLOG_WAIT_MASK); | |
626 drawn_backlog_item = item; | |
627 if (item.text.container.empty()) { | |
628 // cmd から text 内容を再構成 | |
629 TextStream saved_text = text_stream; | |
630 text_stream.Clear(); | |
631 AddText(cmd.Str(cmd.args[0])); | |
632 item.text = text_stream; | |
633 text_stream = saved_text; | |
634 } | |
18 | 635 item.text.InsertColor(0, item.text.container.size(), 0xff,0xff,0); |
17 | 636 text->StartText(item.text); |
0 | 637 text->wid->Flush(); |
638 if (item.face.empty()) text->ResetFace(); | |
639 else text->ShowFace(item.face.c_str()); | |
640 if (kcursor) kcursor->hide(); | |
641 } | |
642 | |
643 void TextImpl::CreateSelBG(void) { | |
644 if (sel_bg1 != 0 || sel_bg2 != 0) return; | |
645 | |
646 const char* btnfile1 = config.GetParaStr("#SELBTN.000.NAME"); | |
647 const char* btnfile2 = config.GetParaStr("#SELBTN.000.BACK"); | |
648 char path[1024]; | |
649 strcpy(path, btnfile1); | |
650 sel_bg1 = parent.Root().NewSurface(path); | |
651 if (sel_bg1 == 0) { | |
652 sprintf(path,"%s.g00",btnfile1); | |
653 sel_bg1 = parent.Root().NewSurface(path); | |
654 } | |
655 strcpy(path, btnfile2); | |
656 sel_bg2 = parent.Root().NewSurface(path); | |
657 if (sel_bg2 == 0) { | |
658 sprintf(path,"%s.g00",btnfile2); | |
659 sel_bg2 = parent.Root().NewSurface(path); | |
660 } | |
661 sel_bg_rect = Rect(0,0,0,0); | |
662 if (sel_bg1) sel_bg_rect.join(Rect(*sel_bg1)); | |
663 if (sel_bg2) sel_bg_rect.join(Rect(*sel_bg2)); | |
664 return; | |
665 } | |
666 | |
667 void TextImpl::CreateSelect(Cmd& cmd) { | |
668 char key[1024]; | |
669 sprintf(key, "#WINDOW.%03d.SELCOM_USE",text_window_number); | |
670 int sel_type = 0; | |
38
658272d883ed
* Support (more or less) button style selects (fuuko's ones)
thib
parents:
18
diff
changeset
|
671 if (cmd.cmd3 == 1) config.GetParam(key, 1, &sel_type); |
658272d883ed
* Support (more or less) button style selects (fuuko's ones)
thib
parents:
18
diff
changeset
|
672 else if (cmd.cmd3 == 3) sel_type = 0; |
0 | 673 |
674 int sel_size = cmd.args.size() / 2; | |
675 int i; | |
676 // cur_backlog_item に次にbacklogに入るべき内容を作成 | |
677 // CreateSelect() 後、SAVEPOINT なので現在のbacklogの内容(前のメッセージ)が | |
678 // backlog に代入される。その後、backlog_item に cur_backlog_item の内容がセットされる(Wait()内) | |
679 char backlog_sel_text[11] = {0x81,0x69,0x91,0x49,0x91,0xf0,0x8e,0x88,0x81,0x6a,0x00}; | |
680 cur_backlog_item.Clear(); | |
681 cur_backlog_item.AddTextPos(cmd); | |
682 cur_backlog_item.text.Add(backlog_sel_text); | |
683 cur_backlog_item.text.AddReturn(); | |
684 sel_backlog_pos.clear(); | |
685 for (i=0; i<sel_size; i++) { | |
686 sel_backlog_pos.push_back(cur_backlog_item.text.container.size()); | |
687 cur_backlog_item.text.Add(cmd.Str(cmd.args[i*2])); | |
688 cur_backlog_item.text.AddReturn(); | |
689 } | |
690 sel_backlog_pos.push_back(cur_backlog_item.text.container.size()); | |
691 | |
692 if (sel_type == 0) { // Princess Bride: 選択ウィンドウを別表示 | |
693 External_select: | |
694 CreateSelBG(); | |
695 hide(); // なので、テキストウィンドウは消去 | |
696 int baseposx, baseposy, repposx, repposy; | |
697 int mojisize, col1, col2; | |
698 config.GetParam("#SELBTN.000.BASEPOS", 2, &baseposx, &baseposy); | |
699 config.GetParam("#SELBTN.000.REPPOS", 2, &repposx, &repposy); | |
700 config.GetParam("#SELBTN.000.MOJISIZE", 1, &mojisize); | |
701 config.GetParam("#SELBTN.000.MOJIDEFAULTCOL", 1, &col1); | |
702 config.GetParam("#SELBTN.000.MOJISELECTCOL", 1, &col2); | |
703 if (col1 == col2) col2 = 1; // CLANNAD でとりあえず。 | |
704 int r, g, b; | |
705 sprintf(key, "#COLOR_TABLE.%03d", col1); | |
706 config.GetParam(key, 3, &r, &g, &b); | |
707 Color fore(r,g,b); | |
708 sprintf(key, "#COLOR_TABLE.%03d", col2); | |
709 config.GetParam(key, 3, &r, &g, &b); | |
710 Color seled(r,g,b); | |
711 | |
712 /* ウィジット作成 */ | |
713 /* ウィンドウ背景の大きさを求める */ | |
714 if (baseposx == 0 && sel_bg_rect.width() != 0) | |
715 baseposx = (parent.Width()-sel_bg_rect.width()) / 2; // ボタン位置をセンタリング | |
716 | |
717 sel_widget = parent.create_node( Rect(0, 0, parent.Width(), parent.Height()),0); | |
718 | |
719 for (i=0; i<sel_size; i++) { | |
720 PicBase* p; | |
721 // 背景作成 | |
722 if (sel_bg2) { | |
723 p = sel_widget->create_node(Rect(baseposx, baseposy, baseposx+sel_bg_rect.width(), baseposy+sel_bg_rect.height()),0); | |
724 p->SetSurface(sel_bg2, 0, 0); | |
725 } | |
726 if (sel_bg1) { | |
727 p = sel_widget->create_node(Rect(baseposx, baseposy, baseposx+sel_bg_rect.width(), baseposy+sel_bg_rect.height()),0); | |
728 p->SetSurface(sel_bg1, 0, 0); | |
729 } | |
730 /* ボタン作成 */ | |
731 const char* str = cmd.Str(cmd.args[i*2]); | |
732 int value = cmd.args[i*2+1].value; | |
733 while(selects.size() <= value) selects.push_back(0); // vector の大きさを広げる | |
734 | |
735 kconv( (const unsigned char*)str, (unsigned char*)key); | |
736 selects[value] = new WidTextButton(event, sel_widget, key, mojisize, WidTextButton::CENTER, | |
737 Rect(baseposx, baseposy, baseposx+sel_bg_rect.width(), baseposy+sel_bg_rect.height()), 1, fore, seled, Color(0,0,0,0)); | |
738 selects[value]->press_func = &PressFuncButton; | |
739 selects[value]->press_pointer = (void*)this; | |
740 | |
741 baseposx += repposx; | |
742 baseposy += repposy; | |
743 } | |
744 sel_widget->show_all(); | |
745 status = WAIT_SELECT_OUTBOX; | |
746 } else { // CLANNAD: テキストウィンドウ内に選択肢表示 | |
747 int mojisize; | |
748 config.GetParam("#SELBTN.000.MOJISIZE", 1, &mojisize); | |
749 Color fore(0xff,0xff,0xff); | |
750 Color seled(0xff,0xff,0xff); | |
751 | |
752 show(); | |
753 if (text == 0) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする | |
754 text->wid->Clear(); | |
755 if (kcursor) kcursor->hide(); | |
756 /* ウィジット作成 : テキスト表示範囲と同じ*/ | |
757 int posx = text->wid->pictext->PosX(); | |
758 int posy = text->wid->pictext->PosY(); | |
759 int sel_w = text->wid->pictext->Width(); | |
760 int sel_h = text->wid->pictext->Height(); | |
761 sel_widget = text->wid->PicNode()->create_node(Rect(posx, posy, posx+sel_w, posy+sel_h), 0); | |
762 | |
763 int sel_y = 0; | |
764 for (i=0; i<sel_size; i++) { | |
765 PicBase* p; | |
766 /* ボタン作成 */ | |
767 const char* str = cmd.Str(cmd.args[i*2]); | |
768 int value = cmd.args[i*2+1].value; | |
769 while(selects.size() <= value) selects.push_back(0); // vector の大きさを広げる | |
770 | |
771 kconv( (const unsigned char*)str, (unsigned char*)key); | |
772 selects[value] = new WidTextButton(event, sel_widget, key, mojisize, WidTextButton::Attribute(WidTextButton::REVERSE | WidTextButton::NOPADDING), | |
773 Rect(0, sel_y, sel_w, sel_y), 1, fore, seled, Color(0,0,0,0)); | |
774 selects[value]->press_func = &PressFuncButton; | |
775 selects[value]->press_pointer = (void*)this; | |
776 | |
777 sel_y += selects[value]->Pic()->Height() + 1; | |
778 } | |
779 sel_widget->show_all(); | |
780 status = WAIT_SELECT_INBOX; | |
781 } | |
782 } | |
783 | |
784 void TextImpl::AddText(const char* str_o) { | |
785 char str[10001]; | |
786 if (text == 0) return; | |
787 /* まず、replace string を変換 */ | |
788 int i; | |
789 int cnt = 0; | |
790 /* * = 81 96 A-Z = 0x82 [0x60-0x79] */ | |
791 /* % = 81 93 A-Z = 0x82 [0x60-0x79] */ | |
792 for (i=0; cnt<10000 && str_o[i] != 0; i++) { | |
793 if (str_o[i] < 0) { | |
794 if ( (unsigned char)str_o[i] == 0x81 && (unsigned char)str_o[i+1] == 0x96 && (unsigned char)str_o[i+2] == 0x82) { | |
795 int c = str_o[i+3]; | |
796 if (c >= 0x60 && c <= 0x79 && replace_name[c-0x60].length() != 0) { // 名前変換 | |
797 i += 3; | |
798 strcpy(str+cnt, replace_name[c-0x60].c_str()); | |
799 cnt += replace_name[c-0x60].length(); | |
800 continue; | |
801 } | |
802 } else if ( (unsigned char)str_o[i] == 0x81 && (unsigned char)str_o[i+1] == 0x93 && (unsigned char)str_o[i+2] == 0x82) { | |
803 int c = str_o[i+3]; | |
804 if (c >= 0x60 && c <= 0x79 && replace_name2[c-0x60].length() != 0) { // 名前変換2 | |
805 i += 3; | |
806 strcpy(str+cnt, replace_name2[c-0x60].c_str()); | |
807 cnt += replace_name2[c-0x60].length(); | |
808 continue; | |
809 } | |
810 } | |
811 str[cnt++] = str_o[i++]; | |
812 } | |
813 str[cnt++] = str_o[i]; | |
814 } | |
815 str[cnt] = 0; | |
816 str[10000] = 0; | |
817 char* str_top = str; | |
818 | |
819 for (char* s = str_top; *s != 0; s++) { | |
820 // if (*(unsigned char*)s == 0xa1 && *(unsigned char*)(s+1) == 0xda) { /* euc */ | |
821 if (*(unsigned char*)s == 0x81 && *(unsigned char*)(s+1) == 0x79) { /* sjis */ | |
822 // 名前 | |
823 *s = 0; | |
824 if (s != str_top) text_stream.Add(str_top); | |
825 s += 2; | |
826 char* name_top = s; | |
827 for (; *s != 0; s++) { | |
828 // if (*(unsigned char*)s == 0xa1 && *(unsigned char*)(s+1) == 0xdb) { /* euc */ | |
829 if (*(unsigned char*)s == 0x81 && *(unsigned char*)(s+1) == 0x7a) { /* sjis */ | |
830 *s = 0; | |
831 s += 2; | |
832 text_stream.AddName(name_top); | |
833 break; | |
834 } | |
835 if (*s < 0 && s[1] != 0) s++; // 全角文字なら2字飛ばす | |
836 } | |
837 str_top = s; | |
838 } | |
839 if (*s == 0x0a) { | |
840 *s = 0; | |
841 text_stream.Add(str_top); | |
842 text_stream.AddReturn(); | |
843 str_top = s; | |
844 } else if (*s < 0 && s[1] != 0) s++; | |
845 } | |
846 text_stream.Add(str_top); | |
847 return; | |
848 } | |
849 | |
850 void TextImpl::Exec(Cmd& cmd) { | |
851 if (cmd.cmd_type == CMD_TEXT) { | |
852 if (text == 0) { | |
853 show(); | |
854 } | |
855 if (cmd.args.size() != 1) return; | |
856 if (ruby_text_flag) { | |
857 ruby_text = cmd.Str(cmd.args[0]); | |
858 ruby_text_flag = 0; | |
859 cmd.clear(); | |
860 return; | |
861 } | |
862 cur_backlog_item.AddTextPos(cmd); | |
863 AddText(cmd.Str(cmd.args[0])); | |
864 char debug[1024]; | |
865 kconv( (unsigned char*)cmd.Str(cmd.args[0]), (unsigned char*)debug); | |
866 eprintf("text: %s\n",debug); | |
867 if (text_parsing) | |
868 cmd.clear(); | |
869 else | |
870 cmd.cmd_type = CMD_SAVEPOINT; | |
871 text_parsing = true; /* テキスト待ち直後のテキスト位置=セーブ位置 */ | |
872 return; | |
873 } | |
874 if (cmd.cmd_type != CMD_OTHER) return; | |
875 /* テキストウィンドウを消去するコマンド類をチェックする */ | |
876 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x21) { | |
877 if (cmd.cmd3 == 0x49 || cmd.cmd3 == 0x4b || cmd.cmd3 == 0x4c) { | |
878 if (text) text->ResetFace(); | |
879 cur_backlog_item.face = ""; | |
880 hide(); | |
881 } | |
882 } | |
883 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x17 && cmd.cmd3 == 0 && cmd.cmd4 == 1) { | |
884 // PlayKoe ; 声出力コマンドをチェックする */ | |
885 cur_backlog_item.koe = cmd.args[0].value; | |
886 } | |
887 if (cmd.cmd1 == 0 && cmd.cmd2 == 3 && cmd.cmd3 == 0x97) { // いいのかなー | |
888 | |
889 if (text) { | |
890 text->ResetFace(); | |
891 text->wid->Clear(); | |
892 } | |
893 cur_backlog_item.face = ""; | |
894 text_stream.Clear(); | |
895 hide(); | |
896 } | |
897 if (cmd.cmd1 == 0 && cmd.cmd2 == 3) { | |
898 if (cmd.cmd3 == 0x11) { // テキスト表示、クリック待ち | |
899 if (text) { | |
900 eprintf("start\n"); | |
901 text->StartText(text_stream); | |
902 if (skip_mode & SKIP_TEXT) text->wid->Flush(); | |
903 else if (kcursor) kcursor->show(); | |
904 status = WAIT_TEXT; | |
905 text_parsing = false; | |
906 } | |
907 backlog_item = cur_backlog_item; | |
908 if (cur_backlog_item.scn == 0 && cur_backlog_item.pos == -1) backlog_item.text = text_stream; | |
909 cur_backlog_item.Clear(); | |
910 | |
911 cmd.clear(); | |
912 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため) | |
913 // これだと1フレーム1テキストしか表示されなくなるので注意 | |
914 } else if (cmd.cmd3 == 3 || cmd.cmd3 == 0xc9) { // リターン挿入 | |
915 text_stream.AddReturn(); | |
916 cur_backlog_item.DeleteTextPos(); | |
917 cmd.clear(); | |
918 } else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更 | |
919 if (text == 0) { | |
920 show(); | |
921 } | |
922 if (cmd.cmd3 == 0x3e8) { | |
923 string s = cmd.Str(cmd.args[0]); | |
924 s += ".g00"; | |
925 if (text) text->ShowFace(s.c_str()); | |
926 cur_backlog_item.face = s; | |
927 cmd.cmd_type = CMD_SAVECMD_ONCE; | |
928 } else if (cmd.cmd3 == 0x3e9) { // 顔グラフィック消去 | |
929 if (text) text->ResetFace(); | |
930 cur_backlog_item.face = ""; | |
931 cmd.cmd_type = CMD_SAVECMD_ONCE; | |
932 } | |
933 } else if (cmd.cmd3 == 0x78) { // ルビ関連 | |
934 if (text == 0) { | |
935 show(); | |
936 } | |
937 if (cmd.cmd4 == 1) { | |
938 ruby_text_flag = true; | |
939 eprintf("SetRubyTextImpl."); | |
940 cmd.clear(); | |
941 } else if (cmd.cmd4 == 0) { | |
942 if (ruby_text.length() == 0) { // ルビを振るテキストがない | |
943 eprintf("Cannot find ruby text.\n"); | |
944 return; | |
945 } | |
946 if (cmd.args.size() != 1) return; | |
947 char debug1[1024], debug2[1024]; | |
948 kconv( (unsigned char*)ruby_text.c_str(), (unsigned char*)debug1); | |
949 kconv( (unsigned char*)cmd.Str(cmd.args[0]), (unsigned char*)debug2); | |
950 eprintf("SetRuby. %s, %s",debug1, debug2); | |
951 text_stream.AddRuby(ruby_text.c_str(), cmd.Str(cmd.args[0])); | |
952 cur_backlog_item.DeleteTextPos(); | |
953 cmd.clear(); | |
954 } | |
955 } else if (cmd.cmd3 == 0x66) { // テキストウィンドウの形 | |
956 if (cmd.cmd4 == 0) { | |
957 eprintf("set text window <- %d\n",cmd.args[0].value); | |
958 if (text) show(cmd.args[0].value); | |
959 else text_window_number = cmd.args[0].value; | |
960 } else if (cmd.cmd4 == 1) { // default value | |
961 eprintf("set text window <- default\n"); | |
962 if (text) show(0); | |
963 else text_window_number = 0; | |
964 } | |
965 cmd.clear(); | |
966 } else if (cmd.cmd3 == 0x67) { // テキストウィンドウ表示? | |
967 show(); | |
968 // 表示の際はテキストをクリアしない? | |
969 // if (text) text->wid->Clear(); | |
970 // text_stream.Clear(); | |
971 cmd.clear(); | |
972 } else if (cmd.cmd3 == 0x68) { // テキスト表示? | |
973 // 全テキスト表示 | |
974 if (text) { | |
975 text->StartText(text_stream); | |
976 text->wid->Flush(); | |
977 } | |
978 cmd.clear(); | |
979 } else if (cmd.cmd3 == 0x98) { // テキストウィンドウクリア? | |
980 show(); | |
981 if (text) text->wid->Clear(); | |
982 text_stream.Clear(); | |
983 cmd.clear(); | |
984 } | |
985 } else if (cmd.cmd1 == 0 && cmd.cmd2 == 2 && (cmd.cmd3 == 1 || cmd.cmd3 == 3) && cmd.cmd4 == 0) { | |
986 // 選択肢 | |
987 CreateSelect(cmd); | |
988 cmd.cmd_type = CMD_ROLLBACKPOINT; /* 選択肢はセーブ位置 / シナリオ巻き戻し位置 */ | |
989 // cmd.clear(); | |
990 } else if (cmd.cmd1 == 0 && cmd.cmd2 == 4) { | |
991 if (cmd.cmd3 == 0x44c) { // テキストスキップ開始 | |
992 status_mask = Status(SKIPMASK | status_mask); | |
993 cmd.clear(); | |
994 } else if (cmd.cmd3 == 0x3e8) { // ウィンドウ消去 | |
995 status_mask = Status(CLEARSCR_MASK | status_mask); | |
996 cmd.clear(); | |
997 } | |
998 } else if (cmd.cmd1 == 1 && cmd.cmd2 == 0x04) { | |
999 /* ウェイト関連命令 */ | |
1000 if (cmd.cmd3 == 0x64 || cmd.cmd3 == 0x6f || cmd.cmd3 == 0x79) { | |
1001 eprintf("wait %dmsec\n",cmd.args[0].value); | |
1002 if (cmd.cmd3 == 0x64 && text) { | |
1003 /* 0x64 だと文字描画中の待ちに使うことがある */ | |
1004 text->StartText(text_stream); | |
1005 text->wid->Flush(); | |
1006 } | |
1007 if (cmd.cmd3 == 0x6f || cmd.cmd3 == 0x79) wait_time = base_time + cmd.args[0].value; | |
1008 else wait_time = old_time + cmd.args[0].value; | |
1009 status = WAIT; | |
1010 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため) | |
1011 } else if (cmd.cmd3 == 0x65 || cmd.cmd3 == 0x70) { | |
1012 eprintf("wait %dmsec(click stop)\n",cmd.args[0].value); | |
1013 if (cmd.cmd3 == 0x70) wait_time = base_time + cmd.args[0].value; | |
1014 else wait_time = old_time + cmd.args[0].value; | |
1015 status = WAIT_CLICK; | |
1016 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため) | |
1017 } else if (cmd.cmd3 == 0x83) { | |
1018 /* マウスがクリックされるまで待つ */ | |
1019 eprintf("wait and get mouse pos at click\n"); | |
1020 wait_time = old_time + 1000 * 1000; | |
1021 status = WAIT_CLICK_MOUSEPOS; | |
1022 wait_savedvar[0] = cmd.args[0]; | |
1023 wait_savedvar[1] = cmd.args[1]; | |
1024 cmd.clear(); | |
1025 } else if (cmd.cmd3 == 0x1fe) { | |
1026 eprintf("get timer value[%d]\n",cmd.args[0].value); | |
1027 if (timer_var.find(cmd.args[0].value) == timer_var.end()) { | |
1028 cmd.SetSysvar(0); | |
1029 } else { | |
1030 TimerAtom& atom = timer_var[cmd.args[0].value]; | |
1031 if (atom.total_time <= 0) atom.total_time = 1; | |
1032 int cur_tm = old_time - atom.start_time; | |
1033 if (cur_tm < 0) cur_tm = atom.total_time; // エラーなら最終時間に合わせる | |
1034 if (cur_tm > atom.total_time) cur_tm = atom.total_time; | |
1035 // use 'long long'(64bit) or 'double'(80bit) type, since total_time, to and from is 32 bit. | |
1036 int v = atom.from + (long long)(atom.to-atom.from)*cur_tm/int(atom.total_time); | |
1037 cmd.SetSysvar(v); | |
1038 } | |
1039 /* From rldev-1.40, reallive.kfn | |
1040 0x72 fun Timer (store) <1:Sys:00114, 1> ('counter') () | |
1041 0x73 fun CmpTimer (store) <1:Sys:00115, 1> ('time') ('time', 'counter') | |
1042 0x74 fun SetTimer <1:Sys:00116, 1> ('time') ('time', 'counter') | |
1043 | |
1044 0x78 fun ResetExTimer <1:Sys:00120, 1> ('counter') () | |
1045 0x79 fun timeEx <1:Sys:00121, 1> ('time') ('time', 'counter') | |
1046 0x7a fun timeExC (store) <1:Sys:00122, 1> ('time') ('time', 'counter') | |
1047 0x7b fun timeExC2 (store) <1:Sys:00123, 1> ('time') ('time', 'counter') // UNDOCUMENTED | |
1048 0x7c fun ExTimer (store) <1:Sys:00124, 1> ('counter') () | |
1049 0x7d fun CmpExTimer (store) <1:Sys:00125, 1> ('time') ('time', 'counter') | |
1050 0x7e fun SetExTimer <1:Sys:00126, 1> ('time') ('time', 'counter') | |
1051 */ | |
1052 | |
1053 } else if (cmd.cmd3 == 0x6e || cmd.cmd3 == 0x78) { // set basetime | |
1054 if (cmd.cmd4 == 1) { | |
1055 eprintf("set basetime\n"); | |
1056 base_time = old_time; | |
1057 cmd.clear(); | |
1058 } else if (cmd.cmd4 == 0) { // n-th base time | |
1059 int index = cmd.args[0].value; | |
1060 eprintf("set basetime (%d)\n",index); | |
1061 TimerAtom& atom = timer_var[index]; | |
1062 atom.from = 0; | |
1063 atom.to = 0; | |
1064 atom.total_time = 0; | |
1065 atom.start_time = old_time; | |
1066 cmd.clear(); | |
1067 } | |
1068 } else if (cmd.cmd3 == 0x72 || cmd.cmd3 == 0x7c) { // get time | |
1069 if (cmd.cmd4 == 1) { // get time | |
1070 eprintf("get time\n"); | |
1071 cmd.SetSysvar(old_time - base_time); | |
1072 } else if (cmd.cmd4 == 0) { // n-th get time | |
1073 int index = cmd.args[0].value; | |
1074 eprintf("get time %dth\n",index); | |
1075 if (timer_var.find(index) == timer_var.end()) cmd.SetSysvar(0); | |
1076 else cmd.SetSysvar(old_time - timer_var[index].start_time); | |
1077 } | |
1078 } else if (cmd.cmd3 == 0x26c || cmd.cmd3 == 0x270) { // set basetime(multi) | |
1079 int j = 0; | |
1080 eprintf("set basetime\n"); | |
1081 int i; for (i=0; i<cmd.argc; i++) { | |
1082 int cnt = cmd.args[j++].value; // 3なので無視 | |
1083 int num = cmd.args[j++].value; | |
1084 TimerAtom& atom = timer_var[num]; | |
1085 atom.from = cmd.args[j++].value; | |
1086 atom.to = cmd.args[j++].value; | |
1087 atom.total_time = cmd.args[j++].value; | |
1088 atom.start_time = old_time; | |
1089 } | |
1090 cmd.clear(); | |
1091 } else if (cmd.cmd3 == 0x276) { // get time (multi) | |
1092 int j = 0; | |
1093 eprintf("get timer value\n"); | |
1094 vector<VarInfo> args = cmd.args; | |
1095 vector<VarInfo>::iterator it = args.begin(); | |
1096 int argc = cmd.argc; | |
1097 int active_timers = 0; | |
1098 int i; for (i=0; i<argc; i++) { | |
1099 int cnt = (it++)->value; | |
1100 int num = (it++)->value; | |
1101 | |
1102 if (timer_var.find(num) == timer_var.end()) { | |
1103 cmd.SetFlagvar(*it++, 0); | |
1104 } else { | |
1105 TimerAtom& atom = timer_var[num]; | |
1106 if (atom.total_time <= 0) atom.total_time = 1; | |
1107 int cur_tm = old_time - atom.start_time; | |
1108 if (cur_tm < 0) cur_tm = atom.total_time; // エラーなら最終時間に合わせる | |
1109 if (cur_tm > atom.total_time) cur_tm = atom.total_time; | |
1110 // use 'long long'(64bit) or 'double'(80bit) type, since total_time, to and from is 32 bit. | |
1111 int v = atom.from + (long long)(atom.to-atom.from)*cur_tm/int(atom.total_time); | |
1112 cmd.SetFlagvar(*it++, v); | |
1113 if (atom.total_time != -1 && cur_tm < atom.total_time) active_timers++; | |
1114 } | |
1115 } | |
1116 if (active_timers) active_timers = 1; | |
1117 cmd.SetSysvar(active_timers); | |
1118 } else if (cmd.cmd3 == 0x1f4) { | |
1119 TimerAtom& atom = timer_var[cmd.args[0].value]; | |
1120 atom.from = cmd.args[1].value; | |
1121 atom.to = cmd.args[2].value; | |
1122 atom.total_time = cmd.args[3].value; | |
1123 atom.start_time = old_time; | |
1124 cmd.clear(); | |
1125 } else if (cmd.cmd3 == 0x3e8) { | |
1126 /* rand() */ | |
1127 int min = 0, max; | |
1128 if (cmd.args.size() == 2) { | |
1129 min = cmd.args[0].value; | |
1130 max = cmd.args[1].value; | |
1131 } else { | |
1132 max = cmd.args[1].value; | |
1133 } | |
1134 if (min > max) { | |
1135 int tmp = max; | |
1136 max = min; | |
1137 min = tmp; | |
1138 } | |
1139 int r = random(); | |
1140 if (min == max) r = min; | |
1141 else r = (r % (max-min)) + min; | |
1142 cmd.SetSysvar(r); | |
1143 } else if (cmd.cmd3 == 0x3ea) { | |
1144 int val = cmd.args[0].value; | |
1145 if (val < 0) val = -val; | |
1146 cmd.SetSysvar(val); | |
1147 } else if (cmd.cmd3 == 0x3ec) { | |
1148 /* min だよなあ・・・*/ | |
1149 int min = cmd.args[0].value; | |
1150 int max = cmd.args[1].value; | |
1151 if (max < min) min = max; | |
1152 cmd.SetSysvar(min); | |
1153 } else if (cmd.cmd3 == 0x3ef) { | |
1154 /* min */ | |
1155 int min = cmd.args[0].value; | |
1156 int max = cmd.args[1].value; | |
1157 if (max < min) min = max; | |
1158 cmd.SetSysvar(min); | |
1159 } else if (cmd.cmd3 == 0x320) { | |
1160 /* range conversion : 比率に丸める */ | |
1161 // アルゴリズムは間違えてるような気がする | |
1162 // | |
1163 if (cmd.args.size() >= 7) { | |
1164 int val = cmd.args[0].value; | |
1165 int offset = cmd.args[1].value; | |
1166 int r_min = cmd.args[2].value; | |
1167 int v_min = cmd.args[3].value; | |
1168 int v_max = cmd.args[4].value; | |
1169 int r_max = cmd.args[5].value; | |
1170 int mode = cmd.args[6].value; | |
1171 // rldev : mode == 1,3 : 'acceralating curve', 2,3: 'decelerating curve' | |
1172 // 複数の引数リスト(r_minからmodeまでのリスト)もつこともあり、その場合は | |
1173 // "cancel out in some way" らしい | |
1174 if (mode == 1 || mode == 3) val += offset; | |
1175 else if (mode == 2 || mode == 4) val -= offset; | |
1176 if (cmd.args.size() != 7) | |
1177 fprintf(stderr,"\n%d/%d: cmd 01-04:0320 : XXXX NOT SUPPORTED LIST : DOUBLE RANGE CONVERSION! XXXXXXXXXXX\n",cmd.scn,cmd.pos); | |
1178 if (val < v_min) val = v_min; | |
1179 if (val > v_max) val = v_max; | |
1180 val = (r_max-r_min)*(val-v_min)/(v_max-v_min) + r_min; | |
1181 cmd.SetSysvar(val); | |
1182 } | |
1183 } else if (cmd.cmd3 == 0x3f1) { | |
1184 /* range 内に丸める */ | |
1185 int min = cmd.args[0].value; | |
1186 int val = cmd.args[1].value; | |
1187 int max = cmd.args[2].value; | |
1188 if (min > max) { | |
1189 int tmp = max; | |
1190 max = min; | |
1191 min = tmp; | |
1192 } | |
1193 if (val < min) val = min; | |
1194 if (val > max) val = max; | |
1195 cmd.SetSysvar(val); | |
1196 } else if (cmd.cmd3 == 0x16c && cmd.cmd4 == 0) { | |
1197 /* なんかよくわからないけどカーソル形状変更にしとく */ | |
1198 SetCursor(cmd.args[0].value); | |
1199 cmd.clear(); | |
1200 } else if (cmd.cmd3 == 0x0bc1) { // メニューからのロード | |
1201 cmd.cmd_type = CMD_LOADREQ; | |
1202 } else if ( (cmd.cmd3 >= 0x8d4 && cmd.cmd3 <= 0x8d8) || cmd.cmd3 == 0x8db || cmd.cmd3 == 0x93f || cmd.cmd3 == 0xa39) { | |
1203 // テキストウィンドウの色設定 | |
1204 int r, g, b, a, flag; | |
1205 if (cmd.cmd3 == 0xa39) { // 元設定を取り出す | |
1206 config.GetOriginalParam("#WINDOW_ATTR", 5, &r, &g, &b, &a, &flag); | |
1207 } else { | |
1208 config.GetParam("#WINDOW_ATTR", 5, &r, &g, &b, &a, &flag); | |
1209 } | |
1210 if (cmd.cmd3 == 0xa39 || cmd.cmd3 == 0x93f) { // 設定を変数に取り出す | |
1211 if (cmd.args.size() != 5) { | |
1212 fprintf(stderr,"cmd 01-04:%4d : invalid arg size\n", cmd.cmd3); | |
1213 } else { | |
1214 vector<VarInfo> args(cmd.args); | |
1215 cmd.SetFlagvar(args[0], r); | |
1216 cmd.SetFlagvar(args[1], g); | |
1217 cmd.SetFlagvar(args[2], b); | |
1218 cmd.SetFlagvar(args[3], a); | |
1219 cmd.SetFlagvar(args[4], flag); | |
1220 } | |
1221 } else { | |
1222 switch(cmd.cmd3) { | |
1223 case 0x8d4: r = cmd.args[0].value; break; | |
1224 case 0x8d5: g = cmd.args[0].value; break; | |
1225 case 0x8d6: b = cmd.args[0].value; break; | |
1226 case 0x8d7: a = cmd.args[0].value; break; | |
1227 case 0x8d8: flag = cmd.args[0].value; break; | |
1228 case 0x8db: | |
1229 r = cmd.args[0].value; | |
1230 g = cmd.args[1].value; | |
1231 b = cmd.args[2].value; | |
1232 a = cmd.args[3].value; | |
1233 flag = cmd.args[4].value; | |
1234 break; | |
1235 } | |
1236 config.SetParam("#WINDOW_ATTR", 5, r, g, b, a, flag); | |
1237 SetWindowColor(r, g, b, a, flag); | |
1238 cmd.clear(); | |
1239 } | |
1240 } else if (cmd.cmd3 == 0xa28 || cmd.cmd3 == 0xa29 || cmd.cmd3 == 0xa2c || cmd.cmd3 == 0xa2d || cmd.cmd3 == 0xa2e) { | |
1241 int v = 0; | |
1242 switch(cmd.cmd3) { | |
1243 case 0xa28: case 0xa2d: config.GetOriginalParam("#INIT_MESSAGE_SPEED", 1, &v); break; | |
1244 case 0xa29: config.GetOriginalParam("#INIT_MESSAGE_SPEED_MOD", 1, &v); break; | |
1245 case 0xa2c: config.GetOriginalParam("#MESSAGE_KEY_WAIT_USE", 1, &v); break; | |
1246 case 0xa2e: config.GetOriginalParam("#MESSAGE_KEY_WAIT_TIME", 1, &v); break; | |
1247 } | |
1248 cmd.SetSysvar(v); | |
1249 } else if (cmd.cmd3 == 0x913 || cmd.cmd3 == 0x914 || cmd.cmd3 == 0x92f || cmd.cmd3 == 0x8af || cmd.cmd3 == 0x8b0 || cmd.cmd3 == 0x8cb) { | |
1250 // テキスト表示速度関連 | |
1251 int m, speed; | |
1252 config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed); | |
1253 config.GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &m); | |
1254 if (cmd.cmd3 == 0x913 || cmd.cmd3 == 0x92f) fprintf(stderr,"TEXT speed %d\n",speed); | |
1255 else if (cmd.cmd3 == 0x914) fprintf(stderr,"TEXT mode %d\n",m); | |
1256 else if (cmd.cmd3 == 0x8af || cmd.cmd3 == 0x8cb) fprintf(stderr,"TEXT %d, %d <- speed %d\n",m,speed,cmd.args[0].value); | |
1257 else fprintf(stderr,"TEXT %d, %d <- mode %d\n",m,speed,cmd.args[0].value); | |
1258 if (cmd.cmd3 == 0x913 || cmd.cmd3 == 0x92f) cmd.SetSysvar(speed); | |
1259 else if (cmd.cmd3 == 0x914) cmd.SetSysvar(m); | |
1260 else { | |
1261 if (cmd.cmd3 == 0x8af || cmd.cmd3 == 0x8cb) speed = cmd.args[0].value; | |
1262 else m = cmd.args[0].value; | |
1263 if (speed < 10) speed = 10; | |
1264 else if (speed > 1000) speed = 1000; | |
1265 config.SetParam("#INIT_MESSAGE_SPEED", 1, speed); | |
1266 config.SetParam("#INIT_MESSAGE_SPEED_MOD", 1, m); | |
1267 if (m) speed = -1; | |
1268 SetTextSpeed(speed); | |
1269 cmd.clear(); | |
1270 } | |
1271 } else if (cmd.cmd3 == 0x92e || cmd.cmd3 == 0x930 || cmd.cmd3 == 0x8ca || cmd.cmd3 == 0x8cc) { | |
1272 // テキストオートモード関連 | |
1273 int m, wait; | |
1274 config.GetParam("#MESSAGE_KEY_WAIT_USE", 1, &m); | |
1275 config.GetParam("#MESSAGE_KEY_WAIT_TIME", 1, &wait); | |
1276 if (cmd.cmd3 == 0x92e) fprintf(stderr,"AUTO mode %d\n",m); | |
1277 else if (cmd.cmd3 == 0x930) fprintf(stderr,"AUTO wait %d\n",wait); | |
1278 else if (cmd.cmd3 == 0x8ca) fprintf(stderr,"AUTO %d,%d <- mode %d\n",m,wait,cmd.args[0].value); | |
1279 else fprintf(stderr,"AUTO %d,%d <- wait %d\n",m,wait,cmd.args[0].value); | |
1280 | |
1281 if (cmd.cmd3 == 0x92e) cmd.SetSysvar(m); | |
1282 else if (cmd.cmd3 == 0x930) cmd.SetSysvar(wait); | |
1283 else { | |
1284 if (cmd.cmd3 == 0x8ca) m = cmd.args[0].value; | |
1285 else wait = cmd.args[1].value; | |
1286 if (wait < 0) wait = 0; | |
1287 else if (wait > 60000) wait = 60000; | |
1288 config.SetParam("#MESSAGE_KEY_WAIT_USE", 1, m); | |
1289 config.SetParam("#MESSAGE_KEY_WAIT_TIME", 1, wait); | |
1290 if (m) SetTextWait(wait); | |
1291 else SetTextWait(-1); | |
1292 cmd.clear(); | |
1293 } | |
1294 } else if (cmd.cmd3 == 0x51f && cmd.cmd4 == 0) { // replace_name2 の設定 | |
1295 int n = cmd.args[0].value; | |
1296 if (n>=0 && n<26) { | |
1297 replace_name2[n] = cmd.Str(cmd.args[1]); | |
1298 } | |
1299 cmd.clear(); | |
1300 } else if (cmd.cmd3 == 0x51e && cmd.cmd4 == 0) { // replace_name2 を得る | |
1301 int n = cmd.args[0].value; | |
1302 if (n >= 0 && n < 26) { | |
1303 cmd.SetStrvar(cmd.args[1], replace_name2[n]); | |
1304 } else { | |
1305 cmd.SetStrvar(cmd.args[1], ""); | |
1306 } | |
1307 } else if (cmd.cmd3 == 0x514 && cmd.cmd4 == 0) { // replace_name を得る | |
1308 int n = cmd.args[0].value; | |
1309 if (n >= 0 && n < 26) { | |
1310 cmd.SetStrvar(cmd.args[1], replace_name[n]); | |
1311 } else { | |
1312 cmd.SetStrvar(cmd.args[1], ""); | |
1313 } | |
1314 } | |
1315 } | |
1316 | |
1317 return; | |
1318 } | |
1319 extern int print_blit; | |
1320 bool TextImpl::Wait(unsigned int current_time, Cmd& cmd) { | |
1321 if (current_time != 0xffffffffUL) old_time = current_time; | |
1322 /* | |
1323 if (event.presscount(MOUSE_UP)) { | |
1324 if (text) text->Pic()->ReBlit(); | |
1325 } | |
1326 if (event.presscount(MOUSE_DOWN)) { | |
1327 print_blit^=1; | |
1328 } | |
1329 */ | |
1330 | |
1331 if (status == NORMAL && status_mask == NORMAL) return false; | |
1332 | |
1333 if (status_mask & WAIT_EXTRN_MASK) return true; | |
1334 if (status_mask & (BACKLOG_MASK|BACKLOG_MASK_FWD) ) { | |
1335 if (status_mask & BACKLOG_WAIT_MASK) ; | |
1336 else { | |
1337 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { | |
1338 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { | |
1339 text->wid->Flush(); // 表示を最後の状態にする | |
1340 } | |
1341 if (status == WAIT_TEXT && text != 0 && kcursor) kcursor->show(); | |
1342 } | |
1343 } | |
1344 if (status_mask & BACKLOG_MASK) { | |
1345 cmd.cmd_type = CMD_BACKLOGREQ; | |
1346 } else { | |
1347 cmd.cmd_type = CMD_BACKLOGREQ_FWD; | |
1348 } | |
1349 status_mask = Status(status_mask & ~(BACKLOG_MASK|BACKLOG_MASK_FWD)); | |
1350 return false; | |
1351 } | |
1352 if ( (status_mask & BACKLOG_WAIT_MASK) && (status_mask & BACKLOG_MASK_KOE)) { | |
1353 if (drawn_backlog_item.koe != -1) { | |
1354 cmd.cmd_type = CMD_OTHER; | |
1355 cmd.cmd1 = 1; | |
1356 cmd.cmd2 = 0x17; | |
1357 cmd.cmd3 = 0; | |
1358 cmd.cmd4 = 1; | |
1359 cmd.args.clear(); | |
1360 cmd.args.push_back(VarInfo(drawn_backlog_item.koe)); | |
1361 cmd.args.push_back(VarInfo(0)); | |
1362 } | |
1363 status_mask = Status(status_mask & ~BACKLOG_MASK_KOE); | |
1364 return false; | |
1365 } | |
1366 if (skip_mode & SKIP_IN_MENU) return false; | |
1367 if (status_mask & SAVEMASK) { | |
1368 cmd.cmd_type = CMD_SAVEREQ; | |
1369 status_mask = Status(status_mask & ~SAVEMASK); | |
1370 return false; | |
1371 } | |
1372 if (status_mask & LOADMASK) { | |
1373 cmd.cmd_type = CMD_LOADREQ; | |
1374 status_mask = Status(status_mask & ~LOADMASK); | |
1375 return false; | |
1376 } | |
1377 if (status_mask & SKIPEND_MASK) { | |
1378 if ( (skip_mode & SKIP_TEXT) && (skip_mode & SKIPEND_TEXT)) { | |
1379 if (skip_mode & SKIPEND_KEY) { // shift skip 中 | |
1380 SkipMode new_mode = SkipMode(skip_mode & (~SKIPEND_TEXT)); | |
1381 if (new_mode & (SKIP_GRP_NOEFFEC || SKIP_GRP_NODRAW)) | |
1382 new_mode = SkipMode(new_mode & (~SKIP_GRP_FAST)); | |
1383 cmd.SetSysvar(TYPE_SYS_SKIPMODE, new_mode); | |
1384 } else { | |
1385 cmd.SetSysvar(TYPE_SYS_SKIPMODE, SKIP_NO); | |
1386 } | |
1387 } | |
1388 status_mask = Status(status_mask & ~SKIPEND_MASK); | |
1389 } | |
1390 if (status_mask & SKIPMASK) { | |
1391 if (skip_mode != SKIP_NO) { | |
1392 cmd.SetSysvar(TYPE_SYS_SKIPMODE, skip_mode | SKIPEND_TEXT); | |
1393 } else { | |
1394 cmd.SetSysvar(TYPE_SYS_SKIPMODE, SKIP_TEXT | SKIP_GRP_FAST | SKIPEND_TEXT); | |
1395 } | |
1396 status_mask = Status(status_mask & ~SKIPMASK); | |
1397 return false; | |
1398 } | |
1399 if (event.presscount(MOUSE_RIGHT)) { | |
1400 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { | |
1401 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { | |
1402 text->wid->Flush(); // 表示を最後の状態にする | |
1403 } | |
1404 cmd.cmd_type = CMD_MENUREQ; | |
1405 if (!(status_mask & STATSAVE_MASK)) { | |
1406 status_saved = status; | |
1407 status_mask = Status(status_mask | STATSAVE_MASK); | |
1408 } | |
1409 return false; | |
1410 } else if (status == WAIT_CLICK_MOUSEPOS) { | |
1411 status = WAIT_CLICK_MOUSEPOSEND_R; | |
1412 } | |
1413 } | |
1414 if (event.presscount(MOUSE_UP)) { | |
1415 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { | |
1416 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { | |
1417 text->wid->Flush(); // 表示を最後の状態にする | |
1418 } | |
1419 cmd.cmd_type = CMD_BACKLOGREQ; | |
1420 if (!(status_mask & STATSAVE_MASK)) { | |
1421 status_saved = status; | |
1422 status_mask = Status(status_mask | STATSAVE_MASK); | |
1423 } | |
1424 return false; | |
1425 } | |
1426 } | |
1427 if (status_mask & CLEARSCR_MASK) { | |
1428 if ( (status == WAIT_TEXT && text != 0 ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { | |
1429 if (skip_mode) skip_mode = SKIP_NO; | |
1430 if (text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { | |
1431 text->wid->Flush(); // 表示を最後の状態にする | |
1432 return true; | |
1433 } | |
1434 status_mask = Status(status_mask & (~CLEARSCR_MASK) | CLEARSCR_WAIT_MASK); | |
1435 if (text) text->hide(); | |
1436 if (kcursor) kcursor->hide(); | |
1437 if (sel_widget) sel_widget->hide(); | |
1438 if (backlog_widget) backlog_widget->hide(); | |
1439 return true; | |
1440 } | |
1441 status_mask = Status(status_mask & (~CLEARSCR_MASK)); | |
1442 return false; | |
1443 } | |
1444 if (status_mask & CLEARSCR_WAIT_MASK) { | |
1445 return true; | |
1446 } | |
1447 if (status == WAIT_TEXT) { | |
1448 if (text == 0) { status = NORMAL; return false;} | |
1449 if (skip_mode & SKIP_TEXT) { | |
1450 } else if (text->wid->status != WidText::PREPARE) { | |
1451 return true; | |
1452 } | |
1453 if (kcursor) kcursor->hide(); | |
1454 text_stream.Clear(); | |
1455 status = NORMAL; | |
1456 cmd.cmd_type = CMD_TEXTEND; | |
1457 return false; | |
1458 } | |
1459 if (status == WAIT) { | |
1460 if (skip_mode & SKIP_TEXT) ; | |
1461 else if (wait_time > current_time) return true; | |
1462 status = NORMAL; | |
1463 } else if (status == WAIT_CLICK) { | |
1464 if (skip_mode & SKIP_TEXT) ; | |
1465 else if (wait_time > current_time) return true; | |
1466 status = NORMAL; | |
1467 cmd.SetSysvar(0); | |
1468 } else if (status == WAIT_ABORT) { | |
1469 cmd.SetSysvar(1); | |
1470 status = NORMAL; | |
1471 } else if (status == WAIT_CLICK_MOUSEPOS || status == WAIT_CLICK_MOUSEPOSEND_L || status == WAIT_CLICK_MOUSEPOSEND_R) { | |
1472 if (status == WAIT_CLICK_MOUSEPOS && (skip_mode & SKIP_TEXT) == 0) return true; // keep wait | |
1473 else { | |
1474 int x, y; | |
1475 event.MousePos(x,y); | |
1476 if (status == WAIT_CLICK_MOUSEPOS) x = y = 0; // skip mode | |
1477 cmd.clear(); | |
1478 cmd.SetFlagvar(wait_savedvar[0], x); | |
1479 cmd.SetFlagvar(wait_savedvar[1], y); | |
1480 if (status == WAIT_CLICK_MOUSEPOSEND_R) cmd.SetSysvar(-1); | |
1481 else cmd.SetSysvar(0); | |
1482 status = NORMAL; | |
1483 } | |
1484 } else if (status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { | |
1485 return true; | |
1486 } else if ( int(status) >= WAIT_SELECT_VALUE) { | |
1487 int sel_val = int(status) - WAIT_SELECT_VALUE; | |
1488 cmd.SetSysvar(sel_val); | |
1489 selects.clear(); | |
1490 delete sel_widget; | |
1491 sel_widget = 0; | |
1492 status = NORMAL; | |
1493 // CreateSelect() で作成された cur_backlog_item を backlog_item へ反映させる | |
1494 cur_backlog_item.text.InsertColor(sel_backlog_pos[sel_val], sel_backlog_pos[sel_val+1], 0xff, 0, 0); | |
1495 backlog_item = cur_backlog_item; | |
1496 cur_backlog_item.Clear(); | |
1497 } | |
1498 return false; | |
1499 } | |
1500 | |
1501 void clearbtn_press(void* pointer, WidButton* button) { | |
1502 if (pointer == 0) return; | |
1503 TextImpl* t = (TextImpl*)pointer; | |
1504 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::CLEARSCR_MASK); | |
1505 return; | |
1506 } | |
1507 void TextImpl::PressFuncSkip(void* pointer, WidButton* from) { | |
1508 if (pointer == 0) return; | |
1509 TextImpl* t = (TextImpl*)pointer; | |
1510 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SKIPMASK); | |
1511 return; | |
1512 } | |
1513 void TextImpl::PressFuncLoad(void* pointer, WidButton* from) { | |
1514 if (pointer == 0) return; | |
1515 TextImpl* t = (TextImpl*)pointer; | |
1516 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::LOADMASK); | |
1517 return; | |
1518 } | |
1519 void TextImpl::PressFuncSave(void* pointer, WidButton* from) { | |
1520 if (pointer == 0) return; | |
1521 TextImpl* t = (TextImpl*)pointer; | |
1522 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SAVEMASK); | |
1523 return; | |
1524 } | |
1525 void TextImpl::PressFuncBacklog(void* pointer, WidButton* from) { | |
1526 if (pointer == 0) return; | |
1527 TextImpl* t = (TextImpl*)pointer; | |
1528 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK); | |
1529 return; | |
1530 } | |
1531 void TextImpl::PressFuncBacklogFwd(void* pointer, WidButton* from) { | |
1532 if (pointer == 0) return; | |
1533 TextImpl* t = (TextImpl*)pointer; | |
1534 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK_FWD); | |
1535 return; | |
1536 } | |
1537 void movebtn_drag(int from_x, int from_y, int x, int y, void* pointer, WidButton* button) { | |
1538 if (pointer == 0) return; | |
1539 fprintf(stderr,"drag.\n"); | |
1540 } | |
1541 #define BTNCNT 10 | |
1542 static char* btnname[BTNCNT] = { | |
1543 "MOVE", | |
1544 "CLEAR", | |
1545 "READJUMP", | |
1546 "AUTOMODE", | |
1547 "MSGBK", | |
1548 "MSGBKLEFT", | |
1549 "MSGBKRIGHT", | |
1550 "EXBTN_000", | |
1551 "EXBTN_001", | |
1552 "EXBTN_002" | |
1553 }; | |
1554 static int btnpos[BTNCNT] = { // g00 ファイル内のボタン情報の位置 | |
1555 // 0, 1, 13, 12, 2, 3, 4, 5, 6, 7 // princess bride? | |
1556 0, 1, 13, 14, 2, 3, 4, 5, 6, 7 // tomoyo after? | |
1557 }; | |
1558 static WidButton::PressFunc btnpress[BTNCNT] = { | |
1559 0, clearbtn_press, &TextImpl::PressFuncSkip,0,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncBacklog,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncSave,&TextImpl::PressFuncLoad,0 | |
1560 }; | |
1561 static WidButton::DragFunc btndrag[BTNCNT] = { | |
1562 movebtn_drag, 0,0,0,0, 0,0,0,0, 0 | |
1563 }; | |
1564 | |
1565 void TextImpl::SetTextSpeed(int speed) { | |
1566 // 100 : 10char / sec | |
1567 // 10 : 100char / sec | |
1568 // text widget: | |
1569 if (speed <= 0) speed = -1; | |
1570 else if (speed > 1000) speed = 1; | |
1571 else speed = 1000 / speed; | |
1572 int i; | |
1573 for (i=0; i<32; i++) | |
1574 if (widgets[i]) widgets[i]->wid->SetSpeed(speed); | |
1575 } | |
1576 void TextImpl::SetTextWait(int wait) { | |
1577 int i; | |
1578 for (i=0; i<32; i++) | |
1579 if (widgets[i]) widgets[i]->wid->SetWait(wait); | |
1580 } | |
1581 | |
1582 void TextImpl::SetWindowColor(int r, int g, int b, int a, bool is_transparent) { | |
1583 char key[1024]; | |
1584 int w; | |
1585 | |
1586 for (w=0; w<32; w++) { | |
1587 if (widgets[w] == 0) continue; | |
1588 sprintf(key, "#WAKU.%03d.000.BACK", w); | |
1589 const char* back = config.GetParaStr(key); | |
1590 if (back == 0 || back[0] == 0) continue; | |
1591 sprintf(key, "%s.g00", back); | |
1592 Surface* back_s = parent.Root().NewSurface(key); | |
1593 if (back_s == 0) continue; | |
1594 Rect rect(*back_s); | |
1595 Surface* new_s = parent.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); | |
1596 DSurfaceMove(back_s, rect, new_s, rect); | |
1597 DSurfaceFillA(new_s, rect, r, g, b, a); | |
1598 widgets[w]->wid->Pic()->SetSurface(new_s, 0, 0); | |
1599 widgets[w]->wid->Pic()->SetSurfaceFreeFlag(1); | |
1600 if (!is_transparent) | |
1601 widgets[w]->wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY); | |
1602 parent.Root().DeleteSurface(back_s); | |
1603 } | |
1604 return; | |
1605 } | |
1606 | |
1607 void TextImpl::SetCursor(int cursor_no) { | |
1608 char key[1024]; | |
1609 sprintf(key, "#CURSOR.%03d.NAME", cursor_no); | |
1610 string path = config.GetParaStr(key); | |
1611 if (path.length() == 0) return; // 名前なし | |
1612 path += ".pdt"; | |
1613 int w,h,cont,speed; | |
1614 sprintf(key, "#CURSOR.%03d.SIZE", cursor_no); | |
1615 config.GetParam(key, 2, &w, &h); | |
1616 sprintf(key, "#CURSOR.%03d.CONT", cursor_no); | |
1617 config.GetParam(key, 1, &cont); | |
1618 sprintf(key, "#CURSOR.%03d.SPEED", cursor_no); | |
1619 config.GetParam(key, 1, &speed); | |
1620 | |
1621 // speed で1周、cont 回変化 | |
1622 if (kcursor) delete kcursor; | |
1623 | |
1624 kcursor = new WidTimeCursor(event, speed/cont, &parent, path.c_str(), 0, 0, w, 0, cont, Rect(0,0,w,h)); | |
1625 int i; | |
1626 for (i=0; i<32; i++) { | |
1627 if (widgets[i]) widgets[i]->wid->SetCursor(kcursor); | |
1628 } | |
1629 } | |
1630 | |
1631 void kconv(const unsigned char* src, unsigned char* dest) { | |
1632 /* input : sjis output: euc */ | |
1633 while(*src) { | |
1634 unsigned int high = *src++; | |
1635 if (high < 0x80) { | |
1636 /* ASCII */ | |
1637 *dest++ = high; continue; | |
1638 } else if (high < 0xa0) { | |
1639 /* SJIS */ | |
1640 high -= 0x71; | |
1641 } else if (high < 0xe0) { | |
1642 /* hankaku KANA */ | |
1643 *dest++ = 0x8e; *dest++ = high; | |
1644 continue; | |
1645 } else { /* high >= 0xe0 : SJIS */ | |
1646 high -= 0xb1; | |
1647 } | |
1648 /* SJIS convert */ | |
1649 high = (high<<1) + 1; | |
1650 | |
1651 unsigned int low = *src++; | |
1652 if (low == 0) break; /* incorrect code */ | |
1653 if (low > 0x7f) low--; | |
1654 if (low >= 0x9e) { | |
1655 low -= 0x7d; | |
1656 high++; | |
1657 } else { | |
1658 low -= 0x1f; | |
1659 } | |
1660 *dest++ = high | 0x80; *dest++ = low | 0x80; | |
1661 } | |
1662 *dest = 0; | |
1663 } | |
1664 void kconv_rev(const unsigned char* src, unsigned char* dest) { | |
1665 /* input : euc output: sjis */ | |
1666 while(*src) { | |
1667 unsigned int high = *src++; | |
1668 if (high < 0x80) { | |
1669 /* ASCII */ | |
1670 *dest++ = high; continue; | |
1671 } else if (high == 0x8e) { /* hankaku KANA */ | |
1672 high = *src; | |
1673 if (high >= 0xa0 && high < 0xe0) | |
1674 *dest++ = *src++; | |
1675 continue; | |
1676 } else { | |
1677 unsigned int low = *src++; | |
1678 if (low == 0) break; /* incorrect code , EOS */ | |
1679 if (low < 0x80) continue; /* incorrect code */ | |
1680 /* convert */ | |
1681 low &= 0x7f; high &= 0x7f; | |
1682 low += (high & 1) ? 0x1f : 0x7d; | |
1683 high = (high-0x21)>>1; | |
1684 high += (high > 0x1e) ? 0xc1 : 0x81; | |
1685 *dest++ = high; | |
1686 if (low > 0x7f) low++; | |
1687 *dest++ = low; | |
1688 } | |
1689 } | |
1690 *dest = 0; | |
1691 } | |
1692 string kconv(const string& s) { | |
1693 char* out = new char[s.length()*2+100]; | |
1694 kconv((const unsigned char*)s.c_str(), (unsigned char*)out); | |
1695 string ret = out; | |
1696 delete[] out; | |
1697 return ret; | |
1698 } | |
1699 string kconv_rev(const string& s) { | |
1700 char* out = new char[s.length()*2+100]; | |
1701 kconv_rev((const unsigned char*)s.c_str(), (unsigned char*)out); | |
1702 string ret = out; | |
1703 delete[] out; | |
1704 return ret; | |
1705 } | |
1706 | |
1707 /**************************************************************:: | |
1708 ** | |
1709 ** Text | |
1710 */ | |
1711 Text::Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config) { | |
1712 pimpl = new TextImpl(_event, _parent, config, backlog, backlog_item); | |
1713 } | |
1714 Text::~Text() { | |
1715 delete pimpl; | |
1716 } | |
1717 void Text::InitWindow(void) { | |
1718 pimpl->InitWindow(); | |
1719 } | |
1720 void Text::Exec(Cmd& cmd) { | |
1721 pimpl->Exec(cmd); | |
1722 } | |
1723 bool Text::Wait(unsigned int current_time, Cmd& cmd) { | |
1724 return pimpl->Wait(current_time, cmd); | |
1725 } | |
1726 void Text::SetSkipMode(SkipMode mode) { | |
1727 pimpl->SetSkipMode(mode); | |
1728 } | |
1729 void Text::Save(std::string& str, bool select_save) { | |
1730 pimpl->Save(str, select_save); | |
1731 } | |
1732 void Text::Load(const char* str) { | |
1733 pimpl->Load(str); | |
1734 } | |
1735 | |
1736 void Text::hide(void) { | |
1737 pimpl->hide(); | |
1738 } | |
1739 void Text::show(void) { | |
1740 pimpl->show(); | |
1741 } | |
1742 void Text::show(int num) { | |
1743 pimpl->show(num); | |
1744 } | |
1745 void Text::DrawBacklog(BacklogItem& item, Cmd& cmd) { | |
1746 pimpl->DrawBacklog(item, cmd); | |
1747 } | |
1748 /**************************************************************:: | |
1749 ** | |
1750 ** BacklogItem | |
1751 */ | |
1752 | |
1753 BacklogItem::BacklogItem(void) { | |
1754 scn = -1; | |
1755 pos = -1; | |
1756 koe = -1; | |
1757 face = ""; | |
1758 text.kanji_type = TextStream::sjis; | |
1759 } | |
1760 void BacklogItem::Clear(void) { | |
1761 scn = -1; | |
1762 pos = -1; | |
1763 koe = -1; | |
1764 text.Clear(); | |
1765 } | |
1766 void BacklogItem::AddTextPos(Cmd& cmd) { | |
1767 if (scn == -1 && pos == -1) { | |
1768 scn = cmd.scn; | |
1769 pos = cmd.pos; | |
1770 return; | |
1771 } | |
1772 DeleteTextPos(); | |
1773 } | |
1774 void BacklogItem::DeleteTextPos(void) { | |
1775 scn = 0; | |
1776 pos = -1; | |
1777 } | |
1778 BacklogItem& BacklogItem::operator =(const BacklogItem& p) { | |
1779 scn = p.scn; | |
1780 pos = p.pos; | |
1781 koe = p.koe; | |
1782 face = p.face; | |
1783 text = p.text; | |
1784 } | |
1785 void BacklogItem::SetSavepos(int p) { | |
1786 Clear(); | |
1787 scn = SaveSelect; | |
1788 pos = p; | |
1789 } | |
1790 | |
1791 Rect TextWindow::WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config) { | |
1792 char key[1024]; | |
1793 sprintf(key, "#WAKU.%03d.000.NAME", waku_no); | |
1794 const char* name = config.GetParaStr(key); | |
1795 if (!name) return Rect(0,0,0,0); | |
1796 std::string str = name; str += ".g00"; | |
1797 Surface* s = pic.Root().NewSurface(str.c_str()); | |
1798 if (!s) return Rect(0,0,0,0); | |
1799 Rect r(*s); | |
1800 pic.Root().DeleteSurface(s); | |
1801 return r; | |
1802 } | |
1803 void TextWindow::MakeWaku(PicContainer& pic, Event::Container& event, int waku_no, int window_no, bool* use_btn, const AyuSysConfig& config, void* callback) { | |
1804 char key[1024]; | |
1805 std::string str; | |
1806 /* 枠を作成 */ | |
1807 sprintf(key, "#WAKU.%03d.000.NAME", waku_no); | |
1808 const char* name = config.GetParaStr(key); | |
1809 if (name && name[0] == 0) name = 0; | |
1810 sprintf(key, "#WAKU.%03d.000.BACK", waku_no); | |
1811 const char* back = config.GetParaStr(key); | |
1812 if (back && back[0] == 0) back = 0; | |
1813 sprintf(key, "#WAKU.%03d.000.BTN", waku_no); | |
1814 const char* btn = config.GetParaStr(key); | |
1815 if (btn && btn[0] == 0) btn = 0; | |
1816 | |
1817 if (name == 0 && back == 0 && btn == 0) return; | |
1818 | |
1819 /* まず、テキスト背景を設定 */ | |
1820 if (back) { | |
1821 str = back; str += ".g00"; | |
1822 int rc,gc,bc,ac, flag; | |
1823 char key[1024]; | |
1824 sprintf(key, "#WINDOW.%03d.ATTR", window_no); | |
1825 if (config.GetParam(key, 5, &rc, &gc, &bc, &ac, &flag) == -1) { | |
1826 config.GetParam("#WINDOW_ATTR", 5, &rc, &gc, &bc, &ac, &flag); | |
1827 } | |
1828 Surface* back_s = pic.Root().NewSurface(str.c_str()); | |
1829 if (back_s) { | |
1830 Rect rect(*back_s); | |
1831 Surface* s = pic.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); | |
1832 DSurfaceMove(back_s, rect, s, rect); | |
1833 DSurfaceFillA(s, rect, rc, gc, bc, ac); // 透明度設定 | |
1834 pic.SetSurface(s, 0, 0); | |
1835 pic.SetSurfaceFreeFlag(1); | |
1836 if (flag == 0) wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY); | |
1837 pic.Root().DeleteSurface(back_s); | |
1838 } | |
1839 } | |
1840 /* その前に枠飾りを設定 */ | |
1841 if (name) { | |
1842 str = name; str += ".g00"; | |
1843 Surface* s = pic.Root().NewSurface(str.c_str()); | |
1844 if (s) { | |
1845 Rect rect(*s); | |
1846 pic.Root().DeleteSurface(s); | |
1847 PicBase* p = pic.create_leaf(Rect(0, 0, rect.width(), rect.height()),0); | |
1848 p->SetSurface(str.c_str(), 0, 0); | |
1849 p->ZMove(ZMOVE_BOTTOM); | |
1850 p->show(); | |
1851 } | |
1852 } | |
1853 if (btn == 0) return; | |
1854 if (use_btn == 0) return; | |
1855 // ボタンの作成 | |
1856 // 使用するボタンについては、必要に応じて show() すること | |
1857 | |
1858 /* ボタンの位置情報を求める */ | |
1859 str = btn; str += ".g00"; | |
1860 ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, str.c_str(), "g00"); | |
1861 if (info == 0) return; // cannot find file | |
1862 const char* data = info->Read(); | |
1863 /* g00 ファイルのヘッダ部分に位置情報は入っている */ | |
1864 /* 存在しなければボタン画像ではない */ | |
1865 if (data == 0 || *data != 2) { | |
1866 delete info; | |
1867 return; | |
1868 } | |
1869 int index_count = read_little_endian_int(data+5); // 0x70 == 112 ( 8 個ずつグループなので、14個のボタン ) が標準 | |
1870 int i; | |
1871 for (i=0; i<BTNCNT; i++) { | |
1872 if (!use_btn[i]) continue; | |
1873 if (btnpos[i]*8 >= index_count) { | |
1874 continue; // ボタンが存在しない | |
1875 } | |
1876 int x, y, w, h; | |
1877 sprintf(key, "#WAKU.%03d.000.%s_BOX", waku_no, btnname[i]); | |
1878 if (config.GetParam(key, 5, 0, &x, &y, &w, &h) == -1) continue; | |
1879 int sx, sy, sdx, sdy, cnt; | |
1880 const char* d = data + 9 + btnpos[i]*24*8; | |
1881 sx = read_little_endian_int(d); | |
1882 sy = read_little_endian_int(d+4); | |
1883 sdx = read_little_endian_int(d+24) - sx; | |
1884 sdy = read_little_endian_int(d+24 + 4) - sy; | |
1885 cnt = 2; | |
1886 if (sx+sdx*2 == read_little_endian_int(d+2*24) && sy+sdy*2 == read_little_endian_int(d+2*24+4)) cnt = 3; | |
1887 WidButton* wid = new WidButton(event, &pic, str.c_str(), sx, sy, sdx, sdy, cnt, Rect(x, y, x+w, y+h), 1); | |
1888 if (btnpress[i]) { wid->press_func = btnpress[i]; wid->press_pointer = callback;} | |
1889 if (btndrag[i]) { wid->drag_func = btndrag[i]; wid->drag_pointer = callback;} | |
1890 } | |
1891 delete info; | |
1892 return; | |
1893 } | |
1894 | |
1895 TextWindow::TextWindow(PicContainer& parent, Event::Container& event, int win_no, const AyuSysConfig& config, void* callback) : | |
1896 wid(0), name_visible(true),name(0),name_container(0), face(0) { | |
1897 int i; for (i=0; i<8; i++) face_pics[i]=0; | |
1898 char key[1024]; | |
1899 bool use_btn[BTNCNT]; | |
1900 int size, rep1, rep2, cntw, cnth, mposx, mposy, posd, posx, posy, minx, miny, waku_no, ruby; | |
1901 sprintf(key, "#WINDOW.%03d.MOJI_SIZE", win_no); if (config.GetParam(key, 1, &size) == -1) return; | |
1902 sprintf(key, "#WINDOW.%03d.MOJI_REP", win_no); if (config.GetParam(key, 2, &rep1, &rep2) == -1) return; | |
1903 sprintf(key, "#WINDOW.%03d.MOJI_CNT", win_no); if (config.GetParam(key, 2, &cntw, &cnth) == -1) return; | |
1904 sprintf(key, "#WINDOW.%03d.POS", win_no); if (config.GetParam(key, 3, &posd, &posx, &posy) == -1) return; | |
1905 sprintf(key, "#WINDOW.%03d.MOJI_POS", win_no); if (config.GetParam(key, 4, &mposy, 0, &mposx, 0) == -1) return; | |
1906 sprintf(key, "#WINDOW.%03d.MOJI_MIN", win_no); if (config.GetParam(key, 2, &minx, &miny) == -1) return; | |
1907 sprintf(key, "#WINDOW.%03d.WAKU_SETNO", win_no);if (config.GetParam(key, 1, &waku_no) == -1) return; | |
1908 sprintf(key, "#WINDOW.%03d.LUBY_SIZE", win_no); if (config.GetParam(key, 1, &ruby) == -1) return; | |
1909 | |
1910 /* テキストウィジット:画面の右下一杯まで使用 */ | |
1911 /* posd == 2 なら画面下にひっつくように配置 */ | |
1912 Rect r(0,0); | |
1913 if (posd == 2) { | |
1914 r = WakuSize(parent, waku_no, config); | |
1915 r = Rect(0, parent.Height()-r.height(), r.width(), parent.Height()); | |
1916 posx = 0; | |
1917 posy = parent.Height()-r.height(); | |
1918 } else /* posd == 0 ? */ | |
1919 r = Rect(posx, posy, parent.Width(), parent.Height()); | |
1920 | |
1921 /* テキストウィンドウの作成 */ | |
1922 int w = size*cntw; int h = (size+ruby+2)*cnth; | |
1923 wid = new WidText(event, &parent, r, Rect(mposx, mposy, mposx+w, mposy+h), size); | |
1924 wid->stream.kanji_type = TextStream::sjis; | |
1925 /* 顔ウィンドウの作成 */ | |
1926 for (i=0; i<8; i++) { | |
1927 int x,y; | |
1928 sprintf(key, "#WINDOW.%03d.FACE.%03d", win_no, i); | |
1929 if (config.GetParam(key, 2, &x, &y) == -1) continue; | |
1930 /* 顔ウィンドウを作成する */ | |
1931 if (x >= 0 && y >= 0) { | |
1932 face_pics[i] = wid->PicNode()->create_leaf(Rect(x,y), PicBase::FIT_SURFACE); | |
1933 } else { | |
1934 face_pics[i] = parent.create_leaf(Rect(x+posx,y+posy), PicBase::FIT_SURFACE); | |
1935 } | |
1936 face_pics[i]->show(); | |
1937 } | |
1938 face = face_pics[0]; | |
1939 // ボタンの設定 | |
1940 for (i=0; i<BTNCNT; i++) { | |
1941 int num; | |
1942 sprintf(key, "#WINDOW.%03d.%s_USE", win_no, btnname[i]); | |
1943 config.GetParam(key, 1, &num); | |
1944 use_btn[i] = (num==0) ? false : true; | |
1945 } | |
1946 // make name window | |
1947 int shadow, name_mod, name_size, name_min, name_center, name_posx, name_posy, name_mposx, name_mposy; | |
1948 sprintf(key, "#WINDOW.%03d.MOJI_SHADOW", win_no); config.GetParam(key, 1, &shadow); | |
1949 sprintf(key, "#WINDOW.%03d.NAME_MOD", win_no); config.GetParam(key, 1, &name_mod); | |
1950 sprintf(key, "#WINDOW.%03d.NAME_MOJI_SIZE", win_no); config.GetParam(key, 1, &name_size); | |
1951 sprintf(key, "#WINDOW.%03d.NAME_MOJI_MIN", win_no); config.GetParam(key, 1, &name_min); | |
1952 sprintf(key, "#WINDOW.%03d.NAME_MOJI_POS", win_no); config.GetParam(key, 2, &name_mposx, &name_mposy); | |
1953 sprintf(key, "#WINDOW.%03d.NAME_CENTERING", win_no); config.GetParam(key, 1, &name_center); | |
1954 sprintf(key, "#WINDOW.%03d.NAME_POS", win_no); config.GetParam(key, 2, &name_posx, &name_posy); | |
1955 // if name_mode==0 name is in the text window | |
1956 // if name_mode == 1 open name window | |
1957 // if name_mode == 2 name is not used | |
1958 if (name_mod) { | |
1959 if (name_mod == 1) { | |
1960 int w = name_size*name_min; int h = name_size; | |
1961 int name_waku; | |
1962 sprintf(key, "#WINDOW.%03d.NAME_WAKU_SETNO", win_no); | |
1963 if (config.GetParam(key, 1, &name_waku) != -1 && name_waku != -1) { | |
1964 Rect waku_r = WakuSize(parent, name_waku, config); | |
1965 waku_r.rmove(r.lx, r.ty); // テキストウィンドウ位置に動かす | |
1966 waku_r.rmove(name_posx, name_posy-waku_r.height()); // NAME_POS へ位置補正 | |
1967 name_container = parent.create_node(waku_r, 0); | |
1968 MakeWaku(*name_container, event, name_waku, win_no, 0, config, callback); | |
1969 Rect name_r(0,0,w,h); | |
1970 name_r.rmove(name_mposx, name_mposy); | |
1971 name = new WidLabel(name_container, name_r, true, 0, name_size); | |
1972 name->show(); | |
1973 } else { // 名前専用枠なし | |
1974 Rect name_r(0, 0, w, h); | |
1975 name_r.rmove(r.lx, r.ty); | |
1976 name_r.rmove(name_posx, name_posy-name_size); | |
1977 name_container = parent.create_node(name_r, 0); | |
1978 name = new WidLabel(name_container, Rect(0,0,w,h), true, 0, name_size); | |
1979 name->show(); | |
1980 name_container->show(); | |
1981 } | |
1982 } else { // name_mod == 2 or 3 | |
1983 name_container = parent.create_node( Rect(0,0,1,1), 0); | |
1984 } | |
1985 } | |
1986 MakeWaku(*wid->PicNode(), event,waku_no, win_no, use_btn, config, callback); | |
1987 } | |
1988 void TextImpl::InitWindow(void) { | |
1989 int i,j,k; | |
1990 int w; | |
1991 std::string str; | |
1992 | |
1993 for (w=0; w<32; w++) { | |
1994 widgets[w] = new TextWindow(parent, event, w, config, (void*)this); | |
1995 if (widgets[w]->wid == 0) { | |
1996 delete widgets[w]; | |
1997 widgets[w] = 0; | |
1998 } | |
1999 } | |
2000 SetCursor(0); | |
2001 for (i=0; i<26; i++) { | |
2002 char buf[1024]; | |
2003 sprintf(buf, "#NAME.%c", i+'A'); | |
2004 const char* s = config.GetParaStr(buf); | |
2005 if (s) replace_name[i] = s; | |
2006 } | |
2007 // replace_name2 : 初期設定 | |
2008 // 渚、秋生、渚 (CLANNAD) | |
2009 char name_nagisa[3] = {0x8f,0x8d,0}; | |
2010 char name_akio[5] = {0x8f, 0x48, 0x90, 0xb6, 0}; | |
2011 replace_name2[0] = name_nagisa; | |
2012 replace_name2[1] = name_akio; | |
2013 replace_name2[2] = name_nagisa; | |
2014 text = 0; | |
2015 /* テキスト速度の設定 */ | |
2016 int speed, mod, wait, auto_mod; | |
2017 config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed); | |
2018 config.GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &mod); | |
2019 config.GetParam("#MESSAGE_KEY_WAIT_USE", 1, &auto_mod); | |
2020 config.GetParam("#MESSAGE_KEY_WAIT_TIME", 1, &wait); | |
2021 if (mod) speed = -1; | |
2022 if (!auto_mod) wait = -1; | |
2023 SetTextSpeed(speed); | |
2024 SetTextWait(wait); | |
2025 return; | |
2026 } |