comparison scn2k/scn2k_text.cc @ 55:f1a27ee7e03c

* started the same changes on scn2k_text.cc * handle opcodes childObj*. In fact, it was handled (in a strange way, but it worked) before the previous changeset
author thib
date Wed, 22 Apr 2009 15:01:42 +0000
parents ddbcbd000206
children c7bcc0ec2267
comparison
equal deleted inserted replaced
54:d7cde171a1de 55:f1a27ee7e03c
161 } 161 }
162 } 162 }
163 } 163 }
164 }; 164 };
165 165
166 class TextImpl { 166 class TextImpl : public CommandHandler {
167 public:
168 TextWindow* text;
169 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
170 WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
171 WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
172 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
173 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
174 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
175 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
176 BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
177 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK)
178 } Status;
179 Status status, status_saved, status_mask;
180 private:
181 std::string ruby_text;
182 bool ruby_text_flag;
183 unsigned int wait_time;
184 unsigned int old_time;
185 unsigned int base_time;
186 int text_window_number;
187 bool text_parsing;
188 TextStream text_stream;
189 SkipMode skip_mode;
190 int save_selectcount;
191
192 std::map<int, TimerAtom> timer_var;
193 std::vector<WidTextButton*> selects;
194 std::vector<int> sel_backlog_pos;
195 string replace_name[26];
196 string replace_name2[26];
197 PicContainer* sel_widget;
198 PicWidget* backlog_widget;
199
200 vector<BacklogItem>& backlog;
201 BacklogItem& backlog_item;
202 BacklogItem cur_backlog_item;
203 BacklogItem drawn_backlog_item;
204
205 public:
206 PicContainer& parent;
207 Event::Container& event;
208 AyuSysConfig *config;
209 private:
210 TextWindow* widgets[32];
211 WidTimeCursor* kcursor;
212 Surface* sel_bg1;
213 Surface* sel_bg2;
214 Rect sel_bg_rect;
215
216 void SetCursor(int num);
217 VarInfo wait_savedvar[2];
218
219 public:
220 void AddText(const char* str);
221
222 static void PressFuncSkip(void* pointer, WidButton* from);
223 static void PressFuncLoad(void* pointer, WidButton* from);
224 static void PressFuncSave(void* pointer, WidButton* from);
225 static void PressFuncBacklog(void* pointer, WidButton* from);
226 static void PressFuncBacklogFwd(void* pointer, WidButton* from);
227 private:
228 static void PressFuncButton(void* pointer, WidButton* from);
229 static bool PressFunc(int x, int y, void* pointer);
230
231 public: 167 public:
232 TextImpl(Event::Container& _event, PicContainer& _parent, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item); 168 TextImpl(Event::Container& _event, PicContainer& _parent, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item);
233 ~TextImpl(); 169 ~TextImpl();
234 void InitWindow(void); 170 void InitWindow(void);
235 void SetWindowColor(int r, int g, int b, int a, bool is_transparent); 171 void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
244 void DrawBacklog(BacklogItem& item, Cmd& cmd); 180 void DrawBacklog(BacklogItem& item, Cmd& cmd);
245 void Save(std::string& str, bool select_save); 181 void Save(std::string& str, bool select_save);
246 void Load(const char* str); 182 void Load(const char* str);
247 void SetSkipMode(SkipMode _mode); 183 void SetSkipMode(SkipMode _mode);
248 void CreateSelBG(void); 184 void CreateSelBG(void);
185
186 void AddText(const char* str);
187
188 static void PressFuncSkip(void* pointer, WidButton* from);
189 static void PressFuncLoad(void* pointer, WidButton* from);
190 static void PressFuncSave(void* pointer, WidButton* from);
191 static void PressFuncBacklog(void* pointer, WidButton* from);
192 static void PressFuncBacklogFwd(void* pointer, WidButton* from);
193
194 private:
195 static void PressFuncButton(void* pointer, WidButton* from);
196 static bool PressFunc(int x, int y, void* pointer);
197 void SetCursor(int num);
198
199 public:
200 TextWindow* text;
201 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
202 WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
203 WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
204 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
205 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
206 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
207 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
208 BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
209 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK |
210 LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD |
211 BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK |
212 CLEARSCR_WAIT_MASK | SKIPEND_MASK)
213 } Status;
214 Status status, status_saved, status_mask;
215
216 private:
217 std::string ruby_text;
218 bool ruby_text_flag;
219 unsigned int wait_time;
220 unsigned int old_time;
221 unsigned int base_time;
222 int text_window_number;
223 bool text_parsing;
224 TextStream text_stream;
225 SkipMode skip_mode;
226 int save_selectcount;
227
228 std::map<int, TimerAtom> timer_var;
229 std::vector<WidTextButton*> selects;
230 std::vector<int> sel_backlog_pos;
231 string replace_name[26];
232 string replace_name2[26];
233 PicContainer* sel_widget;
234 PicWidget* backlog_widget;
235
236 vector<BacklogItem>& backlog;
237 BacklogItem& backlog_item;
238 BacklogItem cur_backlog_item;
239 BacklogItem drawn_backlog_item;
240
241 TextWindow* widgets[32];
242 WidTimeCursor* kcursor;
243 Surface* sel_bg1;
244 Surface* sel_bg2;
245 Rect sel_bg_rect;
246
247 VarInfo wait_savedvar[2];
248
249 AyuSysConfig *config;
250
251 Event::Container& event;
252 PicContainer& parent;
253
254 //Opcode handling
255 void impl_txtClear(Cmd& cmd);
256 void impl_logKoe(Cmd& cmd);
257 void impl_pause(Cmd& cmd);
258 void impl_br(Cmd& cmd);
259 void impl_FaceOpen(Cmd& cmd);
260 void impl_FaceClear(Cmd& cmd);
249 }; 261 };
250 262
251 /**************************************************************:: 263 /**************************************************************::
252 ** 264 **
253 ** TextImpl(implementation) 265 ** TextImpl(implementation)
262 for (i=0; i<32; i++) { 274 for (i=0; i<32; i++) {
263 widgets[i] = 0; 275 widgets[i] = 0;
264 } 276 }
265 text_stream.kanji_type = TextStream::sjis; 277 text_stream.kanji_type = TextStream::sjis;
266 event.RegisterGlobalPressFunc(&PressFunc, (void*)this); 278 event.RegisterGlobalPressFunc(&PressFunc, (void*)this);
279
280 RegisterCommand(1, 33, 73, "grpOpenBg", (CmdImpl) &TextImpl::impl_txtClear);
281 RegisterCommand(1, 33, 75, "grpMulti", (CmdImpl) &TextImpl::impl_txtClear);
282 RegisterCommand(1, 33, 76, "grpOpen", (CmdImpl) &TextImpl::impl_txtClear);
283
284 RegisterCommand(1, 23, 0, "koePlay", (CmdImpl) &TextImpl::impl_logKoe);
285 RegisterCommand(1, 23, 8, "koeDoPlay", (CmdImpl) &TextImpl::impl_logKoe);
286
287 RegisterCommand(0, 3, 151, "msgHide", (CmdImpl) &TextImpl::impl_txtClear);
288 RegisterCommand(0, 3, 17, "pause", (CmdImpl) &TextImpl::impl_pause);
289 RegisterCommand(0, 3, 3, "par", (CmdImpl) &TextImpl::impl_br); //FIXME
290 RegisterCommand(0, 3, 201, "br", (CmdImpl) &TextImpl::impl_br);
291 RegisterCommand(0, 3, 1000, "FaceOpen", (CmdImpl) &TextImpl::impl_FaceOpen);
292 RegisterCommand(0, 3, 1001, "FaceClear", (CmdImpl) &TextImpl::impl_FaceClear);
267 } 293 }
268 294
269 TextImpl::~TextImpl() { 295 TextImpl::~TextImpl() {
270 if (sel_widget) delete sel_widget; 296 if (sel_widget) delete sel_widget;
271 int i; 297 int i;
862 } else if (*s < 0 && s[1] != 0) s++; 888 } else if (*s < 0 && s[1] != 0) s++;
863 } 889 }
864 text_stream.Add(str_top); 890 text_stream.Add(str_top);
865 } 891 }
866 892
893 void TextImpl::impl_txtClear(Cmd& cmd) {
894 if (text != NULL) {
895 text->ResetFace();
896 if (cmd.cmd2 == 3 && cmd.cmd3 == 151)
897 text->wid->Clear();
898 }
899 cur_backlog_item.face = "";
900 if (cmd.cmd2 == 3 && cmd.cmd3 == 151)
901 text_stream.Clear();
902 hide();
903 }
904
905 void TextImpl::impl_logKoe(Cmd& cmd) {
906 // PlayKoe ; 声出力コマンドをチェックする */
907 cur_backlog_item.koe = cmd.args[0].value;
908 }
909
910 void TextImpl::impl_pause(Cmd& cmd) {
911 if (text != NULL) {
912 eprintf("start\n");
913 text->StartText(text_stream);
914 if (skip_mode & SKIP_TEXT) text->wid->Flush();
915 else if (kcursor) kcursor->show();
916 status = WAIT_TEXT;
917 text_parsing = false;
918 }
919 backlog_item = cur_backlog_item;
920 if (cur_backlog_item.scn == 0 && cur_backlog_item.pos == -1) backlog_item.text = text_stream;
921 cur_backlog_item.Clear();
922
923 cmd.clear();
924 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため)
925 }
926
927 void TextImpl::impl_br(Cmd& cmd) {
928 text_stream.AddReturn();
929 cur_backlog_item.DeleteTextPos();
930 cmd.clear();
931 }
932
933 void TextImpl::impl_FaceOpen(Cmd& cmd) {
934 if (text == NULL)
935 show();
936 string s = cmd.Str(cmd.args[0]);
937 s += ".g00";
938 if (text != NULL)
939 text->ShowFace(s.c_str());
940 cur_backlog_item.face = s;
941 cmd.cmd_type = CMD_SAVECMD_ONCE;
942 }
943
944 void TextImpl::impl_FaceClear(Cmd& cmd) {
945 if (text == NULL)
946 show();
947 if (text)
948 text->ResetFace();
949 cur_backlog_item.face = "";
950 cmd.cmd_type = CMD_SAVECMD_ONCE;
951 }
952
867 void TextImpl::Exec(Cmd& cmd) { 953 void TextImpl::Exec(Cmd& cmd) {
868 if (cmd.cmd_type == CMD_TEXT) { 954 if (cmd.cmd_type == CMD_TEXT) {
869 if (text == NULL) { 955 if (text == NULL) {
870 show(); 956 show();
871 } 957 }
886 else 972 else
887 cmd.cmd_type = CMD_SAVEPOINT; 973 cmd.cmd_type = CMD_SAVEPOINT;
888 text_parsing = true; /* テキスト待ち直後のテキスト位置=セーブ位置 */ 974 text_parsing = true; /* テキスト待ち直後のテキスト位置=セーブ位置 */
889 return; 975 return;
890 } 976 }
977
891 if (cmd.cmd_type != CMD_OTHER) return; 978 if (cmd.cmd_type != CMD_OTHER) return;
892 /* テキストウィンドウを消去するコマンド類をチェックする */ 979
893 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x21) { 980 CommandHandler::Exec(cmd);
894 if (cmd.cmd3 == 0x49 || cmd.cmd3 == 0x4b || cmd.cmd3 == 0x4c) { 981
895 if (text) text->ResetFace();
896 cur_backlog_item.face = "";
897 hide();
898 }
899 }
900 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x17 && cmd.cmd3 == 0 && cmd.cmd4 == 1) {
901 // PlayKoe ; 声出力コマンドをチェックする */
902 cur_backlog_item.koe = cmd.args[0].value;
903 }
904 if (cmd.cmd1 == 0 && cmd.cmd2 == 3 && cmd.cmd3 == 0x97) { // いいのかなー
905
906 if (text) {
907 text->ResetFace();
908 text->wid->Clear();
909 }
910 cur_backlog_item.face = "";
911 text_stream.Clear();
912 hide();
913 }
914 if (cmd.cmd1 == 0 && cmd.cmd2 == 3) { 982 if (cmd.cmd1 == 0 && cmd.cmd2 == 3) {
915 if (cmd.cmd3 == 0x11) { // テキスト表示、クリック待ち 983 if (cmd.cmd3 == 0x78) { // ルビ関連
916 if (text) {
917 eprintf("start\n");
918 text->StartText(text_stream);
919 if (skip_mode & SKIP_TEXT) text->wid->Flush();
920 else if (kcursor) kcursor->show();
921 status = WAIT_TEXT;
922 text_parsing = false;
923 }
924 backlog_item = cur_backlog_item;
925 if (cur_backlog_item.scn == 0 && cur_backlog_item.pos == -1) backlog_item.text = text_stream;
926 cur_backlog_item.Clear();
927
928 cmd.clear();
929 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため)
930 // これだと1フレーム1テキストしか表示されなくなるので注意
931 } else if (cmd.cmd3 == 3 || cmd.cmd3 == 0xc9) { // リターン挿入
932 text_stream.AddReturn();
933 cur_backlog_item.DeleteTextPos();
934 cmd.clear();
935 } else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更
936 if (text == NULL) {
937 show();
938 }
939 if (cmd.cmd3 == 0x3e8) {
940 string s = cmd.Str(cmd.args[0]);
941 s += ".g00";
942 if (text) text->ShowFace(s.c_str());
943 cur_backlog_item.face = s;
944 cmd.cmd_type = CMD_SAVECMD_ONCE;
945 } else if (cmd.cmd3 == 0x3e9) { // 顔グラフィック消去
946 if (text) text->ResetFace();
947 cur_backlog_item.face = "";
948 cmd.cmd_type = CMD_SAVECMD_ONCE;
949 }
950 } else if (cmd.cmd3 == 0x78) { // ルビ関連
951 if (text == NULL) { 984 if (text == NULL) {
952 show(); 985 show();
953 } 986 }
954 if (cmd.cmd4 == 1) { 987 if (cmd.cmd4 == 1) {
955 ruby_text_flag = true; 988 ruby_text_flag = true;