/* FileClose: Handles user close request. */ void FileClose(HWND sheet, HWND control) { HWND page = (HWND)SendMessage(sheet, PSM_GETCURRENTPAGEHWND, 0, 0); int sel = IDYES; if (!control) SendMessage(page, AOKTS_Closing, 0, 0); if (scen.needsave()) { sel = MessageBox(sheet, "Do you want to save your changes?", "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } scen.reset(); *setts.ScenPath = '\0'; if (!control) SendMessage(page, AOKTS_Loading, 0, 0); SetSaveState(sheet, MF_ENABLED); SetWindowText(propdata.statusbar, "Scenario reset."); SendMessage(propdata.mapview, MAP_Reset, 0, 0); SetWindowText(sheet, szTitle); }
/* PropSheetProc: Handles special messages pertaining to the property sheet. Note: See PropSheetProc in the Platform SDK docs for parameters and notes. */ int CALLBACK PropSheetProc(HWND sheet, UINT msgid, LPARAM lParam) { switch (msgid) { case PSCB_PRECREATE: { DLGTEMPLATE *templ = (DLGTEMPLATE*)lParam; templ->cy += 5; //add a minimize box templ->style |= WS_MINIMIZEBOX; } break; case PSCB_INITIALIZED: { HWND tooltip; HICON icon; /* Add Menu. */ propdata.menu = LoadMenu(aokts, (LPCSTR)IDM_MAIN); SetMenu(sheet, propdata.menu); //SetSaveState(sheet, MF_GRAYED); scen.reset(); SendMessage(PropSheet_GetCurrentPageHwnd(sheet), AOKTS_Loading, 0, 0); MapView_Reset(propdata.mapview, true); /* Enable appropriate recent file items. */ UpdateRecentMenu(propdata.menu); /* Remove unused buttons. */ for (int i = 0; i < sizeof(PropSheetButtons) / sizeof(WORD); i++) { HWND hWnd = GetDlgItem(sheet, PropSheetButtons[i]); if (hWnd != NULL) { ShowWindow(hWnd, SW_HIDE); EnableWindow(hWnd, FALSE); } } /* Add a tooltip window */ tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "AOKTS Tooltip", WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, sheet, NULL, aokts, NULL); TooltipInit(tooltip); /* Set the big icon */ icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO)); Window_SetIcon(sheet, ICON_BIG, icon); if (setts.editall) { CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND | MF_CHECKED); } else { CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND); } } break; } return 0; }
/* FileOpen: Handles a request to open a file. (Either by menu or generated by the app.) Parameters: HWND sheet: Handle to the property sheet. bool ask: Should AOKTS ask the user which file? int recent: Optionally open from one of the recent file entries. (-1 to disable.) */ void FileOpen(HWND sheet, bool ask, int recent) { OPENFILENAME ofn; struct RecentFile *file = NULL; //the file info will be stored here one way or another char titleBuffer[100]; const char *filename; Game version = scen.game; HWND page = PropSheet_GetCurrentPageHwnd(sheet); //save the scenario if changes have been made (NOT FUNCTIONAL) if (scen.needsave()) { int sel = MessageBox(sheet, askSaveChanges, "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; } /* Using a recent file... */ if (recent >= 0) { ofn.Flags = 0; //make sure no random flags set file = setts.recent_first; /* Parse the linked list to find the one we want */ while (recent--) { if (file) file = file->next; else { MessageBox(sheet, "Warning: Recent File open failed.", "Open Warning", MB_ICONWARNING); } } strcpy(setts.ScenPath, file->path); version = (Game)file->game; } /* Prompt the user for a filename. */ else if (ask) { struct RecentFile *r_parse; char dir[_MAX_PATH]; strcpy(dir, setts.BasePath); strcat(dir, "Scenario"); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = sheet; //ofn.hInstance unused ofn.lpstrFilter = extOpen; ofn.lpstrCustomFilter = NULL; //user should not set custom filters ofn.lpstrFile = setts.ScenPath; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFileTitle = NULL; ofn.lpstrInitialDir = dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_NOCHANGEDIR; if (scen.header.header_type == HT_AOE2SCENARIO) { ofn.nFilterIndex = 1; ofn.lpstrDefExt = "aoe2scenario"; } else { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: case AOHD4: case AOF4: case AOHD6: case AOF6: ofn.nFilterIndex = 1; ofn.lpstrDefExt = "scx"; break; case SWGB: case SWGBCC: ofn.nFilterIndex = 2; ofn.lpstrDefExt = "scx"; break; } } if (!GetOpenFileName(&ofn)) return; switch (ofn.nFilterIndex) { case 1: version = AOC; printf_log("Selected %d, AOE 2.\n", ofn.nFilterIndex); break; case 2: version = SWGB; printf_log("Selected %d, Star Wars.\n", ofn.nFilterIndex); break; } /* Now check if selected file is already on recent list. */ r_parse = setts.recent_first; while (r_parse) { if (!strcmp(r_parse->path, setts.ScenPath)) { file = r_parse; break; } r_parse = r_parse->next; } } /* Open it! */ SendMessage(page, AOKTS_Closing, 0, 0); // set hourglass, might take more than 1ms HCURSOR previous = SetCursor(LoadCursor(NULL, IDC_WAIT)); scen.reset(); try { version = scen.open(setts.ScenPath, setts.TempPath, version); /* Handle recent file stuff */ if (!file) { file = setts.recent_getnext(); strcpy(file->path, setts.ScenPath); strcpy(file->display, PathFindFileName(setts.ScenPath)); file->game = (int)version; } setts.recent_push(file); UpdateRecentMenu(propdata.menu); SetCursor(previous); // for some reason this is always read only. on Wine at least //SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_GRAYED : MF_ENABLED); SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_ENABLED : MF_ENABLED); // set status bar text SetWindowTextW(propdata.statusbar, L"Scenario loaded successfully."); SendMessage(page, AOKTS_Loading, 0, 0); SendMessageW(propdata.mapview, MAP_Recreate, 0, 0); MapView_Reset(propdata.mapview, true); filename = getFilenameFromPath(setts.ScenPath); _snprintf(titleBuffer, sizeof(titleBuffer), "%s - %s", szTitle, filename); SetWindowText(sheet, titleBuffer); } catch (std::exception &ex) { // TODO: better atomic cursor handling? SetCursor(previous); // set status bar text SetWindowText(propdata.statusbar, ex.what()); // report error to user std::string desc = "Failed to open as "; desc.append(gameName(scen.game)); desc.append(" scenario file.\n"); switch (scen.game) { case AOC: desc.append("Try opening as a SWGB scx file instead\nusing File->Open\n"); break; case SWGB: desc.append("Try opening as a Conquerors scx file instead\nusing File->Open\n"); break; } desc.append("\nThe problem: "); desc.append(ex.what()); desc.append("\n\nIf the game is able to open the scenario,\nplease report this error. Thanks."); printf_log("User message: %s\n", desc.c_str()); MessageBox(sheet, desc.c_str(), "Scenario Load Error", MB_ICONWARNING); // unless it's a debug build, clear the bad data #ifndef _DEBUG scen.reset(); SendMessage(page, AOKTS_Closing, 0, 0); #endif /* Updates*/ SendMessage(page, AOKTS_Loading, 0, 0); _snprintf(titleBuffer, sizeof(titleBuffer), "%s", szTitle); SetWindowText(sheet, titleBuffer); } //report errors to logfile fflush(stdout); }