Mercurial > otakunoraifu
comparison scn2k/scn2k_impl.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 35ce1a30f3f9 |
children | ddbcbd000206 |
comparison
equal
deleted
inserted
replaced
51:cbb301016a4e | 52:15a18fbe6f21 |
---|---|
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include <stdexcept> | 28 #include <stdexcept> |
29 #include"scn2k_impl.h" | 29 #include "scn2k_impl.h" |
30 #include"system/file.h" | 30 #include "system/file.h" |
31 #include"system/system_config.h" | 31 #include "system/system_config.h" |
32 #include"window/picture.h" | 32 #include "window/picture.h" |
33 #include"window/system.h" | 33 #include "window/system.h" |
34 | 34 |
35 // #define DEBUG 1 | 35 // #define DEBUG 1 |
36 | 36 |
37 using namespace std; | 37 using namespace std; |
38 | 38 |
54 grp_exec(_event, _parent, flag, flag.cgm_data, mu, config) | 54 grp_exec(_event, _parent, flag, flag.cgm_data, mu, config) |
55 { | 55 { |
56 system_version = 0; | 56 system_version = 0; |
57 skip_mode = SKIP_NO; | 57 skip_mode = SKIP_NO; |
58 | 58 |
59 script_start = 0; | 59 script_start = NULL; |
60 script = 0; | 60 script = NULL; |
61 script_end = 0; | 61 script_end = NULL; |
62 | 62 |
63 backlog_script_scn = -1; | 63 backlog_script_scn = -1; |
64 backlog_script_start = 0; | 64 backlog_script_start = NULL; |
65 backlog_script_end = 0; | 65 backlog_script_end = NULL; |
66 | 66 |
67 save_scn = 0; | 67 save_scn = 0; |
68 save_point = 0; | 68 save_point = 0; |
69 scn_number = 0; | 69 scn_number = 0; |
70 scn_point = 0; | 70 scn_point = 0; |
71 cmd_stack_str = cmd_stack_str_orig; | 71 cmd_stack_str = cmd_stack_str_orig; |
72 | 72 |
73 dialog = 0; | 73 dialog = NULL; |
74 dialog_type = CMD_NOP; | 74 dialog_type = CMD_NOP; |
75 menu = 0; | 75 menu = NULL; |
76 menu_mouseshown = false; | 76 menu_mouseshown = false; |
77 | 77 |
78 /* マウスカーソルを作成 */ | 78 /* マウスカーソルを作成 */ |
79 mouse_type = 0; | 79 mouse_type = 0; |
80 mouse_surface = 0; | 80 mouse_surface = NULL; |
81 mouse_pressed = 0; | 81 mouse_pressed = 0; |
82 ShowCursor(); | 82 ShowCursor(); |
83 | 83 |
84 LoadSys(); | 84 LoadSys(); |
85 text_exec.InitWindow(); | 85 text_exec.InitWindow(); |
99 int offset = 0; | 99 int offset = 0; |
100 int scenario_magic; | 100 int scenario_magic; |
101 | 101 |
102 sprintf(fname, "SEEN%04d.TXT", new_scn_number); | 102 sprintf(fname, "SEEN%04d.TXT", new_scn_number); |
103 ARCINFO* info = file_searcher.Find(FILESEARCH::SCN, fname, ""); | 103 ARCINFO* info = file_searcher.Find(FILESEARCH::SCN, fname, ""); |
104 if (info == 0) goto err; | 104 if (info == NULL) goto err; |
105 data = info->Read(); | 105 data = info->Read(); |
106 | 106 |
107 /* version 確認 */ | 107 /* version 確認 */ |
108 scenario_magic = read_little_endian_int(data + 4); | 108 scenario_magic = read_little_endian_int(data + 4); |
109 if (scenario_magic != 0x2712 && scenario_magic != 0x1adb2) { | 109 if (scenario_magic != 0x2712 && scenario_magic != 0x1adb2) { |
139 fprintf(stderr,"Cannot open scenario number %d\n",new_scn_number); | 139 fprintf(stderr,"Cannot open scenario number %d\n",new_scn_number); |
140 throw std::invalid_argument("Scn2k::OpenScript"); | 140 throw std::invalid_argument("Scn2k::OpenScript"); |
141 | 141 |
142 return false; | 142 return false; |
143 } | 143 } |
144 | |
144 bool Scn2k::ChangeScript(int new_scn_number, int call_no) { | 145 bool Scn2k::ChangeScript(int new_scn_number, int call_no) { |
145 int old_scn_number = scn_number; | 146 int old_scn_number = scn_number; |
146 int old_scn_pt = script - script_start; | 147 int old_scn_pt = script - script_start; |
147 int scn_pt = 0; | 148 int scn_pt = 0; |
148 | 149 |
149 if (script_start) delete[] script_start; | 150 if (script_start) delete[] script_start; |
150 script_start = 0; | 151 script_start = NULL; |
151 script = 0; | 152 script = NULL; |
152 script_end = 0; | 153 script_end = NULL; |
153 | 154 |
154 int call_vec[100]; | 155 int call_vec[100]; |
155 | 156 |
156 try { | 157 try { |
157 script_start = OpenScript(new_scn_number, script_end, call_vec, system_version); | 158 script_start = OpenScript(new_scn_number, script_end, call_vec, system_version); |
174 script = script_start + scn_pt; | 175 script = script_start + scn_pt; |
175 if (script < script_start || script >= script_end) | 176 if (script < script_start || script >= script_end) |
176 fprintf(stderr,"scn %d pt %d: Cannot jump to %d:%d; fall back to the top\n",old_scn_number, old_scn_pt, scn_number, scn_pt); | 177 fprintf(stderr,"scn %d pt %d: Cannot jump to %d:%d; fall back to the top\n",old_scn_number, old_scn_pt, scn_number, scn_pt); |
177 return true; | 178 return true; |
178 } | 179 } |
180 | |
179 bool Scn2k::ReadCmdAt(Cmd& cmd, int scn, int pt) { | 181 bool Scn2k::ReadCmdAt(Cmd& cmd, int scn, int pt) { |
180 const char* d; | 182 const char* d; |
181 if (scn ==scn_number) { | 183 if (scn == scn_number) { |
182 d = script_start + pt; | 184 d = script_start + pt; |
183 if (d < script_start || d >= script_end) { | 185 if (d < script_start || d >= script_end) { |
184 fprintf(stderr,"Cannot read script at current scn %d pt %d\n", scn, pt); | 186 fprintf(stderr,"Cannot read script at current scn %d pt %d\n", scn, pt); |
185 return false; | 187 return false; |
186 } | 188 } |
203 extern bool save_req, load_req; // キーボードからセーブ・ロードできるように | 205 extern bool save_req, load_req; // キーボードからセーブ・ロードできるように |
204 extern bool pressAreq; | 206 extern bool pressAreq; |
205 | 207 |
206 void Scn2k::Elapsed(unsigned int current_time) { | 208 void Scn2k::Elapsed(unsigned int current_time) { |
207 SetWakeup(current_time + 10); // 10msに一回シナリオスクリプト解釈 | 209 SetWakeup(current_time + 10); // 10msに一回シナリオスクリプト解釈 |
208 if (script == 0) return; | 210 if (script == NULL) return; |
209 //VarInfo info; info.type = 6; info.number = 0; // PB の「一回ゲームを開始したことがある」フラグ | 211 //VarInfo info; info.type = 6; info.number = 0; // PB の「一回ゲームを開始したことがある」フラグ |
210 //flag.Set(info,1); | 212 //flag.Set(info,1); |
211 //info.type = 0; info.number = 604; // Princess Bride: クリア対象設定フラグ (聖) | 213 //info.type = 0; info.number = 604; // Princess Bride: クリア対象設定フラグ (聖) |
212 //flag.Set(info, 1); | 214 //flag.Set(info, 1); |
213 | 215 |
274 // if (cmd.cmd_type != CMD_NOP) { | 276 // if (cmd.cmd_type != CMD_NOP) { |
275 if (0) { | 277 if (0) { |
276 fprintf(stderr,"%d / %d : 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", | 278 fprintf(stderr,"%d / %d : 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", |
277 scn_point, script_end-script_start, | 279 scn_point, script_end-script_start, |
278 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); | 280 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); |
279 int i; for (i=0; i<cmd.args.size(); i++) { | 281 int i; |
282 for (i = 0; i<cmd.args.size(); i++) { | |
280 if (i == 0) fprintf(stderr,"\t"); | 283 if (i == 0) fprintf(stderr,"\t"); |
281 VarInfo info = cmd.args[i]; | 284 VarInfo info = cmd.args[i]; |
282 if (info.type == TYPE_STR || info.type == TYPE_VARSTR) | 285 if (info.type == TYPE_STR || info.type == TYPE_VARSTR) |
283 fprintf(stderr,"\"%s\",", cmd.Str(info)); | 286 fprintf(stderr,"\"%s\",", cmd.Str(info)); |
284 else | 287 else |
305 if ( cmd.cmd1 == 0 && cmd.cmd2 == 1 && (cmd.cmd3 == 5 || cmd.cmd3 == 8 || cmd.cmd3 == 16) ) { // local call / simple switch | 308 if ( cmd.cmd1 == 0 && cmd.cmd2 == 1 && (cmd.cmd3 == 5 || cmd.cmd3 == 8 || cmd.cmd3 == 16) ) { // local call / simple switch |
306 int scn_pt = script - script_start; | 309 int scn_pt = script - script_start; |
307 // fprintf(stderr,"\nlocal call %d:%d from %d\n",scn_number,cmd.args[0].value,scn_pt); | 310 // fprintf(stderr,"\nlocal call %d:%d from %d\n",scn_number,cmd.args[0].value,scn_pt); |
308 stack.push_back(StackItem(-1, scn_pt)); | 311 stack.push_back(StackItem(-1, scn_pt)); |
309 } | 312 } |
310 if (cmd.cmd1 == 0 && cmd.cmd2 == 1 && cmd.cmd3 == 1) { | 313 if (cmd.cmd1 == 0 && cmd.cmd2 == 1 && cmd.cmd3 == 1) {//TODO |
311 fprintf(stderr,"*** unsupported: cond 1\n"); | 314 fprintf(stderr,"*** unsupported: cond 1\n"); |
312 } | 315 } |
313 script = script_start + cmd.args[0].value; | 316 script = script_start + cmd.args[0].value; |
314 if (script < script_start || script >= script_end) { | 317 if (script < script_start || script >= script_end) { |
315 fprintf(stderr,"scn %d pt %d: Cannot jump to %d; fall back to the top\n", scn_number, scn_point, cmd.args[0].value); | 318 fprintf(stderr,"scn %d pt %d: Cannot jump to %d; fall back to the top\n", scn_number, scn_point, cmd.args[0].value); |
342 } | 345 } |
343 fprintf(stderr, "\n"); | 346 fprintf(stderr, "\n"); |
344 } | 347 } |
345 break; | 348 break; |
346 } | 349 } |
350 | |
347 if (cmd.cmd_type == CMD_NOP) continue; | 351 if (cmd.cmd_type == CMD_NOP) continue; |
348 | 352 |
349 if (cmd.cmd_type == CMD_TEXT && cmd.pos != -1) { | 353 if (cmd.cmd_type == CMD_TEXT && cmd.pos != -1) { |
350 set<int>& readflag = text_readflag[scn_number]; | 354 set<int>& readflag = text_readflag[scn_number]; |
351 if (readflag.find(cmd.pos) == readflag.end()) { // 未読テキスト発見 | 355 if (readflag.find(cmd.pos) == readflag.end()) { // 未読テキスト発見 |
364 } else if (cmd.cmd_type != CMD_NOP) { | 368 } else if (cmd.cmd_type != CMD_NOP) { |
365 #if DEBUG | 369 #if DEBUG |
366 fprintf(stderr,"%d-%d / %d : unsupported command; 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", | 370 fprintf(stderr,"%d-%d / %d : unsupported command; 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", |
367 cmd.scn, script - script_start, script_end-script_start, | 371 cmd.scn, script - script_start, script_end-script_start, |
368 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); | 372 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); |
369 int i; for (i=0; i<cmd.args.size(); i++) { | 373 int i; |
374 for (i = 0; i<cmd.args.size(); i++) { | |
370 if (i == 0) fprintf(stderr,"\t"); | 375 if (i == 0) fprintf(stderr,"\t"); |
371 VarInfo info = cmd.args[i]; | 376 VarInfo info = cmd.args[i]; |
372 if (info.type == TYPE_STR || info.type == TYPE_VARSTR) | 377 if (info.type == TYPE_STR || info.type == TYPE_VARSTR) |
373 fprintf(stderr,"\"%s\",", cmd.Str(info)); | 378 fprintf(stderr,"\"%s\",", cmd.Str(info)); |
374 else | 379 else |
377 fprintf(stderr,"\n"); | 382 fprintf(stderr,"\n"); |
378 #endif | 383 #endif |
379 cmd.clear(); | 384 cmd.clear(); |
380 } | 385 } |
381 } | 386 } |
382 return; | |
383 } | 387 } |
384 | 388 |
385 void Scn2k::ShowCursor(void) { | 389 void Scn2k::ShowCursor(void) { |
386 HideCursor(); | 390 HideCursor(); |
387 char key[1024]; | 391 char key[1024]; |
388 sprintf(key, "#MOUSE_CURSOR.%03d.NAME",mouse_type); | 392 sprintf(key, "#MOUSE_CURSOR.%03d.NAME",mouse_type); |
389 const char* name = config.GetParaStr(key); | 393 const char* name = config.GetParaStr(key); |
390 if (name == 0 || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR; | 394 if (name == NULL || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR; |
391 else { | 395 else { |
392 mouse_surface = parent.Root().NewSurface(name, COLOR_MASK); | 396 mouse_surface = parent.Root().NewSurface(name, COLOR_MASK); |
393 } | 397 } |
394 if (mouse_surface == 0) mouse_surface = DEFAULT_MOUSECURSOR; | 398 if (mouse_surface == NULL) mouse_surface = DEFAULT_MOUSECURSOR; |
395 System::Main::SetCursor(mouse_surface, Rect(8, 8, 8+32, 8+32)); | 399 System::Main::SetCursor(mouse_surface, Rect(8, 8, 8+32, 8+32)); |
396 } | 400 } |
397 | 401 |
398 void Scn2k::HideCursor(void) { | 402 void Scn2k::HideCursor(void) { |
399 if (mouse_surface) { | 403 if (mouse_surface) { |
400 System::Main::SetCursor(0, Rect(0,0)); | 404 System::Main::SetCursor(0, Rect(0,0)); |
401 if (mouse_surface != DEFAULT_MOUSECURSOR) | 405 if (mouse_surface != DEFAULT_MOUSECURSOR) |
402 parent.Root().DeleteSurface(mouse_surface); | 406 parent.Root().DeleteSurface(mouse_surface); |
403 mouse_surface = 0; | 407 mouse_surface = NULL; |
404 } | 408 } |
405 return; | |
406 } | 409 } |
407 | 410 |
408 bool Scn2k::SysWait(Cmd& cmd) { | 411 bool Scn2k::SysWait(Cmd& cmd) { |
409 | |
410 if (menu) { | 412 if (menu) { |
411 menu->Exec(cmd); | 413 menu->Exec(cmd); |
412 if (menu->status & Scn2kMenu::MENU_DELETE || menu->pimpl == 0) { | 414 if (menu->status & Scn2kMenu::MENU_DELETE || menu->pimpl == NULL) { |
413 delete menu; | 415 delete menu; |
414 menu = 0; | 416 menu = NULL; |
415 if (! menu_mouseshown) HideCursor(); | 417 if (! menu_mouseshown) HideCursor(); |
416 else ShowCursor(); | 418 else ShowCursor(); |
417 SetSkipMode(SkipMode(skip_mode & (~SKIP_IN_MENU) )); | 419 SetSkipMode(SkipMode(skip_mode & (~SKIP_IN_MENU) )); |
418 } | 420 } |
419 if (cmd.cmd_type == CMD_NOP) return true; | 421 if (cmd.cmd_type == CMD_NOP) return true; |
698 script = script_start + s.scn_pt; | 700 script = script_start + s.scn_pt; |
699 cmd.clear(); | 701 cmd.clear(); |
700 } | 702 } |
701 } else if (cmd.cmd1 == 2 && cmd.cmd2 == 1 && cmd.cmd3 == 12) { // DLL Call | 703 } else if (cmd.cmd1 == 2 && cmd.cmd2 == 1 && cmd.cmd3 == 12) { // DLL Call |
702 const char* regname = config.GetParaStr("#REGNAME"); | 704 const char* regname = config.GetParaStr("#REGNAME"); |
703 const char key_lb[] = "KEY\\LittleBusters"; | 705 const char key_lb[] = "KEY\\LittleBusters";//FIXME: too specific to be here? |
704 if (strcmp(regname, key_lb) == 0) { | 706 if (strcmp(regname, key_lb) == 0) { |
705 DllCall_LB(cmd, flag); | 707 DllCall_LB(cmd, flag); |
706 cmd.clear(); | 708 cmd.clear(); |
707 } | 709 } |
708 } else if (cmd.cmd1 == 0 && cmd.cmd2 == 0x04) { // メニューモード | 710 } else if (cmd.cmd1 == 0 && cmd.cmd2 == 0x04) { // メニューモード |
713 SysExec(cmd); | 715 SysExec(cmd); |
714 } | 716 } |
715 } else if (cmd.cmd1 == 1 && cmd.cmd2 == 0x04) { | 717 } else if (cmd.cmd1 == 1 && cmd.cmd2 == 0x04) { |
716 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { // タイトル名設定 | 718 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { // タイトル名設定 |
717 const char* name = cmd.Str(cmd.args[0]); | 719 const char* name = cmd.Str(cmd.args[0]); |
718 if (name == 0) name = ""; | 720 if (name == NULL) name = ""; |
719 window_title = name; | 721 window_title = name; |
720 const char* config_name = config.GetParaStr("#CAPTION"); | 722 const char* config_name = config.GetParaStr("#CAPTION"); |
721 if (config_name == 0) config_name = ""; | 723 if (config_name == NULL) config_name = ""; |
722 string setname = kconv(string(config_name) + " " + window_title); | 724 string setname = kconv(string(config_name) + " " + window_title); |
723 parent.Root().SetWindowCaption(setname.c_str()); | 725 parent.Root().SetWindowCaption(setname.c_str()); |
724 cmd.clear(); | 726 cmd.clear(); |
725 } else if (cmd.cmd3 == 0x82 && cmd.cmd4 == 0) { | 727 } else if (cmd.cmd3 == 0x82 && cmd.cmd4 == 0) { |
726 /* cmd.cmd3 == 0x82 : マウスの press 状態クリアかも */ | 728 /* cmd.cmd3 == 0x82 : マウスの press 状態クリアかも */ |
749 /* 7d1: == 1 || 14c: == 1 || (15e==1&&161==1&&162==0) || (press_val == 2) : スキップ中? タイトル画面のアニメーション終了 */ | 751 /* 7d1: == 1 || 14c: == 1 || (15e==1&&161==1&&162==0) || (press_val == 2) : スキップ中? タイトル画面のアニメーション終了 */ |
750 flag.SetSys(0); | 752 flag.SetSys(0); |
751 cmd.clear(); | 753 cmd.clear(); |
752 } else if (cmd.cmd3 == 0x4b0) { // 終了 | 754 } else if (cmd.cmd3 == 0x4b0) { // 終了 |
753 System::Main::Quit(); | 755 System::Main::Quit(); |
754 //script = 0; script_start = 0; script_end = 0; | 756 //script = NULL; script_start = NULL; script_end = NULL; |
755 cmd.clear(); | 757 cmd.clear(); |
756 cmd.cmd_type = CMD_WAITFRAMEUPDATE; | 758 cmd.cmd_type = CMD_WAITFRAMEUPDATE; |
757 } else if (cmd.cmd3 == 0x4b4 || cmd.cmd3 == 0x4b5) { // 選択肢巻き戻し | 759 } else if (cmd.cmd3 == 0x4b4 || cmd.cmd3 == 0x4b5) { // 選択肢巻き戻し |
758 LoadRollback(cmd); | 760 LoadRollback(cmd); |
759 } else if (cmd.cmd3 == 0x58d) { | 761 } else if (cmd.cmd3 == 0x58d) { |
822 } | 824 } |
823 } | 825 } |
824 | 826 |
825 } | 827 } |
826 | 828 |
827 #include<sys/types.h> | 829 #include <sys/types.h> |
828 #include<sys/stat.h> | 830 #include <sys/stat.h> |
829 #include<errno.h> | 831 #include <errno.h> |
830 #include<unistd.h> | 832 #include <unistd.h> |
831 | 833 |
832 // セーブファイルの名前をつくる | 834 // セーブファイルの名前をつくる |
833 string Scn2k::MakeSaveFile(void) const { | 835 string Scn2k::MakeSaveFile(void) const { |
834 struct stat sstatus; | 836 struct stat sstatus; |
835 string dir = "~/.xkanon"; | 837 string dir = "~/.xkanon"; |
836 | 838 |
837 if (dir.c_str()[0] == '~' && dir.c_str()[1] == '/') { | 839 if (dir.c_str()[0] == '~' && dir.c_str()[1] == '/') { |
838 char* home = getenv("HOME"); | 840 char* home = getenv("HOME"); |
839 if (home != 0) { | 841 if (home != NULL) { |
840 string new_dir = string(home) + (dir.c_str()+1); | 842 string new_dir = string(home) + (dir.c_str()+1); |
841 dir = new_dir; | 843 dir = new_dir; |
842 } | 844 } |
843 } | 845 } |
844 // savepathにファイル名が入っていれば、それをセーブファイルとして使う | 846 // savepathにファイル名が入っていれば、それをセーブファイルとして使う |
869 dir += "/save."; | 871 dir += "/save."; |
870 dir += fname; | 872 dir += fname; |
871 delete[] fname; | 873 delete[] fname; |
872 return dir; | 874 return dir; |
873 } | 875 } |
876 | |
874 // セーブファイルの名前をつくる | 877 // セーブファイルの名前をつくる |
875 string Scn2kSaveTitle::operator() (int number) const { | 878 string Scn2kSaveTitle::operator() (int number) const { |
876 int y,m,d,wd,h,min,sec,msec; | 879 int y,m,d,wd,h,min,sec,msec; |
877 string title; | 880 string title; |
878 if (! impl.StatSaveFile(number, y,m,d,wd,h,min,sec,msec,title)) { | 881 if (! impl.StatSaveFile(number, y,m,d,wd,h,min,sec,msec,title)) { |
880 } else { | 883 } else { |
881 char buf[1024]; | 884 char buf[1024]; |
882 sprintf(buf, "%2d/%2d %2d:%2d ",m,d,h,min); | 885 sprintf(buf, "%2d/%2d %2d:%2d ",m,d,h,min); |
883 return string(buf) + title; | 886 return string(buf) + title; |
884 } | 887 } |
885 }; | 888 } |
886 | 889 |
887 void Scn2k::SaveSys(void) { | 890 void Scn2k::SaveSys(void) { |
888 char buf[1024]; | 891 char buf[1024]; |
889 string save; | 892 string save; |
890 string path = MakeSaveFile(); | 893 string path = MakeSaveFile(); |
891 | 894 |
892 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); save += buf; | 895 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); |
896 save += buf; | |
893 string save_config; | 897 string save_config; |
894 config.DiffOriginal(save_config); | 898 config.DiffOriginal(save_config); |
895 save += "CONFIG="; | 899 save += "CONFIG="; |
896 save += save_config; | 900 save += save_config; |
897 save += "\n"; | 901 save += "\n"; |
915 save += save_readflag; | 919 save += save_readflag; |
916 } | 920 } |
917 | 921 |
918 path += ".0"; | 922 path += ".0"; |
919 FILE* f = fopen(path.c_str(), "w"); | 923 FILE* f = fopen(path.c_str(), "w"); |
920 if (f == 0) { | 924 if (f == NULL) { |
921 fprintf(stderr,"Cannot open save file %s\n",path.c_str()); | 925 fprintf(stderr,"Cannot open save file %s\n",path.c_str()); |
922 return; | 926 return; |
923 } | 927 } |
924 fwrite(save.c_str(), save.length(), 1, f); | 928 fwrite(save.c_str(), save.length(), 1, f); |
925 fclose(f); | 929 fclose(f); |
929 void Scn2k::LoadSys(void) { | 933 void Scn2k::LoadSys(void) { |
930 char buf[1024]; | 934 char buf[1024]; |
931 string path = MakeSaveFile(); | 935 string path = MakeSaveFile(); |
932 path += ".0"; | 936 path += ".0"; |
933 FILE* f = fopen(path.c_str(), "r"); | 937 FILE* f = fopen(path.c_str(), "r"); |
934 if (f == 0) { | 938 if (f == NULL) { |
935 fprintf(stderr, "Cannot open save file %s\n",path.c_str()); | 939 fprintf(stderr, "Cannot open save file %s\n",path.c_str()); |
936 } else { | 940 } else { |
937 fseek(f,0,2); | 941 fseek(f, 0, SEEK_END); |
938 int sz = ftell(f); | 942 int sz = ftell(f); |
939 fseek(f,0,0); | 943 fseek(f, 0, SEEK_SET); |
940 char* savedata = new char[sz+1]; | 944 char* savedata = new char[sz+1]; |
941 fread(savedata, sz, 1, f); | 945 fread(savedata, sz, 1, f); |
942 savedata[sz] = 0; | 946 savedata[sz] = 0; |
943 fclose(f); | 947 fclose(f); |
944 | 948 |
1025 min = t->tm_min; | 1029 min = t->tm_min; |
1026 sec = t->tm_sec; | 1030 sec = t->tm_sec; |
1027 msec = 0; | 1031 msec = 0; |
1028 /* タイトルの取得 */ | 1032 /* タイトルの取得 */ |
1029 FILE* savefile = fopen(path.c_str(), "rb"); | 1033 FILE* savefile = fopen(path.c_str(), "rb"); |
1030 if (savefile == 0) return false; | 1034 if (savefile == NULL) return false; |
1031 char regname[1024]; | 1035 char regname[1024]; |
1032 sprintf(regname, "KEY=%s\n", config.GetParaStr("#REGNAME")); | 1036 sprintf(regname, "KEY=%s\n", config.GetParaStr("#REGNAME")); |
1033 fgets(buf,1000,savefile); | 1037 fgets(buf,1000,savefile); |
1034 if (strncmp(regname, buf, strlen(regname)) != 0) { | 1038 if (strncmp(regname, buf, strlen(regname)) != 0) { |
1035 fprintf(stderr,"invalid save file %s (registory name is not %s)\n",path.c_str(),regname); | 1039 fprintf(stderr,"invalid save file %s (registory name is not %s)\n",path.c_str(),regname); |
1088 return; | 1092 return; |
1089 } | 1093 } |
1090 | 1094 |
1091 void Scn2k::Save(Cmd& cmd) { | 1095 void Scn2k::Save(Cmd& cmd) { |
1092 if (cmd.cmd_type == CMD_SAVEREQ) { | 1096 if (cmd.cmd_type == CMD_SAVEREQ) { |
1093 if (menu == 0) { | 1097 if (menu == NULL) { |
1094 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断 | 1098 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断 |
1095 menu = new Scn2kMenu(Scn2kMenu::MENU_SAVE, *this, flag, text_exec, system_version); | 1099 menu = new Scn2kMenu(Scn2kMenu::MENU_SAVE, *this, flag, text_exec, system_version); |
1096 menu->InitPanel(event, parent); | 1100 menu->InitPanel(event, parent); |
1097 menu->InitTitle(Scn2kSaveTitle(*this)); | 1101 menu->InitTitle(Scn2kSaveTitle(*this)); |
1098 if (mouse_surface) menu_mouseshown = true; | 1102 if (mouse_surface) menu_mouseshown = true; |
1101 return; | 1105 return; |
1102 } | 1106 } |
1103 } | 1107 } |
1104 char buf[1024]; | 1108 char buf[1024]; |
1105 string save; | 1109 string save; |
1106 FILE* f = 0; | 1110 FILE* f = NULL; |
1107 if (save_scn == 0) { | 1111 if (save_scn == 0) { |
1108 fprintf(stderr,"Cannot decide save point\n"); | 1112 fprintf(stderr,"Cannot decide save point\n"); |
1109 return; // セーブ位置が保存されてない | 1113 return; // セーブ位置が保存されてない |
1110 } | 1114 } |
1111 string path = MakeSaveFile(); | 1115 string path = MakeSaveFile(); |
1136 save += *it; | 1140 save += *it; |
1137 save += "[Rollback End]\n"; | 1141 save += "[Rollback End]\n"; |
1138 } | 1142 } |
1139 | 1143 |
1140 f = fopen(path.c_str(), "w"); | 1144 f = fopen(path.c_str(), "w"); |
1141 if (f == 0) { | 1145 if (f == NULL) { |
1142 fprintf(stderr,"Cannot open save file %s\n",path.c_str()); | 1146 fprintf(stderr,"Cannot open save file %s\n",path.c_str()); |
1143 return; | 1147 return; |
1144 } | 1148 } |
1145 fwrite(save.c_str(), save.length(), 1, f); | 1149 fwrite(save.c_str(), save.length(), 1, f); |
1146 fclose(f); | 1150 fclose(f); |
1147 config.SetParam("#LASTSAVE", 1, file_number); | 1151 config.SetParam("#LASTSAVE", 1, file_number); |
1148 cmd.clear(); | 1152 cmd.clear(); |
1149 return; | |
1150 } | 1153 } |
1151 | 1154 |
1152 void Scn2k::Load(Cmd& cmd) { | 1155 void Scn2k::Load(Cmd& cmd) { |
1153 if (cmd.cmd_type == CMD_LOADREQ) { | 1156 if (cmd.cmd_type == CMD_LOADREQ) { |
1154 if (menu == 0) { | 1157 if (menu == NULL) { |
1155 menu = new Scn2kMenu(Scn2kMenu::MENU_LOAD, *this, flag, text_exec, system_version); | 1158 menu = new Scn2kMenu(Scn2kMenu::MENU_LOAD, *this, flag, text_exec, system_version); |
1156 menu->InitPanel(event, parent); | 1159 menu->InitPanel(event, parent); |
1157 menu->InitTitle(Scn2kSaveTitle(*this)); | 1160 menu->InitTitle(Scn2kSaveTitle(*this)); |
1158 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断 | 1161 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断 |
1159 if (mouse_surface) menu_mouseshown = true; | 1162 if (mouse_surface) menu_mouseshown = true; |
1167 int file_number = 1; | 1170 int file_number = 1; |
1168 if (cmd.args.size() == 1) | 1171 if (cmd.args.size() == 1) |
1169 file_number = cmd.args[0].value + 1; | 1172 file_number = cmd.args[0].value + 1; |
1170 sprintf(buf, ".%d",file_number); | 1173 sprintf(buf, ".%d",file_number); |
1171 path += buf; | 1174 path += buf; |
1172 FILE* f = 0; | 1175 FILE* f = NULL; |
1173 if (file_number > 0) f = fopen(path.c_str(), "r"); | 1176 if (file_number > 0) f = fopen(path.c_str(), "r"); |
1174 if (f == 0) { | 1177 if (f == NULL) { |
1175 fprintf(stderr, "Cannot open save file %s\n",path.c_str()); | 1178 fprintf(stderr, "Cannot open save file %s\n",path.c_str()); |
1176 return; | 1179 return; |
1177 } | 1180 } |
1178 | 1181 |
1179 fseek(f,0,2); | 1182 fseek(f, 0, SEEK_END); |
1180 int sz = ftell(f); | 1183 int sz = ftell(f); |
1181 fseek(f,0,0); | 1184 fseek(f, 0, SEEK_SET); |
1182 char* savedata = new char[sz+1]; | 1185 char* savedata = new char[sz+1]; |
1183 fread(savedata, sz, 1, f); | 1186 fread(savedata, sz, 1, f); |
1184 savedata[sz] = 0; | 1187 savedata[sz] = 0; |
1185 fclose(f); | 1188 fclose(f); |
1186 | 1189 |
1195 text_exec.Load(savedata); | 1198 text_exec.Load(savedata); |
1196 grp_exec.Load(savedata); | 1199 grp_exec.Load(savedata); |
1197 rollback_save.clear(); | 1200 rollback_save.clear(); |
1198 new_rollback_save = ""; | 1201 new_rollback_save = ""; |
1199 char* rollback_data = savedata; | 1202 char* rollback_data = savedata; |
1200 while( (rollback_data = strstr(rollback_data,"[Rollback Data]\n")) != 0) { | 1203 while( (rollback_data = strstr(rollback_data,"[Rollback Data]\n")) != NULL) { |
1201 rollback_data += strlen("[Rollback Data]\n"); | 1204 rollback_data += strlen("[Rollback Data]\n"); |
1202 char* rollback_end = strstr(rollback_data, "[Rollback End]\n"); | 1205 char* rollback_end = strstr(rollback_data, "[Rollback End]\n"); |
1203 if (rollback_end == 0) rollback_end = rollback_data + strlen(rollback_data); | 1206 if (rollback_end == NULL) rollback_end = rollback_data + strlen(rollback_data); |
1204 string s(rollback_data, rollback_end); | 1207 string s(rollback_data, rollback_end); |
1205 rollback_save.push_back(s); | 1208 rollback_save.push_back(s); |
1206 rollback_data = rollback_end; | 1209 rollback_data = rollback_end; |
1207 } | 1210 } |
1208 | 1211 |
1217 grp_exec.Exec(cmd); | 1220 grp_exec.Exec(cmd); |
1218 } | 1221 } |
1219 cmd.clear(); | 1222 cmd.clear(); |
1220 | 1223 |
1221 delete[] savedata; | 1224 delete[] savedata; |
1222 return; | |
1223 } | 1225 } |
1224 | 1226 |
1225 void Scn2k::SaveImpl(string& save) { | 1227 void Scn2k::SaveImpl(string& save) { |
1226 char buf[1024]; | 1228 char buf[1024]; |
1227 | 1229 |
1259 stack.clear(); | 1261 stack.clear(); |
1260 cmd_stack.clear(); | 1262 cmd_stack.clear(); |
1261 cmd_stack_str = cmd_stack_str_orig; | 1263 cmd_stack_str = cmd_stack_str_orig; |
1262 | 1264 |
1263 save = strstr(save, "\n[SCENARIO]\n"); | 1265 save = strstr(save, "\n[SCENARIO]\n"); |
1264 if (save == 0) return; | 1266 if (save == NULL) return; |
1265 save += strlen("\n[SCENARIO]\n"); | 1267 save += strlen("\n[SCENARIO]\n"); |
1266 while(save[0] != 0 && save[0] != '[') { // while next section start | 1268 while(save[0] != 0 && save[0] != '[') { // while next section start |
1267 if (strncmp(save, "Scn=", 4) == 0) { | 1269 if (strncmp(save, "Scn=", 4) == 0) { |
1268 sscanf(save, "Scn=%d", &save_scn); | 1270 sscanf(save, "Scn=%d", &save_scn); |
1269 } else if (strncmp(save, "Point=", 6) == 0) { | 1271 } else if (strncmp(save, "Point=", 6) == 0) { |
1270 sscanf(save, "Point=%d", &save_point); | 1272 sscanf(save, "Point=%d", &save_point); |
1271 } else if (strncmp(save, "Title=", 6) == 0) { | 1273 } else if (strncmp(save, "Title=", 6) == 0) { |
1272 save += 6; | 1274 save += 6; |
1273 char* s = strchr(save, '\n'); | 1275 char* s = strchr(save, '\n'); |
1274 if (s == 0) window_title = save; | 1276 if (s == NULL) window_title = save; |
1275 else window_title.assign(save, s-save); | 1277 else window_title.assign(save, s-save); |
1276 const char* config_name = config.GetParaStr("#CAPTION"); | 1278 const char* config_name = config.GetParaStr("#CAPTION"); |
1277 if (config_name == 0) config_name = ""; | 1279 if (config_name == NULL) config_name = ""; |
1278 string setname = kconv(string(config_name)+" "+window_title); | 1280 string setname = kconv(string(config_name)+" "+window_title); |
1279 parent.Root().SetWindowCaption(setname.c_str()); | 1281 parent.Root().SetWindowCaption(setname.c_str()); |
1280 } else if (strncmp(save, "MouseType=", 10) == 0) { | 1282 } else if (strncmp(save, "MouseType=", 10) == 0) { |
1281 sscanf(save, "MouseType=%d", &mouse_type); | 1283 sscanf(save, "MouseType=%d", &mouse_type); |
1282 } else if (strncmp(save, "MouseShown=", 11) == 0) { | 1284 } else if (strncmp(save, "MouseShown=", 11) == 0) { |
1289 sscanf(save, "Stack=%d,%d", &scn, &pt); | 1291 sscanf(save, "Stack=%d,%d", &scn, &pt); |
1290 stack.push_back( StackItem(scn, pt)); | 1292 stack.push_back( StackItem(scn, pt)); |
1291 } else if (strncmp(save, "StackStr=", 9) == 0) { | 1293 } else if (strncmp(save, "StackStr=", 9) == 0) { |
1292 save += 9; | 1294 save += 9; |
1293 char* s = strchr(save, '\n'); | 1295 char* s = strchr(save, '\n'); |
1294 if (s == 0) stack_strbuffer.push_back(""); | 1296 if (s == NULL) stack_strbuffer.push_back(""); |
1295 else stack_strbuffer.push_back(string(save, s-save)); | 1297 else stack_strbuffer.push_back(string(save, s-save)); |
1296 } else if (strncmp(save, "Cmd=", 4) == 0) { | 1298 } else if (strncmp(save, "Cmd=", 4) == 0) { |
1297 CmdSimplified cmd; | 1299 CmdSimplified cmd; |
1298 cmd.Load(save+4, cmd_stack_str); | 1300 cmd.Load(save+4, cmd_stack_str); |
1299 cmd_stack.push_back(cmd); | 1301 cmd_stack.push_back(cmd); |
1302 cmd.Load(save+5, cmd_stack_str); | 1304 cmd.Load(save+5, cmd_stack_str); |
1303 cmd.type = CMD_SAVECMDGRP; | 1305 cmd.type = CMD_SAVECMDGRP; |
1304 cmd_stack.push_back(cmd); | 1306 cmd_stack.push_back(cmd); |
1305 } | 1307 } |
1306 save = strchr(save, '\n'); | 1308 save = strchr(save, '\n'); |
1307 if (save != 0) save++; | 1309 if (save != NULL) save++; |
1308 } | 1310 } |
1309 ChangeScript(save_scn, 0); | 1311 ChangeScript(save_scn, 0); |
1310 script = script_start + save_point; | 1312 script = script_start + save_point; |
1311 return; | 1313 } |
1312 } | 1314 |
1313 void Scn2k::SetSkipMode(SkipMode mode) { | 1315 void Scn2k::SetSkipMode(SkipMode mode) { |
1314 if (skip_mode != mode) { | 1316 if (skip_mode != mode) { |
1315 skip_mode = mode; | 1317 skip_mode = mode; |
1316 text_exec.SetSkipMode(mode); | 1318 text_exec.SetSkipMode(mode); |
1317 grp_exec.SetSkipMode(mode); | 1319 grp_exec.SetSkipMode(mode); |
1347 *param++ = random() % 600 - 300; | 1349 *param++ = random() % 600 - 300; |
1348 *param++ = random() % 700 - 350; | 1350 *param++ = random() % 700 - 350; |
1349 } | 1351 } |
1350 } | 1352 } |
1351 if (cmd.args[5].value != 1) return; | 1353 if (cmd.args[5].value != 1) return; |
1352 static int random_dirtable[] = { | 1354 |
1355 static int random_dirtable[] = { | |
1353 0, 2, 1, 3, 0, 2, 1, 3, | 1356 0, 2, 1, 3, 0, 2, 1, 3, |
1354 1, 3, 2, 0, 1, 3, 2, 0, | 1357 1, 3, 2, 0, 1, 3, 2, 0, |
1355 0, 0, 0, 0, 3, 1, 2, 0, | 1358 0, 0, 0, 0, 3, 1, 2, 0, |
1356 3, 1, 3, 1, 0, 2, 3, 1 | 1359 3, 1, 3, 1, 0, 2, 3, 1 |
1357 }; | 1360 }; |
1361 | |
1358 int* dir = &random_dirtable[(random()&3) * 8]; | 1362 int* dir = &random_dirtable[(random()&3) * 8]; |
1359 for (i=0; i<8; i++) { | 1363 for (i=0; i<8; i++) { |
1360 double* param = lb_ef_param + i*0x60; | 1364 double* param = lb_ef_param + i*0x60; |
1361 double x = random()%600 - 300; | 1365 double x = random()%600 - 300; |
1362 double y = random()%480-240; | 1366 double y = random()%480-240; |
1392 param[16] = -param[10]; | 1396 param[16] = -param[10]; |
1393 param[17] = -param[11]; | 1397 param[17] = -param[11]; |
1394 } | 1398 } |
1395 return; | 1399 return; |
1396 } | 1400 } |
1401 | |
1397 void DLLCall_LB_EF00_1(Cmd& cmd, Flags& flags) { // 計算を行う | 1402 void DLLCall_LB_EF00_1(Cmd& cmd, Flags& flags) { // 計算を行う |
1398 if (lb_ef_param == 0) { | 1403 if (lb_ef_param == 0) { |
1399 fprintf(stderr,"Warning : DLLCall_LB_EF00_1 : Script error : effect calculation was called before setting\n"); | 1404 fprintf(stderr,"Warning : DLLCall_LB_EF00_1 : Script error : effect calculation was called before setting\n"); |
1400 return; | 1405 return; |
1401 } | 1406 } |
1455 ** | 1460 ** |
1456 ** MenuImpl | 1461 ** MenuImpl |
1457 ** | 1462 ** |
1458 */ | 1463 */ |
1459 | 1464 |
1460 #include"window/widget.h" | 1465 #include "window/widget.h" |
1461 #include"window/menuitem.h" | 1466 #include "window/menuitem.h" |
1462 | 1467 |
1463 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a = 0xff); | 1468 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a = 0xff); |
1464 | 1469 |
1465 struct Scn2kMenuImpl { | 1470 struct Scn2kMenuImpl { |
1466 Scn2kMenu& interface; | 1471 Scn2kMenu& interface; |
1471 virtual void InitPanel(Event::Container& event, PicContainer& parent) = 0; | 1476 virtual void InitPanel(Event::Container& event, PicContainer& parent) = 0; |
1472 virtual void InitTitle(const SaveTitle&) = 0; | 1477 virtual void InitTitle(const SaveTitle&) = 0; |
1473 virtual void Cancel(void) = 0; | 1478 virtual void Cancel(void) = 0; |
1474 virtual void Exec(Cmd& cmd) = 0; | 1479 virtual void Exec(Cmd& cmd) = 0; |
1475 Scn2kMenuImpl(Scn2kMenu& _interface) : interface(_interface) { | 1480 Scn2kMenuImpl(Scn2kMenu& _interface) : interface(_interface) { |
1476 menu = 0; | 1481 menu = NULL; |
1477 pevent = 0; | 1482 pevent = NULL; |
1478 pparent = 0; | 1483 pparent = NULL; |
1479 } | 1484 } |
1480 virtual ~Scn2kMenuImpl() { | 1485 virtual ~Scn2kMenuImpl() { |
1481 if (menu) delete menu; | 1486 if (menu) delete menu; |
1482 menu = 0; | 1487 menu = NULL; |
1483 } | 1488 } |
1484 }; | 1489 }; |
1485 | 1490 |
1486 struct LoadMenu : Scn2kMenuImpl { | 1491 struct LoadMenu : Scn2kMenuImpl { |
1487 vector<string> title; | 1492 vector<string> title; |
1507 void SetPage(int new_page); | 1512 void SetPage(int new_page); |
1508 void SetValue(int new_value); | 1513 void SetValue(int new_value); |
1509 void PressOk(void); | 1514 void PressOk(void); |
1510 }; | 1515 }; |
1511 LoadMenu::LoadMenu(Scn2kMenu& _interface) : Scn2kMenuImpl(_interface) { | 1516 LoadMenu::LoadMenu(Scn2kMenu& _interface) : Scn2kMenuImpl(_interface) { |
1512 btn_local = 0; | 1517 btn_local = NULL; |
1513 btn_scale = 0; | 1518 btn_scale = NULL; |
1514 btn_set = 0; | 1519 btn_set = NULL; |
1515 btn_page_val = 0; | 1520 btn_page_val = 0; |
1516 btn_set_val = -1; | 1521 btn_set_val = -1; |
1517 btn_local_val = -1; | 1522 btn_local_val = -1; |
1518 awk_dialog = 0; | 1523 awk_dialog = NULL; |
1519 in_setpage = false; | 1524 in_setpage = false; |
1520 select_page = 0; | 1525 select_page = 0; |
1521 select_value = -1; | 1526 select_value = -1; |
1522 } | 1527 } |
1523 LoadMenu::~LoadMenu() { | 1528 LoadMenu::~LoadMenu() { |
1526 void LoadMenu::InitPanel(Event::Container& event, PicContainer& parent) { | 1531 void LoadMenu::InitPanel(Event::Container& event, PicContainer& parent) { |
1527 pevent = &event; | 1532 pevent = &event; |
1528 pparent = &parent; | 1533 pparent = &parent; |
1529 | 1534 |
1530 if (menu) delete menu; | 1535 if (menu) delete menu; |
1531 menu = 0; | 1536 menu = NULL; |
1532 menu = new MenuItem(&parent, Rect(80,30,560, 450), 1, 3, 0); | 1537 menu = new MenuItem(&parent, Rect(80,30,560, 450), 1, 3, 0); |
1533 Surface* surface = parent.Root().NewSurface(menu->Pic()->Width(), menu->Pic()->Height(), ALPHA_MASK); | 1538 Surface* surface = parent.Root().NewSurface(menu->Pic()->Width(), menu->Pic()->Height(), ALPHA_MASK); |
1534 if (interface.type == Scn2kMenu::MENU_LOAD) { | 1539 if (interface.type == Scn2kMenu::MENU_LOAD) { |
1535 menu->SetLabelTop(new Label(menu->PicNode(), Rect(0,0), true, "Load", 26), Rect(0,0,10,0), Rect(0,0,0,20)); | 1540 menu->SetLabelTop(new Label(menu->PicNode(), Rect(0,0), true, "Load", 26), Rect(0,0,10,0), Rect(0,0,0,20)); |
1536 DSurfaceFill(surface, Rect(*surface), 0, 0, 0x80, 0x80); | 1541 DSurfaceFill(surface, Rect(*surface), 0, 0, 0x80, 0x80); |
1672 for (i=0; i<12; i++) { | 1677 for (i=0; i<12; i++) { |
1673 int old_x = btn_local->item[i]->Pic()->PosX(); | 1678 int old_x = btn_local->item[i]->Pic()->PosX(); |
1674 btn_local->item[i]->Pic()->Move(old_x, i*30-new_point*3); | 1679 btn_local->item[i]->Pic()->Move(old_x, i*30-new_point*3); |
1675 } | 1680 } |
1676 } | 1681 } |
1677 if (btn_page) { | 1682 if (btn_page != NULL) { |
1678 if (select_page%100 == 0) btn_page->SetValue(select_page/100); | 1683 if (select_page%100 == 0) btn_page->SetValue(select_page/100); |
1679 else btn_page->SetValue(-1); | 1684 else btn_page->SetValue(-1); |
1680 } | 1685 } |
1681 if (btn_scale) { | 1686 if (btn_scale != NULL) { |
1682 btn_scale->SetValue(select_page); | 1687 btn_scale->SetValue(select_page); |
1683 } | 1688 } |
1684 in_setpage = false; | 1689 in_setpage = false; |
1685 return; | 1690 } |
1686 } | 1691 |
1687 void LoadMenu::SetValue(int new_value) { | 1692 void LoadMenu::SetValue(int new_value) { |
1688 if (in_setpage) return; | 1693 if (in_setpage) return; |
1689 in_setpage = true; | 1694 in_setpage = true; |
1690 | 1695 |
1691 if (new_value < 0 || new_value > title.size() || | 1696 if (new_value < 0 || new_value > title.size() || |
1704 } | 1709 } |
1705 } | 1710 } |
1706 } | 1711 } |
1707 | 1712 |
1708 in_setpage = false; | 1713 in_setpage = false; |
1709 return; | 1714 } |
1710 } | 1715 |
1711 void LoadMenu::PressOk(void) { | 1716 void LoadMenu::PressOk(void) { |
1712 if (select_value == -1) { | 1717 if (select_value == -1) { |
1713 btn_set->SetValue(-1); // なにもしない | 1718 btn_set->SetValue(-1); // なにもしない |
1714 return; | 1719 return; |
1715 } | 1720 } |
1730 awk_dialog->set_pointer = this; | 1735 awk_dialog->set_pointer = this; |
1731 awk_dialog->set_func = ChangeDialog; | 1736 awk_dialog->set_func = ChangeDialog; |
1732 } | 1737 } |
1733 } | 1738 } |
1734 } | 1739 } |
1740 | |
1735 void LoadMenu::Cancel(void) { | 1741 void LoadMenu::Cancel(void) { |
1736 if (awk_dialog) { // ダイアログのキャンセル | 1742 if (awk_dialog != NULL) { // ダイアログのキャンセル |
1737 awk_dialog->status = Dialog::CANCEL; | 1743 awk_dialog->status = Dialog::CANCEL; |
1738 ChangeDialog(this, awk_dialog); | 1744 ChangeDialog(this, awk_dialog); |
1739 } else { // 一般キャンセル | 1745 } else { // 一般キャンセル |
1740 btn_set->SetValue(1); | 1746 btn_set->SetValue(1); |
1741 } | 1747 } |
1742 } | 1748 } |
1749 | |
1743 void LoadMenu::Exec(Cmd& cmd) { | 1750 void LoadMenu::Exec(Cmd& cmd) { |
1744 } | 1751 } |
1752 | |
1745 void LoadMenu::ChangeBtnPage(void* pointer, MenuItem* widget) { | 1753 void LoadMenu::ChangeBtnPage(void* pointer, MenuItem* widget) { |
1746 LoadMenu* instance = (LoadMenu*)pointer; | 1754 LoadMenu* instance = (LoadMenu*)pointer; |
1747 if (instance->btn_page_val == -1) return; | 1755 if (instance->btn_page_val == -1) return; |
1748 instance->SetPage(instance->btn_page_val*100); | 1756 instance->SetPage(instance->btn_page_val*100); |
1749 } | 1757 } |
1758 | |
1750 void LoadMenu::ChangeBtnScale(void* pointer, Scale* from) { | 1759 void LoadMenu::ChangeBtnScale(void* pointer, Scale* from) { |
1751 LoadMenu* instance = (LoadMenu*)pointer; | 1760 LoadMenu* instance = (LoadMenu*)pointer; |
1752 int value = from->GetValue(); | 1761 int value = from->GetValue(); |
1753 instance->SetPage(value); | 1762 instance->SetPage(value); |
1754 } | 1763 } |
1764 | |
1755 void LoadMenu::ChangeBtnSet(void* pointer, MenuItem* widget) { | 1765 void LoadMenu::ChangeBtnSet(void* pointer, MenuItem* widget) { |
1756 LoadMenu* instance = (LoadMenu*)pointer; | 1766 LoadMenu* instance = (LoadMenu*)pointer; |
1757 if (instance->btn_set_val == 1) { // cancel | 1767 if (instance->btn_set_val == 1) { // cancel |
1758 instance->interface.status = Scn2kMenu::MENU_DELETE; | 1768 instance->interface.status = Scn2kMenu::MENU_DELETE; |
1759 return; | 1769 return; |
1760 } else if (instance->btn_set_val == 0) { // OK | 1770 } else if (instance->btn_set_val == 0) { // OK |
1761 instance->PressOk(); | 1771 instance->PressOk(); |
1762 } | 1772 } |
1763 } | 1773 } |
1774 | |
1764 void LoadMenu::ChangeDialog(void* pointer, Dialog* widget) { | 1775 void LoadMenu::ChangeDialog(void* pointer, Dialog* widget) { |
1765 LoadMenu* instance = (LoadMenu*)pointer; | 1776 LoadMenu* instance = (LoadMenu*)pointer; |
1766 if (widget->status == Dialog::CANCEL) { | 1777 if (widget->status == Dialog::CANCEL) { |
1767 // ダイアログ消去、OK ボタン復帰 | 1778 // ダイアログ消去、OK ボタン復帰 |
1768 delete instance->awk_dialog; | 1779 delete instance->awk_dialog; |
1769 instance->awk_dialog = 0; | 1780 instance->awk_dialog = NULL; |
1770 instance->menu->activate(); | 1781 instance->menu->activate(); |
1771 instance->btn_set->SetValue(-1); | 1782 instance->btn_set->SetValue(-1); |
1772 return; | 1783 return; |
1773 } else if (widget->status == Dialog::OK) { | 1784 } else if (widget->status == Dialog::OK) { |
1774 instance->interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_CMD | Scn2kMenu::MENU_DELETE); | 1785 instance->interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_CMD | Scn2kMenu::MENU_DELETE); |
1775 return; | 1786 return; |
1776 } | 1787 } |
1777 } | 1788 } |
1789 | |
1778 void LoadMenu::ChangeBtnLocal(void* pointer, MenuItem* widget) { | 1790 void LoadMenu::ChangeBtnLocal(void* pointer, MenuItem* widget) { |
1779 LoadMenu* instance = (LoadMenu*)pointer; | 1791 LoadMenu* instance = (LoadMenu*)pointer; |
1780 if (instance->btn_local_val == -1) return; | 1792 if (instance->btn_local_val == -1) return; |
1781 instance->SetValue( (instance->select_page/10) + instance->btn_local_val); | 1793 instance->SetValue( (instance->select_page/10) + instance->btn_local_val); |
1782 } | 1794 } |
1791 void InitPanel(Event::Container& event, PicContainer& parent); | 1803 void InitPanel(Event::Container& event, PicContainer& parent); |
1792 void InitTitle(const SaveTitle&); | 1804 void InitTitle(const SaveTitle&); |
1793 void Cancel(void); | 1805 void Cancel(void); |
1794 void Exec(Cmd& cmd); | 1806 void Exec(Cmd& cmd); |
1795 }; | 1807 }; |
1808 | |
1796 BacklogMenu::BacklogMenu(Scn2kMenu& _interface, Scn2k& _scn, Text& parent_text_exec) : Scn2kMenuImpl(_interface), scn_impl(_scn), text_exec(parent_text_exec) { | 1809 BacklogMenu::BacklogMenu(Scn2kMenu& _interface, Scn2k& _scn, Text& parent_text_exec) : Scn2kMenuImpl(_interface), scn_impl(_scn), text_exec(parent_text_exec) { |
1797 backlog_cnt = -1; | 1810 backlog_cnt = -1; |
1798 backlog_update = false; | 1811 backlog_update = false; |
1799 } | 1812 } |
1813 | |
1800 BacklogMenu::~BacklogMenu() { | 1814 BacklogMenu::~BacklogMenu() { |
1801 } | 1815 } |
1816 | |
1802 void BacklogMenu::InitPanel(Event::Container& event, PicContainer& parent) { | 1817 void BacklogMenu::InitPanel(Event::Container& event, PicContainer& parent) { |
1803 pevent = &event; | 1818 pevent = &event; |
1804 } | 1819 } |
1805 | 1820 |
1806 void BacklogMenu::InitTitle(const SaveTitle& title_op) { | 1821 void BacklogMenu::InitTitle(const SaveTitle& title_op) { |
1807 } | 1822 } |
1823 | |
1808 void BacklogMenu::Cancel(void) { | 1824 void BacklogMenu::Cancel(void) { |
1809 interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_DELETE); | 1825 interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_DELETE); |
1810 } | 1826 } |
1827 | |
1811 void BacklogMenu::Exec(Cmd& cmd) { | 1828 void BacklogMenu::Exec(Cmd& cmd) { |
1812 int command_direction = 0; // forward | 1829 int command_direction = 0; // forward |
1813 if (cmd.cmd_type == CMD_NOP) text_exec.Wait(0xffffffffUL, cmd); | 1830 if (cmd.cmd_type == CMD_NOP) text_exec.Wait(0xffffffffUL, cmd); |
1814 if (cmd.cmd_type == CMD_BACKLOGREQ || pevent->presscount(MOUSE_UP)) { | 1831 if (cmd.cmd_type == CMD_BACKLOGREQ || pevent->presscount(MOUSE_UP)) { |
1815 if (cmd.cmd_type == CMD_BACKLOGREQ) cmd.clear(); | 1832 if (cmd.cmd_type == CMD_BACKLOGREQ) cmd.clear(); |
1872 ** | 1889 ** |
1873 */ | 1890 */ |
1874 | 1891 |
1875 Scn2kMenu::Scn2kMenu(MenuType _type, Scn2k& scn_impl, const Flags& flags, Text& text_exec, int system_version) : | 1892 Scn2kMenu::Scn2kMenu(MenuType _type, Scn2k& scn_impl, const Flags& flags, Text& text_exec, int system_version) : |
1876 cmd(flags, system_version), type(_type) { | 1893 cmd(flags, system_version), type(_type) { |
1877 pimpl = 0; | 1894 pimpl = NULL; |
1878 status = MENU_CONTINUE; | 1895 status = MENU_CONTINUE; |
1879 switch(type) { | 1896 switch(type) { |
1880 case MENU_LOAD: pimpl = new LoadMenu(*this); break; | 1897 case MENU_LOAD: pimpl = new LoadMenu(*this); break; |
1881 case MENU_SAVE: pimpl = new LoadMenu(*this); break; | 1898 case MENU_SAVE: pimpl = new LoadMenu(*this); break; |
1882 case MENU_BACKLOG: pimpl = new BacklogMenu(*this, scn_impl, text_exec); break; | 1899 case MENU_BACKLOG: pimpl = new BacklogMenu(*this, scn_impl, text_exec); break; |
1883 } | 1900 } |
1884 return; | 1901 return; |
1885 } | 1902 } |
1886 Scn2kMenu::~Scn2kMenu() { | 1903 Scn2kMenu::~Scn2kMenu() { |
1887 if (pimpl) delete pimpl; | 1904 if (pimpl) delete pimpl; |
1888 pimpl = 0; | 1905 pimpl = NULL; |
1889 } | 1906 } |
1907 | |
1890 void Scn2kMenu::InitPanel(Event::Container& event, PicContainer& parent) { | 1908 void Scn2kMenu::InitPanel(Event::Container& event, PicContainer& parent) { |
1891 if (pimpl) pimpl->InitPanel(event, parent); | 1909 if (pimpl != NULL) pimpl->InitPanel(event, parent); |
1892 } | 1910 } |
1911 | |
1893 void Scn2kMenu::InitTitle(const SaveTitle& t) { | 1912 void Scn2kMenu::InitTitle(const SaveTitle& t) { |
1894 if (pimpl) pimpl->InitTitle(t); | 1913 if (pimpl != NULL) pimpl->InitTitle(t); |
1895 } | 1914 } |
1915 | |
1896 void Scn2kMenu::Cancel(void) { | 1916 void Scn2kMenu::Cancel(void) { |
1897 if (pimpl) pimpl->Cancel(); | 1917 if (pimpl) pimpl->Cancel(); |
1898 } | 1918 } |
1919 | |
1899 void Scn2kMenu::Exec(Cmd& ret_cmd) { | 1920 void Scn2kMenu::Exec(Cmd& ret_cmd) { |
1900 if (pimpl == 0) return; | 1921 if (pimpl == NULL) return; |
1901 pimpl->Exec(ret_cmd); | 1922 pimpl->Exec(ret_cmd); |
1902 if (pimpl->pevent->presscount(MOUSE_RIGHT)) { | 1923 if (pimpl->pevent->presscount(MOUSE_RIGHT)) { |
1903 Cancel(); | 1924 Cancel(); |
1904 } | 1925 } |
1905 if (status & MENU_CMD && cmd.cmd_type != CMD_NOP) { | 1926 if (status & MENU_CMD && cmd.cmd_type != CMD_NOP) { |
1909 char* tmp_cmd_str = cmd_str; | 1930 char* tmp_cmd_str = cmd_str; |
1910 cmd.write(tmp_cmd, tmp_cmd_str); | 1931 cmd.write(tmp_cmd, tmp_cmd_str); |
1911 ret_cmd.read(tmp_cmd); | 1932 ret_cmd.read(tmp_cmd); |
1912 } | 1933 } |
1913 } | 1934 } |
1935 | |
1914 void Scn2kMenu::activate(void) { | 1936 void Scn2kMenu::activate(void) { |
1915 if (pimpl && pimpl->menu) pimpl->menu->activate(); | 1937 if (pimpl != NULL && pimpl->menu) pimpl->menu->activate(); |
1916 } | 1938 } |
1939 | |
1917 void Scn2kMenu::deactivate(void) { | 1940 void Scn2kMenu::deactivate(void) { |
1918 if (pimpl && pimpl->menu) pimpl->menu->deactivate(); | 1941 if (pimpl != NULL && pimpl->menu) pimpl->menu->deactivate(); |
1919 } | 1942 } |
1920 | 1943 |