2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 1998-2000, 2003-2004, 2008 Matthes Bender
|
|
|
|
* Copyright (c) 2001-2002, 2004-2007 Sven Eberhardt
|
|
|
|
* Copyright (c) 2004, 2007, 2009 Peter Wortmann
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2005-2007, 2009-2010 Günther Brammer
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2006 Armin Burgmeier
|
|
|
|
* Copyright (c) 2009 Nicolas Hake
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2010 Benjamin Herr
|
|
|
|
* Copyright (c) 2010 Mortimer
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Handles engine execution in developer mode */
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4Console.h>
|
|
|
|
#include <C4Application.h>
|
|
|
|
|
|
|
|
#include <C4GameSave.h>
|
2009-06-05 18:00:23 +00:00
|
|
|
#include <C4Game.h>
|
|
|
|
#include <C4MessageInput.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
#include <C4UserMessages.h>
|
|
|
|
#include <C4Version.h>
|
|
|
|
#include <C4Language.h>
|
|
|
|
#include <C4Player.h>
|
2009-06-05 18:00:23 +00:00
|
|
|
#include <C4Landscape.h>
|
|
|
|
#include <C4GraphicsSystem.h>
|
2010-09-29 01:44:05 +00:00
|
|
|
#include <C4Viewport.h>
|
2009-06-12 23:09:32 +00:00
|
|
|
#include <C4PlayerList.h>
|
2009-06-15 22:06:37 +00:00
|
|
|
#include <C4GameControl.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#include <StdFile.h>
|
|
|
|
#include <StdRegistry.h>
|
|
|
|
|
2010-03-22 17:00:47 +00:00
|
|
|
#define FILE_SELECT_FILTER_FOR_C4S "Clonk 4 Scenario\0" \
|
2010-03-28 18:58:01 +00:00
|
|
|
"*.c4s;*.c4f;Scenario.txt\0" \
|
|
|
|
"\0"
|
2010-03-22 17:00:47 +00:00
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
using namespace OpenFileFlags;
|
|
|
|
|
|
|
|
C4Console::C4Console(): C4ConsoleGUI()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
Active = false;
|
|
|
|
Editing = true;
|
2009-05-08 13:28:41 +00:00
|
|
|
ScriptCounter=0;
|
|
|
|
FrameCounter=0;
|
2009-08-15 18:50:32 +00:00
|
|
|
fGameOpen=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
hWindow=NULL;
|
2010-12-11 18:50:38 +00:00
|
|
|
#endif
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4Console::~C4Console()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
#if defined(USE_X11) && !defined(WITH_DEVELOPER_MODE)
|
2009-05-08 13:28:41 +00:00
|
|
|
void C4Console::HandleMessage (XEvent & e)
|
|
|
|
{
|
|
|
|
// Parent handling
|
|
|
|
C4ConsoleBase::HandleMessage(e);
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
switch (e.type)
|
|
|
|
{
|
|
|
|
case FocusIn:
|
2009-05-08 13:28:41 +00:00
|
|
|
Application.Active = true;
|
|
|
|
break;
|
2010-03-28 18:58:01 +00:00
|
|
|
case FocusOut:
|
2009-05-08 13:28:41 +00:00
|
|
|
Application.Active = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-11 18:50:38 +00:00
|
|
|
#endif // USE_X11
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
CStdWindow * C4Console::Init(CStdApp * pApp)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-11 18:50:38 +00:00
|
|
|
return C4ConsoleGUI::CreateConsoleWindow(pApp);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Console::In(const char *szText)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Active || !szText) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// begins with '/'? then it's a command
|
|
|
|
if (*szText == '/')
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:18:45 +00:00
|
|
|
::MessageInput.ProcessCommand(szText);
|
2009-05-08 13:28:41 +00:00
|
|
|
// done
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// begins with '#'? then it's a message. Route cia ProcessInput to allow #/sound
|
|
|
|
if (*szText == '#')
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:18:45 +00:00
|
|
|
::MessageInput.ProcessInput(szText + 1);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// editing enabled?
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!EditCursor.EditingOK()) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// pass through network queue
|
2009-06-15 22:06:37 +00:00
|
|
|
::Control.DoInput(CID_Script, new C4ControlScript(szText, C4ControlScript::SCOPE_Console, false), CDT_Decide);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Someone defines Status as int....
|
|
|
|
#ifdef Status
|
|
|
|
#undef Status
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void C4Console::DoPlay()
|
|
|
|
{
|
|
|
|
Game.Unpause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4Console::DoHalt()
|
|
|
|
{
|
|
|
|
Game.Pause();
|
|
|
|
}
|
|
|
|
|
2010-12-14 01:06:23 +00:00
|
|
|
void C4Console::UpdateStatusBars()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-14 01:06:23 +00:00
|
|
|
if (!Active) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Frame counter
|
|
|
|
if (Game.FrameCounter!=FrameCounter)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
FrameCounter=Game.FrameCounter;
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
|
|
|
str.Format("Frame: %i",FrameCounter);
|
2010-12-11 18:50:38 +00:00
|
|
|
C4ConsoleGUI::DisplayInfoText(CONSOLE_FrameCounter, str);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Script counter
|
|
|
|
if (Game.Script.Counter!=ScriptCounter)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
ScriptCounter=Game.Script.Counter;
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
|
|
|
str.Format("Script: %i",ScriptCounter);
|
2010-12-11 18:50:38 +00:00
|
|
|
C4ConsoleGUI::DisplayInfoText(CONSOLE_ScriptCounter, str);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Time & FPS
|
|
|
|
if ((Game.Time!=Time) || (Game.FPS!=FPS))
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Time=Game.Time;
|
|
|
|
FPS=Game.FPS;
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
|
|
|
str.Format("%02d:%02d:%02d (%i FPS)",Time/3600,(Time%3600)/60,Time%60,FPS);
|
2010-12-11 18:50:38 +00:00
|
|
|
C4ConsoleGUI::DisplayInfoText(CONSOLE_TimeFPS, str);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::SaveGame(bool fSaveGame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Network hosts only
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled() && !::Network.isHost())
|
2009-08-15 18:50:32 +00:00
|
|
|
{ Message(LoadResStr("IDS_GAME_NOCLIENTSAVE")); return false; }
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Can't save to child groups
|
|
|
|
if (Game.ScenarioFile.GetMother())
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
|
|
|
str.Format(LoadResStr("IDS_CNS_NOCHILDSAVE"),
|
2010-03-28 18:58:01 +00:00
|
|
|
GetFilename(Game.ScenarioFile.GetName()));
|
2009-05-11 13:09:53 +00:00
|
|
|
Message(str.getData());
|
2009-08-15 18:50:32 +00:00
|
|
|
return false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Save game to open scenario file
|
2009-08-15 18:50:32 +00:00
|
|
|
bool fOkay=true;
|
2010-12-11 18:50:38 +00:00
|
|
|
Console.SetCursor(C4ConsoleGUI::CURSOR_Wait);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4GameSave *pGameSave;
|
|
|
|
if (fSaveGame)
|
|
|
|
pGameSave = new C4GameSaveSavegame();
|
|
|
|
else
|
2009-06-05 15:20:41 +00:00
|
|
|
pGameSave = new C4GameSaveScenario(!Console.Active || ::Landscape.Mode==C4LSC_Exact, false);
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!pGameSave->Save(Game.ScenarioFile, false))
|
2009-08-15 18:50:32 +00:00
|
|
|
{ Out("Game::Save failed"); fOkay=false; }
|
2009-05-08 13:28:41 +00:00
|
|
|
delete pGameSave;
|
|
|
|
|
|
|
|
// Close and reopen scenario file to fix file changes
|
|
|
|
if (!Game.ScenarioFile.Close())
|
2009-08-15 18:50:32 +00:00
|
|
|
{ Out("ScenarioFile::Close failed"); fOkay=false; }
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!Game.ScenarioFile.Open(Game.ScenarioFilename))
|
2009-08-15 18:50:32 +00:00
|
|
|
{ Out("ScenarioFile::Open failed"); fOkay=false; }
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
Console.SetCursor(C4ConsoleGUI::CURSOR_Normal);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Initialize/script notification
|
|
|
|
if (Game.fScriptCreatedObjects)
|
|
|
|
if (!fSaveGame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str(LoadResStr("IDS_CNS_SCRIPTCREATEDOBJECTS"));
|
|
|
|
str += LoadResStr("IDS_CNS_WARNDOUBLE");
|
|
|
|
Message(str.getData());
|
2009-08-15 18:50:32 +00:00
|
|
|
Game.fScriptCreatedObjects=false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Status report
|
|
|
|
if (!fOkay) Message(LoadResStr("IDS_CNS_SAVERROR"));
|
|
|
|
else Out(LoadResStr(fSaveGame ? "IDS_CNS_GAMESAVED" : "IDS_CNS_SCENARIOSAVED"));
|
|
|
|
|
|
|
|
return fOkay;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileSave(bool fSaveGame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Don't quicksave games over scenarios
|
|
|
|
if (fSaveGame)
|
|
|
|
if (!Game.C4S.Head.SaveGame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Message(LoadResStr("IDS_CNS_NOGAMEOVERSCEN"));
|
2009-08-15 18:50:32 +00:00
|
|
|
return false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Save game
|
|
|
|
return SaveGame(fSaveGame);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileSaveAs(bool fSaveGame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Do save-as dialog
|
|
|
|
char filename[512+1];
|
|
|
|
SCopy(Game.ScenarioFile.GetName(),filename);
|
|
|
|
if (!FileSelect(filename,512,
|
2010-03-28 18:58:01 +00:00
|
|
|
"Clonk 4 Scenario\0*.c4s\0\0",
|
|
|
|
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY,
|
|
|
|
true)) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
DefaultExtension(filename,"c4s");
|
2009-08-15 18:50:32 +00:00
|
|
|
bool fOkay=true;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Close current scenario file
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Game.ScenarioFile.Close()) fOkay=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Copy current scenario file to target
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!C4Group_CopyItem(Game.ScenarioFilename,filename)) fOkay=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Open new scenario file
|
|
|
|
SCopy(filename,Game.ScenarioFilename);
|
|
|
|
|
|
|
|
SetCaption(GetFilename(Game.ScenarioFilename));
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Game.ScenarioFile.Open(Game.ScenarioFilename)) fOkay=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Failure message
|
|
|
|
if (!fOkay)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
Message(FormatString(LoadResStr("IDS_CNS_SAVEASERROR"),Game.ScenarioFilename).getData()); return false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Save game
|
|
|
|
return SaveGame(fSaveGame);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4Console::Message(const char *szMessage, bool fQuery)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Active) return false;
|
2010-12-11 18:50:38 +00:00
|
|
|
return C4ConsoleGUI::Message(szMessage, fQuery);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileOpen()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Get scenario file name
|
|
|
|
char c4sfile[512+1]="";
|
|
|
|
if (!FileSelect(c4sfile,512,
|
2010-03-22 17:00:47 +00:00
|
|
|
FILE_SELECT_FILTER_FOR_C4S,
|
|
|
|
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST))
|
|
|
|
return false;
|
2010-10-04 19:39:19 +00:00
|
|
|
Application.ClearCommandLine();
|
2009-05-08 13:28:41 +00:00
|
|
|
// Open game
|
2011-01-06 23:51:35 +00:00
|
|
|
Application.OpenGame(c4sfile);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileOpenWPlrs()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Get scenario file name
|
|
|
|
char c4sfile[512+1]="";
|
|
|
|
if (!FileSelect(c4sfile,512,
|
2010-03-22 17:00:47 +00:00
|
|
|
FILE_SELECT_FILTER_FOR_C4S,
|
|
|
|
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST))
|
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Get player file name(s)
|
|
|
|
char c4pfile[4096+1]="";
|
|
|
|
if (!FileSelect(c4pfile,4096,
|
2010-03-28 18:58:01 +00:00
|
|
|
"Clonk 4 Player\0*.c4p\0\0",
|
|
|
|
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER
|
|
|
|
)) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Compose command line
|
2010-10-04 19:39:19 +00:00
|
|
|
Application.ClearCommandLine();
|
2009-05-08 13:28:41 +00:00
|
|
|
if (DirectoryExists(c4pfile)) // Multiplayer
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-10-04 19:39:19 +00:00
|
|
|
const char *cptr = c4pfile + SLen(c4pfile) + 1;
|
2009-05-08 13:28:41 +00:00
|
|
|
while (*cptr)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-10-04 19:39:19 +00:00
|
|
|
char c4pfile2[512 + 1] = "";
|
|
|
|
SAppend(c4pfile, c4pfile2, 512);
|
|
|
|
SAppend(DirSep, c4pfile2, 512);
|
|
|
|
SAppend(cptr, c4pfile2, 512);
|
|
|
|
SAddModule(Game.PlayerFilenames, c4pfile2);
|
|
|
|
cptr += SLen(cptr) + 1;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
else // Single player
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-10-04 19:39:19 +00:00
|
|
|
SAddModule(Game.PlayerFilenames, c4pfile);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Open game
|
2011-01-06 23:51:35 +00:00
|
|
|
Application.OpenGame(c4sfile);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileClose()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-06 23:51:35 +00:00
|
|
|
if (!fGameOpen) return false;
|
|
|
|
Application.QuitGame();
|
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileSelect(char *sFilename, int iSize, const char * szFilter, DWORD dwFlags, bool fSave)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-11 18:50:38 +00:00
|
|
|
return C4ConsoleGUI::FileSelect(sFilename, iSize, szFilter, dwFlags, fSave);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileRecord()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// only in running mode
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Game.IsRunning || !::Control.IsRuntimeRecordPossible()) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// start record!
|
2009-06-15 22:06:37 +00:00
|
|
|
::Control.RequestRuntimeRecord();
|
2009-05-08 13:28:41 +00:00
|
|
|
// disable menuitem
|
2010-12-11 18:50:38 +00:00
|
|
|
RecordingEnabled();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::ClearPointers(C4Object *pObj)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
EditCursor.ClearPointers(pObj);
|
|
|
|
PropertyDlg.ClearPointers(pObj);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::Default()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
EditCursor.Default();
|
|
|
|
PropertyDlg.Default();
|
|
|
|
ToolsDlg.Default();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::Clear()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
C4ConsoleBase::Clear();
|
|
|
|
EditCursor.Clear();
|
|
|
|
PropertyDlg.Clear();
|
|
|
|
ToolsDlg.Clear();
|
|
|
|
ClearViewportMenu();
|
|
|
|
ClearPlayerMenu();
|
|
|
|
ClearNetMenu();
|
2010-03-28 18:58:01 +00:00
|
|
|
if (pSurface) delete pSurface;
|
2010-03-25 19:58:46 +00:00
|
|
|
pSurface = 0;
|
2009-05-08 13:28:41 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
Application.Quit();
|
|
|
|
#endif
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::Close()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Application.Quit();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4Console::FileQuit()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Close();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::HelpAbout()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
StdStrBuf strCopyright;
|
|
|
|
strCopyright.Format("Copyright (c) %s %s", C4COPYRIGHT_YEAR, C4COPYRIGHT_COMPANY);
|
2010-12-11 18:50:38 +00:00
|
|
|
ShowAboutWithCopyright(strCopyright);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::ViewportNew()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-09-29 01:44:05 +00:00
|
|
|
::Viewports.CreateViewport(NO_OWNER);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4Console::UpdateViewportMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Active) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
ClearViewportMenu();
|
2009-06-12 23:09:32 +00:00
|
|
|
for (C4Player *pPlr=::Players.First; pPlr; pPlr=pPlr->Next)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
StdStrBuf sText;
|
|
|
|
sText.Format(LoadResStr("IDS_CNS_NEWPLRVIEWPORT"),pPlr->GetName());
|
2010-12-11 18:50:38 +00:00
|
|
|
C4ConsoleGUI::AddMenuItemForPlayer(pPlr, sText);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::ClearViewportMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!Active) return;
|
2010-12-11 18:50:38 +00:00
|
|
|
C4ConsoleGUI::ClearViewportMenu();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::EditTitle()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled()) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
Game.Title.Open();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::EditScript()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled()) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
Game.Script.Open();
|
2010-03-27 16:05:02 +00:00
|
|
|
::ScriptEngine.ReLink(&::Definitions);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::EditInfo()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled()) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
Game.Info.Open();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::EditObjects()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
ObjectListDlg.Open();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::UpdateInputCtrl()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
int cnt;
|
|
|
|
C4AulScriptFunc *pRef;
|
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
ClearInput();
|
2009-05-08 13:28:41 +00:00
|
|
|
// add global and standard functions
|
2010-12-11 18:50:38 +00:00
|
|
|
std::vector<char*> functions;
|
2009-06-05 15:21:11 +00:00
|
|
|
for (C4AulFunc *pFn = ::ScriptEngine.GetFirstFunc(); pFn; pFn = ::ScriptEngine.GetNextFunc(pFn))
|
2010-12-11 18:50:38 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (pFn->GetPublic())
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-11 18:50:38 +00:00
|
|
|
functions.push_back(pFn->Name);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Add scenario script functions
|
2010-12-11 18:50:38 +00:00
|
|
|
if (pRef=Game.Script.GetSFunc(0))
|
|
|
|
functions.push_back((char*)C4ConsoleGUI::LIST_DIVIDER);
|
2010-01-25 04:00:59 +00:00
|
|
|
for (cnt=0; (pRef=Game.Script.GetSFunc(cnt)); cnt++)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-11 18:50:38 +00:00
|
|
|
functions.push_back(pRef->Name);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-12-11 18:50:38 +00:00
|
|
|
SetInputFunctions(functions);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4Console::UpdatePlayerMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Active) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
ClearPlayerMenu();
|
2009-06-12 23:09:32 +00:00
|
|
|
for (C4Player *pPlr=::Players.First; pPlr; pPlr=pPlr->Next)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
StdStrBuf sText;
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled())
|
2009-05-08 13:28:41 +00:00
|
|
|
sText.Format(LoadResStr("IDS_CNS_PLRQUITNET"),pPlr->GetName(),pPlr->AtClientName);
|
|
|
|
else
|
|
|
|
sText.Format(LoadResStr("IDS_CNS_PLRQUIT"),pPlr->GetName());
|
2010-12-11 18:50:38 +00:00
|
|
|
AddKickPlayerMenuItem(pPlr, sText, (!::Network.isEnabled() || ::Network.isHost()) && Editing);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::UpdateMenus()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!Active) return;
|
|
|
|
EnableControls(fGameOpen);
|
|
|
|
UpdatePlayerMenu();
|
|
|
|
UpdateViewportMenu();
|
|
|
|
UpdateNetMenu();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::PlayerJoin()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Get player file name(s)
|
|
|
|
char c4pfile[4096+1]="";
|
|
|
|
if (!FileSelect(c4pfile,4096,
|
2010-03-28 18:58:01 +00:00
|
|
|
"Clonk 4 Player\0*.c4p\0\0",
|
|
|
|
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER
|
|
|
|
)) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Compose player file list
|
|
|
|
char c4plist[6000]="";
|
|
|
|
// Multiple players
|
|
|
|
if (DirectoryExists(c4pfile))
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
const char *cptr = c4pfile+SLen(c4pfile)+1;
|
|
|
|
while (*cptr)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
SNewSegment(c4plist);
|
2010-03-28 18:58:01 +00:00
|
|
|
SAppend(c4pfile,c4plist); SAppend(DirSep ,c4plist); SAppend(cptr,c4plist);
|
2009-05-08 13:28:41 +00:00
|
|
|
cptr += SLen(cptr)+1;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Single player
|
|
|
|
else
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
SAppend(c4pfile,c4plist);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Join players (via network/ctrl queue)
|
|
|
|
char szPlayerFilename[_MAX_PATH+1];
|
|
|
|
for (int iPar=0; SCopySegment(c4plist,iPar,szPlayerFilename,';',_MAX_PATH); iPar++)
|
|
|
|
if (szPlayerFilename[0])
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-06-05 15:19:46 +00:00
|
|
|
if (::Network.isEnabled())
|
|
|
|
::Network.Players.JoinLocalPlayer(szPlayerFilename, true);
|
2009-05-08 13:28:41 +00:00
|
|
|
else
|
2009-06-12 23:09:32 +00:00
|
|
|
::Players.CtrlJoinLocalNoNetwork(szPlayerFilename, Game.Clients.getLocalID(), Game.Clients.getLocalName());
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::UpdateNetMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Active & network hosting check
|
|
|
|
if (!Active) return;
|
2009-06-05 15:19:46 +00:00
|
|
|
if (!::Network.isHost() || !::Network.isEnabled()) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Clear old
|
|
|
|
ClearNetMenu();
|
|
|
|
// Insert menu
|
2011-01-04 19:31:55 +00:00
|
|
|
C4ConsoleGUI::AddNetMenu();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Host
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
|
|
|
str.Format(LoadResStr("IDS_MNU_NETHOST"),Game.Clients.getLocalName(),Game.Clients.getLocalID());
|
2010-12-11 18:50:38 +00:00
|
|
|
AddNetMenuItemForPlayer(IDM_NET_CLIENT1+Game.Clients.getLocalID(), str);
|
2009-05-08 13:28:41 +00:00
|
|
|
// Clients
|
2009-06-05 15:19:46 +00:00
|
|
|
for (C4Network2Client *pClient=::Network.Clients.GetNextClient(NULL); pClient; pClient=::Network.Clients.GetNextClient(pClient))
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
str.Format(LoadResStr(pClient->isActivated() ? "IDS_MNU_NETCLIENT" : "IDS_MNU_NETCLIENTDE"),
|
|
|
|
pClient->getName(), pClient->getID());
|
2010-12-11 18:50:38 +00:00
|
|
|
AddNetMenuItemForPlayer(IDM_NET_CLIENT1+pClient->getID(), str);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
return;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::ClearNetMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!Active) return;
|
2011-01-04 19:31:55 +00:00
|
|
|
C4ConsoleGUI::ClearNetMenu();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-12-11 18:50:38 +00:00
|
|
|
void C4Console::SetCaptionToFilename(const char* szFilename)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-11 18:50:38 +00:00
|
|
|
SetCaption(GetFilename(szFilename));
|
|
|
|
C4ConsoleGUI::SetCaptionToFileName(szFilename);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4Console::Execute()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
EditCursor.Execute();
|
|
|
|
PropertyDlg.Execute();
|
|
|
|
ObjectListDlg.Execute();
|
|
|
|
UpdateStatusBars();
|
2009-06-05 15:14:20 +00:00
|
|
|
::GraphicsSystem.Execute();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-01-06 23:51:35 +00:00
|
|
|
void C4Console::InitGame()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-06 23:51:35 +00:00
|
|
|
if (!Active) return;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Default game dependent members
|
|
|
|
Default();
|
2011-01-06 23:51:35 +00:00
|
|
|
SetCaptionToFilename(Game.ScenarioFilename);
|
2009-05-08 13:28:41 +00:00
|
|
|
// Init game dependent members
|
2011-01-06 23:51:35 +00:00
|
|
|
EditCursor.Init();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Console updates
|
2009-08-15 18:50:32 +00:00
|
|
|
fGameOpen=true;
|
2009-05-08 13:28:41 +00:00
|
|
|
UpdateInputCtrl();
|
|
|
|
EnableControls(fGameOpen);
|
|
|
|
UpdatePlayerMenu();
|
|
|
|
UpdateViewportMenu();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-01-06 23:51:35 +00:00
|
|
|
void C4Console::CloseGame()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-06 23:51:35 +00:00
|
|
|
if (!Active || !fGameOpen) return;
|
2009-08-15 18:50:32 +00:00
|
|
|
fGameOpen=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
EnableControls(fGameOpen);
|
|
|
|
SetCaption(LoadResStr("IDS_CNS_CONSOLE"));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4Console::TogglePause()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return Game.TogglePause();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|