30 #include "C4Version.h"
40 #define GetWideLPARAM(c) reinterpret_cast<LPARAM>(static_cast<wchar_t*>(GetWideChar(c)))
48 if (!console->
Active)
return false;
51 minfo.cbSize =
sizeof(minfo);
52 minfo.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA | MIIM_STATE;
53 minfo.fType = MFT_STRING;
56 minfo.dwTypeData = getMBufPtr<wchar_t>(td);
57 minfo.cch = wcslen(minfo.dwTypeData);
58 if (!fEnabled) minfo.fState|=MFS_GRAYED;
59 return !!InsertMenuItemW(hMenu,0,
false,&minfo);
141 HINSTANCE instance = application->GetInstance();
157 if (!console.
Active)
return;
187 RECT client_rc = { 0,0,252,101 }, button_rc = { 207,182,254,202 };
190 ::GetWindowRect(button, &button_rc);
201 RECT rc = { 0,0,0,0 };
210 SWP_NOOWNERZORDER | SWP_NOZORDER);
217 SWP_NOOWNERZORDER | SWP_NOZORDER);
219 ::SetWindowPos(::GetDlgItem(
hPropertyDlg, IDOK),
nullptr,
224 SWP_NOOWNERZORDER | SWP_NOZORDER);
232 RECT console_rc = { 0,0,356,252 };
238 RECT button_rc = { 288,180,350,200 };
242 RECT status_rc = { 222,205,350,223 };
252 RECT rc = { 0,0,0,0 };
264 SWP_NOOWNERZORDER | SWP_NOZORDER);
271 SWP_NOOWNERZORDER | SWP_NOZORDER);
278 SWP_NOOWNERZORDER | SWP_NOZORDER);
285 SWP_NOOWNERZORDER | SWP_NOZORDER);
292 SWP_NOOWNERZORDER | SWP_NOZORDER);
299 SWP_NOOWNERZORDER | SWP_NOZORDER);
306 SWP_NOOWNERZORDER | SWP_NOZORDER);
313 SWP_NOOWNERZORDER | SWP_NOZORDER);
320 SWP_NOOWNERZORDER | SWP_NOZORDER);
326 SWP_NOOWNERZORDER | SWP_NOZORDER);
332 SWP_NOOWNERZORDER | SWP_NOZORDER);
336 void C4ConsoleGUI::UpdateMenuText(HMENU hMenu) { state->
UpdateMenuText(*
this, hMenu); }
338 static void ClearDlg(HWND &handle)
341 DestroyWindow(handle);
345 INT_PTR CALLBACK
ConsoleDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
364 if (wParam == MCI_NOTIFY_SUCCESSFUL)
370 SendMessage(hDlg, DM_SETDEFID, (WPARAM)IDOK, (LPARAM)0);
371 Console.UpdateMenuText(GetMenu(hDlg));
376 switch (LOWORD(wParam))
381 wchar_t buffer[16000];
444 if (!plr)
return true;
458 if (
SEqual2((
const char *)lParam,
"IDS_"))
461 Log((
const char *)lParam);
466 COPYDATASTRUCT* pcds =
reinterpret_cast<COPYDATASTRUCT *
>(lParam);
470 const char *szPath =
reinterpret_cast<const char *
>(pcds->lpData);
471 if (szPath[pcds->cbData - 1])
break;
478 case WM_INPUTLANGCHANGE:
483 case WM_GETMINMAXINFO:
487 MINMAXINFO *info =
reinterpret_cast<MINMAXINFO *
>(lParam);
488 info->ptMinTrackSize.x =
Console.state->console_default_width;
489 info->ptMinTrackSize.y =
Console.state->console_default_height;
492 case WM_SIZING:
Console.state->ConsoleUpdateSize();
break;
493 case WM_WINDOWPOSCHANGED:
495 const WINDOWPOS *data =
reinterpret_cast<const WINDOWPOS *
>(lParam);
496 if (data && !(data->flags & SWP_NOSIZE))
Console.state->ConsoleUpdateSize();
508 friend INT_PTR CALLBACK
ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
584 #include <commctrl.h>
585 INT_PTR CALLBACK
ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
603 PostMessage(hDlg,WM_USER,0,0);
611 switch (LOWORD(wParam))
613 case SB_THUMBTRACK:
case SB_THUMBPOSITION:
614 iValue=HIWORD(wParam);
617 case SB_PAGEUP:
case SB_PAGEDOWN:
618 case SB_LINEUP:
case SB_LINEDOWN:
627 switch (LOWORD(wParam))
667 switch (HIWORD(wParam))
673 WORD idCombo = LOWORD(wParam);
674 int32_t cursel = SendDlgItemMessage(hDlg, idCombo, CB_GETCURSEL, 0, 0);
675 SendDlgItemMessage(hDlg, idCombo, CB_GETLBTEXT, cursel, (LPARAM)str);
678 const char *astr = str_buf.
getData();
712 SendMessage(hDlg,DM_SETDEFID,(WPARAM)IDOK,(LPARAM)0);
716 case WM_SIZING:
Console.state->PropertyDlgUpdateSize();
break;
717 case WM_WINDOWPOSCHANGED:
719 const WINDOWPOS *data =
reinterpret_cast<const WINDOWPOS *
>(lParam);
720 if (data && !(data->flags & SWP_NOSIZE))
Console.state->PropertyDlgUpdateSize();
726 switch (LOWORD(wParam))
731 wchar_t buffer[16000];
752 void C4ConsoleGUI::Win32KeepDialogsFloating(HWND hwnd)
756 if (
Console.state->hPropertyDlg)
757 SetWindowLongPtr(
Console.state->hPropertyDlg, GWLP_HWNDPARENT,
reinterpret_cast<LONG_PTR
>(hwnd));
759 SetWindowLongPtr(
Console.
ToolsDlg.state->hDialog, GWLP_HWNDPARENT,
reinterpret_cast<LONG_PTR
>(hwnd));
762 bool C4ConsoleGUI::Win32DialogMessageHandling(MSG *msg)
764 return (hWindow && IsDialogMessage(hWindow,msg)) || (
Console.state->hPropertyDlg && IsDialogMessage(
Console.state->hPropertyDlg,msg));
793 FORMAT_MESSAGE_ALLOCATE_BUFFER |
794 FORMAT_MESSAGE_FROM_SYSTEM |
795 FORMAT_MESSAGE_IGNORE_INSERTS,
799 (
wchar_t *)&lpMsgBuf,
813 SendMessage(hWindow,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(application->GetInstance(),MAKEINTRESOURCE(
IDI_00_C4X)));
814 SendMessage(hWindow,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(application->GetInstance(),MAKEINTRESOURCE(
IDI_00_C4X)));
824 ShowWindow(hWindow,SW_SHOWNORMAL);
825 UpdateWindow(hWindow);
847 EnableWindow( GetDlgItem(hWindow,IDOK), fEnable);
863 EnableMenuItem(GetMenu(hWindow),
IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED );
867 EnableMenuItem(GetMenu(hWindow),
IDM_FILE_SAVE, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
868 EnableMenuItem(GetMenu(hWindow),
IDM_FILE_SAVEAS, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
869 EnableMenuItem(GetMenu(hWindow),
IDM_FILE_CLOSE, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
872 EnableMenuItem(GetMenu(hWindow),
IDM_PLAYER_JOIN, MF_BYCOMMAND | ((fEnable &&
Editing) ? MF_ENABLED : MF_GRAYED));
873 EnableMenuItem(GetMenu(hWindow),
IDM_VIEWPORT_NEW, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
888 if (!message || !*message)
return;
889 int len,len2,lines;
wchar_t *buffer, *buffer2;
892 len2 = len+std::min<int32_t>(messageW.
getSize()/
sizeof(
wchar_t)+2, 5000);
893 buffer =
new wchar_t [len2];
896 if (buffer[0]) wcscat(buffer, L
"\r\n");
897 wcsncat(buffer,getBufPtr<wchar_t>(messageW),len2-wcslen(buffer)-1);
898 if (wcslen(buffer) > 60000) buffer2 = buffer + wcslen(buffer) - 60000;
else buffer2 = buffer;
901 lines = SendDlgItemMessage(hWindow,
IDC_EDITOUTPUT,EM_GETLINECOUNT,(WPARAM)0,(LPARAM)0);
902 SendDlgItemMessage(hWindow,
IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,(LPARAM)lines);
903 UpdateWindow(hWindow);
909 SendDlgItemMessage(hWindow,
IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,0);
910 UpdateWindow(hWindow);
938 SetDlgItemTextW(hWindow,dialog_item,
text.GetWideChar());
939 UpdateWindow(GetDlgItem(hWindow,dialog_item));
944 return (IDOK==MessageBoxW(hWindow,
GetWideChar(message),
ADDL(C4ENGINECAPTION),query ? (MB_OKCANCEL | MB_ICONEXCLAMATION) : MB_ICONEXCLAMATION));
949 EnableMenuItem(GetMenu(hWindow),
IDM_FILE_RECORD, MF_BYCOMMAND | MF_GRAYED);
955 MessageBoxW(
nullptr, strMessage.GetWideChar(),
ADDL(C4ENGINECAPTION), MB_ICONINFORMATION | MB_TASKMODAL);
960 enum { ArbitraryMaximumLength = 4096 };
961 wchar_t buffer[ArbitraryMaximumLength];
963 wcsncpy(buffer, sFilename->GetWideChar(), ArbitraryMaximumLength - 1);
964 buffer[ArbitraryMaximumLength - 1] = 0;
967 ofn.lStructSize=
sizeof(ofn);
968 ofn.hwndOwner=hWindow;
969 const char *
s = szFilter;
970 while (*
s)
s =
s + strlen(
s) + 1;
972 int n =
s - szFilter;
973 int len = MultiByteToWideChar(CP_UTF8, 0, szFilter, n,
nullptr, 0);
975 filt.
SetSize(len *
sizeof(
wchar_t));
976 MultiByteToWideChar(CP_UTF8, 0, szFilter, n, getMBufPtr<wchar_t>(filt), len );
977 ofn.lpstrFilter=getMBufPtr<wchar_t>(filt);
978 ofn.lpstrFile=buffer;
979 ofn.nMaxFile=ArbitraryMaximumLength;
983 size_t l = GetCurrentDirectoryW(0,
nullptr);
984 auto *wd =
new wchar_t[l];
985 GetCurrentDirectoryW(l,wd);
987 fResult = !!GetSaveFileNameW(&ofn);
989 fResult = !!GetOpenFileNameW(&ofn);
991 SetCurrentDirectoryW(wd);
993 len = WideCharToMultiByte(CP_UTF8, 0, buffer, ArbitraryMaximumLength,
nullptr, 0,
nullptr,
nullptr);
995 WideCharToMultiByte(CP_UTF8, 0, buffer, ArbitraryMaximumLength, sFilename->
getMData(), sFilename->
getSize(),
nullptr,
nullptr);
1011 if (!InsertMenuW(GetMenu(hWindow),state->
MenuIndexHelp,MF_BYPOSITION | MF_POPUP,(UINT_PTR)CreateMenu(),
LoadResStrW(
"IDS_MNU_NET")))
return;
1014 DrawMenuBar(hWindow);
1020 DeleteMenu(GetMenu(hWindow),state->
MenuIndexNet,MF_BYPOSITION);
1023 DrawMenuBar(hWindow);
1034 while (DeleteMenu(hMenu,1,MF_BYPOSITION));
1046 HWND hDialog = CreateDialog(
Application.GetInstance(),
1050 if (!hDialog)
return false;
1055 SetWindowTextW(hDialog,
LoadResStrW(
"IDS_DLG_PROPERTIES"));
1057 EnableWindow( GetDlgItem(hDialog,IDOK),
Editing );
1062 SetWindowPos(hDialog,hWindow,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
1063 ShowWindow(hDialog,SW_SHOWNOACTIVATE);
1072 static void SetComboItems(HWND hCombo, std::list<const char*> &items)
1074 for (
auto & item : items)
1077 SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)L
"----------");
1086 if (!hDialog)
return;
1087 int iLine = SendDlgItemMessage(hDialog,
IDC_EDITOUTPUT,EM_GETFIRSTVISIBLELINE,(WPARAM)0,(LPARAM)0);
1089 SendDlgItemMessage(hDialog,
IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,(LPARAM)iLine);
1098 wchar_t szLastText[500+1];
1100 GetWindowTextW(hCombo, szLastText, 500);
1102 SendMessage(hCombo, CB_RESETCONTENT, 0, 0);
1107 SetWindowTextW(hCombo, szLastText);
1113 SendMessage(hCombo, CB_RESETCONTENT, 0, 0);
1114 SetComboItems(hCombo, functions);
1121 while (DeleteMenu(hMenu,1,MF_BYPOSITION));
1137 Init(C4Window::WindowKind::W_Control, &
Application,
nullptr,
nullptr);
1138 this->hWindow = this->renderwnd = hwndControl;
1152 if (dlg->state->hDialog)
return true;
1153 dlg->state->hDialog = CreateDialog(
Application.GetInstance(),
1157 if (!dlg->state->hDialog)
return false;
1159 SetWindowTextW(dlg->state->hDialog,
LoadResStrW(
"IDS_DLG_TOOLS"));
1165 dlg->state->LoadBitmaps(
Application.GetInstance());
1167 if (
pDraw && !dlg->state->pPreviewWindow)
1173 SetWindowPos(dlg->state->hDialog,
Console.hWindow,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
1174 ShowWindow(dlg->state->hDialog,SW_SHOWNOACTIVATE);
1195 SendDlgItemMessage(dlg->state->hDialog,
IDC_COMBOBGMATERIAL, CB_ADDSTRING, 0, (LPARAM)L
"----------");
1210 HWND hDialog = state->
hDialog;
1250 for (
int i = 0; i < 2; ++i)
1252 WORD box = boxes[i];
1253 const char *material = materials[i];
1254 const char *texture = textures[i];
1256 SendDlgItemMessage(state->
hDialog, box, CB_RESETCONTENT, 0, (LPARAM)0);
1258 bool fAnyEntry =
false; int32_t cnt;
const char *szTexture;
1276 SendDlgItemMessage(state->
hDialog, box, CB_INSERTSTRING, 0, (LPARAM)L
"-------");
1298 if (!sfcPreview)
return;
1300 int32_t iPrvWdt,iPrvHgt;
1305 iPrvWdt=rect.right-rect.left;
1306 iPrvHgt=rect.bottom-rect.top;
1308 if (!sfcPreview->
UpdateSize(iPrvWdt, iPrvHgt))
return;
1341 iPrvWdt/2,iPrvHgt/2,
1352 SendMessage(hwndTrack,TBM_SETPAGESIZE,0,(LPARAM)5);
1353 SendMessage(hwndTrack,TBM_SETLINESIZE,0,(LPARAM)1);
1354 SendMessage(hwndTrack,TBM_SETRANGE,(WPARAM)
false,
1357 UpdateWindow(hwndTrack);
1362 if (!state->
hDialog)
return false;
1370 if (!state->
hDialog)
return false;
1402 HWND hDialog = state->
hDialog;
#define WM_USER_RELOADFILE
#define IDM_VIEWPORT_NEW2
#define IDM_VIEWPORT_NEW1
StdStrBuf::wchar_t_holder LoadResStrW(const char *id)
INT_PTR CALLBACK ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
bool SetMenuItemText(HMENU hMenu, WORD id, const char *szText)
bool AddMenuItem(C4ConsoleGUI *console, HMENU hMenu, DWORD dwID, const char *szString, bool fEnabled)
INT_PTR CALLBACK ConsoleDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK PropertyDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
const int32_t C4M_Background
C4Application Application
const char * LoadResStr(const char *id)
bool Log(const char *szMessage)
C4MaterialMap MaterialMap
BYTE Mat2PixColDefault(int32_t mat)
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
StdBuf GetWideCharBuf(const char *utf8)
bool SEqual2(const char *szStr1, const char *szStr2)
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
bool SEqual(const char *szStr1, const char *szStr2)
bool Inside(T ival, U lbound, V rbound)
StdStrBuf FormatString(const char *szFmt,...)
bool WildcardMatch(const char *szWildcard, const char *szString)
void OnKeyboardLayoutChanged() override
C4MusicSystem MusicSystem
C4Client * getClientByID(int32_t iID) const
void CtrlRemove(const C4Client *pClient, const char *szReason)
int32_t getLocalID() const
const char * GetSubkeyPath(const char *subkey)
class C4ToolsDlg * GetOwner()
InternalState(class C4ToolsDlg *owner)
int console_ok_button_width
int console_default_height
int property_dlg_inputarea_height
void PropertyDlgInitLayout()
int console_button_height
State(C4ConsoleGUI *console)
BOOL RegisterConsoleWindowClass(HINSTANCE hInst)
void CreateBitmaps(C4AbstractApp *application)
int property_dlg_okbutton_width
int console_default_width
bool AddMenuItem(HMENU hMenu, DWORD dwID, const char *szString, bool fEnabled=true)
void UpdateMenuText(C4ConsoleGUI &console, HMENU hMenu)
void PropertyDlgUpdateSize()
void AddKickPlayerMenuItem(C4Player *player, StdStrBuf &player_text, bool enabled)
void SetCursor(Cursor cursor)
void EnableControls(bool fEnable)
void ToolsDlgSelectBackMaterial(C4ToolsDlg *dlg, const char *material)
bool UpdateHaltCtrls(bool fHalt)
void SetCaptionToFileName(const char *file_name)
void DoEnableControls(bool fEnable)
void AddMenuItemForPlayer(C4Player *player, StdStrBuf &player_text)
void DeleteConsoleWindow()
bool FileSelect(StdStrBuf *sFilename, const char *szFilter, DWORD dwFlags, bool fSave)
void AddNetMenuItemForPlayer(int32_t client_id, const char *text, C4ConsoleGUI::ClientOperation co)
bool UpdateModeCtrls(int iMode)
bool CreateConsoleWindow(C4AbstractApp *application)
void Out(const char *message)
void ToolsDlgSelectMaterial(C4ToolsDlg *dlg, const char *material)
void ShowAboutWithCopyright(StdStrBuf ©right)
void PropertyDlgUpdate(class C4EditCursorSelection &rSelection, bool force_function_update)
bool ToolsDlgOpen(class C4ToolsDlg *dlg)
void SetInputFunctions(std::list< const char * > &functions)
C4Object * PropertyDlgObject
void DisplayInfoText(InfoTextType type, StdStrBuf &text)
bool DoUpdateHaltCtrls(bool fHalt)
bool Message(const char *message, bool query)
void ToolsDlgSelectTexture(C4ToolsDlg *dlg, const char *texture)
void ToolsDlgSelectBackTexture(C4ToolsDlg *dlg, const char *texture)
void ToolsDlgInitMaterialCtrls(class C4ToolsDlg *dlg)
~C4ConsoleGUIPreviewWindow() override
C4ConsoleGUIPreviewWindow(HWND hwndControl)
bool In(const char *szText)
bool FileOpen(const char *filename=nullptr, bool host_in_network=false)
void RegisterRecentInput(const char *input, RecentScriptInputLists section)
std::list< const char * > GetScriptSuggestions(class C4PropList *target, RecentScriptInputLists section) const
bool FileSaveAs(bool fSaveGame, bool export_packed=false)
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
static C4ControlPlayerAction * Eliminate(const C4Player *source)
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
void DrawPatternedCircle(C4Surface *sfcDest, int x, int y, int r, BYTE col, C4Pattern &Pattern, CStdPalette &rPal)
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
bool SetMode(int32_t iMode)
bool In(const char *szText)
C4EditCursorSelection & GetSelection()
StdStrBuf GetDataString() const
C4Object * GetObject(int32_t index=0) const
bool IsRuntimeRecordPossible() const
bool ReloadFile(const char *filepath)
LandscapeMode GetMode() const
CStdPalette * GetPal() const
int32_t Get(const char *szMaterial)
bool isLobbyActive() const
bool Set(class C4Surface *sfcSource, int iZoom=0)
C4Player * Get(int iPlayer) const
class C4Surface * Surface
bool UpdateSize(int wdt, int hgt)
bool PageFlip(C4Rect *pSrcRt=nullptr, C4Rect *pDstRt=nullptr)
const C4Pattern & GetPattern() const
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
const char * GetTexture(int32_t iIndex)
const C4TexMapEntry * GetEntry(int32_t iIndex) const
bool CreateViewport(int32_t player_nr, bool silent=false)
virtual C4Window * Init(WindowKind windowKind, C4AbstractApp *pApp, const char *Title, const C4Rect *size)
void SetTitle(const char *Title)
void SetSize(size_t inSize)
void SetLength(size_t iLength)
const char * getData() const
int ReplaceChar(char cOld, char cNew)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
#define IDC_BUTTONMODEDYNAMIC
#define IDC_STATICMATERIAL
#define IDC_STATICFOREGROUND
#define IDC_BUTTONMODEPLAY
#define IDC_COMBOFGTEXTURE
#define IDC_STATICBACKGROUND
#define IDC_BUTTONMODEEXACT
#define IDC_STATICTEXTURE
#define IDC_COMBOBGMATERIAL
#define IDC_COMBOBGTEXTURE
#define IDC_BUTTONMODEEDIT
#define IDM_FILE_OPENWPLRS
#define IDC_BUTTONMODESTATIC
#define IDC_COMBOFGMATERIAL
#define IDC_BUTTONRELOADDEF
#define IDC_BUTTONMODEDRAW
#define IDM_FILE_SAVEGAMEAS