annotate scn2k/scn2k_impl.cc @ 24:c9e218c2c3f1

Makes xclannad buildable without libvorbis
author thib
date Fri, 27 Feb 2009 16:02:32 +0000
parents 94fe9153efa5
children 01aa5ddf7dc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 #include <stdexcept>
223b71206888 Initial import
thib
parents:
diff changeset
29 #include"scn2k_impl.h"
223b71206888 Initial import
thib
parents:
diff changeset
30 #include"system/file.h"
223b71206888 Initial import
thib
parents:
diff changeset
31 #include"system/system_config.h"
223b71206888 Initial import
thib
parents:
diff changeset
32 #include"window/picture.h"
223b71206888 Initial import
thib
parents:
diff changeset
33 #include"window/system.h"
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 // #define DEBUG 1
223b71206888 Initial import
thib
parents:
diff changeset
36
223b71206888 Initial import
thib
parents:
diff changeset
37 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
38
223b71206888 Initial import
thib
parents:
diff changeset
39 /**********************************************
223b71206888 Initial import
thib
parents:
diff changeset
40 ** Scn2k
223b71206888 Initial import
thib
parents:
diff changeset
41 */
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 void kconv(const unsigned char* src, unsigned char* dest);
223b71206888 Initial import
thib
parents:
diff changeset
44 void kconv_rev(const unsigned char* src, unsigned char* dest);
223b71206888 Initial import
thib
parents:
diff changeset
45 string kconv(const string& s);
223b71206888 Initial import
thib
parents:
diff changeset
46 string kconv_rev(const string& s);
223b71206888 Initial import
thib
parents:
diff changeset
47
223b71206888 Initial import
thib
parents:
diff changeset
48 Scn2k::Scn2k(Event::Container& _event, PicContainer& _parent, class MuSys& mu, AyuSysConfig& _config) :
223b71206888 Initial import
thib
parents:
diff changeset
49 Event::Time(_event),
223b71206888 Initial import
thib
parents:
diff changeset
50 event(_event),
223b71206888 Initial import
thib
parents:
diff changeset
51 parent(_parent),
223b71206888 Initial import
thib
parents:
diff changeset
52 config(_config),
223b71206888 Initial import
thib
parents:
diff changeset
53 text_exec(_event, _parent, config),
223b71206888 Initial import
thib
parents:
diff changeset
54 grp_exec(_event, _parent, flag, flag.cgm_data, mu, config)
223b71206888 Initial import
thib
parents:
diff changeset
55 {
223b71206888 Initial import
thib
parents:
diff changeset
56 system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
57 skip_mode = SKIP_NO;
223b71206888 Initial import
thib
parents:
diff changeset
58
223b71206888 Initial import
thib
parents:
diff changeset
59 script_start = 0;
223b71206888 Initial import
thib
parents:
diff changeset
60 script = 0;
223b71206888 Initial import
thib
parents:
diff changeset
61 script_end = 0;
223b71206888 Initial import
thib
parents:
diff changeset
62
223b71206888 Initial import
thib
parents:
diff changeset
63 backlog_script_scn = -1;
223b71206888 Initial import
thib
parents:
diff changeset
64 backlog_script_start = 0;
223b71206888 Initial import
thib
parents:
diff changeset
65 backlog_script_end = 0;
223b71206888 Initial import
thib
parents:
diff changeset
66
223b71206888 Initial import
thib
parents:
diff changeset
67 save_scn = 0;
223b71206888 Initial import
thib
parents:
diff changeset
68 save_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
69 scn_number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
70 scn_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
71 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
72
223b71206888 Initial import
thib
parents:
diff changeset
73 dialog = 0;
223b71206888 Initial import
thib
parents:
diff changeset
74 dialog_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
75 menu = 0;
223b71206888 Initial import
thib
parents:
diff changeset
76 menu_mouseshown = false;
223b71206888 Initial import
thib
parents:
diff changeset
77
223b71206888 Initial import
thib
parents:
diff changeset
78 /* マウスカーソルを作成 */
223b71206888 Initial import
thib
parents:
diff changeset
79 mouse_type = 0;
223b71206888 Initial import
thib
parents:
diff changeset
80 mouse_surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
81 mouse_pressed = 0;
223b71206888 Initial import
thib
parents:
diff changeset
82 ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
83
223b71206888 Initial import
thib
parents:
diff changeset
84 LoadSys();
223b71206888 Initial import
thib
parents:
diff changeset
85 text_exec.InitWindow();
223b71206888 Initial import
thib
parents:
diff changeset
86 grp_exec.InitSel(config);
223b71206888 Initial import
thib
parents:
diff changeset
87 }
223b71206888 Initial import
thib
parents:
diff changeset
88
223b71206888 Initial import
thib
parents:
diff changeset
89 Scn2k::~Scn2k() {
223b71206888 Initial import
thib
parents:
diff changeset
90 HideCursor();
223b71206888 Initial import
thib
parents:
diff changeset
91 SaveSys();
223b71206888 Initial import
thib
parents:
diff changeset
92 }
223b71206888 Initial import
thib
parents:
diff changeset
93
223b71206888 Initial import
thib
parents:
diff changeset
94 char* Scn2k::OpenScript(int new_scn_number, char*& end, int* call_vec, int& system_version) {
223b71206888 Initial import
thib
parents:
diff changeset
95 char fname[1024];
223b71206888 Initial import
thib
parents:
diff changeset
96 const char* data;
223b71206888 Initial import
thib
parents:
diff changeset
97 char* ret_data;
223b71206888 Initial import
thib
parents:
diff changeset
98 int offset = 0;
223b71206888 Initial import
thib
parents:
diff changeset
99 int scenario_magic;
223b71206888 Initial import
thib
parents:
diff changeset
100
223b71206888 Initial import
thib
parents:
diff changeset
101 sprintf(fname, "SEEN%04d.TXT", new_scn_number);
223b71206888 Initial import
thib
parents:
diff changeset
102 ARCINFO* info = file_searcher.Find(FILESEARCH::SCN, fname, "");
223b71206888 Initial import
thib
parents:
diff changeset
103 if (info == 0) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
104 data = info->Read();
223b71206888 Initial import
thib
parents:
diff changeset
105
223b71206888 Initial import
thib
parents:
diff changeset
106 /* version 確認 */
223b71206888 Initial import
thib
parents:
diff changeset
107 scenario_magic = read_little_endian_int(data + 4);
223b71206888 Initial import
thib
parents:
diff changeset
108 if (scenario_magic != 0x2712 && scenario_magic != 0x1adb2) {
223b71206888 Initial import
thib
parents:
diff changeset
109 fprintf(stderr,"Invalid scenario header : scenario number %d\n",new_scn_number);
223b71206888 Initial import
thib
parents:
diff changeset
110 goto err;
223b71206888 Initial import
thib
parents:
diff changeset
111 }
223b71206888 Initial import
thib
parents:
diff changeset
112 if (read_little_endian_int(data) == 0x1cc) {
223b71206888 Initial import
thib
parents:
diff changeset
113 system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
114 offset = 0x1cc + read_little_endian_int(data+0x20) + 4;
223b71206888 Initial import
thib
parents:
diff changeset
115 } else if (read_little_endian_int(data) == 0x1d0) {
223b71206888 Initial import
thib
parents:
diff changeset
116 system_version = 1;
223b71206888 Initial import
thib
parents:
diff changeset
117 offset = read_little_endian_int(data + 0x20);
223b71206888 Initial import
thib
parents:
diff changeset
118 } else {
223b71206888 Initial import
thib
parents:
diff changeset
119 fprintf(stderr,"Invalid scenario header : scenario number %d\n",new_scn_number);
223b71206888 Initial import
thib
parents:
diff changeset
120 goto err;
223b71206888 Initial import
thib
parents:
diff changeset
121 }
223b71206888 Initial import
thib
parents:
diff changeset
122 /* header から subroutine number とりだし */
223b71206888 Initial import
thib
parents:
diff changeset
123 if (call_vec) {
223b71206888 Initial import
thib
parents:
diff changeset
124 int i;
223b71206888 Initial import
thib
parents:
diff changeset
125 for (i=0; i<100; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
126 call_vec[i] = read_little_endian_int(data + 0x34 + i * 4);
223b71206888 Initial import
thib
parents:
diff changeset
127 }
223b71206888 Initial import
thib
parents:
diff changeset
128 }
223b71206888 Initial import
thib
parents:
diff changeset
129 ret_data = new char[info->Size() - offset + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
130 memcpy(ret_data, data+offset, info->Size()-offset);
223b71206888 Initial import
thib
parents:
diff changeset
131 memset(ret_data+info->Size()-offset, 0, 1024);
223b71206888 Initial import
thib
parents:
diff changeset
132 end = ret_data + info->Size() - offset;
223b71206888 Initial import
thib
parents:
diff changeset
133 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
134 return ret_data;
223b71206888 Initial import
thib
parents:
diff changeset
135
223b71206888 Initial import
thib
parents:
diff changeset
136 err:
223b71206888 Initial import
thib
parents:
diff changeset
137 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
138 fprintf(stderr,"Cannot open scenario number %d\n",new_scn_number);
223b71206888 Initial import
thib
parents:
diff changeset
139 throw std::invalid_argument("Scn2k::OpenScript");
223b71206888 Initial import
thib
parents:
diff changeset
140
223b71206888 Initial import
thib
parents:
diff changeset
141 return false;
223b71206888 Initial import
thib
parents:
diff changeset
142 }
223b71206888 Initial import
thib
parents:
diff changeset
143 bool Scn2k::ChangeScript(int new_scn_number, int call_no) {
223b71206888 Initial import
thib
parents:
diff changeset
144 int old_scn_number = scn_number;
223b71206888 Initial import
thib
parents:
diff changeset
145 int old_scn_pt = script - script_start;
223b71206888 Initial import
thib
parents:
diff changeset
146 int scn_pt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
147
223b71206888 Initial import
thib
parents:
diff changeset
148 if (script_start) delete[] script_start;
223b71206888 Initial import
thib
parents:
diff changeset
149 script_start = 0;
223b71206888 Initial import
thib
parents:
diff changeset
150 script = 0;
223b71206888 Initial import
thib
parents:
diff changeset
151 script_end = 0;
223b71206888 Initial import
thib
parents:
diff changeset
152
223b71206888 Initial import
thib
parents:
diff changeset
153 int call_vec[100];
223b71206888 Initial import
thib
parents:
diff changeset
154
223b71206888 Initial import
thib
parents:
diff changeset
155 try {
223b71206888 Initial import
thib
parents:
diff changeset
156 script_start = OpenScript(new_scn_number, script_end, call_vec, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
157 } catch(...) {
223b71206888 Initial import
thib
parents:
diff changeset
158 fprintf(stderr,"\tFrom script %d pt %d\n",old_scn_number, old_scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
159 throw;
223b71206888 Initial import
thib
parents:
diff changeset
160 }
223b71206888 Initial import
thib
parents:
diff changeset
161 if (call_no > 0 && call_no < 100) {
223b71206888 Initial import
thib
parents:
diff changeset
162 scn_pt = call_vec[call_no];
223b71206888 Initial import
thib
parents:
diff changeset
163 if (scn_pt == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
164 fprintf(stderr,"Invalid subroutine number: scn %d sub %d\n",new_scn_number, call_no);
223b71206888 Initial import
thib
parents:
diff changeset
165 scn_pt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
166 }
223b71206888 Initial import
thib
parents:
diff changeset
167 } else if (call_no < 0) {
223b71206888 Initial import
thib
parents:
diff changeset
168 scn_pt = -call_no; // デバッグ用
223b71206888 Initial import
thib
parents:
diff changeset
169 }
223b71206888 Initial import
thib
parents:
diff changeset
170
223b71206888 Initial import
thib
parents:
diff changeset
171 scn_number = new_scn_number;
223b71206888 Initial import
thib
parents:
diff changeset
172 scn_point = scn_pt;
223b71206888 Initial import
thib
parents:
diff changeset
173 script = script_start + scn_pt;
223b71206888 Initial import
thib
parents:
diff changeset
174 if (script < script_start || script >= script_end)
223b71206888 Initial import
thib
parents:
diff changeset
175 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);
223b71206888 Initial import
thib
parents:
diff changeset
176 return true;
223b71206888 Initial import
thib
parents:
diff changeset
177 }
223b71206888 Initial import
thib
parents:
diff changeset
178 bool Scn2k::ReadCmdAt(Cmd& cmd, int scn, int pt) {
223b71206888 Initial import
thib
parents:
diff changeset
179 const char* d;
223b71206888 Initial import
thib
parents:
diff changeset
180 if (scn ==scn_number) {
223b71206888 Initial import
thib
parents:
diff changeset
181 d = script_start + pt;
223b71206888 Initial import
thib
parents:
diff changeset
182 if (d < script_start || d >= script_end) {
223b71206888 Initial import
thib
parents:
diff changeset
183 fprintf(stderr,"Cannot read script at current scn %d pt %d\n", scn, pt);
223b71206888 Initial import
thib
parents:
diff changeset
184 return false;
223b71206888 Initial import
thib
parents:
diff changeset
185 }
223b71206888 Initial import
thib
parents:
diff changeset
186 } else {
223b71206888 Initial import
thib
parents:
diff changeset
187 if (backlog_script_scn != scn) {
223b71206888 Initial import
thib
parents:
diff changeset
188 if (backlog_script_start) delete[] backlog_script_start;
223b71206888 Initial import
thib
parents:
diff changeset
189 backlog_script_start = OpenScript(scn, backlog_script_end, 0, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
190 }
223b71206888 Initial import
thib
parents:
diff changeset
191 d = backlog_script_start + pt;
223b71206888 Initial import
thib
parents:
diff changeset
192 if (d < backlog_script_start || d >= backlog_script_end) {
223b71206888 Initial import
thib
parents:
diff changeset
193 fprintf(stderr,"Cannot read script at scn %d pt %d\n", scn, pt);
223b71206888 Initial import
thib
parents:
diff changeset
194 return false;
223b71206888 Initial import
thib
parents:
diff changeset
195 }
223b71206888 Initial import
thib
parents:
diff changeset
196 }
223b71206888 Initial import
thib
parents:
diff changeset
197
223b71206888 Initial import
thib
parents:
diff changeset
198 cmd.GetCmd(flag, d);
223b71206888 Initial import
thib
parents:
diff changeset
199 return true;
223b71206888 Initial import
thib
parents:
diff changeset
200 }
223b71206888 Initial import
thib
parents:
diff changeset
201
223b71206888 Initial import
thib
parents:
diff changeset
202 extern bool save_req, load_req; // キーボードからセーブ・ロードできるように
223b71206888 Initial import
thib
parents:
diff changeset
203 extern bool pressAreq;
223b71206888 Initial import
thib
parents:
diff changeset
204
223b71206888 Initial import
thib
parents:
diff changeset
205 void Scn2k::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
206 SetWakeup(current_time + 10); // 10msに一回シナリオスクリプト解釈
223b71206888 Initial import
thib
parents:
diff changeset
207 if (script == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
208 //VarInfo info; info.type = 6; info.number = 0; // PB の「一回ゲームを開始したことがある」フラグ
223b71206888 Initial import
thib
parents:
diff changeset
209 //flag.Set(info,1);
223b71206888 Initial import
thib
parents:
diff changeset
210 //info.type = 0; info.number = 604; // Princess Bride: クリア対象設定フラグ (聖)
223b71206888 Initial import
thib
parents:
diff changeset
211 //flag.Set(info, 1);
223b71206888 Initial import
thib
parents:
diff changeset
212
223b71206888 Initial import
thib
parents:
diff changeset
213
223b71206888 Initial import
thib
parents:
diff changeset
214 Cmd cmd(flag, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
215 int cnt1;
223b71206888 Initial import
thib
parents:
diff changeset
216 int cnt2 = 1000; // flag / jump / flag 系コマンドの最大実行回数
223b71206888 Initial import
thib
parents:
diff changeset
217
223b71206888 Initial import
thib
parents:
diff changeset
218 /* XXX */
223b71206888 Initial import
thib
parents:
diff changeset
219 if (save_req) {
223b71206888 Initial import
thib
parents:
diff changeset
220 save_req = false;
223b71206888 Initial import
thib
parents:
diff changeset
221 load_req = false;
223b71206888 Initial import
thib
parents:
diff changeset
222 cmd.cmd_type = CMD_SAVEREQ;
223b71206888 Initial import
thib
parents:
diff changeset
223 } else if (load_req) {
223b71206888 Initial import
thib
parents:
diff changeset
224 load_req = false;
223b71206888 Initial import
thib
parents:
diff changeset
225 save_req = false;
223b71206888 Initial import
thib
parents:
diff changeset
226 cmd.cmd_type = CMD_LOADREQ;
223b71206888 Initial import
thib
parents:
diff changeset
227 }
223b71206888 Initial import
thib
parents:
diff changeset
228 if (pressAreq) {
223b71206888 Initial import
thib
parents:
diff changeset
229 pressAreq = false;
223b71206888 Initial import
thib
parents:
diff changeset
230 LoadRollback(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
231 return;
223b71206888 Initial import
thib
parents:
diff changeset
232 }
223b71206888 Initial import
thib
parents:
diff changeset
233
223b71206888 Initial import
thib
parents:
diff changeset
234 /* キー入力などに対応 */
223b71206888 Initial import
thib
parents:
diff changeset
235 // メニュー内以外で shift キーが押されたらスキップ開始
223b71206888 Initial import
thib
parents:
diff changeset
236 if ( (skip_mode&SKIP_IN_MENU) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
237 if (event.pressed(KEY_SHIFT)) {
223b71206888 Initial import
thib
parents:
diff changeset
238 if (skip_mode & SKIP_TEXT) {
223b71206888 Initial import
thib
parents:
diff changeset
239 ; // スキップ中ならなにもしない
223b71206888 Initial import
thib
parents:
diff changeset
240 } else {
223b71206888 Initial import
thib
parents:
diff changeset
241 SetSkipMode(SkipMode(SKIP_TEXT | SKIP_GRP_NOEFFEC | SKIPEND_KEY));
223b71206888 Initial import
thib
parents:
diff changeset
242 }
223b71206888 Initial import
thib
parents:
diff changeset
243 } else {
223b71206888 Initial import
thib
parents:
diff changeset
244 if ( skip_mode & SKIPEND_KEY) {
223b71206888 Initial import
thib
parents:
diff changeset
245 if ( (skip_mode & SKIPEND_TEXT) && (skip_mode & SKIP_TEXT)) {
223b71206888 Initial import
thib
parents:
diff changeset
246 SkipMode new_skip_mode = SkipMode(skip_mode & (~SKIPEND_KEY));
223b71206888 Initial import
thib
parents:
diff changeset
247 if ( (new_skip_mode & SKIP_GRP_FAST) || (new_skip_mode & SKIP_GRP_NODRAW)) {
223b71206888 Initial import
thib
parents:
diff changeset
248 new_skip_mode = SkipMode(skip_mode & (~SKIP_GRP_NOEFFEC));
223b71206888 Initial import
thib
parents:
diff changeset
249 }
223b71206888 Initial import
thib
parents:
diff changeset
250 SetSkipMode(new_skip_mode);
223b71206888 Initial import
thib
parents:
diff changeset
251 } else {
223b71206888 Initial import
thib
parents:
diff changeset
252 SetSkipMode(SKIP_NO);
223b71206888 Initial import
thib
parents:
diff changeset
253 }
223b71206888 Initial import
thib
parents:
diff changeset
254 }
223b71206888 Initial import
thib
parents:
diff changeset
255 }
223b71206888 Initial import
thib
parents:
diff changeset
256 }
223b71206888 Initial import
thib
parents:
diff changeset
257
223b71206888 Initial import
thib
parents:
diff changeset
258 for (cnt1=0; cnt1<20; cnt1++) { // 一回につき 20 個のコマンド実行
223b71206888 Initial import
thib
parents:
diff changeset
259 // 他のコマンド実行中なら終了
223b71206888 Initial import
thib
parents:
diff changeset
260 if ( (cmd.cmd_type == CMD_NOP && SysWait(cmd)) ||
223b71206888 Initial import
thib
parents:
diff changeset
261 // (cmd.cmd_type == CMD_NOP && text_exec.Wait(current_time, cmd)) ||
223b71206888 Initial import
thib
parents:
diff changeset
262 // (cmd.cmd_type == CMD_NOP && grp_exec.Wait(current_time, cmd))) {
223b71206888 Initial import
thib
parents:
diff changeset
263 (cmd.cmd_type == CMD_NOP && grp_exec.Wait(current_time, cmd)) ||
223b71206888 Initial import
thib
parents:
diff changeset
264 (cmd.cmd_type == CMD_NOP && text_exec.Wait(current_time, cmd))) {
223b71206888 Initial import
thib
parents:
diff changeset
265 break;
223b71206888 Initial import
thib
parents:
diff changeset
266 }
223b71206888 Initial import
thib
parents:
diff changeset
267 // コマンド読み込み
223b71206888 Initial import
thib
parents:
diff changeset
268 for (; cnt2 > 0; cnt2--) {
223b71206888 Initial import
thib
parents:
diff changeset
269 scn_point = script - script_start;
223b71206888 Initial import
thib
parents:
diff changeset
270 eprintf("%d / %d :", script - script_start, script_end-script_start);
223b71206888 Initial import
thib
parents:
diff changeset
271 // fprintf(stderr,"%d: %d / %d :",scn_number, script - script_start, script_end-script_start);
223b71206888 Initial import
thib
parents:
diff changeset
272 cmd.GetCmd(flag, script);
223b71206888 Initial import
thib
parents:
diff changeset
273 // if (cmd.cmd_type != CMD_NOP) {
223b71206888 Initial import
thib
parents:
diff changeset
274 if (0) {
223b71206888 Initial import
thib
parents:
diff changeset
275 fprintf(stderr,"%d / %d : 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",
223b71206888 Initial import
thib
parents:
diff changeset
276 scn_point, script_end-script_start,
223b71206888 Initial import
thib
parents:
diff changeset
277 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc);
223b71206888 Initial import
thib
parents:
diff changeset
278 int i; for (i=0; i<cmd.args.size(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
279 if (i == 0) fprintf(stderr,"\t");
223b71206888 Initial import
thib
parents:
diff changeset
280 VarInfo info = cmd.args[i];
223b71206888 Initial import
thib
parents:
diff changeset
281 if (info.type == TYPE_STR || info.type == TYPE_VARSTR)
223b71206888 Initial import
thib
parents:
diff changeset
282 fprintf(stderr,"\"%s\",", cmd.Str(info));
223b71206888 Initial import
thib
parents:
diff changeset
283 else
223b71206888 Initial import
thib
parents:
diff changeset
284 fprintf(stderr,"%d,",info.value);
223b71206888 Initial import
thib
parents:
diff changeset
285 }
223b71206888 Initial import
thib
parents:
diff changeset
286 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
287 }
223b71206888 Initial import
thib
parents:
diff changeset
288 cmd.scn = scn_number;
223b71206888 Initial import
thib
parents:
diff changeset
289 cmd.pos = scn_point;
223b71206888 Initial import
thib
parents:
diff changeset
290 if (cmd.IsError()) break;
223b71206888 Initial import
thib
parents:
diff changeset
291 if (cmd.cmd_type == CMD_NOP) continue;
223b71206888 Initial import
thib
parents:
diff changeset
292 if (cmd.cmd_type == CMD_JMP) {
223b71206888 Initial import
thib
parents:
diff changeset
293 // local jump
223b71206888 Initial import
thib
parents:
diff changeset
294 if (cmd.cmd1 == 0 && cmd.cmd2 == 1 && cmd.cmd3 == 16) {
223b71206888 Initial import
thib
parents:
diff changeset
295 int i;
223b71206888 Initial import
thib
parents:
diff changeset
296 for (i=0; i<cmd.args.size()-1; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
297 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
298 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
299 var.number = i;
223b71206888 Initial import
thib
parents:
diff changeset
300 flag.Set(var, cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
301 }
223b71206888 Initial import
thib
parents:
diff changeset
302 cmd.args[0].value = cmd.args[i].value;
223b71206888 Initial import
thib
parents:
diff changeset
303 }
223b71206888 Initial import
thib
parents:
diff changeset
304 if ( cmd.cmd1 == 0 && cmd.cmd2 == 1 && (cmd.cmd3 == 5 || cmd.cmd3 == 8 || cmd.cmd3 == 16) ) { // local call / simple switch
223b71206888 Initial import
thib
parents:
diff changeset
305 int scn_pt = script - script_start;
223b71206888 Initial import
thib
parents:
diff changeset
306 // fprintf(stderr,"\nlocal call %d:%d from %d\n",scn_number,cmd.args[0].value,scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
307 stack.push_back(StackItem(-1, scn_pt));
223b71206888 Initial import
thib
parents:
diff changeset
308 }
223b71206888 Initial import
thib
parents:
diff changeset
309 if (cmd.cmd1 == 0 && cmd.cmd2 == 1 && cmd.cmd3 == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
310 fprintf(stderr,"*** unsupported: cond 1\n");
223b71206888 Initial import
thib
parents:
diff changeset
311 }
223b71206888 Initial import
thib
parents:
diff changeset
312 script = script_start + cmd.args[0].value;
223b71206888 Initial import
thib
parents:
diff changeset
313 if (script < script_start || script >= script_end) {
223b71206888 Initial import
thib
parents:
diff changeset
314 fprintf(stderr,"scn %d pt %d: Cannot jump to %d; fall back to the top\n",scn_number, cmd.args[0].value);
223b71206888 Initial import
thib
parents:
diff changeset
315 script = script_start;
223b71206888 Initial import
thib
parents:
diff changeset
316 }
223b71206888 Initial import
thib
parents:
diff changeset
317 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
318 continue;
223b71206888 Initial import
thib
parents:
diff changeset
319 }
223b71206888 Initial import
thib
parents:
diff changeset
320 if (flag.Exec(cmd)) continue;
223b71206888 Initial import
thib
parents:
diff changeset
321 break;
223b71206888 Initial import
thib
parents:
diff changeset
322 }
223b71206888 Initial import
thib
parents:
diff changeset
323 if (cmd.IsError()) {
223b71206888 Initial import
thib
parents:
diff changeset
324 fprintf(stderr,"cmd error occured: scn %d pt %d / cur %d",scn_number,scn_point,script-script_start);
223b71206888 Initial import
thib
parents:
diff changeset
325 while(script < script_end) {
223b71206888 Initial import
thib
parents:
diff changeset
326 if (*script == 0x29 && script[1] == 0x0a) {script++;break;}
223b71206888 Initial import
thib
parents:
diff changeset
327 if (*script == 0 && script[1] == 0x0a) {script++;break;}
223b71206888 Initial import
thib
parents:
diff changeset
328 if (*script == 0 && script[1] == 0x23) {script++;break;}
223b71206888 Initial import
thib
parents:
diff changeset
329 script++;
223b71206888 Initial import
thib
parents:
diff changeset
330 fprintf(stderr," -> fall back to %d\n",script-script_start);
223b71206888 Initial import
thib
parents:
diff changeset
331 }
223b71206888 Initial import
thib
parents:
diff changeset
332 const char* dprev = script - 0x60;
223b71206888 Initial import
thib
parents:
diff changeset
333 if (dprev < script_start) dprev = script_start;
223b71206888 Initial import
thib
parents:
diff changeset
334 int ilen = (script-dprev+65)/16;
223b71206888 Initial import
thib
parents:
diff changeset
335 int i; for (i=0; i<ilen; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
336 fprintf(stderr, "%6d: ",dprev-script_start);
223b71206888 Initial import
thib
parents:
diff changeset
337 int j; for (j=0; j<16; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
338 if (dprev >= script_end) break;
223b71206888 Initial import
thib
parents:
diff changeset
339 fprintf(stderr, "%02x ",*(unsigned char*)(dprev));
223b71206888 Initial import
thib
parents:
diff changeset
340 dprev++;
223b71206888 Initial import
thib
parents:
diff changeset
341 }
223b71206888 Initial import
thib
parents:
diff changeset
342 fprintf(stderr, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
343 }
223b71206888 Initial import
thib
parents:
diff changeset
344 break;
223b71206888 Initial import
thib
parents:
diff changeset
345 }
223b71206888 Initial import
thib
parents:
diff changeset
346 if (cmd.cmd_type == CMD_NOP) continue;
223b71206888 Initial import
thib
parents:
diff changeset
347
223b71206888 Initial import
thib
parents:
diff changeset
348 if (cmd.cmd_type == CMD_TEXT && cmd.pos != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
349 set<int>& readflag = text_readflag[scn_number];
223b71206888 Initial import
thib
parents:
diff changeset
350 if (readflag.find(cmd.pos) == readflag.end()) { // 未読テキスト発見
223b71206888 Initial import
thib
parents:
diff changeset
351 readflag.insert(cmd.pos);
223b71206888 Initial import
thib
parents:
diff changeset
352 if (skip_mode & SKIPEND_TEXT) {
223b71206888 Initial import
thib
parents:
diff changeset
353 if (!(skip_mode & SKIPEND_KEY)) SetSkipMode(SKIP_NO);
223b71206888 Initial import
thib
parents:
diff changeset
354 }
223b71206888 Initial import
thib
parents:
diff changeset
355 }
223b71206888 Initial import
thib
parents:
diff changeset
356 }
223b71206888 Initial import
thib
parents:
diff changeset
357 text_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
358 grp_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
359 SysExec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
360 if (cmd.cmd_type == CMD_WAITFRAMEUPDATE) {
223b71206888 Initial import
thib
parents:
diff changeset
361 SetWakeup(Event::Time::FRAME_UPDATE);
223b71206888 Initial import
thib
parents:
diff changeset
362 break;
223b71206888 Initial import
thib
parents:
diff changeset
363 } else if (cmd.cmd_type != CMD_NOP) {
223b71206888 Initial import
thib
parents:
diff changeset
364 #if DEBUG
223b71206888 Initial import
thib
parents:
diff changeset
365 fprintf(stderr,"%d-%d / %d : unsupported command; 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",
223b71206888 Initial import
thib
parents:
diff changeset
366 cmd.scn, script - script_start, script_end-script_start,
223b71206888 Initial import
thib
parents:
diff changeset
367 cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc);
223b71206888 Initial import
thib
parents:
diff changeset
368 int i; for (i=0; i<cmd.args.size(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
369 if (i == 0) fprintf(stderr,"\t");
223b71206888 Initial import
thib
parents:
diff changeset
370 VarInfo info = cmd.args[i];
223b71206888 Initial import
thib
parents:
diff changeset
371 if (info.type == TYPE_STR || info.type == TYPE_VARSTR)
223b71206888 Initial import
thib
parents:
diff changeset
372 fprintf(stderr,"\"%s\",", cmd.Str(info));
223b71206888 Initial import
thib
parents:
diff changeset
373 else
223b71206888 Initial import
thib
parents:
diff changeset
374 fprintf(stderr,"%d,",info.value);
223b71206888 Initial import
thib
parents:
diff changeset
375 }
223b71206888 Initial import
thib
parents:
diff changeset
376 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
377 #endif
223b71206888 Initial import
thib
parents:
diff changeset
378 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
379 }
223b71206888 Initial import
thib
parents:
diff changeset
380 }
223b71206888 Initial import
thib
parents:
diff changeset
381 return;
223b71206888 Initial import
thib
parents:
diff changeset
382 }
223b71206888 Initial import
thib
parents:
diff changeset
383
223b71206888 Initial import
thib
parents:
diff changeset
384 void Scn2k::ShowCursor(void) {
223b71206888 Initial import
thib
parents:
diff changeset
385 HideCursor();
223b71206888 Initial import
thib
parents:
diff changeset
386 char key[1024];
223b71206888 Initial import
thib
parents:
diff changeset
387 sprintf(key, "#MOUSE_CURSOR.%03d.NAME",mouse_type);
223b71206888 Initial import
thib
parents:
diff changeset
388 const char* name = config.GetParaStr(key);
223b71206888 Initial import
thib
parents:
diff changeset
389 if (name == 0 || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR;
223b71206888 Initial import
thib
parents:
diff changeset
390 else {
223b71206888 Initial import
thib
parents:
diff changeset
391 mouse_surface = parent.Root().NewSurface(name, COLOR_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
392 }
223b71206888 Initial import
thib
parents:
diff changeset
393 if (mouse_surface == 0) mouse_surface = DEFAULT_MOUSECURSOR;
223b71206888 Initial import
thib
parents:
diff changeset
394 System::Main::SetCursor(mouse_surface, Rect(8, 8, 8+32, 8+32));
223b71206888 Initial import
thib
parents:
diff changeset
395 }
223b71206888 Initial import
thib
parents:
diff changeset
396
223b71206888 Initial import
thib
parents:
diff changeset
397 void Scn2k::HideCursor(void) {
223b71206888 Initial import
thib
parents:
diff changeset
398 if (mouse_surface) {
223b71206888 Initial import
thib
parents:
diff changeset
399 System::Main::SetCursor(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
400 if (mouse_surface != DEFAULT_MOUSECURSOR)
223b71206888 Initial import
thib
parents:
diff changeset
401 parent.Root().DeleteSurface(mouse_surface);
223b71206888 Initial import
thib
parents:
diff changeset
402 mouse_surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
403 }
223b71206888 Initial import
thib
parents:
diff changeset
404 return;
223b71206888 Initial import
thib
parents:
diff changeset
405 }
223b71206888 Initial import
thib
parents:
diff changeset
406
223b71206888 Initial import
thib
parents:
diff changeset
407 bool Scn2k::SysWait(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
408
223b71206888 Initial import
thib
parents:
diff changeset
409 if (menu) {
223b71206888 Initial import
thib
parents:
diff changeset
410 menu->Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
411 if (menu->status & Scn2kMenu::MENU_DELETE || menu->pimpl == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
412 delete menu;
223b71206888 Initial import
thib
parents:
diff changeset
413 menu = 0;
223b71206888 Initial import
thib
parents:
diff changeset
414 if (! menu_mouseshown) HideCursor();
223b71206888 Initial import
thib
parents:
diff changeset
415 else ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
416 SetSkipMode(SkipMode(skip_mode & (~SKIP_IN_MENU) ));
223b71206888 Initial import
thib
parents:
diff changeset
417 }
223b71206888 Initial import
thib
parents:
diff changeset
418 if (cmd.cmd_type == CMD_NOP) return true;
223b71206888 Initial import
thib
parents:
diff changeset
419 else return false; /* exec command */
223b71206888 Initial import
thib
parents:
diff changeset
420 }
223b71206888 Initial import
thib
parents:
diff changeset
421 return false;
223b71206888 Initial import
thib
parents:
diff changeset
422 }
223b71206888 Initial import
thib
parents:
diff changeset
423
223b71206888 Initial import
thib
parents:
diff changeset
424 void DllCall_LB(Cmd& cmd, Flags& flags);
223b71206888 Initial import
thib
parents:
diff changeset
425 void Scn2k::SysExec(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
426 if (cmd.cmd_type == CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
427 int i;
223b71206888 Initial import
thib
parents:
diff changeset
428 for (i=0; i<cmd.args.size(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
429 if (cmd.args[i].type == TYPE_SYS) {
223b71206888 Initial import
thib
parents:
diff changeset
430 if (cmd.args[i].number == TYPE_SYS_SYS) {
223b71206888 Initial import
thib
parents:
diff changeset
431 flag.SetSys(cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
432 } else if (cmd.args[i].number == TYPE_SYS_SKIPMODE) {
223b71206888 Initial import
thib
parents:
diff changeset
433 SetSkipMode(SkipMode(cmd.args[i].value));
223b71206888 Initial import
thib
parents:
diff changeset
434 }
223b71206888 Initial import
thib
parents:
diff changeset
435 } else if (cmd.args[i].type == TYPE_VARSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
436 flag.SetStr(cmd.args[i].number, cmd.Str(cmd.args[i]));
223b71206888 Initial import
thib
parents:
diff changeset
437 } else {
223b71206888 Initial import
thib
parents:
diff changeset
438 flag.Set(cmd.args[i], cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
439 }
223b71206888 Initial import
thib
parents:
diff changeset
440 }
223b71206888 Initial import
thib
parents:
diff changeset
441 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
442 }
223b71206888 Initial import
thib
parents:
diff changeset
443 if (cmd.cmd_type == CMD_SAVEPOINT || cmd.cmd_type == CMD_ROLLBACKPOINT) {
223b71206888 Initial import
thib
parents:
diff changeset
444 if (text_exec.backlog_item.scn != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
445 text_exec.backlog.push_back(text_exec.backlog_item);
223b71206888 Initial import
thib
parents:
diff changeset
446 text_exec.backlog_item.Clear();
223b71206888 Initial import
thib
parents:
diff changeset
447 }
223b71206888 Initial import
thib
parents:
diff changeset
448 save_scn = scn_number;
223b71206888 Initial import
thib
parents:
diff changeset
449 save_point = scn_point;
223b71206888 Initial import
thib
parents:
diff changeset
450 if (!new_rollback_save.empty()) {
223b71206888 Initial import
thib
parents:
diff changeset
451 rollback_save.push_back(new_rollback_save);
223b71206888 Initial import
thib
parents:
diff changeset
452 new_rollback_save = "";
223b71206888 Initial import
thib
parents:
diff changeset
453 }
223b71206888 Initial import
thib
parents:
diff changeset
454 if (cmd.cmd_type == CMD_ROLLBACKPOINT) SaveRollback();
223b71206888 Initial import
thib
parents:
diff changeset
455 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
456 }
223b71206888 Initial import
thib
parents:
diff changeset
457 if (cmd.cmd_type == CMD_SAVEREQ || cmd.cmd_type == CMD_SAVE) {
223b71206888 Initial import
thib
parents:
diff changeset
458 Save(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
459 return;
223b71206888 Initial import
thib
parents:
diff changeset
460 }
223b71206888 Initial import
thib
parents:
diff changeset
461 if (cmd.cmd_type == CMD_LOADREQ || cmd.cmd_type == CMD_LOAD) {
223b71206888 Initial import
thib
parents:
diff changeset
462 Load(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
463 return;
223b71206888 Initial import
thib
parents:
diff changeset
464 }
223b71206888 Initial import
thib
parents:
diff changeset
465 if (cmd.cmd_type == CMD_BACKLOGREQ || cmd.cmd_type == CMD_BACKLOGREQ_FWD) {
223b71206888 Initial import
thib
parents:
diff changeset
466 if (menu) {
223b71206888 Initial import
thib
parents:
diff changeset
467 fprintf(stderr,"BACKLOG_REQ requested!!!\n");
223b71206888 Initial import
thib
parents:
diff changeset
468 return;
223b71206888 Initial import
thib
parents:
diff changeset
469 }
223b71206888 Initial import
thib
parents:
diff changeset
470 if (cmd.cmd_type == CMD_BACKLOGREQ_FWD) {
223b71206888 Initial import
thib
parents:
diff changeset
471 cmd.clear(); // backlog mode 以外で fwd を押されてもなにもしない
223b71206888 Initial import
thib
parents:
diff changeset
472 return;
223b71206888 Initial import
thib
parents:
diff changeset
473 }
223b71206888 Initial import
thib
parents:
diff changeset
474 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断
223b71206888 Initial import
thib
parents:
diff changeset
475 menu = new Scn2kMenu(Scn2kMenu::MENU_BACKLOG, *this, flag, text_exec, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
476 menu->InitPanel(event, parent);
223b71206888 Initial import
thib
parents:
diff changeset
477 menu->InitTitle(Scn2kSaveTitle(*this));
223b71206888 Initial import
thib
parents:
diff changeset
478 if (mouse_surface) menu_mouseshown = true;
223b71206888 Initial import
thib
parents:
diff changeset
479 else menu_mouseshown = false;
223b71206888 Initial import
thib
parents:
diff changeset
480 ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
481 return;
223b71206888 Initial import
thib
parents:
diff changeset
482 }
223b71206888 Initial import
thib
parents:
diff changeset
483 if (cmd.cmd_type == CMD_MENUREQ) {
223b71206888 Initial import
thib
parents:
diff changeset
484 int scn=0, pt=0;
223b71206888 Initial import
thib
parents:
diff changeset
485 config.GetParam("#CANCELCALL", 2, &scn, &pt);
223b71206888 Initial import
thib
parents:
diff changeset
486 if (scn) {
223b71206888 Initial import
thib
parents:
diff changeset
487 // 右クリックされたら global call を行う
223b71206888 Initial import
thib
parents:
diff changeset
488 cmd.cmd_type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
489 cmd.cmd1 = 0;
223b71206888 Initial import
thib
parents:
diff changeset
490 cmd.cmd2 = 1;
223b71206888 Initial import
thib
parents:
diff changeset
491 cmd.cmd3 = 0x0c;
223b71206888 Initial import
thib
parents:
diff changeset
492 cmd.cmd4 = 1;
223b71206888 Initial import
thib
parents:
diff changeset
493 cmd.args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
494 cmd.args.push_back(VarInfo(SCN_INFO_MENU));
223b71206888 Initial import
thib
parents:
diff changeset
495 cmd.args.push_back(0);
223b71206888 Initial import
thib
parents:
diff changeset
496 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断
223b71206888 Initial import
thib
parents:
diff changeset
497 }
223b71206888 Initial import
thib
parents:
diff changeset
498 }
223b71206888 Initial import
thib
parents:
diff changeset
499 if (cmd.cmd_type == CMD_SAVECMDGRP || cmd.cmd_type == CMD_SAVECMDGRP_START || cmd.cmd_type == CMD_SAVECMDGRP_ONCE || cmd.cmd_type == CMD_SAVECMD_ONCE) {
223b71206888 Initial import
thib
parents:
diff changeset
500 // 画像コマンド等はスタックに保存し、セーブ時に保存できるようにする
223b71206888 Initial import
thib
parents:
diff changeset
501 if (cmd.cmd_type == CMD_SAVECMDGRP_START) {
223b71206888 Initial import
thib
parents:
diff changeset
502 vector<CmdSimplified>::iterator it, cur;
223b71206888 Initial import
thib
parents:
diff changeset
503 cur = cmd_stack.begin();
223b71206888 Initial import
thib
parents:
diff changeset
504 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
505 /* 画像関連コマンド以外を別にする */
223b71206888 Initial import
thib
parents:
diff changeset
506 for (it=cmd_stack.begin(); it != cmd_stack.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
507 if (it->type != CMD_SAVECMDGRP && it->type != CMD_SAVECMDGRP_START && it->type != CMD_SAVECMDGRP_ONCE) {
223b71206888 Initial import
thib
parents:
diff changeset
508 cur->copy(*it, cmd_stack_str);
223b71206888 Initial import
thib
parents:
diff changeset
509 cur++;
223b71206888 Initial import
thib
parents:
diff changeset
510 }
223b71206888 Initial import
thib
parents:
diff changeset
511 }
223b71206888 Initial import
thib
parents:
diff changeset
512 cmd_stack.erase(cur, cmd_stack.end());
223b71206888 Initial import
thib
parents:
diff changeset
513 }
223b71206888 Initial import
thib
parents:
diff changeset
514 if (cmd.cmd_type == CMD_SAVECMD_ONCE || cmd.cmd_type == CMD_SAVECMDGRP_ONCE) { // 同じコマンドがあれば削除する
223b71206888 Initial import
thib
parents:
diff changeset
515 vector<CmdSimplified>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
516 for (it = cmd_stack.end(); it != cmd_stack.begin(); ) {
223b71206888 Initial import
thib
parents:
diff changeset
517 --it;
223b71206888 Initial import
thib
parents:
diff changeset
518 if (it->cmd1 == cmd.cmd1 && it->cmd2 == cmd.cmd2 && it->cmd3 == cmd.cmd3 && it->cmd4 == cmd.cmd4) {
223b71206888 Initial import
thib
parents:
diff changeset
519 cmd_stack.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
520 break;
223b71206888 Initial import
thib
parents:
diff changeset
521 }
223b71206888 Initial import
thib
parents:
diff changeset
522 }
223b71206888 Initial import
thib
parents:
diff changeset
523 }
223b71206888 Initial import
thib
parents:
diff changeset
524 CmdSimplified cmd_item;
223b71206888 Initial import
thib
parents:
diff changeset
525 cmd.write(cmd_item, cmd_stack_str);
223b71206888 Initial import
thib
parents:
diff changeset
526 cmd_stack.push_back(cmd_item);
223b71206888 Initial import
thib
parents:
diff changeset
527 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
528 if (cmd_stack_str > cmd_stack_str_orig + 30000) { // char cmd_stack_str_orig[32768]
223b71206888 Initial import
thib
parents:
diff changeset
529 fprintf(stderr,"Error in Scn2k::SysExec: too long cmdstack (%d): stack string overflow\n",cmd_stack.size());
223b71206888 Initial import
thib
parents:
diff changeset
530 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
531 cmd_stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
532 }
223b71206888 Initial import
thib
parents:
diff changeset
533 }
223b71206888 Initial import
thib
parents:
diff changeset
534 if (cmd.cmd_type != CMD_OTHER) return;
223b71206888 Initial import
thib
parents:
diff changeset
535 if (cmd.cmd1 == 0 && cmd.cmd2 == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
536 if (cmd.cmd3 == 0x0b) { // global jump
6
2c890434e30f Add call_no in global jumps
thib
parents: 0
diff changeset
537 int call_no = 0;
15
38226842bac8 Fixed new_pt in global calls
thib
parents: 12
diff changeset
538 if (cmd.args.size() >= 2) call_no = cmd.args[1].value;
0
223b71206888 Initial import
thib
parents:
diff changeset
539 eprintf("global jump to %d\n",cmd.args[0].value);
6
2c890434e30f Add call_no in global jumps
thib
parents: 0
diff changeset
540 if (! ChangeScript(cmd.args[0].value, call_no)) return; // 読み込めない; abort.
0
223b71206888 Initial import
thib
parents:
diff changeset
541 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
542 } else if (cmd.cmd3 == 0x0c || cmd.cmd3 == 0x12) { // call (0x12 の方は微妙)
223b71206888 Initial import
thib
parents:
diff changeset
543 int new_scn = cmd.args[0].value;
223b71206888 Initial import
thib
parents:
diff changeset
544 int new_pt = 0;
15
38226842bac8 Fixed new_pt in global calls
thib
parents: 12
diff changeset
545 if (cmd.args.size() >= 2) { // subroutine number が付く
0
223b71206888 Initial import
thib
parents:
diff changeset
546 // 引数が付くのもあるらしい
223b71206888 Initial import
thib
parents:
diff changeset
547 new_pt = cmd.args[1].value;
223b71206888 Initial import
thib
parents:
diff changeset
548 }
223b71206888 Initial import
thib
parents:
diff changeset
549 if (new_scn == SCN_INFO_MENU) { // menu call
223b71206888 Initial import
thib
parents:
diff changeset
550 config.GetParam("#CANCELCALL", 2, &new_scn, &new_pt);
223b71206888 Initial import
thib
parents:
diff changeset
551 stack.push_back(StackItem(SCN_INFO, SCN_INFO_MENU)); // menu call を示す特殊な記号
223b71206888 Initial import
thib
parents:
diff changeset
552 } else {
223b71206888 Initial import
thib
parents:
diff changeset
553 int i;
223b71206888 Initial import
thib
parents:
diff changeset
554 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
555 // ローカル変数を伴う subroutine call
223b71206888 Initial import
thib
parents:
diff changeset
556 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
557 var.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
558 int saved_vars = 0;
223b71206888 Initial import
thib
parents:
diff changeset
559 for (i=0; i<40; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
560 int val = flag.Get(var.type, i);
223b71206888 Initial import
thib
parents:
diff changeset
561 if (val != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
562 stack.push_back(StackItem(SCN_INFO_LOCALS + i, val));
223b71206888 Initial import
thib
parents:
diff changeset
563 saved_vars++;
223b71206888 Initial import
thib
parents:
diff changeset
564 }
223b71206888 Initial import
thib
parents:
diff changeset
565 }
223b71206888 Initial import
thib
parents:
diff changeset
566 var.type = TYPE_VARLOCSTR;
223b71206888 Initial import
thib
parents:
diff changeset
567 for (i=0; i<3; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
568 string s = flag.Str(var.type, i);
223b71206888 Initial import
thib
parents:
diff changeset
569 if (s.size()) {
223b71206888 Initial import
thib
parents:
diff changeset
570 int sp = stack_strbuffer.size();
223b71206888 Initial import
thib
parents:
diff changeset
571 stack.push_back(StackItem(SCN_INFO_LOCALSTR+i, sp));
223b71206888 Initial import
thib
parents:
diff changeset
572 stack_strbuffer.push_back(s);
223b71206888 Initial import
thib
parents:
diff changeset
573 saved_vars++;
223b71206888 Initial import
thib
parents:
diff changeset
574 }
223b71206888 Initial import
thib
parents:
diff changeset
575 }
223b71206888 Initial import
thib
parents:
diff changeset
576 stack.push_back(StackItem(SCN_INFO, SCN_INFO_LOCALS + saved_vars));
223b71206888 Initial import
thib
parents:
diff changeset
577
223b71206888 Initial import
thib
parents:
diff changeset
578 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
579 var.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
580 // 特殊な subroutine call なので、余計な情報を引数に渡す
223b71206888 Initial import
thib
parents:
diff changeset
581 for (i=2; i<cmd.args.size(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
582 flag.Set(var, cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
583 // fprintf(stderr,"<%d:%d>=%d;",var.type,var.number,cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
584 var.number++;
223b71206888 Initial import
thib
parents:
diff changeset
585 }
223b71206888 Initial import
thib
parents:
diff changeset
586 // fprintf(stderr,"%d; ",stack.size());
223b71206888 Initial import
thib
parents:
diff changeset
587 }
223b71206888 Initial import
thib
parents:
diff changeset
588 int scn_pt = script - script_start;
223b71206888 Initial import
thib
parents:
diff changeset
589 stack.push_back(StackItem(scn_number, scn_pt));
223b71206888 Initial import
thib
parents:
diff changeset
590 // fprintf(stderr,"\nglobal call %d:%d from %d:%d\n",new_scn,new_pt,scn_number,scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
591 eprintf("global call to %d, %d\n",new_scn, new_pt);
223b71206888 Initial import
thib
parents:
diff changeset
592 if (! ChangeScript(new_scn, new_pt)) return; // 読み込めない; abort.
223b71206888 Initial import
thib
parents:
diff changeset
593 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
594 } else if (cmd.cmd3 == 0x65) { // 文字列の返り値をセットする
223b71206888 Initial import
thib
parents:
diff changeset
595 int arg1 = cmd.args[0].value;
223b71206888 Initial import
thib
parents:
diff changeset
596 string s = cmd.Str(cmd.args[1]);
223b71206888 Initial import
thib
parents:
diff changeset
597 int sp = stack_strbuffer.size();
223b71206888 Initial import
thib
parents:
diff changeset
598 stack.push_back(StackItem(SCN_INFO_RETSTR+arg1, sp));
223b71206888 Initial import
thib
parents:
diff changeset
599 stack_strbuffer.push_back(s);
223b71206888 Initial import
thib
parents:
diff changeset
600 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
601 } else if (cmd.cmd3 == 0x0d || cmd.cmd3 == 0x0a || cmd.cmd3 == 0x11 || cmd.cmd3 == 0x13) { // return (0a: local return) (0x13はよくわからない)
223b71206888 Initial import
thib
parents:
diff changeset
602 // fprintf(stderr,"global return : stack size %d\n",stack.size());
223b71206888 Initial import
thib
parents:
diff changeset
603 if (stack.empty()) {
223b71206888 Initial import
thib
parents:
diff changeset
604 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
605 return; // スタックがおかしい:abort
223b71206888 Initial import
thib
parents:
diff changeset
606 }
223b71206888 Initial import
thib
parents:
diff changeset
607 map<int, string> retstr;
223b71206888 Initial import
thib
parents:
diff changeset
608 while( (!stack.empty()) && stack.back().scn_number >= SCN_INFO_RETSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
609 int ret_num = stack.back().scn_number - SCN_INFO_RETSTR;
223b71206888 Initial import
thib
parents:
diff changeset
610 // fprintf(stderr,"\nRetStr;");
223b71206888 Initial import
thib
parents:
diff changeset
611 string str = stack_strbuffer.back();
223b71206888 Initial import
thib
parents:
diff changeset
612 stack_strbuffer.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
613 retstr[ret_num] = str;
223b71206888 Initial import
thib
parents:
diff changeset
614 stack.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
615 }
223b71206888 Initial import
thib
parents:
diff changeset
616 if (stack.empty()) {
223b71206888 Initial import
thib
parents:
diff changeset
617 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
618 return; // スタックがおかしい:abort
223b71206888 Initial import
thib
parents:
diff changeset
619 }
223b71206888 Initial import
thib
parents:
diff changeset
620 StackItem s = stack.back();
223b71206888 Initial import
thib
parents:
diff changeset
621 stack.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
622 bool localvar_init = false;
223b71206888 Initial import
thib
parents:
diff changeset
623 while( (!stack.empty()) && stack.back().scn_number == SCN_INFO) {
223b71206888 Initial import
thib
parents:
diff changeset
624 int mode = stack.back().scn_pt;
223b71206888 Initial import
thib
parents:
diff changeset
625 stack.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
626 if (mode == SCN_INFO_MENU) {
223b71206888 Initial import
thib
parents:
diff changeset
627 // fprintf(stderr,"\nInfo Menu;");
223b71206888 Initial import
thib
parents:
diff changeset
628 // menu モード終了
223b71206888 Initial import
thib
parents:
diff changeset
629 SetSkipMode(SkipMode(skip_mode & (~SKIP_IN_MENU) ));
223b71206888 Initial import
thib
parents:
diff changeset
630 } else if (mode >= SCN_INFO_LOCALS && mode <= SCN_INFO_LOCALS+50) {
223b71206888 Initial import
thib
parents:
diff changeset
631 // fprintf(stderr,"\nInfo Local;");
223b71206888 Initial import
thib
parents:
diff changeset
632 int i;
223b71206888 Initial import
thib
parents:
diff changeset
633 // ローカル変数を元に戻す
223b71206888 Initial import
thib
parents:
diff changeset
634 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
635 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
636 var.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
637 for (i=0; i<40; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
638 var.number = i;
223b71206888 Initial import
thib
parents:
diff changeset
639 flag.Set(var, 0);
223b71206888 Initial import
thib
parents:
diff changeset
640 }
223b71206888 Initial import
thib
parents:
diff changeset
641 var.type = TYPE_VARLOCSTR;
223b71206888 Initial import
thib
parents:
diff changeset
642 for (i=0; i<3; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
643 var.number = i;
223b71206888 Initial import
thib
parents:
diff changeset
644 flag.SetStr(var, "");
223b71206888 Initial import
thib
parents:
diff changeset
645 }
223b71206888 Initial import
thib
parents:
diff changeset
646 int args = mode - SCN_INFO_LOCALS;
223b71206888 Initial import
thib
parents:
diff changeset
647 // fprintf(stderr," args = %d; ",args);
223b71206888 Initial import
thib
parents:
diff changeset
648 for (i=0; i<args; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
649 if (stack.empty() || stack.back().scn_number < SCN_INFO) {
223b71206888 Initial import
thib
parents:
diff changeset
650 fprintf(stderr,"Fatal : Invalid stack found in preserved local variables!\n");
223b71206888 Initial import
thib
parents:
diff changeset
651 break;
223b71206888 Initial import
thib
parents:
diff changeset
652 }
223b71206888 Initial import
thib
parents:
diff changeset
653 var.number = stack.back().scn_number;
223b71206888 Initial import
thib
parents:
diff changeset
654 // fprintf(stderr,"%d:%d; ",stack.back().scn_number,stack.back().scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
655 if (var.number >= SCN_INFO_LOCALS && var.number < SCN_INFO_LOCALSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
656 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
657 var.number -= SCN_INFO_LOCALS;
223b71206888 Initial import
thib
parents:
diff changeset
658 flag.Set(var, stack.back().scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
659 } else if (var.number >= SCN_INFO_LOCALSTR && var.number < SCN_INFO_RETSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
660 var.type = TYPE_VARLOCSTR;
223b71206888 Initial import
thib
parents:
diff changeset
661 var.number -= SCN_INFO_LOCALSTR;
223b71206888 Initial import
thib
parents:
diff changeset
662 flag.SetStr(var, stack_strbuffer.back());
223b71206888 Initial import
thib
parents:
diff changeset
663 stack_strbuffer.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
664 }
223b71206888 Initial import
thib
parents:
diff changeset
665 stack.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
666 }
223b71206888 Initial import
thib
parents:
diff changeset
667 }
223b71206888 Initial import
thib
parents:
diff changeset
668 // fprintf(stderr,"stack size %d string size %d\n",stack.size(),stack_strbuffer.size());
223b71206888 Initial import
thib
parents:
diff changeset
669 }
223b71206888 Initial import
thib
parents:
diff changeset
670 if (cmd.cmd3 == 0x11 || cmd.cmd3 == 0x13) {
223b71206888 Initial import
thib
parents:
diff changeset
671 // fprintf(stderr,"\nSet RetLocal;");
223b71206888 Initial import
thib
parents:
diff changeset
672 // 返り値をセットする
223b71206888 Initial import
thib
parents:
diff changeset
673 map<int,string>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
674 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
675 var.type = TYPE_VARLOCSTR;
223b71206888 Initial import
thib
parents:
diff changeset
676 for (it=retstr.begin(); it!=retstr.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
677 var.number = it->first;
223b71206888 Initial import
thib
parents:
diff changeset
678 flag.SetStr(var, it->second);
223b71206888 Initial import
thib
parents:
diff changeset
679 }
223b71206888 Initial import
thib
parents:
diff changeset
680 var.type = 11;
223b71206888 Initial import
thib
parents:
diff changeset
681 // fprintf(stderr,"return : cmd.cmd3 == 0x11; size %d\n",cmd.args.size());
223b71206888 Initial import
thib
parents:
diff changeset
682 if (cmd.args.size() == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
683 // fprintf(stderr,"return value %d\n",cmd.args[0].value);
223b71206888 Initial import
thib
parents:
diff changeset
684 flag.SetSys(cmd.args[0].value);
223b71206888 Initial import
thib
parents:
diff changeset
685 } else {
223b71206888 Initial import
thib
parents:
diff changeset
686 int i;for (i=0; i<cmd.args.size(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
687 var.number = i;
223b71206888 Initial import
thib
parents:
diff changeset
688 flag.Set(var, cmd.args[i].value);
223b71206888 Initial import
thib
parents:
diff changeset
689 }
223b71206888 Initial import
thib
parents:
diff changeset
690 }
223b71206888 Initial import
thib
parents:
diff changeset
691 }
223b71206888 Initial import
thib
parents:
diff changeset
692 // fprintf(stderr,"global return : return to %d:%d\n",s.scn_number,s.scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
693 // fprintf(stderr,"\nglobal return %d:%d from %d:%d\n",s.scn_number,s.scn_pt,scn_number, script - script_start);
223b71206888 Initial import
thib
parents:
diff changeset
694 if (s.scn_number != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
695 if (! ChangeScript(s.scn_number, 0)) return; // 読み込めない; abort.
223b71206888 Initial import
thib
parents:
diff changeset
696 }
223b71206888 Initial import
thib
parents:
diff changeset
697 script = script_start + s.scn_pt;
223b71206888 Initial import
thib
parents:
diff changeset
698 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
699 }
223b71206888 Initial import
thib
parents:
diff changeset
700 } else if (cmd.cmd1 == 2 && cmd.cmd2 == 1 && cmd.cmd3 == 12) { // DLL Call
223b71206888 Initial import
thib
parents:
diff changeset
701 const char* regname = config.GetParaStr("#REGNAME");
223b71206888 Initial import
thib
parents:
diff changeset
702 const char key_lb[] = "KEY\\LittleBusters";
223b71206888 Initial import
thib
parents:
diff changeset
703 if (strcmp(regname, key_lb) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
704 DllCall_LB(cmd, flag);
223b71206888 Initial import
thib
parents:
diff changeset
705 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
706 }
223b71206888 Initial import
thib
parents:
diff changeset
707 } else if (cmd.cmd1 == 0 && cmd.cmd2 == 0x04) { // メニューモード
223b71206888 Initial import
thib
parents:
diff changeset
708 if (cmd.cmd3 == 300 || cmd.cmd3 == 301 || cmd.cmd3 == 302) {
223b71206888 Initial import
thib
parents:
diff changeset
709 // メニューからのreturn
223b71206888 Initial import
thib
parents:
diff changeset
710 cmd.cmd2 = 1;
223b71206888 Initial import
thib
parents:
diff changeset
711 cmd.cmd3 = 0x0d;
223b71206888 Initial import
thib
parents:
diff changeset
712 SysExec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
713 }
223b71206888 Initial import
thib
parents:
diff changeset
714 } else if (cmd.cmd1 == 1 && cmd.cmd2 == 0x04) {
223b71206888 Initial import
thib
parents:
diff changeset
715 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { // タイトル名設定
223b71206888 Initial import
thib
parents:
diff changeset
716 const char* name = cmd.Str(cmd.args[0]);
223b71206888 Initial import
thib
parents:
diff changeset
717 if (name == 0) name = "";
223b71206888 Initial import
thib
parents:
diff changeset
718 window_title = name;
223b71206888 Initial import
thib
parents:
diff changeset
719 const char* config_name = config.GetParaStr("#CAPTION");
223b71206888 Initial import
thib
parents:
diff changeset
720 if (config_name == 0) config_name = "";
223b71206888 Initial import
thib
parents:
diff changeset
721 string setname = kconv(string(config_name) + " " + window_title);
223b71206888 Initial import
thib
parents:
diff changeset
722 parent.Root().SetWindowCaption(setname.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
723 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
724 } else if (cmd.cmd3 == 0x82 && cmd.cmd4 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
725 /* cmd.cmd3 == 0x82 : マウスの press 状態クリアかも */
223b71206888 Initial import
thib
parents:
diff changeset
726 event.presscount(MOUSE_LEFT);
223b71206888 Initial import
thib
parents:
diff changeset
727 event.presscount(MOUSE_RIGHT);
223b71206888 Initial import
thib
parents:
diff changeset
728 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
729 } else if (cmd.cmd3 == 0x85 && cmd.cmd4 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
730 int x,y,left,right;
223b71206888 Initial import
thib
parents:
diff changeset
731 event.MousePos(x,y);
223b71206888 Initial import
thib
parents:
diff changeset
732 if (event.presscount(MOUSE_LEFT)) left = 2;
223b71206888 Initial import
thib
parents:
diff changeset
733 else if (event.pressed(MOUSE_LEFT)) left = 1;
223b71206888 Initial import
thib
parents:
diff changeset
734 else left = 0;
223b71206888 Initial import
thib
parents:
diff changeset
735
223b71206888 Initial import
thib
parents:
diff changeset
736 if (event.presscount(MOUSE_RIGHT)) right = 2;
223b71206888 Initial import
thib
parents:
diff changeset
737 else if (event.pressed(MOUSE_RIGHT)) right = 1;
223b71206888 Initial import
thib
parents:
diff changeset
738 else right = 0;
223b71206888 Initial import
thib
parents:
diff changeset
739
223b71206888 Initial import
thib
parents:
diff changeset
740 // eprintf("mouse pos\n");
223b71206888 Initial import
thib
parents:
diff changeset
741 flag.Set(cmd.args[0], x);
223b71206888 Initial import
thib
parents:
diff changeset
742 flag.Set(cmd.args[1], y);
223b71206888 Initial import
thib
parents:
diff changeset
743 flag.Set(cmd.args[2], left);
223b71206888 Initial import
thib
parents:
diff changeset
744 flag.Set(cmd.args[3], right);
223b71206888 Initial import
thib
parents:
diff changeset
745 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
746 } else if (cmd.cmd3 == 0x15e || cmd.cmd3 == 0x161 || cmd.cmd3 == 0x162 || cmd.cmd3 == 0x14c || cmd.cmd3 == 0x7d1) {
223b71206888 Initial import
thib
parents:
diff changeset
747 /* 15e, 161, 162, 14c, 7d1 : なんらかのシステム情報を返す(skip modeなど?) */
223b71206888 Initial import
thib
parents:
diff changeset
748 /* 7d1: == 1 || 14c: == 1 || (15e==1&&161==1&&162==0) || (press_val == 2) : スキップ中? タイトル画面のアニメーション終了 */
223b71206888 Initial import
thib
parents:
diff changeset
749 flag.SetSys(0);
223b71206888 Initial import
thib
parents:
diff changeset
750 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
751 } else if (cmd.cmd3 == 0x4b0) { // 終了
223b71206888 Initial import
thib
parents:
diff changeset
752 System::Main::Quit();
223b71206888 Initial import
thib
parents:
diff changeset
753 script = 0; script_start = 0; script_end = 0;
223b71206888 Initial import
thib
parents:
diff changeset
754 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
755 cmd.cmd_type = CMD_WAITFRAMEUPDATE;
223b71206888 Initial import
thib
parents:
diff changeset
756 } else if (cmd.cmd3 == 0x4b4 || cmd.cmd3 == 0x4b5) { // 選択肢巻き戻し
223b71206888 Initial import
thib
parents:
diff changeset
757 LoadRollback(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
758 } else if (cmd.cmd3 == 0x58d) {
223b71206888 Initial import
thib
parents:
diff changeset
759 // 前にロード|セーブされた番号を返す。
16
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
760 int lastsave;
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
761 config.GetParam("#LASTSAVE", 1, &lastsave);
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
762 flag.SetSys(lastsave-1);
0
223b71206888 Initial import
thib
parents:
diff changeset
763 } else if (cmd.cmd3 == 0x585) {
223b71206888 Initial import
thib
parents:
diff changeset
764 // 第一引数の記録された日付、タイトルなどが返される
223b71206888 Initial import
thib
parents:
diff changeset
765 // データがないなら sys に 0が、あるなら 1 が返る
223b71206888 Initial import
thib
parents:
diff changeset
766 int y,m,d,wd,h,min,s,ms;
223b71206888 Initial import
thib
parents:
diff changeset
767 string title;
223b71206888 Initial import
thib
parents:
diff changeset
768 fprintf(stderr,"StatSave %d:",cmd.args[0].value+1);
223b71206888 Initial import
thib
parents:
diff changeset
769 if (StatSaveFile(cmd.args[0].value+1,y,m,d,wd,h,min,s,ms,title) == true) {
223b71206888 Initial import
thib
parents:
diff changeset
770 flag.Set(cmd.args[1], y);
223b71206888 Initial import
thib
parents:
diff changeset
771 flag.Set(cmd.args[2], m);
223b71206888 Initial import
thib
parents:
diff changeset
772 flag.Set(cmd.args[3], d);
223b71206888 Initial import
thib
parents:
diff changeset
773 flag.Set(cmd.args[4], wd);
223b71206888 Initial import
thib
parents:
diff changeset
774 flag.Set(cmd.args[5], h);
223b71206888 Initial import
thib
parents:
diff changeset
775 flag.Set(cmd.args[6], min);
223b71206888 Initial import
thib
parents:
diff changeset
776 flag.Set(cmd.args[7], s);
223b71206888 Initial import
thib
parents:
diff changeset
777 flag.Set(cmd.args[8], ms);
223b71206888 Initial import
thib
parents:
diff changeset
778 if (cmd.args[9].type == TYPE_VARSTR) {
12
2e6a92ed913b Fixes savegames names
thib
parents: 8
diff changeset
779 flag.SetStr(cmd.args[9], kconv_rev(title));
0
223b71206888 Initial import
thib
parents:
diff changeset
780 }
223b71206888 Initial import
thib
parents:
diff changeset
781 flag.SetSys(1);
223b71206888 Initial import
thib
parents:
diff changeset
782 } else {
223b71206888 Initial import
thib
parents:
diff changeset
783 flag.SetSys(0);
223b71206888 Initial import
thib
parents:
diff changeset
784 }
223b71206888 Initial import
thib
parents:
diff changeset
785 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
786 } else if (cmd.cmd3 == 0xc23) { // save
223b71206888 Initial import
thib
parents:
diff changeset
787 Save(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
788 } else if (cmd.cmd3 == 0xc25) { // load
223b71206888 Initial import
thib
parents:
diff changeset
789 Load(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
790 } else if (cmd.cmd3 == 0x4b1 || cmd.cmd3 == 0x4b3) { // menu へ戻る (4b3: バッドエンド)
223b71206888 Initial import
thib
parents:
diff changeset
791 int scn_start;
223b71206888 Initial import
thib
parents:
diff changeset
792 if (config.GetParam("#SEEN_MENU", 1, &scn_start) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
793 ChangeScript(scn_start, 0);
223b71206888 Initial import
thib
parents:
diff changeset
794 save_scn = 0;
223b71206888 Initial import
thib
parents:
diff changeset
795 save_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
796 window_title = "";
223b71206888 Initial import
thib
parents:
diff changeset
797 const char* window_title_config = config.GetParaStr("#CAPTION");
223b71206888 Initial import
thib
parents:
diff changeset
798 if (window_title_config) window_title = window_title_config;
223b71206888 Initial import
thib
parents:
diff changeset
799 parent.Root().SetWindowCaption(kconv(window_title).c_str());
223b71206888 Initial import
thib
parents:
diff changeset
800 stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
801 cmd_stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
802 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
803 flag.Load("");
223b71206888 Initial import
thib
parents:
diff changeset
804 text_exec.Load("");
223b71206888 Initial import
thib
parents:
diff changeset
805 grp_exec.Load("");
223b71206888 Initial import
thib
parents:
diff changeset
806 SetSkipMode(SKIP_NO);
223b71206888 Initial import
thib
parents:
diff changeset
807 }
223b71206888 Initial import
thib
parents:
diff changeset
808 } else if (cmd.cmd3 == 0xcc) {
223b71206888 Initial import
thib
parents:
diff changeset
809 eprintf("show mouse cursor\n");
223b71206888 Initial import
thib
parents:
diff changeset
810 ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
811 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
812 } else if (cmd.cmd3 == 0xcd) {
223b71206888 Initial import
thib
parents:
diff changeset
813 eprintf("hide mouse cursor\n");
223b71206888 Initial import
thib
parents:
diff changeset
814 HideCursor();
223b71206888 Initial import
thib
parents:
diff changeset
815 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
816 } else if (cmd.cmd3 == 0xcf) {
223b71206888 Initial import
thib
parents:
diff changeset
817 mouse_type = cmd.args[0].value;
223b71206888 Initial import
thib
parents:
diff changeset
818 eprintf("change mouse cursor : %d\n", mouse_type);
223b71206888 Initial import
thib
parents:
diff changeset
819 if (mouse_surface) ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
820 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
821 }
223b71206888 Initial import
thib
parents:
diff changeset
822 }
223b71206888 Initial import
thib
parents:
diff changeset
823
223b71206888 Initial import
thib
parents:
diff changeset
824 }
223b71206888 Initial import
thib
parents:
diff changeset
825
223b71206888 Initial import
thib
parents:
diff changeset
826 #include<sys/types.h>
223b71206888 Initial import
thib
parents:
diff changeset
827 #include<sys/stat.h>
223b71206888 Initial import
thib
parents:
diff changeset
828 #include<errno.h>
223b71206888 Initial import
thib
parents:
diff changeset
829 #include<unistd.h>
223b71206888 Initial import
thib
parents:
diff changeset
830
223b71206888 Initial import
thib
parents:
diff changeset
831 // セーブファイルの名前をつくる
223b71206888 Initial import
thib
parents:
diff changeset
832 string Scn2k::MakeSaveFile(void) const {
223b71206888 Initial import
thib
parents:
diff changeset
833 struct stat sstatus;
223b71206888 Initial import
thib
parents:
diff changeset
834 string dir = "~/.xkanon";
223b71206888 Initial import
thib
parents:
diff changeset
835
223b71206888 Initial import
thib
parents:
diff changeset
836 if (dir.c_str()[0] == '~' && dir.c_str()[1] == '/') {
223b71206888 Initial import
thib
parents:
diff changeset
837 char* home = getenv("HOME");
223b71206888 Initial import
thib
parents:
diff changeset
838 if (home != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
839 string new_dir = string(home) + (dir.c_str()+1);
223b71206888 Initial import
thib
parents:
diff changeset
840 dir = new_dir;
223b71206888 Initial import
thib
parents:
diff changeset
841 }
223b71206888 Initial import
thib
parents:
diff changeset
842 }
223b71206888 Initial import
thib
parents:
diff changeset
843 // savepathにファイル名が入っていれば、それをセーブファイルとして使う
223b71206888 Initial import
thib
parents:
diff changeset
844 if (stat(dir.c_str(), &sstatus) == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
845 if (errno != ENOENT) {
223b71206888 Initial import
thib
parents:
diff changeset
846 fprintf(stderr,"Cannot open save file; dir %s is not directory\n",dir.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
847 return "";
223b71206888 Initial import
thib
parents:
diff changeset
848 }
223b71206888 Initial import
thib
parents:
diff changeset
849 if (mkdir(dir.c_str(), S_IRWXU) != 0 && errno != EEXIST) {
223b71206888 Initial import
thib
parents:
diff changeset
850 fprintf(stderr, "Cannot create directory %s ; Please create manually!!\n",dir.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
851 }
223b71206888 Initial import
thib
parents:
diff changeset
852 } else {
223b71206888 Initial import
thib
parents:
diff changeset
853 if ( (sstatus.st_mode & S_IFMT) == S_IFREG) {
223b71206888 Initial import
thib
parents:
diff changeset
854 return dir;
223b71206888 Initial import
thib
parents:
diff changeset
855 }
223b71206888 Initial import
thib
parents:
diff changeset
856 }
223b71206888 Initial import
thib
parents:
diff changeset
857 // ファイル名を作る
223b71206888 Initial import
thib
parents:
diff changeset
858 const char* regname = config.GetParaStr("#REGNAME");
223b71206888 Initial import
thib
parents:
diff changeset
859
223b71206888 Initial import
thib
parents:
diff changeset
860 char* fname = new char[strlen(regname)+1];
223b71206888 Initial import
thib
parents:
diff changeset
861 /* レジストリ名をファイル名として有効なものにする */
223b71206888 Initial import
thib
parents:
diff changeset
862 int i; for (i=0; regname[i]!=0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
863 char c = regname[i];
223b71206888 Initial import
thib
parents:
diff changeset
864 if (c == '\\' || c == '/' || c == ':' || c <= 0x20) c = '_';
223b71206888 Initial import
thib
parents:
diff changeset
865 fname[i] = tolower(c);
223b71206888 Initial import
thib
parents:
diff changeset
866 }
223b71206888 Initial import
thib
parents:
diff changeset
867 fname[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
868 dir += "/save.";
223b71206888 Initial import
thib
parents:
diff changeset
869 dir += fname;
8
55b577e5f5b5 Some memory leaks fixed
thib
parents: 6
diff changeset
870 delete[] fname;
0
223b71206888 Initial import
thib
parents:
diff changeset
871 return dir;
223b71206888 Initial import
thib
parents:
diff changeset
872 }
223b71206888 Initial import
thib
parents:
diff changeset
873 // セーブファイルの名前をつくる
223b71206888 Initial import
thib
parents:
diff changeset
874 string Scn2kSaveTitle::operator() (int number) const {
223b71206888 Initial import
thib
parents:
diff changeset
875 int y,m,d,wd,h,min,sec,msec;
223b71206888 Initial import
thib
parents:
diff changeset
876 string title;
223b71206888 Initial import
thib
parents:
diff changeset
877 if (! impl.StatSaveFile(number, y,m,d,wd,h,min,sec,msec,title)) {
223b71206888 Initial import
thib
parents:
diff changeset
878 return "";
223b71206888 Initial import
thib
parents:
diff changeset
879 } else {
223b71206888 Initial import
thib
parents:
diff changeset
880 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
881 sprintf(buf, "%2d/%2d %2d:%2d ",m,d,h,min);
223b71206888 Initial import
thib
parents:
diff changeset
882 return string(buf) + title;
223b71206888 Initial import
thib
parents:
diff changeset
883 }
223b71206888 Initial import
thib
parents:
diff changeset
884 };
223b71206888 Initial import
thib
parents:
diff changeset
885
223b71206888 Initial import
thib
parents:
diff changeset
886 void Scn2k::SaveSys(void) {
223b71206888 Initial import
thib
parents:
diff changeset
887 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
888 string save;
223b71206888 Initial import
thib
parents:
diff changeset
889 string path = MakeSaveFile();
223b71206888 Initial import
thib
parents:
diff changeset
890
223b71206888 Initial import
thib
parents:
diff changeset
891 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
892 string save_config;
223b71206888 Initial import
thib
parents:
diff changeset
893 config.DiffOriginal(save_config);
223b71206888 Initial import
thib
parents:
diff changeset
894 save += "CONFIG=";
223b71206888 Initial import
thib
parents:
diff changeset
895 save += save_config;
223b71206888 Initial import
thib
parents:
diff changeset
896 save += "\n";
223b71206888 Initial import
thib
parents:
diff changeset
897 string save_flag; flag.SaveSys(save_flag);
223b71206888 Initial import
thib
parents:
diff changeset
898 save += save_flag;
223b71206888 Initial import
thib
parents:
diff changeset
899 string save_grp; grp_exec.SaveSys(save_grp);
223b71206888 Initial import
thib
parents:
diff changeset
900 save += save_grp;
223b71206888 Initial import
thib
parents:
diff changeset
901 map<int,set<int> >::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
902 save += "[TextRead]\n";
223b71206888 Initial import
thib
parents:
diff changeset
903 for (it=text_readflag.begin(); it != text_readflag.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
904 set<int>& read_flag = it->second;
223b71206888 Initial import
thib
parents:
diff changeset
905 set<int>::iterator jt;
223b71206888 Initial import
thib
parents:
diff changeset
906 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
907 sprintf(buf,"T<%05d>=",it->first);
223b71206888 Initial import
thib
parents:
diff changeset
908 string save_readflag = buf;
223b71206888 Initial import
thib
parents:
diff changeset
909 for (jt=read_flag.begin(); jt != read_flag.end(); jt++) {
223b71206888 Initial import
thib
parents:
diff changeset
910 sprintf(buf, "%d,", *jt);
223b71206888 Initial import
thib
parents:
diff changeset
911 save_readflag += buf;
223b71206888 Initial import
thib
parents:
diff changeset
912 }
223b71206888 Initial import
thib
parents:
diff changeset
913 save_readflag += "\n";
223b71206888 Initial import
thib
parents:
diff changeset
914 save += save_readflag;
223b71206888 Initial import
thib
parents:
diff changeset
915 }
223b71206888 Initial import
thib
parents:
diff changeset
916
223b71206888 Initial import
thib
parents:
diff changeset
917 path += ".0";
223b71206888 Initial import
thib
parents:
diff changeset
918 FILE* f = fopen(path.c_str(), "w");
223b71206888 Initial import
thib
parents:
diff changeset
919 if (f == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
920 fprintf(stderr,"Cannot open save file %s\n",path.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
921 return;
223b71206888 Initial import
thib
parents:
diff changeset
922 }
223b71206888 Initial import
thib
parents:
diff changeset
923 fwrite(save.c_str(), save.length(), 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
924 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
925 return;
223b71206888 Initial import
thib
parents:
diff changeset
926 }
223b71206888 Initial import
thib
parents:
diff changeset
927
223b71206888 Initial import
thib
parents:
diff changeset
928 void Scn2k::LoadSys(void) {
223b71206888 Initial import
thib
parents:
diff changeset
929 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
930 string path = MakeSaveFile();
223b71206888 Initial import
thib
parents:
diff changeset
931 path += ".0";
223b71206888 Initial import
thib
parents:
diff changeset
932 FILE* f = fopen(path.c_str(), "r");
223b71206888 Initial import
thib
parents:
diff changeset
933 if (f == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
934 fprintf(stderr, "Cannot open save file %s\n",path.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
935 } else {
223b71206888 Initial import
thib
parents:
diff changeset
936 fseek(f,0,2);
223b71206888 Initial import
thib
parents:
diff changeset
937 int sz = ftell(f);
223b71206888 Initial import
thib
parents:
diff changeset
938 fseek(f,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
939 char* savedata = new char[sz+1];
223b71206888 Initial import
thib
parents:
diff changeset
940 fread(savedata, sz, 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
941 savedata[sz] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
942 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
943
223b71206888 Initial import
thib
parents:
diff changeset
944 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME"));
223b71206888 Initial import
thib
parents:
diff changeset
945 if (strncmp(savedata, buf, strlen(buf)) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
946 fprintf(stderr,"Invalid header in save file %s: it must be started with \"%s\"\n",buf);
223b71206888 Initial import
thib
parents:
diff changeset
947 } else {
223b71206888 Initial import
thib
parents:
diff changeset
948 char* config_str = strstr(savedata, "\nCONFIG=");
223b71206888 Initial import
thib
parents:
diff changeset
949 if (config_str) {
223b71206888 Initial import
thib
parents:
diff changeset
950 config_str += strlen("\nCONFIG=");
223b71206888 Initial import
thib
parents:
diff changeset
951 char* strend = strchr(config_str, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
952 if (strend) {
223b71206888 Initial import
thib
parents:
diff changeset
953 int l = strend - config_str;
223b71206888 Initial import
thib
parents:
diff changeset
954 char* config_copy = new char[l+1];
223b71206888 Initial import
thib
parents:
diff changeset
955 strncpy(config_copy, config_str, l);
223b71206888 Initial import
thib
parents:
diff changeset
956 config_copy[l] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
957 config.PatchOriginal(config_copy);
223b71206888 Initial import
thib
parents:
diff changeset
958 delete[] config_copy;
223b71206888 Initial import
thib
parents:
diff changeset
959 }
223b71206888 Initial import
thib
parents:
diff changeset
960 }
223b71206888 Initial import
thib
parents:
diff changeset
961 flag.LoadSys(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
962 grp_exec.LoadSys(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
963 char* save = strstr(savedata, "\n[TextRead]\n");
223b71206888 Initial import
thib
parents:
diff changeset
964 if (save) {
223b71206888 Initial import
thib
parents:
diff changeset
965 save += strlen("\n[TextRead]\n");
223b71206888 Initial import
thib
parents:
diff changeset
966 do {
223b71206888 Initial import
thib
parents:
diff changeset
967 if (save[0] == '[') break; // next section
223b71206888 Initial import
thib
parents:
diff changeset
968 char* next_save = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
969 if (next_save) {
223b71206888 Initial import
thib
parents:
diff changeset
970 *next_save++ = 0;
223b71206888 Initial import
thib
parents:
diff changeset
971 }
223b71206888 Initial import
thib
parents:
diff changeset
972 // T<XXXXX>=YYY,YYY,YYY,...
223b71206888 Initial import
thib
parents:
diff changeset
973 if (strncmp(save,"T<",2) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
974 int scn_num = atoi(save+2);
223b71206888 Initial import
thib
parents:
diff changeset
975 set<int>& read_flag = text_readflag[scn_num];
223b71206888 Initial import
thib
parents:
diff changeset
976 save += strlen("T<XXXXX>=");
223b71206888 Initial import
thib
parents:
diff changeset
977 while(save && *save) {
223b71206888 Initial import
thib
parents:
diff changeset
978 if (save[0] >= '0' && save[0] <= '9') {
223b71206888 Initial import
thib
parents:
diff changeset
979 int num = atoi(save);
223b71206888 Initial import
thib
parents:
diff changeset
980 read_flag.insert(num);
223b71206888 Initial import
thib
parents:
diff changeset
981 }
223b71206888 Initial import
thib
parents:
diff changeset
982 save = strchr(save, ',');
223b71206888 Initial import
thib
parents:
diff changeset
983 if (save) save++;
223b71206888 Initial import
thib
parents:
diff changeset
984 }
223b71206888 Initial import
thib
parents:
diff changeset
985 }
223b71206888 Initial import
thib
parents:
diff changeset
986 save = next_save;
223b71206888 Initial import
thib
parents:
diff changeset
987 } while(save);
223b71206888 Initial import
thib
parents:
diff changeset
988 }
223b71206888 Initial import
thib
parents:
diff changeset
989
223b71206888 Initial import
thib
parents:
diff changeset
990 }
223b71206888 Initial import
thib
parents:
diff changeset
991 delete[] savedata;
223b71206888 Initial import
thib
parents:
diff changeset
992 }
223b71206888 Initial import
thib
parents:
diff changeset
993
223b71206888 Initial import
thib
parents:
diff changeset
994 /* 初期化 */
223b71206888 Initial import
thib
parents:
diff changeset
995 int scn_start; config.GetParam("#SEEN_START", 1, &scn_start);
223b71206888 Initial import
thib
parents:
diff changeset
996 ChangeScript(scn_start, 0);
223b71206888 Initial import
thib
parents:
diff changeset
997 save_scn = 0;
223b71206888 Initial import
thib
parents:
diff changeset
998 save_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
999 window_title = "";
223b71206888 Initial import
thib
parents:
diff changeset
1000 const char* window_title_config = config.GetParaStr("#CAPTION");
223b71206888 Initial import
thib
parents:
diff changeset
1001 if (window_title_config) window_title = window_title_config;
223b71206888 Initial import
thib
parents:
diff changeset
1002 parent.Root().SetWindowCaption(kconv(window_title).c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1003 stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1004 cmd_stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1005 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
1006
223b71206888 Initial import
thib
parents:
diff changeset
1007 return;
223b71206888 Initial import
thib
parents:
diff changeset
1008 }
223b71206888 Initial import
thib
parents:
diff changeset
1009
223b71206888 Initial import
thib
parents:
diff changeset
1010 bool Scn2k::StatSaveFile(int num, int& year, int& month, int& day, int& wday, int& hour,int& min, int& sec, int& msec, string& title) const {
223b71206888 Initial import
thib
parents:
diff changeset
1011 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1012 string path = MakeSaveFile();
19
94fe9153efa5 Enable the 99th save
thib
parents: 16
diff changeset
1013 if (num <= 0 || num > 100) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1014 sprintf(buf,".%d",num);
223b71206888 Initial import
thib
parents:
diff changeset
1015 path += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1016
223b71206888 Initial import
thib
parents:
diff changeset
1017 struct stat sb;
223b71206888 Initial import
thib
parents:
diff changeset
1018 if (stat(path.c_str(), &sb) == -1) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1019 struct tm* t = localtime(&sb.st_mtime);
16
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
1020 year = t->tm_year;
0
223b71206888 Initial import
thib
parents:
diff changeset
1021 month = t->tm_mon + 1;
223b71206888 Initial import
thib
parents:
diff changeset
1022 day = t->tm_mday;
223b71206888 Initial import
thib
parents:
diff changeset
1023 hour = t->tm_hour;
223b71206888 Initial import
thib
parents:
diff changeset
1024 min = t->tm_min;
16
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
1025 sec = t->tm_sec;
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
1026 msec = 0;
0
223b71206888 Initial import
thib
parents:
diff changeset
1027 /* タイトルの取得 */
223b71206888 Initial import
thib
parents:
diff changeset
1028 FILE* savefile = fopen(path.c_str(), "rb");
223b71206888 Initial import
thib
parents:
diff changeset
1029 if (savefile == 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1030 char regname[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1031 sprintf(regname, "KEY=%s\n", config.GetParaStr("#REGNAME"));
223b71206888 Initial import
thib
parents:
diff changeset
1032 fgets(buf,1000,savefile);
223b71206888 Initial import
thib
parents:
diff changeset
1033 if (strncmp(regname, buf, strlen(regname)) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1034 fprintf(stderr,"invalid save file %s (registory name is not %s)\n",path.c_str(),regname);
223b71206888 Initial import
thib
parents:
diff changeset
1035 fclose(savefile);
223b71206888 Initial import
thib
parents:
diff changeset
1036 return false;
223b71206888 Initial import
thib
parents:
diff changeset
1037 }
223b71206888 Initial import
thib
parents:
diff changeset
1038 title="none";
223b71206888 Initial import
thib
parents:
diff changeset
1039 while(!feof(savefile)) {
223b71206888 Initial import
thib
parents:
diff changeset
1040 fgets(buf,1000,savefile);
223b71206888 Initial import
thib
parents:
diff changeset
1041 if (strncmp(buf,"Title=",6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1042 if (buf[strlen(buf)-2] == 0x0a) buf[strlen(buf)-2] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1043 if (strlen(buf) > 20) buf[20] = 0, buf[21] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1044 title = kconv(buf+6);
223b71206888 Initial import
thib
parents:
diff changeset
1045 break;
223b71206888 Initial import
thib
parents:
diff changeset
1046 }
223b71206888 Initial import
thib
parents:
diff changeset
1047 }
223b71206888 Initial import
thib
parents:
diff changeset
1048 fclose(savefile);
223b71206888 Initial import
thib
parents:
diff changeset
1049 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1050 }
223b71206888 Initial import
thib
parents:
diff changeset
1051
223b71206888 Initial import
thib
parents:
diff changeset
1052 void Scn2k::SaveRollback(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1053 fprintf(stderr,"Save rollback\n");
223b71206888 Initial import
thib
parents:
diff changeset
1054 new_rollback_save = "";
223b71206888 Initial import
thib
parents:
diff changeset
1055 string save_sys; SaveImpl(save_sys);
223b71206888 Initial import
thib
parents:
diff changeset
1056 string save_flag; flag.Save(save_flag);
223b71206888 Initial import
thib
parents:
diff changeset
1057 string save_text; text_exec.Save(save_text, true);
223b71206888 Initial import
thib
parents:
diff changeset
1058 string save_grp; grp_exec.Save(save_grp);
223b71206888 Initial import
thib
parents:
diff changeset
1059 new_rollback_save += save_sys;
223b71206888 Initial import
thib
parents:
diff changeset
1060 new_rollback_save += save_flag;
223b71206888 Initial import
thib
parents:
diff changeset
1061 new_rollback_save += save_text;
223b71206888 Initial import
thib
parents:
diff changeset
1062 new_rollback_save += save_grp;
223b71206888 Initial import
thib
parents:
diff changeset
1063 }
223b71206888 Initial import
thib
parents:
diff changeset
1064
223b71206888 Initial import
thib
parents:
diff changeset
1065 void Scn2k::LoadRollback(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1066 if (rollback_save.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1067 new_rollback_save = "";
223b71206888 Initial import
thib
parents:
diff changeset
1068 string savedata = rollback_save.back();
223b71206888 Initial import
thib
parents:
diff changeset
1069 rollback_save.pop_back();
223b71206888 Initial import
thib
parents:
diff changeset
1070 LoadImpl(savedata.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1071 flag.Load(savedata.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1072 text_exec.Load(savedata.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1073 grp_exec.Load(savedata.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1074
223b71206888 Initial import
thib
parents:
diff changeset
1075 /* 画面の回復など */
223b71206888 Initial import
thib
parents:
diff changeset
1076 SetSkipMode(SKIP_NO);
223b71206888 Initial import
thib
parents:
diff changeset
1077 vector<CmdSimplified>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1078 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1079 for (it = cmd_stack.begin(); it != cmd_stack.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1080 cmd.read(*it);
223b71206888 Initial import
thib
parents:
diff changeset
1081 cmd.cmd_type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1082 flag.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1083 text_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1084 grp_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1085 }
223b71206888 Initial import
thib
parents:
diff changeset
1086 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1087 return;
223b71206888 Initial import
thib
parents:
diff changeset
1088 }
223b71206888 Initial import
thib
parents:
diff changeset
1089
223b71206888 Initial import
thib
parents:
diff changeset
1090 void Scn2k::Save(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1091 if (cmd.cmd_type == CMD_SAVEREQ) {
223b71206888 Initial import
thib
parents:
diff changeset
1092 if (menu == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1093 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断
223b71206888 Initial import
thib
parents:
diff changeset
1094 menu = new Scn2kMenu(Scn2kMenu::MENU_SAVE, *this, flag, text_exec, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
1095 menu->InitPanel(event, parent);
223b71206888 Initial import
thib
parents:
diff changeset
1096 menu->InitTitle(Scn2kSaveTitle(*this));
223b71206888 Initial import
thib
parents:
diff changeset
1097 if (mouse_surface) menu_mouseshown = true;
223b71206888 Initial import
thib
parents:
diff changeset
1098 else menu_mouseshown = false;
223b71206888 Initial import
thib
parents:
diff changeset
1099 ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
1100 return;
223b71206888 Initial import
thib
parents:
diff changeset
1101 }
223b71206888 Initial import
thib
parents:
diff changeset
1102 }
223b71206888 Initial import
thib
parents:
diff changeset
1103 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1104 string save;
223b71206888 Initial import
thib
parents:
diff changeset
1105 FILE* f = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1106 if (save_scn == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1107 fprintf(stderr,"Cannot decide save point\n");
223b71206888 Initial import
thib
parents:
diff changeset
1108 return; // セーブ位置が保存されてない
223b71206888 Initial import
thib
parents:
diff changeset
1109 }
223b71206888 Initial import
thib
parents:
diff changeset
1110 string path = MakeSaveFile();
223b71206888 Initial import
thib
parents:
diff changeset
1111 int file_number = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1112 if (cmd.args.size() == 1)
223b71206888 Initial import
thib
parents:
diff changeset
1113 file_number = cmd.args[0].value + 1;
223b71206888 Initial import
thib
parents:
diff changeset
1114 if (file_number <= 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1115 fprintf(stderr, "Cannot open save file %s\n",path.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1116 return;
223b71206888 Initial import
thib
parents:
diff changeset
1117 }
223b71206888 Initial import
thib
parents:
diff changeset
1118 sprintf(buf, ".%d",file_number);
223b71206888 Initial import
thib
parents:
diff changeset
1119 path += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1120
223b71206888 Initial import
thib
parents:
diff changeset
1121 /* セーブファイル確認 */
223b71206888 Initial import
thib
parents:
diff changeset
1122
223b71206888 Initial import
thib
parents:
diff changeset
1123 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1124 string save_sys; SaveImpl(save_sys);
223b71206888 Initial import
thib
parents:
diff changeset
1125 string save_flag; flag.Save(save_flag);
223b71206888 Initial import
thib
parents:
diff changeset
1126 string save_text; text_exec.Save(save_text, false);
223b71206888 Initial import
thib
parents:
diff changeset
1127 string save_grp; grp_exec.Save(save_grp);
223b71206888 Initial import
thib
parents:
diff changeset
1128 save += save_sys;
223b71206888 Initial import
thib
parents:
diff changeset
1129 save += save_flag;
223b71206888 Initial import
thib
parents:
diff changeset
1130 save += save_text;
223b71206888 Initial import
thib
parents:
diff changeset
1131 save += save_grp;
223b71206888 Initial import
thib
parents:
diff changeset
1132 vector<string>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1133 for (it=rollback_save.begin(); it != rollback_save.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1134 save += "[Rollback Data]\n";
223b71206888 Initial import
thib
parents:
diff changeset
1135 save += *it;
223b71206888 Initial import
thib
parents:
diff changeset
1136 save += "[Rollback End]\n";
223b71206888 Initial import
thib
parents:
diff changeset
1137 }
223b71206888 Initial import
thib
parents:
diff changeset
1138
223b71206888 Initial import
thib
parents:
diff changeset
1139 f = fopen(path.c_str(), "w");
223b71206888 Initial import
thib
parents:
diff changeset
1140 if (f == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1141 fprintf(stderr,"Cannot open save file %s\n",path.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1142 return;
223b71206888 Initial import
thib
parents:
diff changeset
1143 }
223b71206888 Initial import
thib
parents:
diff changeset
1144 fwrite(save.c_str(), save.length(), 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
1145 fclose(f);
16
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 15
diff changeset
1146 config.SetParam("#LASTSAVE", 1, file_number);
0
223b71206888 Initial import
thib
parents:
diff changeset
1147 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1148 return;
223b71206888 Initial import
thib
parents:
diff changeset
1149 }
223b71206888 Initial import
thib
parents:
diff changeset
1150
223b71206888 Initial import
thib
parents:
diff changeset
1151 void Scn2k::Load(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1152 if (cmd.cmd_type == CMD_LOADREQ) {
223b71206888 Initial import
thib
parents:
diff changeset
1153 if (menu == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1154 menu = new Scn2kMenu(Scn2kMenu::MENU_LOAD, *this, flag, text_exec, system_version);
223b71206888 Initial import
thib
parents:
diff changeset
1155 menu->InitPanel(event, parent);
223b71206888 Initial import
thib
parents:
diff changeset
1156 menu->InitTitle(Scn2kSaveTitle(*this));
223b71206888 Initial import
thib
parents:
diff changeset
1157 SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断
223b71206888 Initial import
thib
parents:
diff changeset
1158 if (mouse_surface) menu_mouseshown = true;
223b71206888 Initial import
thib
parents:
diff changeset
1159 else menu_mouseshown = false;
223b71206888 Initial import
thib
parents:
diff changeset
1160 ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
1161 return;
223b71206888 Initial import
thib
parents:
diff changeset
1162 }
223b71206888 Initial import
thib
parents:
diff changeset
1163 }
223b71206888 Initial import
thib
parents:
diff changeset
1164 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1165 string path = MakeSaveFile();
223b71206888 Initial import
thib
parents:
diff changeset
1166 int file_number = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1167 if (cmd.args.size() == 1)
223b71206888 Initial import
thib
parents:
diff changeset
1168 file_number = cmd.args[0].value + 1;
223b71206888 Initial import
thib
parents:
diff changeset
1169 sprintf(buf, ".%d",file_number);
223b71206888 Initial import
thib
parents:
diff changeset
1170 path += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1171 FILE* f = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1172 if (file_number > 0) f = fopen(path.c_str(), "r");
223b71206888 Initial import
thib
parents:
diff changeset
1173 if (f == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1174 fprintf(stderr, "Cannot open save file %s\n",path.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1175 return;
223b71206888 Initial import
thib
parents:
diff changeset
1176 }
223b71206888 Initial import
thib
parents:
diff changeset
1177
223b71206888 Initial import
thib
parents:
diff changeset
1178 fseek(f,0,2);
223b71206888 Initial import
thib
parents:
diff changeset
1179 int sz = ftell(f);
223b71206888 Initial import
thib
parents:
diff changeset
1180 fseek(f,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
1181 char* savedata = new char[sz+1];
223b71206888 Initial import
thib
parents:
diff changeset
1182 fread(savedata, sz, 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
1183 savedata[sz] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1184 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
1185
223b71206888 Initial import
thib
parents:
diff changeset
1186 sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME"));
223b71206888 Initial import
thib
parents:
diff changeset
1187 if (strncmp(savedata, buf, strlen(buf)) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1188 fprintf(stderr,"Invalid header in save file %s: it must be started with \"%s\"\n",buf);
223b71206888 Initial import
thib
parents:
diff changeset
1189 delete[] savedata;
223b71206888 Initial import
thib
parents:
diff changeset
1190 return;
223b71206888 Initial import
thib
parents:
diff changeset
1191 }
223b71206888 Initial import
thib
parents:
diff changeset
1192 LoadImpl(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
1193 flag.Load(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
1194 text_exec.Load(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
1195 grp_exec.Load(savedata);
223b71206888 Initial import
thib
parents:
diff changeset
1196 rollback_save.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1197 new_rollback_save = "";
223b71206888 Initial import
thib
parents:
diff changeset
1198 char* rollback_data = savedata;
223b71206888 Initial import
thib
parents:
diff changeset
1199 while( (rollback_data = strstr(rollback_data,"[Rollback Data]\n")) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1200 rollback_data += strlen("[Rollback Data]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1201 char* rollback_end = strstr(rollback_data, "[Rollback End]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1202 if (rollback_end == 0) rollback_end = rollback_data + strlen(rollback_data);
223b71206888 Initial import
thib
parents:
diff changeset
1203 string s(rollback_data, rollback_end);
223b71206888 Initial import
thib
parents:
diff changeset
1204 rollback_save.push_back(s);
223b71206888 Initial import
thib
parents:
diff changeset
1205 rollback_data = rollback_end;
223b71206888 Initial import
thib
parents:
diff changeset
1206 }
223b71206888 Initial import
thib
parents:
diff changeset
1207
223b71206888 Initial import
thib
parents:
diff changeset
1208 /* 画面の回復など */
223b71206888 Initial import
thib
parents:
diff changeset
1209 SetSkipMode(SKIP_NO);
223b71206888 Initial import
thib
parents:
diff changeset
1210 vector<CmdSimplified>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1211 for (it = cmd_stack.begin(); it != cmd_stack.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1212 cmd.read(*it);
223b71206888 Initial import
thib
parents:
diff changeset
1213 cmd.cmd_type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1214 flag.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1215 text_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1216 grp_exec.Exec(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1217 }
223b71206888 Initial import
thib
parents:
diff changeset
1218 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1219 return;
223b71206888 Initial import
thib
parents:
diff changeset
1220 }
223b71206888 Initial import
thib
parents:
diff changeset
1221
223b71206888 Initial import
thib
parents:
diff changeset
1222 void Scn2k::SaveImpl(string& save) {
223b71206888 Initial import
thib
parents:
diff changeset
1223 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1224
223b71206888 Initial import
thib
parents:
diff changeset
1225 /* save point */
223b71206888 Initial import
thib
parents:
diff changeset
1226 sprintf(buf, "\n[SCENARIO]\nScn=%d\nPoint=%d\n",save_scn, save_point); save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1227 sprintf(buf, "Title=%s\nMouseType=%d\nMouseShown=1\n",window_title.c_str(), mouse_type); save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1228 vector<StackItem>::iterator sit;
223b71206888 Initial import
thib
parents:
diff changeset
1229 for (sit=stack.begin(); sit!=stack.end(); sit++) {
223b71206888 Initial import
thib
parents:
diff changeset
1230 if (sit->scn_number == SCN_INFO && sit->scn_pt == SCN_INFO_MENU) break; // メニューに入る直前までのスタックを保存
223b71206888 Initial import
thib
parents:
diff changeset
1231 sprintf(buf, "Stack=%d,%d\n",sit->scn_number,sit->scn_pt);
223b71206888 Initial import
thib
parents:
diff changeset
1232 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1233 }
223b71206888 Initial import
thib
parents:
diff changeset
1234 vector<string>::reverse_iterator ssit;
223b71206888 Initial import
thib
parents:
diff changeset
1235 for (ssit=stack_strbuffer.rbegin(); ssit != stack_strbuffer.rend(); ssit++) {
223b71206888 Initial import
thib
parents:
diff changeset
1236 sprintf(buf, "StackStr=%s\n",ssit->c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1237 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1238 }
223b71206888 Initial import
thib
parents:
diff changeset
1239 vector<CmdSimplified>::iterator cit;
223b71206888 Initial import
thib
parents:
diff changeset
1240 for (cit=cmd_stack.begin(); cit != cmd_stack.end(); cit++) {
223b71206888 Initial import
thib
parents:
diff changeset
1241 if (cit->type == CMD_SAVECMDGRP || cit->type == CMD_SAVECMDGRP_ONCE || cit->type == CMD_SAVECMDGRP_START) {
223b71206888 Initial import
thib
parents:
diff changeset
1242 save += "CmdG=";
223b71206888 Initial import
thib
parents:
diff changeset
1243 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1244 save += "Cmd=";
223b71206888 Initial import
thib
parents:
diff changeset
1245 }
223b71206888 Initial import
thib
parents:
diff changeset
1246 string s; cit->Save(s);
223b71206888 Initial import
thib
parents:
diff changeset
1247 save += s;
223b71206888 Initial import
thib
parents:
diff changeset
1248 save += "\n";
223b71206888 Initial import
thib
parents:
diff changeset
1249 }
223b71206888 Initial import
thib
parents:
diff changeset
1250 }
223b71206888 Initial import
thib
parents:
diff changeset
1251
223b71206888 Initial import
thib
parents:
diff changeset
1252 void Scn2k::LoadImpl(const char* save) {
223b71206888 Initial import
thib
parents:
diff changeset
1253 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1254 save_scn = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1255 save_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1256 window_title = "";
223b71206888 Initial import
thib
parents:
diff changeset
1257 stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1258 cmd_stack.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1259 cmd_stack_str = cmd_stack_str_orig;
223b71206888 Initial import
thib
parents:
diff changeset
1260
223b71206888 Initial import
thib
parents:
diff changeset
1261 save = strstr(save, "\n[SCENARIO]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1262 if (save == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1263 save += strlen("\n[SCENARIO]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1264 while(save[0] != 0 && save[0] != '[') { // while next section start
223b71206888 Initial import
thib
parents:
diff changeset
1265 if (strncmp(save, "Scn=", 4) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1266 sscanf(save, "Scn=%d", &save_scn);
223b71206888 Initial import
thib
parents:
diff changeset
1267 } else if (strncmp(save, "Point=", 6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1268 sscanf(save, "Point=%d", &save_point);
223b71206888 Initial import
thib
parents:
diff changeset
1269 } else if (strncmp(save, "Title=", 6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1270 save += 6;
223b71206888 Initial import
thib
parents:
diff changeset
1271 char* s = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
1272 if (s == 0) window_title = save;
223b71206888 Initial import
thib
parents:
diff changeset
1273 else window_title.assign(save, s-save);
223b71206888 Initial import
thib
parents:
diff changeset
1274 const char* config_name = config.GetParaStr("#CAPTION");
223b71206888 Initial import
thib
parents:
diff changeset
1275 if (config_name == 0) config_name = "";
223b71206888 Initial import
thib
parents:
diff changeset
1276 string setname = kconv(string(config_name)+" "+window_title);
223b71206888 Initial import
thib
parents:
diff changeset
1277 parent.Root().SetWindowCaption(setname.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1278 } else if (strncmp(save, "MouseType=", 10) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1279 sscanf(save, "MouseType=%d", &mouse_type);
223b71206888 Initial import
thib
parents:
diff changeset
1280 } else if (strncmp(save, "MouseShown=", 11) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1281 int v;
223b71206888 Initial import
thib
parents:
diff changeset
1282 sscanf(save, "MouseShown=%d", &v);
223b71206888 Initial import
thib
parents:
diff changeset
1283 if (v) ShowCursor();
223b71206888 Initial import
thib
parents:
diff changeset
1284 else HideCursor();
223b71206888 Initial import
thib
parents:
diff changeset
1285 } else if (strncmp(save, "Stack=", 6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1286 int scn, pt;
223b71206888 Initial import
thib
parents:
diff changeset
1287 sscanf(save, "Stack=%d,%d", &scn, &pt);
223b71206888 Initial import
thib
parents:
diff changeset
1288 stack.push_back( StackItem(scn, pt));
223b71206888 Initial import
thib
parents:
diff changeset
1289 } else if (strncmp(save, "StackStr=", 9) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1290 save += 9;
223b71206888 Initial import
thib
parents:
diff changeset
1291 char* s = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
1292 if (s == 0) stack_strbuffer.push_back("");
223b71206888 Initial import
thib
parents:
diff changeset
1293 else stack_strbuffer.push_back(string(save, s-save));
223b71206888 Initial import
thib
parents:
diff changeset
1294 } else if (strncmp(save, "Cmd=", 4) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1295 CmdSimplified cmd;
223b71206888 Initial import
thib
parents:
diff changeset
1296 cmd.Load(save+4, cmd_stack_str);
223b71206888 Initial import
thib
parents:
diff changeset
1297 cmd_stack.push_back(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1298 } else if (strncmp(save, "CmdG=", 5) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1299 CmdSimplified cmd;
223b71206888 Initial import
thib
parents:
diff changeset
1300 cmd.Load(save+5, cmd_stack_str);
223b71206888 Initial import
thib
parents:
diff changeset
1301 cmd.type = CMD_SAVECMDGRP;
223b71206888 Initial import
thib
parents:
diff changeset
1302 cmd_stack.push_back(cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1303 }
223b71206888 Initial import
thib
parents:
diff changeset
1304 save = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
1305 if (save != 0) save++;
223b71206888 Initial import
thib
parents:
diff changeset
1306 }
223b71206888 Initial import
thib
parents:
diff changeset
1307 ChangeScript(save_scn, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1308 script = script_start + save_point;
223b71206888 Initial import
thib
parents:
diff changeset
1309 return;
223b71206888 Initial import
thib
parents:
diff changeset
1310 }
223b71206888 Initial import
thib
parents:
diff changeset
1311 void Scn2k::SetSkipMode(SkipMode mode) {
223b71206888 Initial import
thib
parents:
diff changeset
1312 if (skip_mode != mode) {
223b71206888 Initial import
thib
parents:
diff changeset
1313 skip_mode = mode;
223b71206888 Initial import
thib
parents:
diff changeset
1314 text_exec.SetSkipMode(mode);
223b71206888 Initial import
thib
parents:
diff changeset
1315 grp_exec.SetSkipMode(mode);
223b71206888 Initial import
thib
parents:
diff changeset
1316 }
223b71206888 Initial import
thib
parents:
diff changeset
1317 }
223b71206888 Initial import
thib
parents:
diff changeset
1318
223b71206888 Initial import
thib
parents:
diff changeset
1319 /***********************************************************
223b71206888 Initial import
thib
parents:
diff changeset
1320 **
223b71206888 Initial import
thib
parents:
diff changeset
1321 ** DLL Call Implementation
223b71206888 Initial import
thib
parents:
diff changeset
1322 **
223b71206888 Initial import
thib
parents:
diff changeset
1323 **/
223b71206888 Initial import
thib
parents:
diff changeset
1324 static double* lb_ef_param = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1325 void DLLCall_LB_EF00_0(Cmd& cmd, Flags& flags) { // エフェクトの設定
223b71206888 Initial import
thib
parents:
diff changeset
1326 if (lb_ef_param == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1327 lb_ef_param = new double[sizeof(double) * 0x60 * 8];
223b71206888 Initial import
thib
parents:
diff changeset
1328 }
223b71206888 Initial import
thib
parents:
diff changeset
1329 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
1330 int param_top, param_size;
223b71206888 Initial import
thib
parents:
diff changeset
1331 if (cmd.args[2].value == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
1332 param_top = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1333 param_size = 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1334 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1335 param_top = cmd.args[3].value;
223b71206888 Initial import
thib
parents:
diff changeset
1336 param_size = cmd.args[4].value;
223b71206888 Initial import
thib
parents:
diff changeset
1337 if (param_top < 0) param_top = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1338 if (param_top > 0x20) param_top = 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1339 if (param_size+param_top > 0x20) param_size = 0x20 - param_top;
223b71206888 Initial import
thib
parents:
diff changeset
1340 }
223b71206888 Initial import
thib
parents:
diff changeset
1341 for (i=0; i<8; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1342 double* param = lb_ef_param + i*0x60 + param_top*3;
223b71206888 Initial import
thib
parents:
diff changeset
1343 for (j=0; j<param_size; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
1344 *param++ = random() % 800 - 400;
223b71206888 Initial import
thib
parents:
diff changeset
1345 *param++ = random() % 600 - 300;
223b71206888 Initial import
thib
parents:
diff changeset
1346 *param++ = random() % 700 - 350;
223b71206888 Initial import
thib
parents:
diff changeset
1347 }
223b71206888 Initial import
thib
parents:
diff changeset
1348 }
223b71206888 Initial import
thib
parents:
diff changeset
1349 if (cmd.args[5].value != 1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1350 static int random_dirtable[] = {
223b71206888 Initial import
thib
parents:
diff changeset
1351 0, 2, 1, 3, 0, 2, 1, 3,
223b71206888 Initial import
thib
parents:
diff changeset
1352 1, 3, 2, 0, 1, 3, 2, 0,
223b71206888 Initial import
thib
parents:
diff changeset
1353 0, 0, 0, 0, 3, 1, 2, 0,
223b71206888 Initial import
thib
parents:
diff changeset
1354 3, 1, 3, 1, 0, 2, 3, 1
223b71206888 Initial import
thib
parents:
diff changeset
1355 };
223b71206888 Initial import
thib
parents:
diff changeset
1356 int* dir = &random_dirtable[(random()&3) * 8];
223b71206888 Initial import
thib
parents:
diff changeset
1357 for (i=0; i<8; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1358 double* param = lb_ef_param + i*0x60;
223b71206888 Initial import
thib
parents:
diff changeset
1359 double x = random()%600 - 300;
223b71206888 Initial import
thib
parents:
diff changeset
1360 double y = random()%480-240;
223b71206888 Initial import
thib
parents:
diff changeset
1361 if (x < 0) x -= 80;
223b71206888 Initial import
thib
parents:
diff changeset
1362 else x += 80;
223b71206888 Initial import
thib
parents:
diff changeset
1363 if (y < 0) y -= 80;
223b71206888 Initial import
thib
parents:
diff changeset
1364 else y += 80;
223b71206888 Initial import
thib
parents:
diff changeset
1365 switch(*dir++) {
223b71206888 Initial import
thib
parents:
diff changeset
1366 case 0:
223b71206888 Initial import
thib
parents:
diff changeset
1367 if (x < 0) x = -x;
223b71206888 Initial import
thib
parents:
diff changeset
1368 if (y < 0) y = -y;
223b71206888 Initial import
thib
parents:
diff changeset
1369 break;
223b71206888 Initial import
thib
parents:
diff changeset
1370 case 1:
223b71206888 Initial import
thib
parents:
diff changeset
1371 if (x > 0) x = -x;
223b71206888 Initial import
thib
parents:
diff changeset
1372 if (y < 0) y = -y;
223b71206888 Initial import
thib
parents:
diff changeset
1373 break;
223b71206888 Initial import
thib
parents:
diff changeset
1374 case 2:
223b71206888 Initial import
thib
parents:
diff changeset
1375 if (x < 0) x = -x;
223b71206888 Initial import
thib
parents:
diff changeset
1376 if (y > 0) y = -y;
223b71206888 Initial import
thib
parents:
diff changeset
1377 break;
223b71206888 Initial import
thib
parents:
diff changeset
1378 case 4:
223b71206888 Initial import
thib
parents:
diff changeset
1379 if (x > 0) x = -x;
223b71206888 Initial import
thib
parents:
diff changeset
1380 if (y > 0) y = -y;
223b71206888 Initial import
thib
parents:
diff changeset
1381 break;
223b71206888 Initial import
thib
parents:
diff changeset
1382 }
223b71206888 Initial import
thib
parents:
diff changeset
1383 param[9] = x*1.2;
223b71206888 Initial import
thib
parents:
diff changeset
1384 param[10] = y*1.2;
223b71206888 Initial import
thib
parents:
diff changeset
1385 param[11] *= 1.2;
223b71206888 Initial import
thib
parents:
diff changeset
1386 param[12] *= -0.08;
223b71206888 Initial import
thib
parents:
diff changeset
1387 param[13] *= -0.08;
223b71206888 Initial import
thib
parents:
diff changeset
1388 param[14] *= -0.08;
223b71206888 Initial import
thib
parents:
diff changeset
1389 param[15] = -param[9];
223b71206888 Initial import
thib
parents:
diff changeset
1390 param[16] = -param[10];
223b71206888 Initial import
thib
parents:
diff changeset
1391 param[17] = -param[11];
223b71206888 Initial import
thib
parents:
diff changeset
1392 }
223b71206888 Initial import
thib
parents:
diff changeset
1393 return;
223b71206888 Initial import
thib
parents:
diff changeset
1394 }
223b71206888 Initial import
thib
parents:
diff changeset
1395 void DLLCall_LB_EF00_1(Cmd& cmd, Flags& flags) { // 計算を行う
223b71206888 Initial import
thib
parents:
diff changeset
1396 if (lb_ef_param == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1397 fprintf(stderr,"Warning : DLLCall_LB_EF00_1 : Script error : effect calculation was called before setting\n");
223b71206888 Initial import
thib
parents:
diff changeset
1398 return;
223b71206888 Initial import
thib
parents:
diff changeset
1399 }
223b71206888 Initial import
thib
parents:
diff changeset
1400 int index = cmd.args[2].value;
223b71206888 Initial import
thib
parents:
diff changeset
1401 int v5_1154 = flags.Get(5, 1154+index);
223b71206888 Initial import
thib
parents:
diff changeset
1402 int j = ((v5_1154) & 0x1f) + index * 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1403 int k = ((v5_1154+1) & 0x1f) + index * 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1404 int l = ((v5_1154+2) & 0x1f) + index * 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1405 int m = ((v5_1154+3) & 0x1f) + index * 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1406 j *= 3;
223b71206888 Initial import
thib
parents:
diff changeset
1407 k *= 3;
223b71206888 Initial import
thib
parents:
diff changeset
1408 l *= 3;
223b71206888 Initial import
thib
parents:
diff changeset
1409 m *= 3;
223b71206888 Initial import
thib
parents:
diff changeset
1410
223b71206888 Initial import
thib
parents:
diff changeset
1411 // 0 < x < 1
223b71206888 Initial import
thib
parents:
diff changeset
1412 // va - vd は 0-1 の範囲で対称性を持つ3次関数
223b71206888 Initial import
thib
parents:
diff changeset
1413 double x = double(flags.Get(5, 1162 + index)) * 0.001;
223b71206888 Initial import
thib
parents:
diff changeset
1414 double va = (x * x * x)/6;
223b71206888 Initial import
thib
parents:
diff changeset
1415 double vb = (-x*x*x + 3*x*x - 3*x + 1) / 6;
223b71206888 Initial import
thib
parents:
diff changeset
1416 double vc = (3*x*x*x - 6*x*x + 4) / 6;
223b71206888 Initial import
thib
parents:
diff changeset
1417 double vd = (-3*x*x*x+3*x*x+3*x+1) / 6;
223b71206888 Initial import
thib
parents:
diff changeset
1418
223b71206888 Initial import
thib
parents:
diff changeset
1419 double r1 = va * lb_ef_param[m+3] + vd * lb_ef_param[l+3] + vc * lb_ef_param[k+3] + vb * lb_ef_param[j+3];
223b71206888 Initial import
thib
parents:
diff changeset
1420 double r2 = va * lb_ef_param[m+2] + vd * lb_ef_param[l+2] + vc * lb_ef_param[k+2] + vb * lb_ef_param[j+2];
223b71206888 Initial import
thib
parents:
diff changeset
1421 double r3 = va * lb_ef_param[m+1] + vd * lb_ef_param[l+1] + vc * lb_ef_param[k+1] + vb * lb_ef_param[j+1];
223b71206888 Initial import
thib
parents:
diff changeset
1422 if (r1 != 400) {
223b71206888 Initial import
thib
parents:
diff changeset
1423 r2 = r2 * 800 / (400-r1);
223b71206888 Initial import
thib
parents:
diff changeset
1424 r3 = r3 * 700 / (400-r1);
223b71206888 Initial import
thib
parents:
diff changeset
1425 }
223b71206888 Initial import
thib
parents:
diff changeset
1426 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
1427 var.type = 5;
223b71206888 Initial import
thib
parents:
diff changeset
1428 var.number = 1151;
223b71206888 Initial import
thib
parents:
diff changeset
1429 flags.Set(var, int(r2));
223b71206888 Initial import
thib
parents:
diff changeset
1430 var.number = 1152;
223b71206888 Initial import
thib
parents:
diff changeset
1431 flags.Set(var, int(r3));
223b71206888 Initial import
thib
parents:
diff changeset
1432 var.number = 1153;
223b71206888 Initial import
thib
parents:
diff changeset
1433 flags.Set(var, int(r1));
223b71206888 Initial import
thib
parents:
diff changeset
1434 return;
223b71206888 Initial import
thib
parents:
diff changeset
1435 }
223b71206888 Initial import
thib
parents:
diff changeset
1436
223b71206888 Initial import
thib
parents:
diff changeset
1437
223b71206888 Initial import
thib
parents:
diff changeset
1438 void DllCall_LB(Cmd& cmd, Flags& flags) { // リトルバスターズ!の EF00.dll をエミュレート
223b71206888 Initial import
thib
parents:
diff changeset
1439 if (cmd.args[0].value == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
1440 // "EF00.dll"
223b71206888 Initial import
thib
parents:
diff changeset
1441 if (cmd.args[1].value == 0) { // エフェクトの設定
223b71206888 Initial import
thib
parents:
diff changeset
1442 DLLCall_LB_EF00_0(cmd, flags);
223b71206888 Initial import
thib
parents:
diff changeset
1443 } else if (cmd.args[1].value == 1) { // 計算を行う
223b71206888 Initial import
thib
parents:
diff changeset
1444 DLLCall_LB_EF00_1(cmd, flags);
223b71206888 Initial import
thib
parents:
diff changeset
1445 }
223b71206888 Initial import
thib
parents:
diff changeset
1446 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1447 fprintf(stderr,"Unsupported DLL call for DLL<%d>\n",cmd.args[0].value);
223b71206888 Initial import
thib
parents:
diff changeset
1448 }
223b71206888 Initial import
thib
parents:
diff changeset
1449 return;
223b71206888 Initial import
thib
parents:
diff changeset
1450 }
223b71206888 Initial import
thib
parents:
diff changeset
1451
223b71206888 Initial import
thib
parents:
diff changeset
1452 /**********************************************************
223b71206888 Initial import
thib
parents:
diff changeset
1453 **
223b71206888 Initial import
thib
parents:
diff changeset
1454 ** MenuImpl
223b71206888 Initial import
thib
parents:
diff changeset
1455 **
223b71206888 Initial import
thib
parents:
diff changeset
1456 */
223b71206888 Initial import
thib
parents:
diff changeset
1457
223b71206888 Initial import
thib
parents:
diff changeset
1458 #include"window/widget.h"
223b71206888 Initial import
thib
parents:
diff changeset
1459 #include"window/menuitem.h"
223b71206888 Initial import
thib
parents:
diff changeset
1460
223b71206888 Initial import
thib
parents:
diff changeset
1461 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a = 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
1462
223b71206888 Initial import
thib
parents:
diff changeset
1463 struct Scn2kMenuImpl {
223b71206888 Initial import
thib
parents:
diff changeset
1464 Scn2kMenu& interface;
223b71206888 Initial import
thib
parents:
diff changeset
1465 MenuItem* menu;
223b71206888 Initial import
thib
parents:
diff changeset
1466 Event::Container* pevent;
223b71206888 Initial import
thib
parents:
diff changeset
1467 PicContainer* pparent;
223b71206888 Initial import
thib
parents:
diff changeset
1468
223b71206888 Initial import
thib
parents:
diff changeset
1469 virtual void InitPanel(Event::Container& event, PicContainer& parent) = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1470 virtual void InitTitle(const SaveTitle&) = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1471 virtual void Cancel(void) = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1472 virtual void Exec(Cmd& cmd) = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1473 Scn2kMenuImpl(Scn2kMenu& _interface) : interface(_interface) {
223b71206888 Initial import
thib
parents:
diff changeset
1474 menu = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1475 pevent = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1476 pparent = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1477 }
223b71206888 Initial import
thib
parents:
diff changeset
1478 virtual ~Scn2kMenuImpl() {
223b71206888 Initial import
thib
parents:
diff changeset
1479 if (menu) delete menu;
223b71206888 Initial import
thib
parents:
diff changeset
1480 menu = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1481 }
223b71206888 Initial import
thib
parents:
diff changeset
1482 };
223b71206888 Initial import
thib
parents:
diff changeset
1483
223b71206888 Initial import
thib
parents:
diff changeset
1484 struct LoadMenu : Scn2kMenuImpl {
223b71206888 Initial import
thib
parents:
diff changeset
1485 vector<string> title;
223b71206888 Initial import
thib
parents:
diff changeset
1486 vector<int> title_valid;
223b71206888 Initial import
thib
parents:
diff changeset
1487 RadioButton* btn_local;
223b71206888 Initial import
thib
parents:
diff changeset
1488 RadioButton* btn_page;
223b71206888 Initial import
thib
parents:
diff changeset
1489 RadioButton* btn_set;
223b71206888 Initial import
thib
parents:
diff changeset
1490 Scale* btn_scale;
223b71206888 Initial import
thib
parents:
diff changeset
1491 Dialog* awk_dialog;
223b71206888 Initial import
thib
parents:
diff changeset
1492 int btn_page_val, btn_set_val, btn_local_val, select_page, select_value;
223b71206888 Initial import
thib
parents:
diff changeset
1493 LoadMenu(Scn2kMenu& _interface);
223b71206888 Initial import
thib
parents:
diff changeset
1494 ~LoadMenu();
223b71206888 Initial import
thib
parents:
diff changeset
1495 void InitPanel(Event::Container& event, PicContainer& parent);
223b71206888 Initial import
thib
parents:
diff changeset
1496 void InitTitle(const SaveTitle&);
223b71206888 Initial import
thib
parents:
diff changeset
1497 void Cancel(void);
223b71206888 Initial import
thib
parents:
diff changeset
1498 void Exec(Cmd& cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1499 static void ChangeBtnPage(void* pointer, MenuItem* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1500 static void ChangeBtnLocal(void* pointer, MenuItem* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1501 static void ChangeBtnScale(void* pointer, Scale* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1502 static void ChangeBtnSet(void* pointer, MenuItem* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1503 static void ChangeDialog(void* pointer, Dialog* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1504 bool in_setpage;
223b71206888 Initial import
thib
parents:
diff changeset
1505 void SetPage(int new_page);
223b71206888 Initial import
thib
parents:
diff changeset
1506 void SetValue(int new_value);
223b71206888 Initial import
thib
parents:
diff changeset
1507 void PressOk(void);
223b71206888 Initial import
thib
parents:
diff changeset
1508 };
223b71206888 Initial import
thib
parents:
diff changeset
1509 LoadMenu::LoadMenu(Scn2kMenu& _interface) : Scn2kMenuImpl(_interface) {
223b71206888 Initial import
thib
parents:
diff changeset
1510 btn_local = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1511 btn_scale = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1512 btn_set = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1513 btn_page_val = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1514 btn_set_val = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1515 btn_local_val = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1516 awk_dialog = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1517 in_setpage = false;
223b71206888 Initial import
thib
parents:
diff changeset
1518 select_page = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1519 select_value = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1520 }
223b71206888 Initial import
thib
parents:
diff changeset
1521 LoadMenu::~LoadMenu() {
223b71206888 Initial import
thib
parents:
diff changeset
1522 if (awk_dialog) delete awk_dialog;
223b71206888 Initial import
thib
parents:
diff changeset
1523 }
223b71206888 Initial import
thib
parents:
diff changeset
1524 void LoadMenu::InitPanel(Event::Container& event, PicContainer& parent) {
223b71206888 Initial import
thib
parents:
diff changeset
1525 pevent = &event;
223b71206888 Initial import
thib
parents:
diff changeset
1526 pparent = &parent;
223b71206888 Initial import
thib
parents:
diff changeset
1527
223b71206888 Initial import
thib
parents:
diff changeset
1528 if (menu) delete menu;
223b71206888 Initial import
thib
parents:
diff changeset
1529 menu = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1530 menu = new MenuItem(&parent, Rect(80,30,560, 450), 1, 3, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1531 Surface* surface = parent.Root().NewSurface(menu->Pic()->Width(), menu->Pic()->Height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
1532 if (interface.type == Scn2kMenu::MENU_LOAD) {
223b71206888 Initial import
thib
parents:
diff changeset
1533 menu->SetLabelTop(new Label(menu->PicNode(), Rect(0,0), true, "Load", 26), Rect(0,0,10,0), Rect(0,0,0,20));
223b71206888 Initial import
thib
parents:
diff changeset
1534 DSurfaceFill(surface, Rect(*surface), 0, 0, 0x80, 0x80);
223b71206888 Initial import
thib
parents:
diff changeset
1535 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1536 menu->SetLabelTop(new Label(menu->PicNode(), Rect(0,0), true, "Save", 26), Rect(0,0,10,0), Rect(0,0,0,20));
223b71206888 Initial import
thib
parents:
diff changeset
1537 DSurfaceFill(surface, Rect(*surface), 0, 0x80, 0, 0x80);
223b71206888 Initial import
thib
parents:
diff changeset
1538 }
223b71206888 Initial import
thib
parents:
diff changeset
1539 menu->Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1540 menu->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
1541
223b71206888 Initial import
thib
parents:
diff changeset
1542 btn_page = new RadioButton(event, menu->PicNode(), Rect(0, 0, 480, 40), 10, 1, &btn_page_val,
223b71206888 Initial import
thib
parents:
diff changeset
1543 Rect(0,0,0,0), 18, Color(0,0,0),Color(0xff,0,0),Color(0xff,0x80,0));
223b71206888 Initial import
thib
parents:
diff changeset
1544 btn_page->set_func = &ChangeBtnPage;
223b71206888 Initial import
thib
parents:
diff changeset
1545 btn_page->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1546 btn_page->SetLabelLeft(new Label(btn_page->PicNode(), Rect(0,0), true, "Page", 18), Rect(0, 0, 180, 0), Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1547 btn_page->Add(" 1 ");
223b71206888 Initial import
thib
parents:
diff changeset
1548 btn_page->Add(" 2 ");
223b71206888 Initial import
thib
parents:
diff changeset
1549 btn_page->Add(" 3 ");
223b71206888 Initial import
thib
parents:
diff changeset
1550 btn_page->Add(" 4 ");
223b71206888 Initial import
thib
parents:
diff changeset
1551 btn_page->Add(" 5 ");
223b71206888 Initial import
thib
parents:
diff changeset
1552 btn_page->Add(" 6 ");
223b71206888 Initial import
thib
parents:
diff changeset
1553 btn_page->Add(" 7 ");
223b71206888 Initial import
thib
parents:
diff changeset
1554 btn_page->Add(" 8 ");
223b71206888 Initial import
thib
parents:
diff changeset
1555 btn_page->Add(" 9 ");
223b71206888 Initial import
thib
parents:
diff changeset
1556 btn_page->Add(" 10 ");
223b71206888 Initial import
thib
parents:
diff changeset
1557 btn_page->pack();
223b71206888 Initial import
thib
parents:
diff changeset
1558 /*
223b71206888 Initial import
thib
parents:
diff changeset
1559 surface = parent.Root().NewSurface(btn_page->Pic()->Width(), btn_page->Pic()->Height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
1560 DSurfaceFill(surface, Rect(*surface), 0xff, 0, 0, 0x80);
223b71206888 Initial import
thib
parents:
diff changeset
1561 btn_page->Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1562 btn_page->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
1563 */
223b71206888 Initial import
thib
parents:
diff changeset
1564 menu->item[0] = btn_page;
223b71206888 Initial import
thib
parents:
diff changeset
1565 btn_set = new RadioButton(event, menu->PicNode(), Rect(0, 0, 480, 40), 2, 1, &btn_set_val,
223b71206888 Initial import
thib
parents:
diff changeset
1566 Rect(0,0,0,0), 18, Color(0,0,0),Color(0xff,0,0),Color(0xff,0x80,0));
223b71206888 Initial import
thib
parents:
diff changeset
1567 btn_set->set_func = &ChangeBtnSet;
223b71206888 Initial import
thib
parents:
diff changeset
1568 btn_set->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1569 btn_set->SetLabelLeft(new Label(btn_set->PicNode(), Rect(0,0)), Rect(0,0,200,0), Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1570 if (interface.type == Scn2kMenu::MENU_LOAD) {
223b71206888 Initial import
thib
parents:
diff changeset
1571 btn_set->Add(" Load ");
223b71206888 Initial import
thib
parents:
diff changeset
1572 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1573 btn_set->Add(" Save ");
223b71206888 Initial import
thib
parents:
diff changeset
1574 }
223b71206888 Initial import
thib
parents:
diff changeset
1575 btn_set->Add(" Cancel ");
223b71206888 Initial import
thib
parents:
diff changeset
1576 btn_set->pack();
223b71206888 Initial import
thib
parents:
diff changeset
1577 /*
223b71206888 Initial import
thib
parents:
diff changeset
1578 surface = parent.Root().NewSurface(btn_set->Pic()->Width(), btn_set->Pic()->Height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
1579 DSurfaceFill(surface, Rect(*surface), 0, 0, 0xff, 0x80);
223b71206888 Initial import
thib
parents:
diff changeset
1580 btn_set->Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1581 btn_set->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
1582 */
223b71206888 Initial import
thib
parents:
diff changeset
1583 menu->item[2] = btn_set;
223b71206888 Initial import
thib
parents:
diff changeset
1584 // void btn_set_press(void* pointer, MenuItem* widget);
223b71206888 Initial import
thib
parents:
diff changeset
1585 // btn_set->set_func = btn_set_press;
223b71206888 Initial import
thib
parents:
diff changeset
1586 // btn_set->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1587 btn_local = new RadioButton(*pevent, menu->PicNode(), Rect(0, 0, 480, 300), 1, 100, &btn_local_val,
223b71206888 Initial import
thib
parents:
diff changeset
1588 Rect(0,0,300,30), 18, Color(0,0,0),Color(0xff,0,0),Color(0xff,0x80,0));
223b71206888 Initial import
thib
parents:
diff changeset
1589 btn_local->set_func = &ChangeBtnLocal;
223b71206888 Initial import
thib
parents:
diff changeset
1590 btn_local->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1591 /*
223b71206888 Initial import
thib
parents:
diff changeset
1592 surface = pparent->Root().NewSurface(btn_local->Pic()->Width(), btn_local->Pic()->Height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
1593 DSurfaceFill(surface, Rect(*surface), 0, 0xff, 0, 0x80);
223b71206888 Initial import
thib
parents:
diff changeset
1594 btn_local->Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1595 btn_local->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
1596 */
223b71206888 Initial import
thib
parents:
diff changeset
1597 menu->item[1] = btn_local;
223b71206888 Initial import
thib
parents:
diff changeset
1598 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1599 for (i=0; i<12; i++)
223b71206888 Initial import
thib
parents:
diff changeset
1600 btn_local->Add("",false);
223b71206888 Initial import
thib
parents:
diff changeset
1601 btn_local->pack();
223b71206888 Initial import
thib
parents:
diff changeset
1602 btn_local->show_all();
223b71206888 Initial import
thib
parents:
diff changeset
1603 menu->pack();
223b71206888 Initial import
thib
parents:
diff changeset
1604
223b71206888 Initial import
thib
parents:
diff changeset
1605 PicBase* local_pic = btn_local->Pic();
223b71206888 Initial import
thib
parents:
diff changeset
1606 int local_x2 = local_pic->PosX() + local_pic->Width();
223b71206888 Initial import
thib
parents:
diff changeset
1607 int local_y2 = local_pic->PosY() + local_pic->Height();
223b71206888 Initial import
thib
parents:
diff changeset
1608 btn_scale = new Scale(*pevent, menu->PicNode(), Rect(local_x2-16, local_pic->PosY(), local_x2, local_y2), Color(0xff, 0x80, 0), true);
223b71206888 Initial import
thib
parents:
diff changeset
1609 btn_scale->SetRange(0, 900);
223b71206888 Initial import
thib
parents:
diff changeset
1610 btn_scale->InitCursor(1024/10);
223b71206888 Initial import
thib
parents:
diff changeset
1611 btn_scale->SetValue(0);
223b71206888 Initial import
thib
parents:
diff changeset
1612 btn_scale->change_func = &ChangeBtnScale;
223b71206888 Initial import
thib
parents:
diff changeset
1613 btn_scale->change_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1614
223b71206888 Initial import
thib
parents:
diff changeset
1615 menu->PicNode()->show_all();
223b71206888 Initial import
thib
parents:
diff changeset
1616 }
223b71206888 Initial import
thib
parents:
diff changeset
1617
223b71206888 Initial import
thib
parents:
diff changeset
1618 void LoadMenu::InitTitle(const SaveTitle& title_op) {
223b71206888 Initial import
thib
parents:
diff changeset
1619 title.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1620 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1621 for (i=1; i<=100; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1622 char buf[100];
223b71206888 Initial import
thib
parents:
diff changeset
1623 sprintf(buf,"%2d:",i);
223b71206888 Initial import
thib
parents:
diff changeset
1624 string t = title_op(i);
223b71206888 Initial import
thib
parents:
diff changeset
1625 string s = string(buf) + t;
223b71206888 Initial import
thib
parents:
diff changeset
1626 if (t.length() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1627 string s = string(buf) + "--------";
223b71206888 Initial import
thib
parents:
diff changeset
1628 title_valid.push_back(0);
223b71206888 Initial import
thib
parents:
diff changeset
1629 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1630 title_valid.push_back(1);
223b71206888 Initial import
thib
parents:
diff changeset
1631 }
223b71206888 Initial import
thib
parents:
diff changeset
1632 title.push_back(s);
223b71206888 Initial import
thib
parents:
diff changeset
1633 }
223b71206888 Initial import
thib
parents:
diff changeset
1634 if (btn_local==0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1635 for (i=0; i<10; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1636 TextButton* button = dynamic_cast<TextButton*>(btn_local->item[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1637 if (button) button->SetText(title[i].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1638 }
223b71206888 Initial import
thib
parents:
diff changeset
1639 }
223b71206888 Initial import
thib
parents:
diff changeset
1640
223b71206888 Initial import
thib
parents:
diff changeset
1641 void LoadMenu::SetPage(int new_page) {
223b71206888 Initial import
thib
parents:
diff changeset
1642 if (new_page < 0) new_page = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1643 if (new_page > 900) new_page = 900;
223b71206888 Initial import
thib
parents:
diff changeset
1644 if (select_page == new_page) return;
223b71206888 Initial import
thib
parents:
diff changeset
1645 if (in_setpage) return;
223b71206888 Initial import
thib
parents:
diff changeset
1646 in_setpage = true;
223b71206888 Initial import
thib
parents:
diff changeset
1647
223b71206888 Initial import
thib
parents:
diff changeset
1648 int prev_page = select_page / 10;
223b71206888 Initial import
thib
parents:
diff changeset
1649 int cur_page = new_page / 10;
223b71206888 Initial import
thib
parents:
diff changeset
1650 int prev_point = select_page%10;
223b71206888 Initial import
thib
parents:
diff changeset
1651 int new_point = new_page%10;
223b71206888 Initial import
thib
parents:
diff changeset
1652 select_page = new_page;
223b71206888 Initial import
thib
parents:
diff changeset
1653 if (prev_page != cur_page) {
223b71206888 Initial import
thib
parents:
diff changeset
1654 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1655 for (i=0; i<12; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1656 TextButton* button = dynamic_cast<TextButton*>(btn_local->item[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1657 if (button) {
223b71206888 Initial import
thib
parents:
diff changeset
1658 if (cur_page+i < title.size()) button->SetText(title[cur_page+i].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
1659 else button->SetText("----");
223b71206888 Initial import
thib
parents:
diff changeset
1660 }
223b71206888 Initial import
thib
parents:
diff changeset
1661 }
223b71206888 Initial import
thib
parents:
diff changeset
1662 // ボタンの内容を変更する
223b71206888 Initial import
thib
parents:
diff changeset
1663 if (select_value < cur_page || select_value > cur_page+12)
223b71206888 Initial import
thib
parents:
diff changeset
1664 btn_local->SetValue(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1665 else
223b71206888 Initial import
thib
parents:
diff changeset
1666 btn_local->SetValue(select_value - cur_page);
223b71206888 Initial import
thib
parents:
diff changeset
1667 }
223b71206888 Initial import
thib
parents:
diff changeset
1668 if (prev_point != new_point) {
223b71206888 Initial import
thib
parents:
diff changeset
1669 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1670 for (i=0; i<12; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1671 int old_x = btn_local->item[i]->Pic()->PosX();
223b71206888 Initial import
thib
parents:
diff changeset
1672 btn_local->item[i]->Pic()->Move(old_x, i*30-new_point*3);
223b71206888 Initial import
thib
parents:
diff changeset
1673 }
223b71206888 Initial import
thib
parents:
diff changeset
1674 }
223b71206888 Initial import
thib
parents:
diff changeset
1675 if (btn_page) {
223b71206888 Initial import
thib
parents:
diff changeset
1676 if (select_page%100 == 0) btn_page->SetValue(select_page/100);
223b71206888 Initial import
thib
parents:
diff changeset
1677 else btn_page->SetValue(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1678 }
223b71206888 Initial import
thib
parents:
diff changeset
1679 if (btn_scale) {
223b71206888 Initial import
thib
parents:
diff changeset
1680 btn_scale->SetValue(select_page);
223b71206888 Initial import
thib
parents:
diff changeset
1681 }
223b71206888 Initial import
thib
parents:
diff changeset
1682 in_setpage = false;
223b71206888 Initial import
thib
parents:
diff changeset
1683 return;
223b71206888 Initial import
thib
parents:
diff changeset
1684 }
223b71206888 Initial import
thib
parents:
diff changeset
1685 void LoadMenu::SetValue(int new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
1686 if (in_setpage) return;
223b71206888 Initial import
thib
parents:
diff changeset
1687 in_setpage = true;
223b71206888 Initial import
thib
parents:
diff changeset
1688
223b71206888 Initial import
thib
parents:
diff changeset
1689 if (new_value < 0 || new_value > title.size() ||
223b71206888 Initial import
thib
parents:
diff changeset
1690 (interface.type == Scn2kMenu::MENU_LOAD && title_valid[new_value] == 0) ) { // 無効な選択肢
223b71206888 Initial import
thib
parents:
diff changeset
1691 if (select_value < select_page/10 || select_value > select_page/10+12)
223b71206888 Initial import
thib
parents:
diff changeset
1692 btn_local->SetValue(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1693 else
223b71206888 Initial import
thib
parents:
diff changeset
1694 btn_local->SetValue(select_value-select_page/10);
223b71206888 Initial import
thib
parents:
diff changeset
1695 } else { // 選択肢を変更する
223b71206888 Initial import
thib
parents:
diff changeset
1696 if (select_value == new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
1697 PressOk(); // ダブルクリック
223b71206888 Initial import
thib
parents:
diff changeset
1698 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1699 select_value = new_value;
223b71206888 Initial import
thib
parents:
diff changeset
1700 if (interface.type == Scn2kMenu::MENU_SAVE && title_valid[select_value] == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1701 PressOk(); // 新しいセーブデータなら無条件に選択
223b71206888 Initial import
thib
parents:
diff changeset
1702 }
223b71206888 Initial import
thib
parents:
diff changeset
1703 }
223b71206888 Initial import
thib
parents:
diff changeset
1704 }
223b71206888 Initial import
thib
parents:
diff changeset
1705
223b71206888 Initial import
thib
parents:
diff changeset
1706 in_setpage = false;
223b71206888 Initial import
thib
parents:
diff changeset
1707 return;
223b71206888 Initial import
thib
parents:
diff changeset
1708 }
223b71206888 Initial import
thib
parents:
diff changeset
1709 void LoadMenu::PressOk(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1710 if (select_value == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1711 btn_set->SetValue(-1); // なにもしない
223b71206888 Initial import
thib
parents:
diff changeset
1712 return;
223b71206888 Initial import
thib
parents:
diff changeset
1713 }
223b71206888 Initial import
thib
parents:
diff changeset
1714 menu->deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
1715 if (interface.type == Scn2kMenu::MENU_LOAD) {
223b71206888 Initial import
thib
parents:
diff changeset
1716 interface.cmd.cmd_type = CMD_LOAD;
223b71206888 Initial import
thib
parents:
diff changeset
1717 interface.cmd.args.push_back(VarInfo(select_value));
223b71206888 Initial import
thib
parents:
diff changeset
1718 awk_dialog = new Dialog(*pevent, pparent, "ファイルをロードしますか?", true);
223b71206888 Initial import
thib
parents:
diff changeset
1719 awk_dialog->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1720 awk_dialog->set_func = ChangeDialog;
223b71206888 Initial import
thib
parents:
diff changeset
1721 } else {// MENU_SAVE
223b71206888 Initial import
thib
parents:
diff changeset
1722 interface.cmd.cmd_type = CMD_SAVE;
223b71206888 Initial import
thib
parents:
diff changeset
1723 interface.cmd.args.push_back(VarInfo(select_value));
223b71206888 Initial import
thib
parents:
diff changeset
1724 if (title_valid[select_value] == 0) { // 新しいセーブデータ
223b71206888 Initial import
thib
parents:
diff changeset
1725 interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_CMD | Scn2kMenu::MENU_DELETE);
223b71206888 Initial import
thib
parents:
diff changeset
1726 } else { // セーブデータを上書き:確認
223b71206888 Initial import
thib
parents:
diff changeset
1727 awk_dialog = new Dialog(*pevent, pparent, "データを上書きしますか?", true);
223b71206888 Initial import
thib
parents:
diff changeset
1728 awk_dialog->set_pointer = this;
223b71206888 Initial import
thib
parents:
diff changeset
1729 awk_dialog->set_func = ChangeDialog;
223b71206888 Initial import
thib
parents:
diff changeset
1730 }
223b71206888 Initial import
thib
parents:
diff changeset
1731 }
223b71206888 Initial import
thib
parents:
diff changeset
1732 }
223b71206888 Initial import
thib
parents:
diff changeset
1733 void LoadMenu::Cancel(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1734 if (awk_dialog) { // ダイアログのキャンセル
223b71206888 Initial import
thib
parents:
diff changeset
1735 awk_dialog->status = Dialog::CANCEL;
223b71206888 Initial import
thib
parents:
diff changeset
1736 ChangeDialog(this, awk_dialog);
223b71206888 Initial import
thib
parents:
diff changeset
1737 } else { // 一般キャンセル
223b71206888 Initial import
thib
parents:
diff changeset
1738 btn_set->SetValue(1);
223b71206888 Initial import
thib
parents:
diff changeset
1739 }
223b71206888 Initial import
thib
parents:
diff changeset
1740 }
223b71206888 Initial import
thib
parents:
diff changeset
1741 void LoadMenu::Exec(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1742 }
223b71206888 Initial import
thib
parents:
diff changeset
1743 void LoadMenu::ChangeBtnPage(void* pointer, MenuItem* widget) {
223b71206888 Initial import
thib
parents:
diff changeset
1744 LoadMenu* instance = (LoadMenu*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
1745 if (instance->btn_page_val == -1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1746 instance->SetPage(instance->btn_page_val*100);
223b71206888 Initial import
thib
parents:
diff changeset
1747 }
223b71206888 Initial import
thib
parents:
diff changeset
1748 void LoadMenu::ChangeBtnScale(void* pointer, Scale* from) {
223b71206888 Initial import
thib
parents:
diff changeset
1749 LoadMenu* instance = (LoadMenu*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
1750 int value = from->GetValue();
223b71206888 Initial import
thib
parents:
diff changeset
1751 instance->SetPage(value);
223b71206888 Initial import
thib
parents:
diff changeset
1752 }
223b71206888 Initial import
thib
parents:
diff changeset
1753 void LoadMenu::ChangeBtnSet(void* pointer, MenuItem* widget) {
223b71206888 Initial import
thib
parents:
diff changeset
1754 LoadMenu* instance = (LoadMenu*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
1755 if (instance->btn_set_val == 1) { // cancel
223b71206888 Initial import
thib
parents:
diff changeset
1756 instance->interface.status = Scn2kMenu::MENU_DELETE;
223b71206888 Initial import
thib
parents:
diff changeset
1757 return;
223b71206888 Initial import
thib
parents:
diff changeset
1758 } else if (instance->btn_set_val == 0) { // OK
223b71206888 Initial import
thib
parents:
diff changeset
1759 instance->PressOk();
223b71206888 Initial import
thib
parents:
diff changeset
1760 }
223b71206888 Initial import
thib
parents:
diff changeset
1761 }
223b71206888 Initial import
thib
parents:
diff changeset
1762 void LoadMenu::ChangeDialog(void* pointer, Dialog* widget) {
223b71206888 Initial import
thib
parents:
diff changeset
1763 LoadMenu* instance = (LoadMenu*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
1764 if (widget->status == Dialog::CANCEL) {
223b71206888 Initial import
thib
parents:
diff changeset
1765 // ダイアログ消去、OK ボタン復帰
223b71206888 Initial import
thib
parents:
diff changeset
1766 delete instance->awk_dialog;
223b71206888 Initial import
thib
parents:
diff changeset
1767 instance->awk_dialog = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1768 instance->menu->activate();
223b71206888 Initial import
thib
parents:
diff changeset
1769 instance->btn_set->SetValue(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1770 return;
223b71206888 Initial import
thib
parents:
diff changeset
1771 } else if (widget->status == Dialog::OK) {
223b71206888 Initial import
thib
parents:
diff changeset
1772 instance->interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_CMD | Scn2kMenu::MENU_DELETE);
223b71206888 Initial import
thib
parents:
diff changeset
1773 return;
223b71206888 Initial import
thib
parents:
diff changeset
1774 }
223b71206888 Initial import
thib
parents:
diff changeset
1775 }
223b71206888 Initial import
thib
parents:
diff changeset
1776 void LoadMenu::ChangeBtnLocal(void* pointer, MenuItem* widget) {
223b71206888 Initial import
thib
parents:
diff changeset
1777 LoadMenu* instance = (LoadMenu*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
1778 if (instance->btn_local_val == -1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1779 instance->SetValue( (instance->select_page/10) + instance->btn_local_val);
223b71206888 Initial import
thib
parents:
diff changeset
1780 }
223b71206888 Initial import
thib
parents:
diff changeset
1781
223b71206888 Initial import
thib
parents:
diff changeset
1782 struct BacklogMenu : Scn2kMenuImpl {
223b71206888 Initial import
thib
parents:
diff changeset
1783 Scn2k& scn_impl;
223b71206888 Initial import
thib
parents:
diff changeset
1784 Text& text_exec;
223b71206888 Initial import
thib
parents:
diff changeset
1785 bool backlog_update;
223b71206888 Initial import
thib
parents:
diff changeset
1786 int backlog_cnt;
223b71206888 Initial import
thib
parents:
diff changeset
1787 BacklogMenu(Scn2kMenu& _interface, Scn2k& scn_impl, Text& text_exec);
223b71206888 Initial import
thib
parents:
diff changeset
1788 ~BacklogMenu();
223b71206888 Initial import
thib
parents:
diff changeset
1789 void InitPanel(Event::Container& event, PicContainer& parent);
223b71206888 Initial import
thib
parents:
diff changeset
1790 void InitTitle(const SaveTitle&);
223b71206888 Initial import
thib
parents:
diff changeset
1791 void Cancel(void);
223b71206888 Initial import
thib
parents:
diff changeset
1792 void Exec(Cmd& cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1793 };
223b71206888 Initial import
thib
parents:
diff changeset
1794 BacklogMenu::BacklogMenu(Scn2kMenu& _interface, Scn2k& _scn, Text& parent_text_exec) : Scn2kMenuImpl(_interface), scn_impl(_scn), text_exec(parent_text_exec) {
223b71206888 Initial import
thib
parents:
diff changeset
1795 backlog_cnt = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1796 backlog_update = false;
223b71206888 Initial import
thib
parents:
diff changeset
1797 }
223b71206888 Initial import
thib
parents:
diff changeset
1798 BacklogMenu::~BacklogMenu() {
223b71206888 Initial import
thib
parents:
diff changeset
1799 }
223b71206888 Initial import
thib
parents:
diff changeset
1800 void BacklogMenu::InitPanel(Event::Container& event, PicContainer& parent) {
223b71206888 Initial import
thib
parents:
diff changeset
1801 pevent = &event;
223b71206888 Initial import
thib
parents:
diff changeset
1802 }
223b71206888 Initial import
thib
parents:
diff changeset
1803
223b71206888 Initial import
thib
parents:
diff changeset
1804 void BacklogMenu::InitTitle(const SaveTitle& title_op) {
223b71206888 Initial import
thib
parents:
diff changeset
1805 }
223b71206888 Initial import
thib
parents:
diff changeset
1806 void BacklogMenu::Cancel(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1807 interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_DELETE);
223b71206888 Initial import
thib
parents:
diff changeset
1808 }
223b71206888 Initial import
thib
parents:
diff changeset
1809 void BacklogMenu::Exec(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1810 int command_direction = 0; // forward
223b71206888 Initial import
thib
parents:
diff changeset
1811 if (cmd.cmd_type == CMD_NOP) text_exec.Wait(0xffffffffUL, cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1812 if (cmd.cmd_type == CMD_BACKLOGREQ || pevent->presscount(MOUSE_UP)) {
223b71206888 Initial import
thib
parents:
diff changeset
1813 if (cmd.cmd_type == CMD_BACKLOGREQ) cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1814 backlog_cnt++;
223b71206888 Initial import
thib
parents:
diff changeset
1815 backlog_update = false;
223b71206888 Initial import
thib
parents:
diff changeset
1816 command_direction = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1817 }
223b71206888 Initial import
thib
parents:
diff changeset
1818 if (cmd.cmd_type == CMD_BACKLOGREQ_FWD || pevent->presscount(MOUSE_DOWN)) {
223b71206888 Initial import
thib
parents:
diff changeset
1819 if (cmd.cmd_type == CMD_BACKLOGREQ_FWD) cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1820 backlog_cnt--;
223b71206888 Initial import
thib
parents:
diff changeset
1821 backlog_update = false;
223b71206888 Initial import
thib
parents:
diff changeset
1822 if (backlog_cnt == -2 || (
223b71206888 Initial import
thib
parents:
diff changeset
1823 (backlog_cnt == -1 && text_exec.backlog_item.scn == -1 && text_exec.backlog_item.pos == -1)) ){
223b71206888 Initial import
thib
parents:
diff changeset
1824 Cancel();
223b71206888 Initial import
thib
parents:
diff changeset
1825 return;
223b71206888 Initial import
thib
parents:
diff changeset
1826 }
223b71206888 Initial import
thib
parents:
diff changeset
1827 command_direction = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1828 }
223b71206888 Initial import
thib
parents:
diff changeset
1829 if (cmd.cmd_type != CMD_NOP) return;
223b71206888 Initial import
thib
parents:
diff changeset
1830 if (backlog_update) return;
223b71206888 Initial import
thib
parents:
diff changeset
1831 // backlog を最新の状態に更新
223b71206888 Initial import
thib
parents:
diff changeset
1832 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1833 BacklogItem item;
223b71206888 Initial import
thib
parents:
diff changeset
1834
223b71206888 Initial import
thib
parents:
diff changeset
1835 retry:
223b71206888 Initial import
thib
parents:
diff changeset
1836 if (backlog_cnt < -1) backlog_cnt = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1837 if (backlog_cnt >= int(text_exec.backlog.size())) backlog_cnt = text_exec.backlog.size() - 1;
223b71206888 Initial import
thib
parents:
diff changeset
1838
223b71206888 Initial import
thib
parents:
diff changeset
1839 if (backlog_cnt == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1840 if (text_exec.backlog_item.scn == -1 && text_exec.backlog_item.pos == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1841 if (text_exec.backlog.size() == 0 || command_direction < 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1842 Cancel();
223b71206888 Initial import
thib
parents:
diff changeset
1843 return;
223b71206888 Initial import
thib
parents:
diff changeset
1844 }
223b71206888 Initial import
thib
parents:
diff changeset
1845 item = text_exec.backlog.back();
223b71206888 Initial import
thib
parents:
diff changeset
1846 backlog_cnt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1847 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1848 // item = text_exec.backlog.back();
223b71206888 Initial import
thib
parents:
diff changeset
1849 item = text_exec.backlog_item;
223b71206888 Initial import
thib
parents:
diff changeset
1850 }
223b71206888 Initial import
thib
parents:
diff changeset
1851 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1852 item = text_exec.backlog[text_exec.backlog.size()-1-backlog_cnt];
223b71206888 Initial import
thib
parents:
diff changeset
1853 }
223b71206888 Initial import
thib
parents:
diff changeset
1854 if (item.scn == BacklogItem::SaveSelect) { // select marker ; skip this item
223b71206888 Initial import
thib
parents:
diff changeset
1855 if (command_direction == 0) command_direction = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1856 backlog_cnt += command_direction;
223b71206888 Initial import
thib
parents:
diff changeset
1857 goto retry;
223b71206888 Initial import
thib
parents:
diff changeset
1858 }
223b71206888 Initial import
thib
parents:
diff changeset
1859 if (item.scn == 0 && item.pos == -1) ; // not read cmd
223b71206888 Initial import
thib
parents:
diff changeset
1860 else {
223b71206888 Initial import
thib
parents:
diff changeset
1861 scn_impl.ReadCmdAt(cmd, item.scn, item.pos);
223b71206888 Initial import
thib
parents:
diff changeset
1862 }
223b71206888 Initial import
thib
parents:
diff changeset
1863 text_exec.DrawBacklog(item, cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1864 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1865 backlog_update = true;
223b71206888 Initial import
thib
parents:
diff changeset
1866 }
223b71206888 Initial import
thib
parents:
diff changeset
1867
223b71206888 Initial import
thib
parents:
diff changeset
1868 /*******************************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
1869 **
223b71206888 Initial import
thib
parents:
diff changeset
1870 **
223b71206888 Initial import
thib
parents:
diff changeset
1871 */
223b71206888 Initial import
thib
parents:
diff changeset
1872
223b71206888 Initial import
thib
parents:
diff changeset
1873 Scn2kMenu::Scn2kMenu(MenuType _type, Scn2k& scn_impl, const Flags& flags, Text& text_exec, int system_version) :
223b71206888 Initial import
thib
parents:
diff changeset
1874 cmd(flags, system_version), type(_type) {
223b71206888 Initial import
thib
parents:
diff changeset
1875 pimpl = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1876 status = MENU_CONTINUE;
223b71206888 Initial import
thib
parents:
diff changeset
1877 switch(type) {
223b71206888 Initial import
thib
parents:
diff changeset
1878 case MENU_LOAD: pimpl = new LoadMenu(*this); break;
223b71206888 Initial import
thib
parents:
diff changeset
1879 case MENU_SAVE: pimpl = new LoadMenu(*this); break;
223b71206888 Initial import
thib
parents:
diff changeset
1880 case MENU_BACKLOG: pimpl = new BacklogMenu(*this, scn_impl, text_exec); break;
223b71206888 Initial import
thib
parents:
diff changeset
1881 }
223b71206888 Initial import
thib
parents:
diff changeset
1882 return;
223b71206888 Initial import
thib
parents:
diff changeset
1883 }
223b71206888 Initial import
thib
parents:
diff changeset
1884 Scn2kMenu::~Scn2kMenu() {
223b71206888 Initial import
thib
parents:
diff changeset
1885 if (pimpl) delete pimpl;
223b71206888 Initial import
thib
parents:
diff changeset
1886 pimpl = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1887 }
223b71206888 Initial import
thib
parents:
diff changeset
1888 void Scn2kMenu::InitPanel(Event::Container& event, PicContainer& parent) {
223b71206888 Initial import
thib
parents:
diff changeset
1889 if (pimpl) pimpl->InitPanel(event, parent);
223b71206888 Initial import
thib
parents:
diff changeset
1890 }
223b71206888 Initial import
thib
parents:
diff changeset
1891 void Scn2kMenu::InitTitle(const SaveTitle& t) {
223b71206888 Initial import
thib
parents:
diff changeset
1892 if (pimpl) pimpl->InitTitle(t);
223b71206888 Initial import
thib
parents:
diff changeset
1893 }
223b71206888 Initial import
thib
parents:
diff changeset
1894 void Scn2kMenu::Cancel(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1895 if (pimpl) pimpl->Cancel();
223b71206888 Initial import
thib
parents:
diff changeset
1896 }
223b71206888 Initial import
thib
parents:
diff changeset
1897 void Scn2kMenu::Exec(Cmd& ret_cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
1898 if (pimpl == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1899 pimpl->Exec(ret_cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1900 if (pimpl->pevent->presscount(MOUSE_RIGHT)) {
223b71206888 Initial import
thib
parents:
diff changeset
1901 Cancel();
223b71206888 Initial import
thib
parents:
diff changeset
1902 }
223b71206888 Initial import
thib
parents:
diff changeset
1903 if (status & MENU_CMD && cmd.cmd_type != CMD_NOP) {
223b71206888 Initial import
thib
parents:
diff changeset
1904 status = Scn2kMenu::MenuStatus(status & (~Scn2kMenu::MENU_CMD) );
223b71206888 Initial import
thib
parents:
diff changeset
1905 CmdSimplified tmp_cmd;
223b71206888 Initial import
thib
parents:
diff changeset
1906 char cmd_str[32768];
223b71206888 Initial import
thib
parents:
diff changeset
1907 char* tmp_cmd_str = cmd_str;
223b71206888 Initial import
thib
parents:
diff changeset
1908 cmd.write(tmp_cmd, tmp_cmd_str);
223b71206888 Initial import
thib
parents:
diff changeset
1909 ret_cmd.read(tmp_cmd);
223b71206888 Initial import
thib
parents:
diff changeset
1910 }
223b71206888 Initial import
thib
parents:
diff changeset
1911 }
223b71206888 Initial import
thib
parents:
diff changeset
1912 void Scn2kMenu::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1913 if (pimpl && pimpl->menu) pimpl->menu->activate();
223b71206888 Initial import
thib
parents:
diff changeset
1914 }
223b71206888 Initial import
thib
parents:
diff changeset
1915 void Scn2kMenu::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1916 if (pimpl && pimpl->menu) pimpl->menu->deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
1917 }
223b71206888 Initial import
thib
parents:
diff changeset
1918