--- trunk/RenegadeMapSelector/RenegadeMapSelector.cpp 2003/03/12 04:33:33 73 +++ trunk/RenegadeMapSelector/RenegadeMapSelector.cpp 2003/03/16 06:15:08 90 @@ -4,23 +4,32 @@ // // RenegadeMapSelector.cpp +#include "RenegadeMapSelector.h" +#include "RenegadeConfig.h" + #ifdef _WIN32 + #include #include #include "resource.h" -#endif -#include "RenegadeMapSelector.h" -#include "RenegadeConfig.h" +#else + +#include "MapSelector.h" + +#endif bool debug = false; string program; RenegadeConfig* config; #ifndef _WIN32 + inline string fix(const string& ansi) { return ansi; } inline void munge(void) { debug = true; } + #else + inline string fix(const wstring& wide) { char* buffer = new char[wide.length() + 1]; @@ -63,6 +72,7 @@ inline void munge(void) debug = true; } + #endif #ifdef _WIN32 @@ -74,8 +84,16 @@ int WINAPI WinMain(HINSTANCE hInstance, int argc; unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc); #else +void selector(void); + int main(int argc, char* argv[]) { + if (!gtk_init_check(&argc, &argv)) + { + cerr << argv[0] << ": Cannot open display, need a clue-by-four?\n"; + + return 1; + } #endif string error; @@ -103,10 +121,23 @@ int main(int argc, char* argv[]) #ifdef _WIN32 MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR); +#else + message(NULL, error, "Bad Arguments", GTK_MESSAGE_ERROR); #endif return 1; } } + else + { + error = "The argument " + arg + " is not a valid argument."; + +#ifdef _WIN32 + MessageBox(NULL, error.c_str(), "Unknown Arguments", MB_ICONWARNING + ); +#else + message(NULL, error, "Unknown Arguments", GTK_MESSAGE_WARNING); +#endif + } } #ifdef _WIN32 @@ -122,12 +153,16 @@ int main(int argc, char* argv[]) #ifdef _WIN32 MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR); +#else + message(NULL, error, "Bad File", GTK_MESSAGE_ERROR); #endif return 1; } #ifdef _WIN32 DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); +#else + MapSelector selector; #endif delete config; @@ -144,6 +179,7 @@ int main(int argc, char* argv[]) } #ifdef _WIN32 + int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -168,7 +204,7 @@ int CALLBACK selector(HWND hwndDlg, UINT GetCurrentDirectory(MAX_PATH + 1, directory); if (debug) cerr << "directory = " << directory << "\n"; - char* data = new char[MAX_PATH + 1]; + char* data = new char[strlen(directory) + 12]; sprintf(data, "%s\\data\\*.mix", directory); delete [] directory; if (debug) cerr << "data = " << data << "\n"; @@ -195,7 +231,7 @@ int CALLBACK selector(HWND hwndDlg, UINT if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0) { MessageBox(hwndDlg, "You need at least one map.", "No Maps", - MB_ICONEXCLAMATION); + MB_ICONINFORMATION); return false; } @@ -285,10 +321,107 @@ int CALLBACK selector(HWND hwndDlg, UINT } break; case IDC_UP_MAP: - cout << "STUB: up\a\n"; + { + unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSELCOUNT, 0, 0); + unsigned* ups = new unsigned[count]; + + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, + count, long(ups)); + + unsigned insert = ups[0] - 1; + + if (debug) cerr << "ups = {\n"; + for (unsigned index = 0; index < count; index++) + { + if (debug) cerr << " [" << index << "] = " << ups[index] + << "\n"; + + char* up = new char[SendMessage(GetDlgItem(hwndDlg, + IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1]; + + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, + ups[index], long(up)); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_DELETESTRING, ups[index], 0); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_INSERTSTRING, insert, long(up)); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, + true, insert++); + } + if (debug) cerr << "}\n"; + + delete [] ups; + + if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSEL, 0, 0) == 0) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); + } + else + { + EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); + } + + if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED + ), LB_GETCOUNT, 0, 0) - 1, 0) == 0) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); + } + } break; case IDC_DOWN_MAP: - cout << "STUB: down\a\n"; + { + unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSELCOUNT, 0, 0); + unsigned* downs = new unsigned[count]; + + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, + count, long(downs)); + + unsigned insert = downs[count - 1] + 1; + + if (debug) cerr << "downs = {\n"; + for (unsigned index = count; index > 0; index--) + { + if (debug) cerr << " [" << index << "] = " << downs[index + - 1] << "\n"; + + char* down = new char[SendMessage(GetDlgItem(hwndDlg, + IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) + + 1]; + + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, + downs[index - 1], long(down)); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_DELETESTRING, downs[index - 1], 0); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_INSERTSTRING, insert, long(down)); + SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, + true, insert--); + } + if (debug) cerr << "}\n"; + + delete [] downs; + + if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSEL, 0, 0) == 0) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); + } + + if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), + LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED + ), LB_GETCOUNT, 0, 0) - 1, 0) == 0) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); + } + else + { + EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); + } + } break; case IDC_AVAILABLE: switch (HIWORD(wParam)) @@ -351,4 +484,5 @@ int CALLBACK selector(HWND hwndDlg, UINT return false; } + #endif