2010-12-11 18:50:38 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 1998-2000, 2003 Matthes Bender
|
|
|
|
* Copyright (c) 2004 Peter Wortmann
|
|
|
|
* Copyright (c) 2005, 2007 Sven Eberhardt
|
2011-09-01 14:58:52 +00:00
|
|
|
* Copyright (c) 2005-2007, 2009-2011 Günther Brammer
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2009 David Dormagen
|
2011-09-01 14:58:52 +00:00
|
|
|
* Copyright (c) 2009, 2011 Nicolas Hake
|
2011-09-01 10:47:54 +00:00
|
|
|
* Copyright (c) 2010 Martin Plicht
|
2010-12-11 18:50:38 +00:00
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4Console.h>
|
|
|
|
|
2012-04-27 17:04:43 +00:00
|
|
|
#include <C4AppWin32Impl.h>
|
|
|
|
#include "C4ConsoleGUI.h"
|
|
|
|
#include <C4DrawGL.h>
|
|
|
|
#include <C4DrawD3D.h>
|
2010-12-11 18:50:38 +00:00
|
|
|
#include <C4Landscape.h>
|
2012-04-27 17:04:43 +00:00
|
|
|
#include <C4Object.h>
|
2010-12-11 18:50:38 +00:00
|
|
|
#include <C4PlayerList.h>
|
|
|
|
#include <C4Texture.h>
|
2012-04-27 17:04:43 +00:00
|
|
|
#include <C4Version.h>
|
2010-12-11 18:50:38 +00:00
|
|
|
#include "C4Viewport.h"
|
2012-04-27 17:04:43 +00:00
|
|
|
#include <StdRegistry.h>
|
2010-12-11 18:50:38 +00:00
|
|
|
|
2011-03-13 16:25:35 +00:00
|
|
|
#include <C4windowswrapper.h>
|
|
|
|
#include <mmsystem.h>
|
2010-12-11 18:50:38 +00:00
|
|
|
#include <commdlg.h>
|
|
|
|
#include "resource.h"
|
2011-08-19 20:03:03 +00:00
|
|
|
#define GetWideLPARAM(c) reinterpret_cast<LPARAM>(static_cast<wchar_t*>(GetWideChar(c)))
|
|
|
|
|
2011-04-03 13:47:02 +00:00
|
|
|
inline StdStrBuf::wchar_t_holder LoadResStrW(const char *id) { return GetWideChar(LoadResStr(id)); }
|
2011-03-11 02:48:25 +00:00
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
bool SetMenuItemText(HMENU hMenu, WORD id, const char *szText);
|
|
|
|
|
|
|
|
bool AddMenuItem(C4ConsoleGUI *console, HMENU hMenu, DWORD dwID, const char *szString, bool fEnabled)
|
|
|
|
{
|
|
|
|
if (!console->Active) return false;
|
2011-04-03 13:47:02 +00:00
|
|
|
MENUITEMINFOW minfo;
|
2010-12-11 18:50:38 +00:00
|
|
|
ZeroMem(&minfo,sizeof(minfo));
|
|
|
|
minfo.cbSize = sizeof(minfo);
|
|
|
|
minfo.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA | MIIM_STATE;
|
|
|
|
minfo.fType = MFT_STRING;
|
|
|
|
minfo.wID = dwID;
|
2011-04-03 13:47:02 +00:00
|
|
|
StdBuf td = GetWideCharBuf(szString);
|
|
|
|
minfo.dwTypeData = getMBufPtr<wchar_t>(td);
|
|
|
|
minfo.cch = wcslen(minfo.dwTypeData);
|
2010-12-11 18:50:38 +00:00
|
|
|
if (!fEnabled) minfo.fState|=MFS_GRAYED;
|
2011-04-03 13:47:02 +00:00
|
|
|
return !!InsertMenuItemW(hMenu,0,false,&minfo);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class C4ConsoleGUI::State
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BOOL RegisterConsoleWindowClass(HINSTANCE hInst);
|
|
|
|
bool AddMenuItem(HMENU hMenu, DWORD dwID, const char *szString, bool fEnabled=true);
|
2011-01-13 17:21:59 +00:00
|
|
|
HWND hPropertyDlg;
|
2010-12-11 18:50:38 +00:00
|
|
|
HBITMAP hbmMouse;
|
|
|
|
HBITMAP hbmMouse2;
|
|
|
|
HBITMAP hbmCursor;
|
|
|
|
HBITMAP hbmCursor2;
|
|
|
|
HBITMAP hbmBrush;
|
|
|
|
HBITMAP hbmBrush2;
|
|
|
|
HBITMAP hbmPlay;
|
|
|
|
HBITMAP hbmPlay2;
|
|
|
|
HBITMAP hbmHalt;
|
|
|
|
HBITMAP hbmHalt2;
|
2011-01-04 19:31:55 +00:00
|
|
|
int MenuIndexFile;
|
|
|
|
int MenuIndexPlayer;
|
|
|
|
int MenuIndexViewport;
|
|
|
|
int MenuIndexNet;
|
|
|
|
int MenuIndexHelp;
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
State(C4ConsoleGUI *console)
|
|
|
|
{
|
|
|
|
hbmMouse=NULL;
|
|
|
|
hbmMouse2=NULL;
|
|
|
|
hbmCursor=NULL;
|
|
|
|
hbmCursor2=NULL;
|
|
|
|
hbmBrush=NULL;
|
|
|
|
hbmBrush2=NULL;
|
|
|
|
hbmPlay=NULL;
|
|
|
|
hbmPlay2=NULL;
|
|
|
|
hbmHalt=NULL;
|
|
|
|
hbmHalt2=NULL;
|
2011-08-30 13:23:49 +00:00
|
|
|
hPropertyDlg=NULL;
|
2011-01-04 19:31:55 +00:00
|
|
|
MenuIndexFile = 0;
|
2011-01-19 01:14:59 +00:00
|
|
|
MenuIndexPlayer = 1;
|
|
|
|
MenuIndexViewport = 2;
|
2011-01-04 19:31:55 +00:00
|
|
|
MenuIndexNet = -1;
|
2011-01-19 01:14:59 +00:00
|
|
|
MenuIndexHelp = 3;
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~State()
|
|
|
|
{
|
|
|
|
if (hbmMouse) DeleteObject(hbmMouse);
|
|
|
|
if (hbmMouse2) DeleteObject(hbmMouse2);
|
|
|
|
if (hbmCursor) DeleteObject(hbmCursor);
|
|
|
|
if (hbmCursor2) DeleteObject(hbmCursor2);
|
|
|
|
if (hbmBrush) DeleteObject(hbmBrush);
|
|
|
|
if (hbmBrush2) DeleteObject(hbmBrush2);
|
|
|
|
if (hbmPlay) DeleteObject(hbmPlay);
|
|
|
|
if (hbmPlay2) DeleteObject(hbmPlay2);
|
|
|
|
if (hbmHalt) DeleteObject(hbmHalt);
|
|
|
|
if (hbmHalt2) DeleteObject(hbmHalt2);
|
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
void CreateBitmaps(C4AbstractApp *application)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
HINSTANCE instance = application->GetInstance();
|
2011-04-03 13:47:02 +00:00
|
|
|
hbmMouse=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_MOUSE));
|
|
|
|
hbmMouse2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_MOUSE2));
|
|
|
|
hbmCursor=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_CURSOR));
|
|
|
|
hbmCursor2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_CURSOR2));
|
|
|
|
hbmBrush=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_BRUSH));
|
|
|
|
hbmBrush2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_BRUSH2));
|
|
|
|
hbmPlay=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_PLAY));
|
|
|
|
hbmPlay2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_PLAY2));
|
|
|
|
hbmHalt=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_HALT));
|
|
|
|
hbmHalt2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_HALT2));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 19:31:55 +00:00
|
|
|
void UpdateMenuText(C4ConsoleGUI &console, HMENU hMenu)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
HMENU hSubMenu;
|
|
|
|
if (!console.Active) return;
|
|
|
|
// File
|
2011-04-03 13:47:02 +00:00
|
|
|
ModifyMenuW(hMenu,MenuIndexFile,MF_BYPOSITION | MF_STRING,0,LoadResStrW("IDS_MNU_FILE"));
|
2011-01-04 19:31:55 +00:00
|
|
|
hSubMenu = GetSubMenu(hMenu,MenuIndexFile);
|
2010-12-11 18:50:38 +00:00
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_OPEN,LoadResStr("IDS_MNU_OPEN"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_OPENWPLRS,LoadResStr("IDS_MNU_OPENWPLRS"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_RECORD,LoadResStr("IDS_MNU_RECORD"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_SAVE,LoadResStr("IDS_MNU_SAVESCENARIO"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_SAVEAS,LoadResStr("IDS_MNU_SAVESCENARIOAS"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_SAVEGAMEAS,LoadResStr("IDS_MNU_SAVEGAMEAS"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_CLOSE,LoadResStr("IDS_MNU_CLOSE"));
|
|
|
|
SetMenuItemText(hSubMenu,IDM_FILE_QUIT,LoadResStr("IDS_MNU_QUIT"));
|
|
|
|
// Player
|
2011-04-03 13:47:02 +00:00
|
|
|
ModifyMenuW(hMenu,MenuIndexPlayer,MF_BYPOSITION | MF_STRING,0,LoadResStrW("IDS_MNU_PLAYER"));
|
2011-01-04 19:31:55 +00:00
|
|
|
hSubMenu = GetSubMenu(hMenu,MenuIndexPlayer);
|
2010-12-11 18:50:38 +00:00
|
|
|
SetMenuItemText(hSubMenu,IDM_PLAYER_JOIN,LoadResStr("IDS_MNU_JOIN"));
|
|
|
|
// Viewport
|
2011-04-03 13:47:02 +00:00
|
|
|
ModifyMenuW(hMenu,MenuIndexViewport,MF_BYPOSITION | MF_STRING,0,LoadResStrW("IDS_MNU_VIEWPORT"));
|
2011-01-04 19:31:55 +00:00
|
|
|
hSubMenu = GetSubMenu(hMenu,MenuIndexViewport);
|
2010-12-11 18:50:38 +00:00
|
|
|
SetMenuItemText(hSubMenu,IDM_VIEWPORT_NEW,LoadResStr("IDS_MNU_NEW"));
|
|
|
|
// Help
|
2011-01-04 19:31:55 +00:00
|
|
|
hSubMenu = GetSubMenu(hMenu,MenuIndexHelp);
|
2010-12-11 18:50:38 +00:00
|
|
|
SetMenuItemText(hSubMenu,IDM_HELP_ABOUT,LoadResStr("IDS_MENU_ABOUT"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-04 19:31:55 +00:00
|
|
|
void C4ConsoleGUI::UpdateMenuText(HMENU hMenu) { state->UpdateMenuText(*this, hMenu); }
|
|
|
|
|
|
|
|
static void ClearDlg(HWND &handle)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
if (handle)
|
|
|
|
DestroyWindow(handle);
|
|
|
|
handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK ConsoleDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_ACTIVATEAPP:
|
|
|
|
Application.Active = wParam != 0;
|
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_DESTROY:
|
|
|
|
StoreWindowPosition(hDlg, "Main", Config.GetSubkeyPath("Console"), false);
|
|
|
|
Application.Quit();
|
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_CLOSE:
|
|
|
|
Console.Close();
|
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case MM_MCINOTIFY:
|
|
|
|
if (wParam == MCI_NOTIFY_SUCCESSFUL)
|
|
|
|
Application.MusicSystem.NotifySuccess();
|
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_INITDIALOG:
|
2010-12-13 16:37:07 +00:00
|
|
|
Console.Active = true;
|
2010-12-11 18:50:38 +00:00
|
|
|
SendMessage(hDlg,DM_SETDEFID,(WPARAM)IDOK,(LPARAM)0);
|
2011-01-04 19:31:55 +00:00
|
|
|
Console.UpdateMenuText(GetMenu(hDlg));
|
2010-12-11 18:50:38 +00:00
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_COMMAND:
|
|
|
|
// Evaluate command
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDOK:
|
|
|
|
// IDC_COMBOINPUT to Console.In()
|
2011-04-03 13:47:02 +00:00
|
|
|
wchar_t buffer[16000];
|
|
|
|
GetDlgItemTextW(hDlg,IDC_COMBOINPUT,buffer,16000);
|
2010-12-11 18:50:38 +00:00
|
|
|
if (buffer[0])
|
2011-04-03 13:47:02 +00:00
|
|
|
Console.In(StdStrBuf(buffer).getData());
|
2010-12-11 18:50:38 +00:00
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONHALT:
|
|
|
|
Console.DoHalt();
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONPLAY:
|
|
|
|
Console.DoPlay();
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODEPLAY:
|
|
|
|
Console.EditCursor.SetMode(C4CNS_ModePlay);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODEEDIT:
|
|
|
|
Console.EditCursor.SetMode(C4CNS_ModeEdit);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODEDRAW:
|
|
|
|
Console.EditCursor.SetMode(C4CNS_ModeDraw);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_QUIT: Console.FileQuit(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_SAVEAS: Console.FileSaveAs(false); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-05-15 17:38:47 +00:00
|
|
|
case IDM_FILE_SAVE: Console.FileSave(); return true;
|
2010-12-11 18:50:38 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_SAVEGAMEAS: Console.FileSaveAs(true); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_OPEN: Console.FileOpen(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_RECORD: Console.FileRecord(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_OPENWPLRS: Console.FileOpenWPlrs(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_FILE_CLOSE: Console.FileClose(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_HELP_ABOUT: Console.HelpAbout(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_PLAYER_JOIN: Console.PlayerJoin(); return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDM_VIEWPORT_NEW: Console.ViewportNew(); return true;
|
|
|
|
}
|
|
|
|
// New player viewport
|
|
|
|
if (Inside((int) LOWORD(wParam),IDM_VIEWPORT_NEW1,IDM_VIEWPORT_NEW2))
|
|
|
|
{
|
|
|
|
::Viewports.CreateViewport(LOWORD(wParam)-IDM_VIEWPORT_NEW1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Remove player
|
|
|
|
if (Inside((int) LOWORD(wParam),IDM_PLAYER_QUIT1,IDM_PLAYER_QUIT2))
|
|
|
|
{
|
|
|
|
::Control.Input.Add(CID_Script, new C4ControlScript(
|
|
|
|
FormatString("EliminatePlayer(%d)", LOWORD(wParam)-IDM_PLAYER_QUIT1).getData()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Remove client
|
|
|
|
if (Inside((int) LOWORD(wParam),IDM_NET_CLIENT1,IDM_NET_CLIENT2))
|
|
|
|
{
|
|
|
|
if (!::Control.isCtrlHost()) return false;
|
|
|
|
Game.Clients.CtrlRemove(Game.Clients.getClientByID(LOWORD(wParam)-IDM_NET_CLIENT1), LoadResStr("IDS_MSG_KICKBYMENU"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_USER_LOG:
|
|
|
|
if (SEqual2((const char *)lParam, "IDS_"))
|
|
|
|
Log(LoadResStr((const char *)lParam));
|
|
|
|
else
|
|
|
|
Log((const char *)lParam);
|
|
|
|
return false;
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
case WM_COPYDATA:
|
|
|
|
COPYDATASTRUCT* pcds = reinterpret_cast<COPYDATASTRUCT *>(lParam);
|
|
|
|
if (pcds->dwData == WM_USER_RELOADFILE)
|
|
|
|
{
|
|
|
|
// get path, ensure proper termination
|
|
|
|
const char *szPath = reinterpret_cast<const char *>(pcds->lpData);
|
|
|
|
if (szPath[pcds->cbData - 1]) break;
|
|
|
|
// reload
|
|
|
|
Game.ReloadFile(szPath);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C4ToolsDlg::State: public C4ConsoleGUI::InternalState<class C4ToolsDlg>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HWND hDialog;
|
|
|
|
#ifdef USE_GL
|
|
|
|
CStdGLCtx* pGLCtx;
|
|
|
|
#endif
|
2011-04-05 16:03:27 +00:00
|
|
|
friend INT_PTR CALLBACK ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
|
2010-12-11 18:50:38 +00:00
|
|
|
HBITMAP hbmBrush,hbmBrush2;
|
|
|
|
HBITMAP hbmLine,hbmLine2;
|
|
|
|
HBITMAP hbmRect,hbmRect2;
|
|
|
|
HBITMAP hbmFill,hbmFill2;
|
|
|
|
HBITMAP hbmPicker,hbmPicker2;
|
|
|
|
HBITMAP hbmIFT;
|
|
|
|
HBITMAP hbmNoIFT;
|
|
|
|
HBITMAP hbmDynamic;
|
|
|
|
HBITMAP hbmStatic;
|
|
|
|
HBITMAP hbmExact;
|
|
|
|
|
|
|
|
State(C4ToolsDlg *toolsDlg): C4ConsoleGUI::InternalState<class C4ToolsDlg>(toolsDlg), hDialog(0),
|
|
|
|
hbmBrush(0), hbmBrush2(0),
|
|
|
|
hbmLine(0), hbmLine2(0),
|
|
|
|
hbmRect(0), hbmRect2(0),
|
|
|
|
hbmFill(0), hbmFill2(0),
|
|
|
|
hbmPicker(0), hbmPicker2(0),
|
|
|
|
hbmIFT(0),
|
|
|
|
hbmNoIFT(0),
|
|
|
|
hbmDynamic(0),
|
|
|
|
hbmStatic(0),
|
|
|
|
hbmExact(0)
|
|
|
|
{
|
|
|
|
pGLCtx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadBitmaps(HINSTANCE instance)
|
|
|
|
{
|
2011-04-03 13:47:02 +00:00
|
|
|
if (!hbmBrush) hbmBrush=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_BRUSH));
|
|
|
|
if (!hbmLine) hbmLine=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_LINE));
|
|
|
|
if (!hbmRect) hbmRect=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_RECT));
|
|
|
|
if (!hbmFill) hbmFill=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_FILL));
|
|
|
|
if (!hbmPicker) hbmPicker=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_PICKER));
|
|
|
|
if (!hbmBrush2) hbmBrush2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_BRUSH2));
|
|
|
|
if (!hbmLine2) hbmLine2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_LINE2));
|
|
|
|
if (!hbmRect2) hbmRect2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_RECT2));
|
|
|
|
if (!hbmFill2) hbmFill2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_FILL2));
|
|
|
|
if (!hbmPicker2) hbmPicker2=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_PICKER2));
|
|
|
|
if (!hbmIFT) hbmIFT=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_IFT));
|
|
|
|
if (!hbmNoIFT) hbmNoIFT=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_NOIFT));
|
|
|
|
if (!hbmDynamic) hbmDynamic=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_DYNAMIC));
|
|
|
|
if (!hbmStatic) hbmStatic=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_STATIC));
|
|
|
|
if (!hbmExact) hbmExact=(HBITMAP)LoadBitmapW(instance,MAKEINTRESOURCEW(IDB_EXACT));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~State()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
// Unload bitmaps
|
|
|
|
if (hbmBrush) DeleteObject(hbmBrush);
|
|
|
|
if (hbmLine) DeleteObject(hbmLine);
|
|
|
|
if (hbmRect) DeleteObject(hbmRect);
|
|
|
|
if (hbmFill) DeleteObject(hbmFill);
|
|
|
|
if (hbmIFT) DeleteObject(hbmIFT);
|
|
|
|
if (hbmNoIFT) DeleteObject(hbmNoIFT);
|
|
|
|
#ifdef USE_GL
|
|
|
|
if (pGLCtx)
|
|
|
|
{
|
|
|
|
delete pGLCtx;
|
|
|
|
pGLCtx = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (hDialog) DestroyWindow(hDialog); hDialog=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Default()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#include <commctrl.h>
|
2011-04-05 16:03:27 +00:00
|
|
|
INT_PTR CALLBACK ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
int32_t iValue;
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_CLOSE:
|
|
|
|
Console.ToolsDlg.Clear();
|
|
|
|
break;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_DESTROY:
|
|
|
|
StoreWindowPosition(hDlg, "Property", Config.GetSubkeyPath("Console"), false);
|
|
|
|
break;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return true;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_PAINT:
|
|
|
|
PostMessage(hDlg,WM_USER,0,0); // For user paint
|
|
|
|
return false;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_USER:
|
|
|
|
Console.ToolsDlg.NeedPreviewUpdate();
|
|
|
|
return true;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_VSCROLL:
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case SB_THUMBTRACK: case SB_THUMBPOSITION:
|
|
|
|
iValue=HIWORD(wParam);
|
|
|
|
Console.ToolsDlg.SetGrade(C4TLS_GradeMax-iValue);
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP: case SB_PAGEDOWN:
|
|
|
|
case SB_LINEUP: case SB_LINEDOWN:
|
|
|
|
iValue=SendDlgItemMessage(hDlg,IDC_SLIDERGRADE,TBM_GETPOS,0,0);
|
|
|
|
Console.ToolsDlg.SetGrade(C4TLS_GradeMax-iValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
case WM_COMMAND:
|
|
|
|
// Evaluate command
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDOK:
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODEDYNAMIC:
|
|
|
|
Console.ToolsDlg.SetLandscapeMode(C4LSC_Dynamic);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODESTATIC:
|
|
|
|
Console.ToolsDlg.SetLandscapeMode(C4LSC_Static);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONMODEEXACT:
|
|
|
|
Console.ToolsDlg.SetLandscapeMode(C4LSC_Exact);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONBRUSH:
|
|
|
|
Console.ToolsDlg.SetTool(C4TLS_Brush, false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONLINE:
|
|
|
|
Console.ToolsDlg.SetTool(C4TLS_Line, false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONRECT:
|
|
|
|
Console.ToolsDlg.SetTool(C4TLS_Rect, false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONFILL:
|
|
|
|
Console.ToolsDlg.SetTool(C4TLS_Fill, false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONPICKER:
|
|
|
|
Console.ToolsDlg.SetTool(C4TLS_Picker, false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONIFT:
|
|
|
|
Console.ToolsDlg.SetIFT(true);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONNOIFT:
|
|
|
|
Console.ToolsDlg.SetIFT(false);
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_COMBOMATERIAL:
|
|
|
|
switch (HIWORD(wParam))
|
|
|
|
{
|
|
|
|
case CBN_SELCHANGE:
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
wchar_t str[100];
|
2010-12-11 18:50:38 +00:00
|
|
|
int32_t cursel = SendDlgItemMessage(hDlg,IDC_COMBOMATERIAL,CB_GETCURSEL,0,0);
|
|
|
|
SendDlgItemMessage(hDlg,IDC_COMBOMATERIAL,CB_GETLBTEXT,cursel,(LPARAM)str);
|
2011-08-19 20:03:03 +00:00
|
|
|
Console.ToolsDlg.SetMaterial(StdStrBuf(str).getData());
|
2010-12-11 18:50:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_COMBOTEXTURE:
|
|
|
|
switch (HIWORD(wParam))
|
|
|
|
{
|
|
|
|
case CBN_SELCHANGE:
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
wchar_t str[100];
|
2010-12-11 18:50:38 +00:00
|
|
|
int32_t cursel = SendDlgItemMessage(hDlg,IDC_COMBOTEXTURE,CB_GETCURSEL,0,0);
|
|
|
|
SendDlgItemMessage(hDlg,IDC_COMBOTEXTURE,CB_GETLBTEXT,cursel,(LPARAM)str);
|
2011-08-19 20:03:03 +00:00
|
|
|
Console.ToolsDlg.SetTexture(StdStrBuf(str).getData());
|
2010-12-11 18:50:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK PropertyDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
case WM_CLOSE:
|
2011-01-13 17:21:59 +00:00
|
|
|
Console.PropertyDlgClose();
|
2010-12-11 18:50:38 +00:00
|
|
|
break;
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
case WM_DESTROY:
|
|
|
|
StoreWindowPosition(hDlg, "Property", Config.GetSubkeyPath("Console"), false);
|
|
|
|
break;
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
SendMessage(hDlg,DM_SETDEFID,(WPARAM)IDOK,(LPARAM)0);
|
|
|
|
return true;
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
case WM_COMMAND:
|
|
|
|
// Evaluate command
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDOK:
|
|
|
|
// IDC_COMBOINPUT to Console.EditCursor.In()
|
2011-04-03 13:47:02 +00:00
|
|
|
wchar_t buffer[16000];
|
|
|
|
GetDlgItemTextW(hDlg,IDC_COMBOINPUT,buffer,16000);
|
2010-12-11 18:50:38 +00:00
|
|
|
if (buffer[0])
|
2011-04-03 13:47:02 +00:00
|
|
|
Console.EditCursor.In(StdStrBuf(buffer).getData());
|
2010-12-11 18:50:38 +00:00
|
|
|
return true;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case IDC_BUTTONRELOADDEF:
|
2011-01-13 00:16:30 +00:00
|
|
|
{
|
|
|
|
C4Object * pObj = Console.EditCursor.GetSelection().GetObject();
|
|
|
|
if (pObj)
|
|
|
|
Game.ReloadDef(pObj->id);
|
2010-12-11 18:50:38 +00:00
|
|
|
return true;
|
2011-01-13 00:16:30 +00:00
|
|
|
}
|
2010-12-11 18:50:38 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
//-----------------------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::Win32KeepDialogsFloating(HWND hwnd)
|
|
|
|
{
|
|
|
|
if (!hwnd)
|
|
|
|
hwnd = hWindow;
|
2011-01-13 17:21:59 +00:00
|
|
|
if (Console.state->hPropertyDlg)
|
|
|
|
SetWindowLongPtr(Console.state->hPropertyDlg, GWLP_HWNDPARENT, reinterpret_cast<LONG_PTR>(hwnd));
|
2010-12-11 18:50:38 +00:00
|
|
|
if (Console.ToolsDlg.state->hDialog)
|
|
|
|
SetWindowLongPtr(Console.ToolsDlg.state->hDialog, GWLP_HWNDPARENT, reinterpret_cast<LONG_PTR>(hwnd));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::Win32DialogMessageHandling(MSG *msg)
|
|
|
|
{
|
2011-01-13 17:21:59 +00:00
|
|
|
return (hWindow && IsDialogMessage(hWindow,msg)) || (Console.state->hPropertyDlg && IsDialogMessage(Console.state->hPropertyDlg,msg));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::SetCursor(Cursor cursor)
|
|
|
|
{
|
|
|
|
::SetCursor(LoadCursor(0,IDC_WAIT));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::UpdateModeCtrls(int iMode)
|
|
|
|
{
|
|
|
|
if (!Active)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEPLAY,BM_SETSTATE,(iMode==C4CNS_ModePlay),0);
|
|
|
|
UpdateWindow(GetDlgItem(hWindow,IDC_BUTTONMODEPLAY));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEEDIT,BM_SETSTATE,(iMode==C4CNS_ModeEdit),0);
|
|
|
|
UpdateWindow(GetDlgItem(hWindow,IDC_BUTTONMODEEDIT));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEDRAW,BM_SETSTATE,(iMode==C4CNS_ModeDraw),0);
|
|
|
|
UpdateWindow(GetDlgItem(hWindow,IDC_BUTTONMODEDRAW));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:12:01 +00:00
|
|
|
C4Window* C4ConsoleGUI::CreateConsoleWindow(C4AbstractApp *application)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
hWindow = CreateDialog(application->GetInstance(), MAKEINTRESOURCE(IDD_CONSOLE), NULL, ConsoleDlgProc);
|
|
|
|
if (!hWindow)
|
|
|
|
{
|
2011-09-21 20:20:52 +00:00
|
|
|
wchar_t * lpMsgBuf;
|
2010-12-11 18:50:38 +00:00
|
|
|
FormatMessage(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
0,
|
2011-09-21 20:20:52 +00:00
|
|
|
(wchar_t *)&lpMsgBuf, // really.
|
2010-12-11 18:50:38 +00:00
|
|
|
0,
|
|
|
|
NULL);
|
2011-09-21 20:20:52 +00:00
|
|
|
Log(FormatString("Error creating dialog window: %s", StdStrBuf(lpMsgBuf).getData()).getData());
|
2010-12-11 18:50:38 +00:00
|
|
|
// Free the buffer.
|
|
|
|
LocalFree(lpMsgBuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Restore window position
|
|
|
|
RestoreWindowPosition(hWindow, "Main", Config.GetSubkeyPath("Console"));
|
|
|
|
// Set icon
|
|
|
|
SendMessage(hWindow,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(application->GetInstance(),MAKEINTRESOURCE(IDI_00_C4X)));
|
|
|
|
SendMessage(hWindow,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(application->GetInstance(),MAKEINTRESOURCE(IDI_00_C4X)));
|
|
|
|
// Set text
|
2012-02-29 22:49:45 +00:00
|
|
|
SetTitle(LoadResStr("IDS_CNS_CONSOLE"));
|
2010-12-11 18:50:38 +00:00
|
|
|
// Load bitmaps
|
|
|
|
state->CreateBitmaps(application);
|
|
|
|
// Enable controls
|
|
|
|
UpdateHaltCtrls(true);
|
|
|
|
EnableControls(fGameOpen);
|
|
|
|
ClearViewportMenu();
|
|
|
|
// Show window and set focus
|
|
|
|
ShowWindow(hWindow,SW_SHOWNORMAL);
|
|
|
|
UpdateWindow(hWindow);
|
|
|
|
SetFocus(hWindow);
|
|
|
|
ShowCursor(true);
|
2010-12-30 16:01:02 +00:00
|
|
|
hRenderWindow = hWindow;
|
2010-12-11 18:50:38 +00:00
|
|
|
// Success
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::DoEnableControls(bool fEnable)
|
|
|
|
{
|
|
|
|
// Set button images (edit modes & halt controls)
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEPLAY,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)(fEnable ? state->hbmMouse : state->hbmMouse2));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEEDIT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((fEnable && Editing) ? state->hbmCursor : state->hbmCursor2));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONMODEDRAW,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((fEnable && Editing) ? state->hbmBrush : state->hbmBrush2));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONPLAY,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)(::Network.isLobbyActive() || fEnable ? state->hbmPlay : state->hbmPlay2));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONHALT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)(::Network.isLobbyActive() || fEnable ? state->hbmHalt : state->hbmHalt2));
|
|
|
|
|
|
|
|
// OK
|
|
|
|
EnableWindow( GetDlgItem(hWindow,IDOK), fEnable);
|
|
|
|
|
|
|
|
// Halt controls
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_BUTTONPLAY), ::Network.isLobbyActive() || fEnable);
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_BUTTONHALT), ::Network.isLobbyActive() || fEnable);
|
|
|
|
|
|
|
|
// Edit modes
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_BUTTONMODEPLAY),(fEnable));
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_BUTTONMODEEDIT),(fEnable && Editing));
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_BUTTONMODEDRAW),(fEnable && Editing));
|
|
|
|
|
|
|
|
// Console input
|
|
|
|
EnableWindow(GetDlgItem(hWindow,IDC_COMBOINPUT), fEnable);
|
|
|
|
|
|
|
|
// File menu
|
|
|
|
// C4Network2 will have to handle that cases somehow (TODO: test)
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED );
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_OPENWPLRS, MF_BYCOMMAND | MF_ENABLED );
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_RECORD, MF_BYCOMMAND | ((Game.IsRunning && ::Control.IsRuntimeRecordPossible()) ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_SAVEGAMEAS, MF_BYCOMMAND | ((fEnable && ::Players.GetCount()) ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_SAVE, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_SAVEAS, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_CLOSE, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
|
|
|
|
|
|
|
|
// Player & viewport menu
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_PLAYER_JOIN, MF_BYCOMMAND | ((fEnable && Editing) ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_VIEWPORT_NEW, MF_BYCOMMAND | (fEnable ? MF_ENABLED : MF_GRAYED));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::DoUpdateHaltCtrls(bool fHalt)
|
|
|
|
{
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONPLAY,BM_SETSTATE,!fHalt,0);
|
|
|
|
UpdateWindow(GetDlgItem(hWindow,IDC_BUTTONPLAY));
|
|
|
|
SendDlgItemMessage(hWindow,IDC_BUTTONHALT,BM_SETSTATE,fHalt,0);
|
|
|
|
UpdateWindow(GetDlgItem(hWindow,IDC_BUTTONHALT));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-04 15:27:38 +00:00
|
|
|
void C4ConsoleGUI::Out(const char* message)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-04 15:27:38 +00:00
|
|
|
if (!Active) return;
|
|
|
|
if (!message || !*message) return;
|
2011-04-03 13:47:02 +00:00
|
|
|
int len,len2,lines; wchar_t *buffer, *buffer2;
|
2010-12-11 18:50:38 +00:00
|
|
|
len = 65000;//SendDlgItemMessage(hWindow,IDC_EDITOUTPUT,EM_LINELENGTH,(WPARAM)0,(LPARAM)0);
|
2011-04-03 13:47:02 +00:00
|
|
|
StdBuf messageW = GetWideCharBuf(message);
|
|
|
|
len2 = len+Min<int32_t>(messageW.getSize()/sizeof(wchar_t)+2, 5000);
|
|
|
|
buffer = new wchar_t [len2];
|
2010-12-11 18:50:38 +00:00
|
|
|
buffer[0]=0;
|
2011-04-03 13:47:02 +00:00
|
|
|
GetDlgItemTextW(hWindow,IDC_EDITOUTPUT,buffer,len);
|
|
|
|
if (buffer[0]) wcscat(buffer, L"\r\n");
|
|
|
|
wcsncat(buffer,getBufPtr<wchar_t>(messageW),len2-wcslen(buffer)-1);
|
|
|
|
if (wcslen(buffer) > 60000) buffer2 = buffer + wcslen(buffer) - 60000; else buffer2 = buffer; // max log length: Otherwise, discard beginning
|
|
|
|
SetDlgItemTextW(hWindow,IDC_EDITOUTPUT,buffer2);
|
2010-12-11 18:50:38 +00:00
|
|
|
delete [] buffer;
|
|
|
|
lines = SendDlgItemMessage(hWindow,IDC_EDITOUTPUT,EM_GETLINECOUNT,(WPARAM)0,(LPARAM)0);
|
|
|
|
SendDlgItemMessage(hWindow,IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,(LPARAM)lines);
|
|
|
|
UpdateWindow(hWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::ClearLog()
|
|
|
|
{
|
2011-04-03 13:47:02 +00:00
|
|
|
SetDlgItemTextW(hWindow,IDC_EDITOUTPUT,L"");
|
2010-12-11 18:50:38 +00:00
|
|
|
SendDlgItemMessage(hWindow,IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,0);
|
|
|
|
UpdateWindow(hWindow);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::SetCaptionToFileName(const char* file_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::DisplayInfoText(C4ConsoleGUI::InfoTextType type, StdStrBuf& text)
|
|
|
|
{
|
2010-12-14 01:06:23 +00:00
|
|
|
if (!Active)
|
|
|
|
return;
|
2010-12-11 18:50:38 +00:00
|
|
|
int dialog_item;
|
|
|
|
switch (type)
|
|
|
|
{
|
2010-12-14 01:06:23 +00:00
|
|
|
case CONSOLE_Cursor:
|
|
|
|
dialog_item = IDC_STATICCURSOR;
|
|
|
|
break;
|
2010-12-11 18:50:38 +00:00
|
|
|
case CONSOLE_FrameCounter:
|
|
|
|
dialog_item = IDC_STATICFRAME;
|
|
|
|
break;
|
|
|
|
case CONSOLE_TimeFPS:
|
|
|
|
dialog_item = IDC_STATICTIME;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
2011-04-03 13:47:02 +00:00
|
|
|
SetDlgItemTextW(hWindow,dialog_item,text.GetWideChar());
|
2010-12-11 18:50:38 +00:00
|
|
|
UpdateWindow(GetDlgItem(hWindow,dialog_item));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::Message(const char *message, bool query)
|
|
|
|
{
|
2011-04-03 13:47:02 +00:00
|
|
|
return (IDOK==MessageBoxW(hWindow,GetWideChar(message),ADDL(C4ENGINECAPTION),query ? (MB_OKCANCEL | MB_ICONEXCLAMATION) : MB_ICONEXCLAMATION));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::RecordingEnabled()
|
|
|
|
{
|
|
|
|
EnableMenuItem(GetMenu(hWindow),IDM_FILE_RECORD, MF_BYCOMMAND | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ShowAboutWithCopyright(StdStrBuf ©right)
|
|
|
|
{
|
|
|
|
StdStrBuf strMessage; strMessage.Format("%s %s\n\n%s", C4ENGINECAPTION, C4VERSION, copyright.getData());
|
2011-04-03 13:47:02 +00:00
|
|
|
MessageBoxW(NULL, strMessage.GetWideChar(), ADDL(C4ENGINECAPTION), MB_ICONINFORMATION | MB_TASKMODAL);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 21:52:40 +00:00
|
|
|
bool C4ConsoleGUI::FileSelect(StdStrBuf *sFilename, const char * szFilter, DWORD dwFlags, bool fSave)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-04-08 21:52:40 +00:00
|
|
|
enum { ArbitraryMaximumLength = 4096 };
|
2011-04-02 16:45:44 +00:00
|
|
|
wchar_t buffer[ArbitraryMaximumLength];
|
|
|
|
wcsncpy(buffer, sFilename->GetWideChar(), ArbitraryMaximumLength - 1);
|
|
|
|
buffer[ArbitraryMaximumLength - 1] = 0;
|
|
|
|
OPENFILENAMEW ofn;
|
2010-12-11 18:50:38 +00:00
|
|
|
ZeroMem(&ofn,sizeof(ofn));
|
|
|
|
ofn.lStructSize=sizeof(ofn);
|
|
|
|
ofn.hwndOwner=hWindow;
|
2011-04-02 16:45:44 +00:00
|
|
|
const char * s = szFilter;
|
|
|
|
while (*s) s = s + strlen(s) + 1;
|
|
|
|
s++;
|
|
|
|
int n = s - szFilter;
|
|
|
|
int len = MultiByteToWideChar(CP_UTF8, 0, szFilter, n, NULL, 0);
|
|
|
|
StdBuf filt;
|
|
|
|
filt.SetSize(len * sizeof(wchar_t));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, szFilter, n, getMBufPtr<wchar_t>(filt), len );
|
|
|
|
ofn.lpstrFilter=getMBufPtr<wchar_t>(filt);
|
2011-04-08 21:52:40 +00:00
|
|
|
ofn.lpstrFile=buffer;
|
|
|
|
ofn.nMaxFile=ArbitraryMaximumLength;
|
2010-12-11 18:50:38 +00:00
|
|
|
ofn.Flags=dwFlags;
|
|
|
|
|
|
|
|
bool fResult;
|
2011-04-02 16:45:44 +00:00
|
|
|
size_t l = GetCurrentDirectoryW(0,0);
|
|
|
|
wchar_t *wd = new wchar_t[l];
|
|
|
|
GetCurrentDirectoryW(l,wd);
|
2010-12-11 18:50:38 +00:00
|
|
|
if (fSave)
|
2011-04-02 16:45:44 +00:00
|
|
|
fResult = !!GetSaveFileNameW(&ofn);
|
2010-12-11 18:50:38 +00:00
|
|
|
else
|
2011-04-02 16:45:44 +00:00
|
|
|
fResult = !!GetOpenFileNameW(&ofn);
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
// Reset working directory to exe path as Windows file dialog might have changed it
|
2011-04-02 16:45:44 +00:00
|
|
|
SetCurrentDirectoryW(wd);
|
|
|
|
delete[] wd;
|
|
|
|
len = WideCharToMultiByte(CP_UTF8, 0, buffer, ArbitraryMaximumLength, NULL, 0, 0, 0);
|
|
|
|
sFilename->SetLength(len - 1);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, buffer, ArbitraryMaximumLength, sFilename->getMData(), sFilename->getSize(), 0, 0);
|
2010-12-11 18:50:38 +00:00
|
|
|
return fResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::AddMenuItemForPlayer(C4Player* player, StdStrBuf& player_text)
|
|
|
|
{
|
2011-01-04 19:31:55 +00:00
|
|
|
AddMenuItem(this, GetSubMenu(GetMenu(hWindow),state->MenuIndexViewport),IDM_VIEWPORT_NEW1+player->Number,player_text.getData(), true);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::AddKickPlayerMenuItem(C4Player *player, StdStrBuf& player_text, bool enabled)
|
|
|
|
{
|
2011-01-04 19:31:55 +00:00
|
|
|
AddMenuItem(this, GetSubMenu(GetMenu(hWindow),state->MenuIndexPlayer),IDM_PLAYER_QUIT1+player->Number,player_text.getData(),(!::Network.isEnabled() || ::Network.isHost()) && Editing);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 19:31:55 +00:00
|
|
|
void C4ConsoleGUI::AddNetMenu()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-04-03 13:47:02 +00:00
|
|
|
if (!InsertMenuW(GetMenu(hWindow),state->MenuIndexHelp,MF_BYPOSITION | MF_POPUP,(UINT_PTR)CreateMenu(),LoadResStrW("IDS_MNU_NET"))) return;
|
2011-01-04 19:31:55 +00:00
|
|
|
state->MenuIndexNet=state->MenuIndexHelp;
|
|
|
|
state->MenuIndexHelp++;
|
|
|
|
DrawMenuBar(hWindow);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 19:31:55 +00:00
|
|
|
void C4ConsoleGUI::ClearNetMenu()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-04 19:31:55 +00:00
|
|
|
if (state->MenuIndexNet<0) return;
|
|
|
|
DeleteMenu(GetMenu(hWindow),state->MenuIndexNet,MF_BYPOSITION);
|
|
|
|
state->MenuIndexNet=-1;
|
|
|
|
state->MenuIndexHelp--;
|
|
|
|
DrawMenuBar(hWindow);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text)
|
|
|
|
{
|
2011-01-04 19:31:55 +00:00
|
|
|
AddMenuItem(this, GetSubMenu(GetMenu(hWindow),state->MenuIndexNet), IDM_NET_CLIENT1+Game.Clients.getLocalID(), text.getData(), true);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ClearViewportMenu()
|
|
|
|
{
|
2011-01-04 19:31:55 +00:00
|
|
|
HMENU hMenu = GetSubMenu(GetMenu(hWindow),state->MenuIndexViewport);
|
2010-12-11 18:50:38 +00:00
|
|
|
while (DeleteMenu(hMenu,1,MF_BYPOSITION));
|
|
|
|
}
|
|
|
|
|
2011-01-13 17:21:59 +00:00
|
|
|
void C4ConsoleGUI::ToolsDlgClose()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-13 17:21:59 +00:00
|
|
|
::ClearDlg(Console.ToolsDlg.state->hDialog);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ToolsDlgSetTexture(class C4ToolsDlg *dlg, const char *texture)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOTEXTURE,CB_SELECTSTRING,0,GetWideLPARAM(texture));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ToolsDlgSetMaterial(class C4ToolsDlg *dlg, const char *material)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOMATERIAL,CB_SELECTSTRING,0,GetWideLPARAM(material));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 17:21:59 +00:00
|
|
|
bool C4ConsoleGUI::PropertyDlgOpen()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-13 17:21:59 +00:00
|
|
|
if (state->hPropertyDlg) return true;
|
|
|
|
HWND hDialog = CreateDialog(Application.GetInstance(),
|
2010-12-11 18:50:38 +00:00
|
|
|
MAKEINTRESOURCE(IDD_PROPERTIES),
|
|
|
|
Console.hWindow,
|
2011-04-03 13:47:02 +00:00
|
|
|
PropertyDlgProc);
|
2011-01-13 17:21:59 +00:00
|
|
|
if (!hDialog) return false;
|
|
|
|
state->hPropertyDlg = hDialog;
|
2010-12-11 18:50:38 +00:00
|
|
|
// Set text
|
2011-04-03 13:47:02 +00:00
|
|
|
SetWindowTextW(hDialog,LoadResStrW("IDS_DLG_PROPERTIES"));
|
2010-12-11 18:50:38 +00:00
|
|
|
// Enable controls
|
2011-01-13 17:21:59 +00:00
|
|
|
EnableWindow( GetDlgItem(hDialog,IDOK), Editing );
|
|
|
|
EnableWindow( GetDlgItem(hDialog,IDC_COMBOINPUT), Editing );
|
|
|
|
EnableWindow( GetDlgItem(hDialog,IDC_BUTTONRELOADDEF), Editing );
|
2010-12-11 18:50:38 +00:00
|
|
|
// Show window
|
2011-01-13 17:21:59 +00:00
|
|
|
RestoreWindowPosition(hDialog, "Property", Config.GetSubkeyPath("Console"));
|
|
|
|
SetWindowPos(hDialog,hWindow,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
|
|
|
|
ShowWindow(hDialog,SW_SHOWNOACTIVATE);
|
2010-12-11 18:50:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-13 17:21:59 +00:00
|
|
|
void C4ConsoleGUI::PropertyDlgClose()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-13 17:21:59 +00:00
|
|
|
::ClearDlg(state->hPropertyDlg);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 22:40:55 +00:00
|
|
|
static void SetComboItems(HWND hCombo, std::list<const char*> &items)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-10-13 22:40:55 +00:00
|
|
|
for (std::list<const char*>::iterator it = items.begin(); it != items.end(); it++)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-10-13 22:40:55 +00:00
|
|
|
if (!*it)
|
2011-08-19 20:03:03 +00:00
|
|
|
SendMessage(hCombo,CB_INSERTSTRING,0,(LPARAM)L"----------");
|
2010-12-11 18:50:38 +00:00
|
|
|
else
|
2011-08-19 20:03:03 +00:00
|
|
|
SendMessage(hCombo,CB_ADDSTRING,0,GetWideLPARAM(*it));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 17:21:59 +00:00
|
|
|
void C4ConsoleGUI::PropertyDlgUpdate(C4ObjectList &rSelection)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-13 17:21:59 +00:00
|
|
|
HWND hDialog = state->hPropertyDlg;
|
|
|
|
if (!hDialog) return;
|
|
|
|
int iLine = SendDlgItemMessage(hDialog,IDC_EDITOUTPUT,EM_GETFIRSTVISIBLELINE,(WPARAM)0,(LPARAM)0);
|
2011-04-03 13:47:02 +00:00
|
|
|
SetDlgItemTextW(hDialog,IDC_EDITOUTPUT,rSelection.GetDataString().GetWideChar());
|
2011-01-13 17:21:59 +00:00
|
|
|
SendDlgItemMessage(hDialog,IDC_EDITOUTPUT,EM_LINESCROLL,(WPARAM)0,(LPARAM)iLine);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_EDITOUTPUT));
|
|
|
|
|
|
|
|
if (PropertyDlgObject == rSelection.GetObject()) return;
|
|
|
|
PropertyDlgObject = rSelection.GetObject();
|
|
|
|
|
2011-10-13 22:40:55 +00:00
|
|
|
std::list<const char *> functions = ::ScriptEngine.GetFunctionNames(PropertyDlgObject ? &PropertyDlgObject->Def->Script : 0);
|
2011-01-13 17:21:59 +00:00
|
|
|
HWND hCombo = GetDlgItem(state->hPropertyDlg, IDC_COMBOINPUT);
|
2011-04-03 13:47:02 +00:00
|
|
|
wchar_t szLastText[500+1];
|
2010-12-11 18:50:38 +00:00
|
|
|
// Remember old window text
|
2011-04-03 13:47:02 +00:00
|
|
|
GetWindowTextW(hCombo, szLastText, 500);
|
2010-12-11 18:50:38 +00:00
|
|
|
// Clear
|
|
|
|
SendMessage(hCombo, CB_RESETCONTENT, 0, 0);
|
|
|
|
|
2011-01-13 17:21:59 +00:00
|
|
|
SetComboItems(GetDlgItem(state->hPropertyDlg,IDC_COMBOINPUT), functions);
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
// Restore
|
2011-04-03 13:47:02 +00:00
|
|
|
SetWindowTextW(hCombo, szLastText);
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 22:40:55 +00:00
|
|
|
void C4ConsoleGUI::SetInputFunctions(std::list<const char*> &functions)
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
|
|
|
SetComboItems(GetDlgItem(hWindow,IDC_COMBOINPUT), functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ClearPlayerMenu()
|
|
|
|
{
|
|
|
|
if (!Active) return;
|
2011-01-04 19:31:55 +00:00
|
|
|
HMENU hMenu = GetSubMenu(GetMenu(hWindow),state->MenuIndexPlayer);
|
2010-12-11 18:50:38 +00:00
|
|
|
while (DeleteMenu(hMenu,1,MF_BYPOSITION));
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ClearInput()
|
|
|
|
{
|
|
|
|
HWND hCombo = GetDlgItem(hWindow,IDC_COMBOINPUT);
|
|
|
|
// Clear
|
|
|
|
SendMessage(hCombo,CB_RESETCONTENT,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void C4ConsoleGUI::ClearPropertyDlg(C4PropertyDlg *dlg)
|
|
|
|
{
|
|
|
|
if (dlg->state->hDialog) DestroyWindow(PropertyDlg.hDialog); PropertyDlg.hDialog=NULL;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool C4ConsoleGUI::ToolsDlgOpen(C4ToolsDlg *dlg)
|
|
|
|
{
|
|
|
|
if (dlg->state->hDialog) return true;
|
|
|
|
dlg->state->hDialog = CreateDialog(Application.GetInstance(),
|
|
|
|
MAKEINTRESOURCE(IDD_TOOLS),
|
|
|
|
Console.hWindow,
|
2011-04-03 13:47:02 +00:00
|
|
|
ToolsDlgProc);
|
2010-12-11 18:50:38 +00:00
|
|
|
if (!dlg->state->hDialog) return false;
|
|
|
|
// Set text
|
2011-04-03 13:47:02 +00:00
|
|
|
SetWindowTextW(dlg->state->hDialog,LoadResStrW("IDS_DLG_TOOLS"));
|
|
|
|
SetDlgItemTextW(dlg->state->hDialog,IDC_STATICMATERIAL,LoadResStrW("IDS_CTL_MATERIAL"));
|
|
|
|
SetDlgItemTextW(dlg->state->hDialog,IDC_STATICTEXTURE,LoadResStrW("IDS_CTL_TEXTURE"));
|
2010-12-11 18:50:38 +00:00
|
|
|
// Load bitmaps if necessary
|
|
|
|
dlg->state->LoadBitmaps(Application.GetInstance());
|
|
|
|
// create target ctx for OpenGL rendering
|
|
|
|
#ifdef USE_GL
|
2011-10-03 14:30:18 +00:00
|
|
|
if (pDraw && !dlg->state->pGLCtx)
|
|
|
|
dlg->state->pGLCtx = pDraw->CreateContext(GetDlgItem(dlg->state->hDialog,IDC_PREVIEW), &Application);
|
2010-12-11 18:50:38 +00:00
|
|
|
#endif
|
|
|
|
// Show window
|
|
|
|
RestoreWindowPosition(dlg->state->hDialog, "Property", Config.GetSubkeyPath("Console"));
|
|
|
|
SetWindowPos(dlg->state->hDialog,Console.hWindow,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
|
|
|
|
ShowWindow(dlg->state->hDialog,SW_SHOWNOACTIVATE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ToolsDlgInitMaterialCtrls(class C4ToolsDlg *dlg)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOMATERIAL,CB_ADDSTRING,0,GetWideLPARAM(C4TLS_MatSky));
|
2010-12-11 18:50:38 +00:00
|
|
|
for (int32_t cnt=0; cnt< ::MaterialMap.Num; cnt++)
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOMATERIAL,CB_ADDSTRING,0,GetWideLPARAM(::MaterialMap.Map[cnt].Name));
|
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOMATERIAL,CB_SELECTSTRING,0,GetWideLPARAM(dlg->Material));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::UpdateToolCtrls()
|
|
|
|
{
|
|
|
|
HWND hDialog = state->hDialog;
|
2010-12-12 12:58:10 +00:00
|
|
|
int32_t Tool = this->Tool;
|
2010-12-11 18:50:38 +00:00
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONBRUSH,BM_SETSTATE,(Tool==C4TLS_Brush),0);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_BUTTONBRUSH));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONLINE,BM_SETSTATE,(Tool==C4TLS_Line),0);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_BUTTONLINE));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONRECT,BM_SETSTATE,(Tool==C4TLS_Rect),0);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_BUTTONRECT));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONFILL,BM_SETSTATE,(Tool==C4TLS_Fill),0);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_BUTTONFILL));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONPICKER,BM_SETSTATE,(Tool==C4TLS_Picker),0);
|
|
|
|
UpdateWindow(GetDlgItem(hDialog,IDC_BUTTONPICKER));
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ToolsDlgSelectTexture(C4ToolsDlg *dlg, const char *texture)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOTEXTURE,CB_SELECTSTRING,0,GetWideLPARAM(texture));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ConsoleGUI::ToolsDlgSelectMaterial(C4ToolsDlg *dlg, const char *material)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(dlg->state->hDialog,IDC_COMBOMATERIAL,CB_SELECTSTRING,0,GetWideLPARAM(material));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::UpdateTextures()
|
|
|
|
{
|
|
|
|
// Refill dlg
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_RESETCONTENT,0,(LPARAM)0);
|
|
|
|
// bottom-most: any invalid textures
|
|
|
|
bool fAnyEntry = false; int32_t cnt; const char *szTexture;
|
|
|
|
if (::Landscape.Mode!=C4LSC_Exact)
|
|
|
|
for (cnt=0; (szTexture=::TextureMap.GetTexture(cnt)); cnt++)
|
|
|
|
{
|
|
|
|
if (!::TextureMap.GetIndex(Material, szTexture, false))
|
|
|
|
{
|
|
|
|
fAnyEntry = true;
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_INSERTSTRING,0,GetWideLPARAM(szTexture));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// separator
|
|
|
|
if (fAnyEntry)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_INSERTSTRING,0,(LPARAM)L"-------");
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// atop: valid textures
|
|
|
|
for (cnt=0; (szTexture=::TextureMap.GetTexture(cnt)); cnt++)
|
|
|
|
{
|
|
|
|
// Current material-texture valid? Always valid for exact mode
|
|
|
|
if (::TextureMap.GetIndex(Material,szTexture,false) || ::Landscape.Mode==C4LSC_Exact)
|
|
|
|
{
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_INSERTSTRING,0,GetWideLPARAM(szTexture));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// reselect current
|
2011-08-19 20:03:03 +00:00
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_SELECTSTRING,0,GetWideLPARAM(Texture));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::NeedPreviewUpdate()
|
|
|
|
{
|
|
|
|
if (!state->hDialog) return;
|
|
|
|
|
2011-10-03 14:06:41 +00:00
|
|
|
C4Surface * sfcPreview;
|
2010-12-11 18:50:38 +00:00
|
|
|
int32_t iPrvWdt,iPrvHgt;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
GetClientRect(GetDlgItem(state->hDialog,IDC_PREVIEW),&rect);
|
|
|
|
|
|
|
|
iPrvWdt=rect.right-rect.left;
|
|
|
|
iPrvHgt=rect.bottom-rect.top;
|
|
|
|
|
2011-10-03 14:06:41 +00:00
|
|
|
if (!(sfcPreview=new C4Surface(iPrvWdt,iPrvHgt))) return;
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
// fill bg
|
2011-10-03 14:30:18 +00:00
|
|
|
pDraw->DrawBoxDw(sfcPreview,0,0,iPrvWdt-1,iPrvHgt-1,C4RGB(0x80,0x80,0x80));
|
2010-12-11 18:50:38 +00:00
|
|
|
BYTE bCol = 0;
|
2011-09-30 20:15:51 +00:00
|
|
|
C4Pattern Pattern;
|
2010-12-11 18:50:38 +00:00
|
|
|
// Sky material: sky as pattern only
|
|
|
|
if (SEqual(Material,C4TLS_MatSky))
|
|
|
|
{
|
|
|
|
Pattern.Set(::Landscape.Sky.Surface, 0);
|
|
|
|
}
|
|
|
|
// Material-Texture
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bCol=Mat2PixColDefault(::MaterialMap.Get(Material));
|
|
|
|
// Get/Create TexMap entry
|
|
|
|
BYTE iTex = ::TextureMap.GetIndex(Material, Texture, true);
|
|
|
|
if (iTex)
|
|
|
|
{
|
|
|
|
// Define texture pattern
|
|
|
|
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
|
|
|
|
// Security
|
|
|
|
if (pTex)
|
|
|
|
{
|
|
|
|
// Set drawing pattern
|
|
|
|
Pattern = pTex->GetPattern();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IsWindowEnabled(GetDlgItem(state->hDialog,IDC_PREVIEW)))
|
2011-10-03 14:30:18 +00:00
|
|
|
pDraw->DrawPatternedCircle( sfcPreview,
|
2011-08-03 23:30:37 +00:00
|
|
|
iPrvWdt/2,iPrvHgt/2,
|
|
|
|
Grade,
|
|
|
|
bCol, Pattern, *::Landscape.GetPal());
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
//Application.DDraw->AttachPrimaryPalette(sfcPreview);
|
|
|
|
|
|
|
|
#ifdef USE_DIRECTX
|
|
|
|
if (pD3D)
|
|
|
|
pD3D->BlitSurface2Window( sfcPreview,
|
|
|
|
0,0,iPrvWdt,iPrvHgt,
|
2010-12-14 01:06:48 +00:00
|
|
|
GetDlgItem(state->hDialog,IDC_PREVIEW),
|
2010-12-11 18:50:38 +00:00
|
|
|
rect.left,rect.top,rect.right,rect.bottom);
|
|
|
|
#endif
|
|
|
|
#ifdef USE_GL
|
|
|
|
// FIXME: This activates the wrong GL context. To avoid breaking the main window display,
|
|
|
|
// FIXME: it has been disabled for the moment
|
|
|
|
//if (pGLCtx->Select())
|
|
|
|
//{
|
|
|
|
// pGL->Blit(sfcPreview, 0,0,(float)iPrvWdt,(float)iPrvHgt, Application.pWindow->pSurface, rect.left,rect.top, iPrvWdt,iPrvHgt);
|
|
|
|
// Application.pWindow->pSurface->PageFlip();
|
|
|
|
//}
|
|
|
|
#endif
|
|
|
|
delete sfcPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::InitGradeCtrl()
|
|
|
|
{
|
|
|
|
if (!state->hDialog) return;
|
|
|
|
HWND hwndTrack = GetDlgItem(state->hDialog,IDC_SLIDERGRADE);
|
|
|
|
SendMessage(hwndTrack,TBM_SETPAGESIZE,0,(LPARAM)5);
|
|
|
|
SendMessage(hwndTrack,TBM_SETLINESIZE,0,(LPARAM)1);
|
|
|
|
SendMessage(hwndTrack,TBM_SETRANGE,(WPARAM)false,
|
|
|
|
(LPARAM) MAKELONG(C4TLS_GradeMin,C4TLS_GradeMax));
|
|
|
|
SendMessage(hwndTrack,TBM_SETPOS,(WPARAM)true,(LPARAM)C4TLS_GradeMax-Grade);
|
|
|
|
UpdateWindow(hwndTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ToolsDlg::PopMaterial()
|
|
|
|
{
|
|
|
|
if (!state->hDialog) return false;
|
|
|
|
SetFocus(GetDlgItem(state->hDialog,IDC_COMBOMATERIAL));
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOMATERIAL,CB_SHOWDROPDOWN,true,0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4ToolsDlg::PopTextures()
|
|
|
|
{
|
|
|
|
if (!state->hDialog) return false;
|
|
|
|
SetFocus(GetDlgItem(state->hDialog,IDC_COMBOTEXTURE));
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_COMBOTEXTURE,CB_SHOWDROPDOWN,true,0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::UpdateIFTControls()
|
|
|
|
{
|
|
|
|
if (!state->hDialog)
|
|
|
|
return;
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_BUTTONNOIFT,BM_SETSTATE,(ModeIFT==0),0);
|
|
|
|
UpdateWindow(GetDlgItem(state->hDialog,IDC_BUTTONNOIFT));
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_BUTTONIFT,BM_SETSTATE,(ModeIFT==1),0);
|
|
|
|
UpdateWindow(GetDlgItem(state->hDialog,IDC_BUTTONIFT));
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4ToolsDlg::UpdateLandscapeModeCtrls()
|
|
|
|
{
|
|
|
|
int32_t iMode = ::Landscape.Mode;
|
|
|
|
// Dynamic: enable only if dynamic anyway
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_BUTTONMODEDYNAMIC,BM_SETSTATE,(iMode==C4LSC_Dynamic),0);
|
|
|
|
EnableWindow(GetDlgItem(state->hDialog,IDC_BUTTONMODEDYNAMIC),(iMode==C4LSC_Dynamic));
|
|
|
|
UpdateWindow(GetDlgItem(state->hDialog,IDC_BUTTONMODEDYNAMIC));
|
|
|
|
// Static: enable only if map available
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_BUTTONMODESTATIC,BM_SETSTATE,(iMode==C4LSC_Static),0);
|
|
|
|
EnableWindow(GetDlgItem(state->hDialog,IDC_BUTTONMODESTATIC),(::Landscape.Map!=NULL));
|
|
|
|
UpdateWindow(GetDlgItem(state->hDialog,IDC_BUTTONMODESTATIC));
|
|
|
|
// Exact: enable always
|
|
|
|
SendDlgItemMessage(state->hDialog,IDC_BUTTONMODEEXACT,BM_SETSTATE,(iMode==C4LSC_Exact),0);
|
|
|
|
UpdateWindow(GetDlgItem(state->hDialog,IDC_BUTTONMODEEXACT));
|
|
|
|
// Set dialog caption
|
2011-04-03 13:47:02 +00:00
|
|
|
SetWindowTextW(state->hDialog,LoadResStrW(iMode==C4LSC_Dynamic ? "IDS_DLG_DYNAMIC" : iMode==C4LSC_Static ? "IDS_DLG_STATIC" : "IDS_DLG_EXACT"));
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 16:16:51 +00:00
|
|
|
|
|
|
|
void C4ToolsDlg::EnableControls()
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2011-01-04 16:16:51 +00:00
|
|
|
HWND hDialog = state->hDialog;
|
2010-12-11 18:50:38 +00:00
|
|
|
int32_t iLandscapeMode=::Landscape.Mode;
|
|
|
|
// Set bitmap buttons
|
2011-01-04 16:16:51 +00:00
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONBRUSH,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((iLandscapeMode>=C4LSC_Static) ? state->hbmBrush : state->hbmBrush2));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONLINE,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((iLandscapeMode>=C4LSC_Static) ? state->hbmLine : state->hbmLine2));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONRECT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((iLandscapeMode>=C4LSC_Static) ? state->hbmRect : state->hbmRect2));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONFILL,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((iLandscapeMode>=C4LSC_Exact) ? state->hbmFill : state->hbmFill2));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONPICKER,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)((iLandscapeMode>=C4LSC_Static) ? state->hbmPicker : state->hbmPicker2));
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONIFT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)state->hbmIFT);
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONNOIFT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)state->hbmNoIFT);
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONMODEDYNAMIC,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)state->hbmDynamic);
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONMODESTATIC,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)state->hbmStatic);
|
|
|
|
SendDlgItemMessage(hDialog,IDC_BUTTONMODEEXACT,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)state->hbmExact);
|
2010-12-11 18:50:38 +00:00
|
|
|
// Enable drawing controls
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONBRUSH),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONLINE),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONRECT),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONFILL),(iLandscapeMode>=C4LSC_Exact));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONPICKER),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONIFT),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_BUTTONNOIFT),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_COMBOMATERIAL),(iLandscapeMode>=C4LSC_Static));
|
2011-01-04 16:16:51 +00:00
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_COMBOTEXTURE),(iLandscapeMode>=C4LSC_Static) && !SEqual(Material,C4TLS_MatSky));
|
2010-12-11 18:50:38 +00:00
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_STATICMATERIAL),(iLandscapeMode>=C4LSC_Static));
|
2011-01-04 16:16:51 +00:00
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_STATICTEXTURE),(iLandscapeMode>=C4LSC_Static) && !SEqual(Material,C4TLS_MatSky));
|
2010-12-11 18:50:38 +00:00
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_SLIDERGRADE),(iLandscapeMode>=C4LSC_Static));
|
|
|
|
EnableWindow(GetDlgItem(hDialog,IDC_PREVIEW),(iLandscapeMode>=C4LSC_Static));
|
2011-01-04 16:16:51 +00:00
|
|
|
|
|
|
|
NeedPreviewUpdate();
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2010-12-13 02:11:06 +00:00
|
|
|
#include "C4ConsoleGUICommon.h"
|