mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Initial 'Load file' map support for Windows
'Load file' opens a file dialog allowing you to load maps from anywhere on disc
This commit is contained in:
parent
f1b2de34d4
commit
f7561ebb2a
10
src/Menus.c
10
src/Menus.c
@ -384,7 +384,7 @@ static void ListScreen_ContextRecreated(void* screen) {
|
||||
ListScreen_UpdatePage(s);
|
||||
|
||||
if (!s->UploadClick) return;
|
||||
ButtonWidget_SetConst(&s->upload, "Upload", &s->font);
|
||||
ButtonWidget_SetConst(&s->upload, Input_TouchMode ? "Upload" : "Load file...", &s->font);
|
||||
}
|
||||
|
||||
static void ListScreen_Reload(struct ListScreen* s) {
|
||||
@ -1764,14 +1764,12 @@ static void LoadLevelScreen_LoadEntries(struct ListScreen* s) {
|
||||
StringsBuffer_Sort(&s->entries);
|
||||
}
|
||||
|
||||
#ifdef CC_BUILD_WEB
|
||||
static void LoadLevelScreen_UploadCallback(const cc_string* path) { Map_LoadFrom(path); }
|
||||
static void LoadLevelScreen_UploadFunc(void* s, void* w) {
|
||||
Window_OpenFileDialog(".cw", LoadLevelScreen_UploadCallback);
|
||||
Platform_LogConst("UPLOAD");
|
||||
cc_result res = Window_OpenFileDialog(".cw", LoadLevelScreen_UploadCallback);
|
||||
if (res) Logger_SimpleWarn(res, "showing open file dialog");
|
||||
}
|
||||
#else
|
||||
#define LoadLevelScreen_UploadFunc NULL
|
||||
#endif
|
||||
|
||||
void LoadLevelScreen_Show(void) {
|
||||
struct ListScreen* s = &ListScreen;
|
||||
|
@ -363,6 +363,10 @@ static void ShowDialogCore(const char* title, const char* msg) {
|
||||
(*env)->DeleteLocalRef(env, args[1].l);
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static struct Bitmap fb_bmp;
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
|
||||
|
@ -607,6 +607,10 @@ static void ShowDialogCore(const char* title, const char* msg) {
|
||||
showingDialog = false;
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static CGrafPtr fb_port;
|
||||
static struct Bitmap fb_bmp;
|
||||
static CGColorSpaceRef colorSpace;
|
||||
|
@ -272,6 +272,10 @@ static void ShowDialogCore(const char* title, const char* msg) {
|
||||
SDL_ShowSimpleMessageBox(0, title, msg, win_handle);
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static SDL_Surface* surface;
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||
surface = SDL_GetWindowSurface(win_handle);
|
||||
|
@ -549,7 +549,7 @@ cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callb
|
||||
uploadCallback = callback;
|
||||
/* Calls Window_OnFileUploaded on success */
|
||||
interop_OpenFileDialog(filter);
|
||||
return ERR_NOT_SUPPORTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) { }
|
||||
|
@ -22,6 +22,7 @@
|
||||
/* Hence the actual minimum supported OS is Windows 2000. This just avoids redeclaring structs. */
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
|
||||
/* https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpixelformat */
|
||||
#define CC_WIN_STYLE WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
|
||||
@ -136,7 +137,8 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
/* Set before position change, in case mouse buttons changed when outside window */
|
||||
Input_SetNonRepeatable(KEY_LMOUSE, wParam & 0x01);
|
||||
if (!(wParam & 0x01)) Input_SetReleased(KEY_LMOUSE);
|
||||
//Input_SetNonRepeatable(KEY_LMOUSE, wParam & 0x01);
|
||||
Input_SetNonRepeatable(KEY_RMOUSE, wParam & 0x02);
|
||||
Input_SetNonRepeatable(KEY_MMOUSE, wParam & 0x10);
|
||||
/* TODO: do we need to set XBUTTON1/XBUTTON2 here */
|
||||
@ -535,6 +537,31 @@ static void ShowDialogCore(const char* title, const char* msg) {
|
||||
MessageBoxA(win_handle, msg, title, 0);
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
cc_string path; char pathBuffer[MAX_PATH];
|
||||
WCHAR str[MAX_PATH] = { 0 };
|
||||
OPENFILENAMEW ofn = { 0 };
|
||||
int i;
|
||||
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = win_handle;
|
||||
ofn.lpstrFile = str;
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.lpstrFilter = L"All\0*.*\0CW files\0*.cw\0"; // TODO rethink
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
|
||||
|
||||
if (!GetOpenFileNameW(&ofn))
|
||||
return CommDlgExtendedError();
|
||||
String_InitArray(path, pathBuffer);
|
||||
|
||||
for (i = 0; i < MAX_PATH && str[i]; i++) {
|
||||
String_Append(&path, Convert_CodepointToCP437(str[i]));
|
||||
}
|
||||
callback(&path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HDC draw_DC;
|
||||
static HBITMAP draw_DIB;
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||
|
@ -966,6 +966,10 @@ static void ShowDialogCore(const char* title, const char* msg) {
|
||||
XFlush(m.dpy); /* flush so window disappears immediately */
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static GC fb_gc;
|
||||
static XImage* fb_image;
|
||||
static struct Bitmap fb_bmp;
|
||||
|
@ -507,6 +507,10 @@ void ShowDialogCore(const char* title, const char* msg) {
|
||||
CFRelease(msgCF);
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static struct Bitmap fb_bmp;
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
|
||||
|
@ -260,6 +260,10 @@ void Window_LockLandscapeOrientation(cc_bool lock) {
|
||||
[UIViewController attemptRotationToDeviceOrientation];
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const char* filter, OpenFileDialogCallback callback) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
/*#########################################################################################################################*
|
||||
*--------------------------------------------------------2D window--------------------------------------------------------*
|
||||
|
Loading…
x
Reference in New Issue
Block a user