Commit d8cd4364 authored by 247321453's avatar 247321453

opt code

parent 3ee3c4d1
...@@ -9,19 +9,32 @@ bool exit_on_return = false; ...@@ -9,19 +9,32 @@ bool exit_on_return = false;
bool bot_mode = false; bool bot_mode = false;
void ClickButton(irr::gui::IGUIElement* btn) { void ClickButton(irr::gui::IGUIElement* btn) {
irr::SEvent event; irr::SEvent event{};
event.EventType = irr::EET_GUI_EVENT; event.EventType = irr::EET_GUI_EVENT;
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED; event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
event.GUIEvent.Caller = btn; event.GUIEvent.Caller = btn;
ygo::mainGame->device->postEventFromUser(event); ygo::mainGame->device->postEventFromUser(event);
} }
char* sub_string(const char* str, int start, int count=-1){
char* tmp = new char[1024];
int len = strlen(str);
int index = 0;
if(count < 0){
count = len - start;
}
for (int j = start; j < len && count > 0; count--, j++) {
tmp[index++] = str[j];
}
tmp[index] = '\0';
return tmp;
}
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t* target){
int count = listbox->getItemCount(); int count = listbox->getItemCount();
for(int i = 0; i < count; i++){ for(int i = 0; i < count; i++){
auto item = listbox->getListItem(i); auto item = listbox->getListItem(i);
if(wcscmp(item, target)){ if(wcscmp(item, target) == 0){
return i; return i;
} }
} }
...@@ -55,15 +68,20 @@ int main(int argc, char* argv[]) { ...@@ -55,15 +68,20 @@ int main(int argc, char* argv[]) {
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
//android //android
for(int i = 0; i < argc; ++i) { for(int i = 0; i < argc; ++i) {
char* arg = argv[i].c_str(); const char* arg = argv[i].c_str();
#else #else
//pc的第一个是exe的路径 //pc的第一个是exe的路径
for(int i = 1; i < argc; ++i) { for(int i = 1; i < argc; ++i) {
char* arg = argv[i]; char* arg = argv[i];
#endif #endif
if(arg[0] == '-' && arg[1] == 'e') { if (arg[0] == '-' && arg[1] == 'e') {
ygo::dataManager.LoadDB(&arg[2]); wchar_t fname[1024];
} else if(!strcmp(arv, "-k")) { // Keep on return char* tmp = sub_string(arg, 2);
BufferIO::DecodeUTF8(tmp, fname);
__android_log_print(ANDROID_LOG_INFO, "ygo", "load cdb=%s", tmp);
ygo::dataManager.LoadDB(fname);
delete tmp;
} else if(!strcmp(arg, "-k")) { // Keep on return
exit_on_return = false; exit_on_return = false;
keep_on_return = true; keep_on_return = true;
} else if(!strcmp(arg, "-c")) { // Create host } else if(!strcmp(arg, "-c")) { // Create host
...@@ -81,7 +99,7 @@ int main(int argc, char* argv[]) { ...@@ -81,7 +99,7 @@ int main(int argc, char* argv[]) {
int index = 0; int index = 0;
if((i+1) < argc){//下一个参数是录像名 if((i+1) < argc){//下一个参数是录像名
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
char* name = argv[i+1].c_str(); const char* name = argv[i+1].c_str();
#else #else
char* name = argv[i+1]; char* name = argv[i+1];
#endif #endif
...@@ -91,6 +109,7 @@ int main(int argc, char* argv[]) { ...@@ -91,6 +109,7 @@ int main(int argc, char* argv[]) {
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname); index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
if(open_file){ if(open_file){
ygo::mainGame->lstReplayList->setSelected(index); ygo::mainGame->lstReplayList->setSelected(index);
...@@ -103,7 +122,7 @@ int main(int argc, char* argv[]) { ...@@ -103,7 +122,7 @@ int main(int argc, char* argv[]) {
int index = 0; int index = 0;
if((i+1) < argc){//下一个参数是文件名 if((i+1) < argc){//下一个参数是文件名
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
char* name = argv[i+1].c_str(); const char* name = argv[i+1].c_str();
#else #else
char* name = argv[i+1]; char* name = argv[i+1];
#endif #endif
...@@ -113,6 +132,7 @@ int main(int argc, char* argv[]) { ...@@ -113,6 +132,7 @@ int main(int argc, char* argv[]) {
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname); index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnSingleMode); ClickButton(ygo::mainGame->btnSingleMode);
if(open_file){ if(open_file){
ygo::mainGame->lstSinglePlayList->setSelected(index); ygo::mainGame->lstSinglePlayList->setSelected(index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment