Initial commit
This commit is contained in:
256
devtools/create_engine/create_engine.cpp
Normal file
256
devtools/create_engine/create_engine.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define MAX_LINE_LENGTH 256
|
||||
|
||||
// Specified engine name with different cases
|
||||
#define MAX_ENGINE_NAME_LENGTH 64
|
||||
char engineUppercase[MAX_ENGINE_NAME_LENGTH];
|
||||
char engineCamelcase[MAX_ENGINE_NAME_LENGTH];
|
||||
char engineLowercase[MAX_ENGINE_NAME_LENGTH];
|
||||
|
||||
// List of files to be copied to create engine
|
||||
static const char *const FILENAMES[] = {
|
||||
"files/configure.engine", "files/console.cpp", "files/console.h",
|
||||
"files/credits.pl", "files/detection.cpp", "files/detection.h",
|
||||
"files/detection_tables.h", "files/metaengine.cpp",
|
||||
"files/metaengine.h", "files/module.mk", "files/xyzzy.cpp",
|
||||
"files/xyzzy.h", "files/POTFILES", nullptr
|
||||
};
|
||||
|
||||
static const char *const FILENAMES_EVENTS[] = {
|
||||
"files/configure.engine", "files/console.cpp", "files/console.h",
|
||||
"files/credits.pl", "files/detection.cpp", "files/detection.h",
|
||||
"files/detection_tables.h",
|
||||
"files_events/events.cpp", "files_events/events.h",
|
||||
"files_events/messages.cpp", "files_events/messages.h",
|
||||
"files/metaengine.cpp", "files/metaengine.h",
|
||||
"files_events/module.mk", "files_events/xyzzy.cpp",
|
||||
"files_events/xyzzy.h", "files/POTFILES", "files_events/views.h",
|
||||
"files_events/view.cpp", "files_events/view.h",
|
||||
"files_events/view1.cpp", "files_events/view1.h",
|
||||
nullptr
|
||||
};
|
||||
|
||||
const char *const ENGINES = "create_project ..\\.. --msvc\n";
|
||||
|
||||
bool fileExists(const char *name) {
|
||||
#ifdef _WIN32
|
||||
return (GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES);
|
||||
#else
|
||||
return (!access(name, F_OK));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool createDirectory(const char *name) {
|
||||
#ifdef _WIN32
|
||||
return CreateDirectoryA(name, nullptr);
|
||||
#else
|
||||
return (!mkdir(name, 0755));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Replaces any occurrences of the xyzzy placeholder with
|
||||
// whatever engine name was specified
|
||||
void replace_placeholders(char line[MAX_LINE_LENGTH]) {
|
||||
char buf[MAX_LINE_LENGTH];
|
||||
char *pos;
|
||||
|
||||
while ((pos = strstr(line, "XYZZY"))) {
|
||||
*pos = '\0';
|
||||
snprintf(buf, MAX_LINE_LENGTH, "%s%s%s", line,
|
||||
engineUppercase, pos + 5);
|
||||
strncpy(line, buf, MAX_LINE_LENGTH);
|
||||
}
|
||||
|
||||
while ((pos = strstr(line, "Xyzzy"))) {
|
||||
*pos = '\0';
|
||||
snprintf(buf, MAX_LINE_LENGTH, "%s%s%s", line,
|
||||
engineCamelcase, pos + 5);
|
||||
strncpy(line, buf, MAX_LINE_LENGTH);
|
||||
}
|
||||
|
||||
while ((pos = strstr(line, "xyzzy"))) {
|
||||
*pos = '\0';
|
||||
snprintf(buf, MAX_LINE_LENGTH, "%s%s%s", line,
|
||||
engineLowercase, pos + 5);
|
||||
strncpy(line, buf, MAX_LINE_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
// Loops through copying and processing a single file
|
||||
void process_file(FILE *in, FILE *out) {
|
||||
char line[MAX_LINE_LENGTH] = { 0 };
|
||||
|
||||
// Get each line until there are none left
|
||||
while (fgets(line, MAX_LINE_LENGTH, in)) {
|
||||
// Do any replacements of engine name
|
||||
replace_placeholders(line);
|
||||
|
||||
// Write out the line
|
||||
fputs(line, out);
|
||||
}
|
||||
}
|
||||
|
||||
// Copies and processes the specified file
|
||||
void process_file(const char *filePath, const char *prefix, const char *prefix2) {
|
||||
char srcFilename[MAX_LINE_LENGTH], destFilename[MAX_LINE_LENGTH];
|
||||
const char *filename = strchr(filePath, '/') + 1;
|
||||
|
||||
snprintf(srcFilename, MAX_LINE_LENGTH, "%s/%s", prefix2, filePath);
|
||||
if (!strncmp(filename, "xyzzy.", 6))
|
||||
snprintf(destFilename, MAX_LINE_LENGTH, "%s/engines/%s/%s.%s",
|
||||
prefix, engineLowercase, engineLowercase, filename + 6);
|
||||
else
|
||||
snprintf(destFilename, MAX_LINE_LENGTH, "%s/engines/%s/%s",
|
||||
prefix, engineLowercase, filename);
|
||||
|
||||
printf("Creating file %s...", destFilename);
|
||||
fflush(stdout);
|
||||
|
||||
FILE *in, *out;
|
||||
if (!(in = fopen(srcFilename, "r"))) {
|
||||
printf("Could not locate file - %s\n", srcFilename);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!(out = fopen(destFilename, "w"))) {
|
||||
printf("Could not create file - %s\n", destFilename);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
process_file(in, out);
|
||||
|
||||
printf("done\n");
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
// For Visual Studio convenience, creates a copy of the
|
||||
// create_msvc.bat to <engine>.bat that allows creating
|
||||
// the ScummVM solution with just that engine enabled
|
||||
void create_batch_file(const char *prefix) {
|
||||
FILE *in, *out;
|
||||
char line[MAX_LINE_LENGTH];
|
||||
char destFilename[MAX_LINE_LENGTH];
|
||||
|
||||
snprintf(destFilename, MAX_LINE_LENGTH, "%s/dists/msvc/create_msvc.bat", prefix);
|
||||
if (!(in = fopen(destFilename, "r"))) {
|
||||
printf("Could not open create_msvc.bat\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
snprintf(destFilename, MAX_LINE_LENGTH, "%s/dists/msvc/%s.bat", prefix, engineLowercase);
|
||||
|
||||
printf("Creating file %s...", destFilename);
|
||||
fflush(stdout);
|
||||
|
||||
if (!(out = fopen(destFilename, "w"))) {
|
||||
printf("Could not create %s.bat\n", engineLowercase);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Get each line until there are none left
|
||||
while (fgets(line, MAX_LINE_LENGTH, in)) {
|
||||
if (!strcmp(line, ENGINES)) {
|
||||
snprintf(line + strlen(line) - 1, MAX_LINE_LENGTH - strlen(line) + 1,
|
||||
" --disable-all-engines --disable-detection-full --enable-engine=%s\n",
|
||||
engineLowercase);
|
||||
}
|
||||
|
||||
// Write out the line
|
||||
fputs(line, out);
|
||||
}
|
||||
|
||||
printf("done\n");
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
printf("Please specify engine name as a parameter\n");
|
||||
printf("With an optional -events to create an events based engine.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isEvents = (argc == 3) && !strcmp(argv[2], "-events");
|
||||
|
||||
// Set up different cased engine names
|
||||
for (size_t i = 0; i < strlen(argv[1]) + 1; ++i) {
|
||||
engineUppercase[i] = toupper(argv[1][i]);
|
||||
engineLowercase[i] = tolower(argv[1][i]);
|
||||
engineCamelcase[i] = (i == 0) ?
|
||||
engineUppercase[i] : engineLowercase[i];
|
||||
}
|
||||
|
||||
char prefix[100];
|
||||
char prefix2[100];
|
||||
if (fileExists("../../engines")) {
|
||||
strcpy(prefix, "../..");
|
||||
strcpy(prefix2, ".");
|
||||
} else if (fileExists("engines")) {
|
||||
strcpy(prefix, ".");
|
||||
strcpy(prefix2, "devtools/create_engine");
|
||||
} else {
|
||||
printf("Cound not locate engines directory. Run from the scummvm source root directory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Create a directory for the new engine
|
||||
char folder[MAX_LINE_LENGTH];
|
||||
snprintf(folder, MAX_LINE_LENGTH, "%s/engines/%s", prefix, engineLowercase);
|
||||
|
||||
printf("Creating directory %s...", folder);
|
||||
fflush(stdout);
|
||||
|
||||
if (!createDirectory(folder)) {
|
||||
printf("Could not create engine folder.\n");
|
||||
perror(folder);
|
||||
return 0;
|
||||
}
|
||||
printf("done\n");
|
||||
|
||||
// Process the files
|
||||
const char *const *filenames = isEvents ? FILENAMES_EVENTS : FILENAMES;
|
||||
for (const char *const *filename = filenames; *filename; ++filename)
|
||||
process_file(*filename, prefix, prefix2);
|
||||
|
||||
create_batch_file(prefix);
|
||||
|
||||
printf("Engine generation complete.\n");
|
||||
return 0;
|
||||
}
|
||||
1
devtools/create_engine/files/POTFILES
Normal file
1
devtools/create_engine/files/POTFILES
Normal file
@@ -0,0 +1 @@
|
||||
engines/xyzzy/metaengine.cpp
|
||||
3
devtools/create_engine/files/configure.engine
Normal file
3
devtools/create_engine/files/configure.engine
Normal file
@@ -0,0 +1,3 @@
|
||||
# This file is included from the main "configure" script
|
||||
# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] [components]
|
||||
add_engine xyzzy "Xyzzy" no "" "" "" ""
|
||||
38
devtools/create_engine/files/console.cpp
Normal file
38
devtools/create_engine/files/console.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xyzzy/console.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
Console::Console() : GUI::Debugger() {
|
||||
registerCmd("test", WRAP_METHOD(Console, Cmd_test));
|
||||
}
|
||||
|
||||
Console::~Console() {
|
||||
}
|
||||
|
||||
bool Console::Cmd_test(int argc, const char **argv) {
|
||||
debugPrintf("Test\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
40
devtools/create_engine/files/console.h
Normal file
40
devtools/create_engine/files/console.h
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_CONSOLE_H
|
||||
#define XYZZY_CONSOLE_H
|
||||
|
||||
#include "gui/debugger.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
class Console : public GUI::Debugger {
|
||||
private:
|
||||
bool Cmd_test(int argc, const char **argv);
|
||||
public:
|
||||
Console();
|
||||
~Console() override;
|
||||
};
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
|
||||
#endif // XYZZY_CONSOLE_H
|
||||
3
devtools/create_engine/files/credits.pl
Normal file
3
devtools/create_engine/files/credits.pl
Normal file
@@ -0,0 +1,3 @@
|
||||
begin_section("Xyzzy");
|
||||
add_person("Name 1", "Handle 1", "");
|
||||
end_section();
|
||||
45
devtools/create_engine/files/detection.cpp
Normal file
45
devtools/create_engine/files/detection.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/plugins.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/file.h"
|
||||
#include "common/md5.h"
|
||||
#include "common/str-array.h"
|
||||
#include "common/translation.h"
|
||||
#include "common/util.h"
|
||||
#include "xyzzy/detection.h"
|
||||
#include "xyzzy/detection_tables.h"
|
||||
|
||||
const DebugChannelDef XyzzyMetaEngineDetection::debugFlagList[] = {
|
||||
{ Xyzzy::kDebugGraphics, "Graphics", "Graphics debug level" },
|
||||
{ Xyzzy::kDebugPath, "Path", "Pathfinding debug level" },
|
||||
{ Xyzzy::kDebugFilePath, "FilePath", "File path debug level" },
|
||||
{ Xyzzy::kDebugScan, "Scan", "Scan for unrecognised games" },
|
||||
{ Xyzzy::kDebugScript, "Script", "Enable debug script dump" },
|
||||
DEBUG_CHANNEL_END
|
||||
};
|
||||
|
||||
XyzzyMetaEngineDetection::XyzzyMetaEngineDetection() : AdvancedMetaEngineDetection(
|
||||
Xyzzy::gameDescriptions, Xyzzy::xyzzyGames) {
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN_STATIC(XYZZY_DETECTION, PLUGIN_TYPE_ENGINE_DETECTION, XyzzyMetaEngineDetection);
|
||||
69
devtools/create_engine/files/detection.h
Normal file
69
devtools/create_engine/files/detection.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_DETECTION_H
|
||||
#define XYZZY_DETECTION_H
|
||||
|
||||
#include "engines/advancedDetector.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
enum XyzzyDebugChannels {
|
||||
kDebugGraphics = 1,
|
||||
kDebugPath,
|
||||
kDebugScan,
|
||||
kDebugFilePath,
|
||||
kDebugScript,
|
||||
};
|
||||
|
||||
extern const PlainGameDescriptor xyzzyGames[];
|
||||
|
||||
extern const ADGameDescription gameDescriptions[];
|
||||
|
||||
#define GAMEOPTION_ORIGINAL_SAVELOAD GUIO_GAMEOPTIONS1
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
|
||||
class XyzzyMetaEngineDetection : public AdvancedMetaEngineDetection<ADGameDescription> {
|
||||
static const DebugChannelDef debugFlagList[];
|
||||
|
||||
public:
|
||||
XyzzyMetaEngineDetection();
|
||||
~XyzzyMetaEngineDetection() override {}
|
||||
|
||||
const char *getName() const override {
|
||||
return "xyzzy";
|
||||
}
|
||||
|
||||
const char *getEngineName() const override {
|
||||
return "Xyzzy";
|
||||
}
|
||||
|
||||
const char *getOriginalCopyright() const override {
|
||||
return "Xyzzy (C)";
|
||||
}
|
||||
|
||||
const DebugChannelDef *getDebugChannels() const override {
|
||||
return debugFlagList;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // XYZZY_DETECTION_H
|
||||
43
devtools/create_engine/files/detection_tables.h
Normal file
43
devtools/create_engine/files/detection_tables.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
const PlainGameDescriptor xyzzyGames[] = {
|
||||
{ "xyzzy", "Xyzzy" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
const ADGameDescription gameDescriptions[] = {
|
||||
{
|
||||
"xyzzy",
|
||||
nullptr,
|
||||
AD_ENTRY1s("file1.bin", "00000000000000000000000000000000", 11111),
|
||||
Common::EN_ANY,
|
||||
Common::kPlatformDOS,
|
||||
ADGF_UNSTABLE,
|
||||
GUIO1(GUIO_NONE)
|
||||
},
|
||||
|
||||
AD_TABLE_END_MARKER
|
||||
};
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
69
devtools/create_engine/files/metaengine.cpp
Normal file
69
devtools/create_engine/files/metaengine.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/translation.h"
|
||||
|
||||
#include "xyzzy/metaengine.h"
|
||||
#include "xyzzy/detection.h"
|
||||
#include "xyzzy/xyzzy.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
static const ADExtraGuiOptionsMap optionsList[] = {
|
||||
{
|
||||
GAMEOPTION_ORIGINAL_SAVELOAD,
|
||||
{
|
||||
_s("Use original save/load screens"),
|
||||
_s("Use the original save/load screens instead of the ScummVM ones"),
|
||||
"original_menus",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
AD_EXTRA_GUI_OPTIONS_TERMINATOR
|
||||
};
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
|
||||
const char *XyzzyMetaEngine::getName() const {
|
||||
return "xyzzy";
|
||||
}
|
||||
|
||||
const ADExtraGuiOptionsMap *XyzzyMetaEngine::getAdvancedExtraGuiOptions() const {
|
||||
return Xyzzy::optionsList;
|
||||
}
|
||||
|
||||
Common::Error XyzzyMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
|
||||
*engine = new Xyzzy::XyzzyEngine(syst, desc);
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
bool XyzzyMetaEngine::hasFeature(MetaEngineFeature f) const {
|
||||
return checkExtendedSaves(f) ||
|
||||
(f == kSupportsLoadingDuringStartup);
|
||||
}
|
||||
|
||||
#if PLUGIN_ENABLED_DYNAMIC(XYZZY)
|
||||
REGISTER_PLUGIN_DYNAMIC(XYZZY, PLUGIN_TYPE_ENGINE, XyzzyMetaEngine);
|
||||
#else
|
||||
REGISTER_PLUGIN_STATIC(XYZZY, PLUGIN_TYPE_ENGINE, XyzzyMetaEngine);
|
||||
#endif
|
||||
43
devtools/create_engine/files/metaengine.h
Normal file
43
devtools/create_engine/files/metaengine.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_METAENGINE_H
|
||||
#define XYZZY_METAENGINE_H
|
||||
|
||||
#include "engines/advancedDetector.h"
|
||||
|
||||
class XyzzyMetaEngine : public AdvancedMetaEngine<ADGameDescription> {
|
||||
public:
|
||||
const char *getName() const override;
|
||||
|
||||
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
|
||||
|
||||
/**
|
||||
* Determine whether the engine supports the specified MetaEngine feature.
|
||||
*
|
||||
* Used by e.g. the launcher to determine whether to enable the Load button.
|
||||
*/
|
||||
bool hasFeature(MetaEngineFeature f) const override;
|
||||
|
||||
const ADExtraGuiOptionsMap *getAdvancedExtraGuiOptions() const override;
|
||||
};
|
||||
|
||||
#endif // XYZZY_METAENGINE_H
|
||||
17
devtools/create_engine/files/module.mk
Normal file
17
devtools/create_engine/files/module.mk
Normal file
@@ -0,0 +1,17 @@
|
||||
MODULE := engines/xyzzy
|
||||
|
||||
MODULE_OBJS = \
|
||||
xyzzy.o \
|
||||
console.o \
|
||||
metaengine.o
|
||||
|
||||
# This module can be built as a plugin
|
||||
ifeq ($(ENABLE_XYZZY), DYNAMIC_PLUGIN)
|
||||
PLUGIN := 1
|
||||
endif
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
|
||||
# Detection objects
|
||||
DETECT_OBJS += $(MODULE)/detection.o
|
||||
109
devtools/create_engine/files/xyzzy.cpp
Normal file
109
devtools/create_engine/files/xyzzy.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xyzzy/xyzzy.h"
|
||||
#include "graphics/framelimiter.h"
|
||||
#include "xyzzy/detection.h"
|
||||
#include "xyzzy/console.h"
|
||||
#include "common/scummsys.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/debug-channels.h"
|
||||
#include "common/events.h"
|
||||
#include "common/system.h"
|
||||
#include "engines/util.h"
|
||||
#include "graphics/paletteman.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
XyzzyEngine *g_engine;
|
||||
|
||||
XyzzyEngine::XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst),
|
||||
_gameDescription(gameDesc), _randomSource("Xyzzy") {
|
||||
g_engine = this;
|
||||
}
|
||||
|
||||
XyzzyEngine::~XyzzyEngine() {
|
||||
delete _screen;
|
||||
}
|
||||
|
||||
uint32 XyzzyEngine::getFeatures() const {
|
||||
return _gameDescription->flags;
|
||||
}
|
||||
|
||||
Common::String XyzzyEngine::getGameId() const {
|
||||
return _gameDescription->gameId;
|
||||
}
|
||||
|
||||
Common::Error XyzzyEngine::run() {
|
||||
// Initialize 320x200 paletted graphics mode
|
||||
initGraphics(320, 200);
|
||||
_screen = new Graphics::Screen();
|
||||
|
||||
// Set the engine's debugger console
|
||||
setDebugger(new Console());
|
||||
|
||||
// If a savegame was selected from the launcher, load it
|
||||
int saveSlot = ConfMan.getInt("save_slot");
|
||||
if (saveSlot != -1)
|
||||
(void)loadGameState(saveSlot);
|
||||
|
||||
// Draw a series of boxes on screen as a sample
|
||||
for (int i = 0; i < 100; ++i)
|
||||
_screen->frameRect(Common::Rect(i, i, 320 - i, 200 - i), i);
|
||||
_screen->update();
|
||||
|
||||
// Simple event handling loop
|
||||
byte pal[256 * 3] = { 0 };
|
||||
Common::Event e;
|
||||
int offset = 0;
|
||||
|
||||
Graphics::FrameLimiter limiter(g_system, 60);
|
||||
while (!shouldQuit()) {
|
||||
while (g_system->getEventManager()->pollEvent(e)) {
|
||||
}
|
||||
|
||||
// Cycle through a simple palette
|
||||
++offset;
|
||||
for (int i = 0; i < 256; ++i)
|
||||
pal[i * 3 + 1] = (i + offset) % 256;
|
||||
g_system->getPaletteManager()->setPalette(pal, 0, 256);
|
||||
// Delay for a bit. All events loops should have a delay
|
||||
// to prevent the system being unduly loaded
|
||||
limiter.delayBeforeSwap();
|
||||
_screen->update();
|
||||
limiter.startFrame();
|
||||
}
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
Common::Error XyzzyEngine::syncGame(Common::Serializer &s) {
|
||||
// The Serializer has methods isLoading() and isSaving()
|
||||
// if you need to specific steps; for example setting
|
||||
// an array size after reading it's length, whereas
|
||||
// for saving it would write the existing array's length
|
||||
int dummy = 0;
|
||||
s.syncAsUint32LE(dummy);
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
105
devtools/create_engine/files/xyzzy.h
Normal file
105
devtools/create_engine/files/xyzzy.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_H
|
||||
#define XYZZY_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/system.h"
|
||||
#include "common/error.h"
|
||||
#include "common/fs.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "common/random.h"
|
||||
#include "common/serializer.h"
|
||||
#include "common/util.h"
|
||||
#include "engines/engine.h"
|
||||
#include "engines/savestate.h"
|
||||
#include "graphics/screen.h"
|
||||
|
||||
#include "xyzzy/detection.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
struct XyzzyGameDescription;
|
||||
|
||||
class XyzzyEngine : public Engine {
|
||||
private:
|
||||
const ADGameDescription *_gameDescription;
|
||||
Common::RandomSource _randomSource;
|
||||
protected:
|
||||
// Engine APIs
|
||||
Common::Error run() override;
|
||||
public:
|
||||
Graphics::Screen *_screen = nullptr;
|
||||
public:
|
||||
XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc);
|
||||
~XyzzyEngine() override;
|
||||
|
||||
uint32 getFeatures() const;
|
||||
|
||||
/**
|
||||
* Returns the game Id
|
||||
*/
|
||||
Common::String getGameId() const;
|
||||
|
||||
/**
|
||||
* Gets a random number
|
||||
*/
|
||||
uint32 getRandomNumber(uint maxNum) {
|
||||
return _randomSource.getRandomNumber(maxNum);
|
||||
}
|
||||
|
||||
bool hasFeature(EngineFeature f) const override {
|
||||
return
|
||||
(f == kSupportsLoadingDuringRuntime) ||
|
||||
(f == kSupportsSavingDuringRuntime) ||
|
||||
(f == kSupportsReturnToLauncher);
|
||||
};
|
||||
|
||||
bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
|
||||
return true;
|
||||
}
|
||||
bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a serializer to allow implementing savegame
|
||||
* loading and saving using a single method
|
||||
*/
|
||||
Common::Error syncGame(Common::Serializer &s);
|
||||
|
||||
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
|
||||
Common::Serializer s(nullptr, stream);
|
||||
return syncGame(s);
|
||||
}
|
||||
Common::Error loadGameStream(Common::SeekableReadStream *stream) override {
|
||||
Common::Serializer s(stream, nullptr);
|
||||
return syncGame(s);
|
||||
}
|
||||
};
|
||||
|
||||
extern XyzzyEngine *g_engine;
|
||||
#define SHOULD_QUIT ::Xyzzy::g_engine->shouldQuit()
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
|
||||
#endif // XYZZY_H
|
||||
344
devtools/create_engine/files_events/events.cpp
Normal file
344
devtools/create_engine/files_events/events.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "graphics/screen.h"
|
||||
#include "xyzzy/events.h"
|
||||
#include "xyzzy/xyzzy.h"
|
||||
#include "xyzzy/views.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
Events *g_events;
|
||||
|
||||
Events::Events() : UIElement("Root", nullptr) {
|
||||
g_events = this;
|
||||
}
|
||||
|
||||
Events::~Events() {
|
||||
g_events = nullptr;
|
||||
}
|
||||
|
||||
void Events::runGame() {
|
||||
uint currTime, nextFrameTime = 0;
|
||||
_screen = new Graphics::Screen();
|
||||
Views views; // Loads all views in the structure
|
||||
|
||||
// Run the game
|
||||
int saveSlot = ConfMan.getInt("save_slot");
|
||||
if (saveSlot != -1)
|
||||
g_engine->loadGameState(saveSlot);
|
||||
|
||||
addView("View1");
|
||||
|
||||
Common::Event e;
|
||||
while (!_views.empty() && !shouldQuit()) {
|
||||
while (g_system->getEventManager()->pollEvent(e)) {
|
||||
if (e.type == Common::EVENT_QUIT ||
|
||||
e.type == Common::EVENT_RETURN_TO_LAUNCHER) {
|
||||
_views.clear();
|
||||
break;
|
||||
} else {
|
||||
processEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (_views.empty())
|
||||
break;
|
||||
|
||||
g_system->delayMillis(10);
|
||||
if ((currTime = g_system->getMillis()) >= nextFrameTime) {
|
||||
nextFrameTime = currTime + FRAME_DELAY;
|
||||
tick();
|
||||
drawElements();
|
||||
_screen->update();
|
||||
}
|
||||
}
|
||||
|
||||
delete _screen;
|
||||
}
|
||||
|
||||
void Events::processEvent(Common::Event &ev) {
|
||||
switch (ev.type) {
|
||||
case Common::EVENT_KEYDOWN:
|
||||
if (ev.kbd.keycode < Common::KEYCODE_NUMLOCK)
|
||||
msgKeypress(KeypressMessage(ev.kbd));
|
||||
break;
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
||||
msgAction(ActionMessage(ev.customType));
|
||||
break;
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
case Common::EVENT_MBUTTONDOWN:
|
||||
msgMouseDown(MouseDownMessage(ev.type, ev.mouse));
|
||||
break;
|
||||
case Common::EVENT_LBUTTONUP:
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
case Common::EVENT_MBUTTONUP:
|
||||
msgMouseUp(MouseUpMessage(ev.type, ev.mouse));
|
||||
break;
|
||||
case Common::EVENT_MOUSEMOVE:
|
||||
msgMouseMove(MouseMoveMessage(ev.type, ev.mouse));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Events::replaceView(UIElement *ui, bool replaceAllViews) {
|
||||
assert(ui);
|
||||
UIElement *priorView = focusedView();
|
||||
|
||||
if (replaceAllViews) {
|
||||
clearViews();
|
||||
|
||||
} else if (!_views.empty()) {
|
||||
priorView->msgUnfocus(UnfocusMessage());
|
||||
_views.pop();
|
||||
}
|
||||
|
||||
_views.push(ui);
|
||||
ui->redraw();
|
||||
ui->msgFocus(FocusMessage(priorView));
|
||||
}
|
||||
|
||||
void Events::replaceView(const Common::String &name, bool replaceAllViews) {
|
||||
replaceView(findView(name));
|
||||
}
|
||||
|
||||
void Events::addView(UIElement *ui) {
|
||||
assert(ui);
|
||||
UIElement *priorView = focusedView();
|
||||
|
||||
if (!_views.empty())
|
||||
priorView->msgUnfocus(UnfocusMessage());
|
||||
|
||||
_views.push(ui);
|
||||
ui->redraw();
|
||||
ui->msgFocus(FocusMessage(priorView));
|
||||
}
|
||||
|
||||
void Events::addView(const Common::String &name) {
|
||||
addView(findView(name));
|
||||
}
|
||||
|
||||
void Events::popView() {
|
||||
UIElement *priorView = focusedView();
|
||||
priorView->msgUnfocus(UnfocusMessage());
|
||||
_views.pop();
|
||||
|
||||
for (int i = 0; i < (int)_views.size() - 1; ++i) {
|
||||
_views[i]->redraw();
|
||||
_views[i]->draw();
|
||||
}
|
||||
|
||||
if (!_views.empty()) {
|
||||
UIElement *view = focusedView();
|
||||
view->msgFocus(FocusMessage(priorView));
|
||||
view->redraw();
|
||||
view->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Events::redrawViews() {
|
||||
for (uint i = 0; i < _views.size(); ++i) {
|
||||
_views[i]->redraw();
|
||||
_views[i]->draw();
|
||||
}
|
||||
}
|
||||
|
||||
bool Events::isPresent(const Common::String &name) const {
|
||||
for (uint i = 0; i < _views.size(); ++i) {
|
||||
if (_views[i]->_name == name)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Events::clearViews() {
|
||||
if (!_views.empty())
|
||||
focusedView()->msgUnfocus(UnfocusMessage());
|
||||
|
||||
_views.clear();
|
||||
}
|
||||
|
||||
void Events::addKeypress(const Common::KeyCode kc) {
|
||||
Common::KeyState ks;
|
||||
ks.keycode = kc;
|
||||
if (kc >= Common::KEYCODE_SPACE && kc <= Common::KEYCODE_TILDE)
|
||||
ks.ascii = kc;
|
||||
|
||||
focusedView()->msgKeypress(KeypressMessage(ks));
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
Bounds::Bounds(Common::Rect &innerBounds) :
|
||||
_bounds(0, 0, 320, 200),
|
||||
_innerBounds(innerBounds),
|
||||
left(_bounds.left), top(_bounds.top),
|
||||
right(_bounds.right), bottom(_bounds.bottom) {
|
||||
}
|
||||
|
||||
Bounds &Bounds::operator=(const Common::Rect &r) {
|
||||
_bounds = r;
|
||||
_innerBounds = r;
|
||||
_innerBounds.grow(-_borderSize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Bounds::setBorderSize(size_t borderSize) {
|
||||
_borderSize = borderSize;
|
||||
_innerBounds = *this;
|
||||
_innerBounds.grow(-_borderSize);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
UIElement::UIElement(const Common::String &name) :
|
||||
_name(name), _parent(g_engine), _bounds(_innerBounds) {
|
||||
g_engine->_children.push_back(this);
|
||||
}
|
||||
|
||||
UIElement::UIElement(const Common::String &name, UIElement *uiParent) :
|
||||
_name(name), _parent(uiParent),
|
||||
_bounds(_innerBounds) {
|
||||
if (_parent)
|
||||
_parent->_children.push_back(this);
|
||||
}
|
||||
|
||||
void UIElement::redraw() {
|
||||
_needsRedraw = true;
|
||||
|
||||
for (size_t i = 0; i < _children.size(); ++i)
|
||||
_children[i]->redraw();
|
||||
}
|
||||
|
||||
void UIElement::drawElements() {
|
||||
if (_needsRedraw) {
|
||||
draw();
|
||||
_needsRedraw = false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _children.size(); ++i)
|
||||
_children[i]->drawElements();
|
||||
}
|
||||
|
||||
UIElement *UIElement::findViewGlobally(const Common::String &name) {
|
||||
return g_events->findView(name);
|
||||
}
|
||||
|
||||
void UIElement::focus() {
|
||||
g_events->replaceView(this);
|
||||
}
|
||||
|
||||
void UIElement::close() {
|
||||
assert(g_events->focusedView() == this);
|
||||
g_events->popView();
|
||||
}
|
||||
|
||||
bool UIElement::isFocused() const {
|
||||
return g_events->focusedView() == this;
|
||||
}
|
||||
|
||||
void UIElement::clearSurface() {
|
||||
Graphics::ManagedSurface s = getSurface();
|
||||
s.fillRect(Common::Rect(s.w, s.h), 0);
|
||||
}
|
||||
|
||||
void UIElement::draw() {
|
||||
for (size_t i = 0; i < _children.size(); ++i) {
|
||||
_children[i]->draw();
|
||||
}
|
||||
}
|
||||
|
||||
bool UIElement::tick() {
|
||||
if (_timeoutCtr && --_timeoutCtr == 0) {
|
||||
timeout();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _children.size(); ++i) {
|
||||
if (_children[i]->tick())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UIElement *UIElement::findView(const Common::String &name) {
|
||||
if (_name.equalsIgnoreCase(name))
|
||||
return this;
|
||||
|
||||
UIElement *result;
|
||||
for (size_t i = 0; i < _children.size(); ++i) {
|
||||
if ((result = _children[i]->findView(name)) != nullptr)
|
||||
return result;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UIElement::replaceView(UIElement *ui, bool replaceAllViews) {
|
||||
g_events->replaceView(ui, replaceAllViews);
|
||||
}
|
||||
|
||||
void UIElement::replaceView(const Common::String &name, bool replaceAllViews) {
|
||||
g_events->replaceView(name, replaceAllViews);
|
||||
}
|
||||
|
||||
void UIElement::addView(UIElement *ui) {
|
||||
g_events->addView(ui);
|
||||
}
|
||||
|
||||
void UIElement::addView(const Common::String &name) {
|
||||
g_events->addView(name);
|
||||
}
|
||||
|
||||
void UIElement::addView() {
|
||||
g_events->addView(this);
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface UIElement::getSurface() const {
|
||||
return Graphics::ManagedSurface(*g_events->getScreen(), _bounds);
|
||||
}
|
||||
|
||||
int UIElement::getRandomNumber(int minNumber, int maxNumber) {
|
||||
return g_engine->getRandomNumber(maxNumber - minNumber + 1) + minNumber;
|
||||
}
|
||||
|
||||
int UIElement::getRandomNumber(int maxNumber) {
|
||||
return g_engine->getRandomNumber(maxNumber);
|
||||
}
|
||||
|
||||
void UIElement::delaySeconds(uint seconds) {
|
||||
_timeoutCtr = seconds * FRAME_RATE;
|
||||
}
|
||||
|
||||
void UIElement::delayFrames(uint frames) {
|
||||
_timeoutCtr = frames;
|
||||
}
|
||||
|
||||
void UIElement::timeout() {
|
||||
redraw();
|
||||
}
|
||||
|
||||
} // namespace Xyzzy
|
||||
397
devtools/create_engine/files_events/events.h
Normal file
397
devtools/create_engine/files_events/events.h
Normal file
@@ -0,0 +1,397 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_EVENTS_H
|
||||
#define XYZZY_EVENTS_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/stack.h"
|
||||
#include "graphics/screen.h"
|
||||
#include "xyzzy/messages.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
#define FRAME_RATE 20
|
||||
#define FRAME_DELAY (1000 / FRAME_RATE)
|
||||
|
||||
class Events;
|
||||
|
||||
/**
|
||||
* Implements a thunk layer around an element's bounds,
|
||||
* allowing access to it as if it were a simple Common::Rect,
|
||||
* but any changes to it will also be applied to a linked inner bounds
|
||||
*/
|
||||
struct Bounds {
|
||||
private:
|
||||
Common::Rect _bounds;
|
||||
Common::Rect &_innerBounds;
|
||||
int _borderSize = 0;
|
||||
public:
|
||||
const int16 &left;
|
||||
const int16 ⊤
|
||||
const int16 &right;
|
||||
const int16 ⊥
|
||||
public:
|
||||
Bounds(Common::Rect &innerBounds);
|
||||
operator const Common::Rect &() const { return _bounds; }
|
||||
Bounds &operator=(const Common::Rect &r);
|
||||
void setBorderSize(size_t borderSize);
|
||||
size_t borderSize() const { return _borderSize; }
|
||||
int16 width() const { return _bounds.width(); }
|
||||
int16 height() const { return _bounds.height(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* User interface element
|
||||
*/
|
||||
class UIElement {
|
||||
friend class Events;
|
||||
private:
|
||||
int _timeoutCtr = 0;
|
||||
protected:
|
||||
UIElement *_parent;
|
||||
Common::Array<UIElement *> _children;
|
||||
Common::Rect _innerBounds;
|
||||
Bounds _bounds;
|
||||
bool _needsRedraw = true;
|
||||
Common::String _name;
|
||||
protected:
|
||||
/**
|
||||
* Set a delay countdown in seconds, after which timeout() is called
|
||||
*/
|
||||
void delaySeconds(uint seconds);
|
||||
|
||||
/**
|
||||
* Set a delay countdown in frames, after which timeout() is called
|
||||
*/
|
||||
void delayFrames(uint frames);
|
||||
|
||||
/**
|
||||
* Returns true if a delay is active
|
||||
*/
|
||||
bool isDelayActive() const {
|
||||
return _timeoutCtr != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any active delay
|
||||
*/
|
||||
void cancelDelay() {
|
||||
_timeoutCtr = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an active timeout countdown expired
|
||||
*/
|
||||
virtual void timeout();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Outer method for doing drawing
|
||||
*
|
||||
*/
|
||||
void drawElements();
|
||||
|
||||
/**
|
||||
* Finds a view globally
|
||||
*/
|
||||
static UIElement *findViewGlobally(const Common::String &name);
|
||||
public:
|
||||
UIElement(const Common::String &name, UIElement *uiParent);
|
||||
UIElement(const Common::String &name);
|
||||
virtual ~UIElement() {}
|
||||
|
||||
/**
|
||||
* Returns true if the elements needs to be redrawn
|
||||
*/
|
||||
bool needsRedraw() const { return _needsRedraw; }
|
||||
|
||||
/**
|
||||
* Sets that the element needs to be redrawn
|
||||
*/
|
||||
void redraw();
|
||||
|
||||
/**
|
||||
* Focuses the element as the current view
|
||||
*/
|
||||
void focus();
|
||||
|
||||
/**
|
||||
* Closes the current view. The view must have been added
|
||||
* via addView, so there's a remaining view afterwards
|
||||
*/
|
||||
virtual void close();
|
||||
|
||||
/*
|
||||
* Returns true if the view is focused
|
||||
*/
|
||||
bool isFocused() const;
|
||||
|
||||
/**
|
||||
* Sets the focus to a new view
|
||||
*/
|
||||
void replaceView(UIElement *ui, bool replaceAllViews = false);
|
||||
void replaceView(const Common::String &name, bool replaceAllViews = false);
|
||||
|
||||
/**
|
||||
* Adds a focused view to the view stack without replacing current one
|
||||
*/
|
||||
void addView(UIElement *ui);
|
||||
void addView(const Common::String &name);
|
||||
void addView();
|
||||
void open() { addView(); }
|
||||
|
||||
/**
|
||||
* Returns a random number
|
||||
*/
|
||||
int getRandomNumber(int minNumber, int maxNumber);
|
||||
int getRandomNumber(int maxNumber);
|
||||
|
||||
/**
|
||||
* Sets the element's bounds
|
||||
*/
|
||||
virtual void setBounds(const Common::Rect &r) {
|
||||
_bounds = r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the element's bounds
|
||||
*/
|
||||
Common::Rect getBounds() const {
|
||||
return _bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a surface for drawing the element
|
||||
*/
|
||||
Graphics::ManagedSurface getSurface() const;
|
||||
|
||||
/**
|
||||
* Clear the surface
|
||||
*/
|
||||
virtual void clearSurface();
|
||||
|
||||
/**
|
||||
* Draws the element
|
||||
*/
|
||||
virtual void draw();
|
||||
|
||||
/**
|
||||
* Called for game frame ticks
|
||||
*/
|
||||
virtual bool tick();
|
||||
|
||||
/**
|
||||
* Find a view by name
|
||||
*/
|
||||
virtual UIElement *findView(const Common::String &name);
|
||||
|
||||
/**
|
||||
* Handles events
|
||||
*/
|
||||
// Mouse move only has a minimal implementation for performance reasons
|
||||
protected:
|
||||
virtual bool msgMouseMove(const MouseMoveMessage &msg) { return false; }
|
||||
public:
|
||||
bool send(const MouseMoveMessage &msg) { return msgMouseMove(msg); }
|
||||
|
||||
#define MESSAGE(NAME) \
|
||||
protected: \
|
||||
virtual bool msg##NAME(const NAME##Message &e) { \
|
||||
for (Common::Array<UIElement *>::iterator it = _children.begin(); \
|
||||
it != _children.end(); ++it) { \
|
||||
if ((*it)->msg##NAME(e)) return true; \
|
||||
} \
|
||||
return false; \
|
||||
} \
|
||||
public: \
|
||||
bool send(const Common::String &viewName, const NAME##Message &msg) { \
|
||||
UIElement *view = UIElement::findViewGlobally(viewName); \
|
||||
assert(view); \
|
||||
return view->msg##NAME(msg); \
|
||||
} \
|
||||
bool send(const NAME##Message &msg) { \
|
||||
return msg##NAME(msg); \
|
||||
} \
|
||||
|
||||
MESSAGE(Focus);
|
||||
MESSAGE(Unfocus);
|
||||
MESSAGE(MouseEnter);
|
||||
MESSAGE(MouseLeave);
|
||||
MESSAGE(Keypress);
|
||||
MESSAGE(MouseDown);
|
||||
MESSAGE(MouseUp);
|
||||
MESSAGE(Action);
|
||||
MESSAGE(Game);
|
||||
MESSAGE(Value);
|
||||
#undef MESSAGE
|
||||
};
|
||||
|
||||
/**
|
||||
* Main events and view manager. This is kept separate from the engine
|
||||
* class because the engine may add a lot of globals and bring in other
|
||||
* classes. So to save on compilation time, classes that only need to
|
||||
* access basic view management methods like addView or replaceView
|
||||
* only need to include events.h rather than the whole engine.
|
||||
*/
|
||||
class Events : public UIElement {
|
||||
private:
|
||||
Graphics::Screen *_screen = nullptr;
|
||||
Common::Stack<UIElement *> _views;
|
||||
protected:
|
||||
/**
|
||||
* Process an event
|
||||
*/
|
||||
void processEvent(Common::Event &ev);
|
||||
|
||||
/**
|
||||
* Returns true if the game should quit
|
||||
*/
|
||||
virtual bool shouldQuit() const = 0;
|
||||
|
||||
/**
|
||||
* Overrides events we want to only go to the focused view
|
||||
*/
|
||||
#define MESSAGE(NAME) \
|
||||
bool msg##NAME(const NAME##Message &e) override { \
|
||||
return !_views.empty() ? focusedView()->msg##NAME(e) : false; \
|
||||
}
|
||||
MESSAGE(Action);
|
||||
MESSAGE(Focus);
|
||||
MESSAGE(Unfocus);
|
||||
MESSAGE(MouseEnter);
|
||||
MESSAGE(MouseLeave);
|
||||
MESSAGE(Keypress);
|
||||
MESSAGE(MouseDown);
|
||||
MESSAGE(MouseUp);
|
||||
MESSAGE(MouseMove);
|
||||
#undef MESSAGE
|
||||
public:
|
||||
Events();
|
||||
virtual ~Events();
|
||||
|
||||
/**
|
||||
* Main game loop
|
||||
*/
|
||||
void runGame();
|
||||
|
||||
/**
|
||||
* Sets the focus to a new view
|
||||
*/
|
||||
void replaceView(UIElement *ui, bool replaceAllViews = false);
|
||||
void replaceView(const Common::String &name, bool replaceAllViews = false);
|
||||
|
||||
/**
|
||||
* Adds a focused view to the view stack without replacing current one
|
||||
*/
|
||||
void addView(UIElement *ui);
|
||||
void addView(const Common::String &name);
|
||||
|
||||
/**
|
||||
* Clears the view list
|
||||
*/
|
||||
void clearViews();
|
||||
|
||||
/**
|
||||
* Pops a view from the view stack
|
||||
*/
|
||||
void popView();
|
||||
|
||||
/**
|
||||
* Redraws the views in order. This is used in rare cases
|
||||
* where a view draws outside it's defined area, and needs
|
||||
* to restore whether the background was before
|
||||
*/
|
||||
void redrawViews();
|
||||
|
||||
/**
|
||||
* Returns the currently focused view, if any
|
||||
*/
|
||||
UIElement *focusedView() const {
|
||||
return _views.empty() ? nullptr : _views.top();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view prior to the current view, if any
|
||||
*/
|
||||
UIElement *priorView() const {
|
||||
return _views.size() < 2 ? nullptr :
|
||||
_views[_views.size() - 2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a view of a given name is present
|
||||
* at all in the visible view stack
|
||||
*/
|
||||
bool isPresent(const Common::String &name) const;
|
||||
|
||||
/**
|
||||
* Returns true if combat is active
|
||||
*/
|
||||
bool isInCombat() const {
|
||||
return isPresent("Combat");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying screen
|
||||
*/
|
||||
Graphics::Screen *getScreen() const {
|
||||
return _screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the focused view
|
||||
*/
|
||||
void drawElements() {
|
||||
if (!_views.empty())
|
||||
focusedView()->drawElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a keypress to the event queue
|
||||
*/
|
||||
void addKeypress(const Common::KeyCode kc);
|
||||
|
||||
/**
|
||||
* Events manager doesn't have any intrinsic drawing
|
||||
*/
|
||||
void draw() override {}
|
||||
|
||||
/**
|
||||
* Called once every game frame
|
||||
*/
|
||||
bool tick() override {
|
||||
return !_views.empty() ? focusedView()->tick() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling the close method for g_events closes the active view
|
||||
*/
|
||||
void close() override {
|
||||
focusedView()->close();
|
||||
}
|
||||
};
|
||||
|
||||
extern Events *g_events;
|
||||
|
||||
} // namespace Xyzzy
|
||||
|
||||
#endif
|
||||
43
devtools/create_engine/files_events/messages.cpp
Normal file
43
devtools/create_engine/files_events/messages.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xyzzy/messages.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
MouseMessage::MouseMessage(Common::EventType type,
|
||||
const Common::Point &pos) : Message(), _pos(pos) {
|
||||
switch (type) {
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
_button = MB_RIGHT;
|
||||
break;
|
||||
case Common::EVENT_MBUTTONDOWN:
|
||||
case Common::EVENT_MBUTTONUP:
|
||||
_button = MB_MIDDLE;
|
||||
break;
|
||||
default:
|
||||
_button = MB_LEFT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Xyzzy
|
||||
111
devtools/create_engine/files_events/messages.h
Normal file
111
devtools/create_engine/files_events/messages.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_MESSAGES_H
|
||||
#define XYZZY_MESSAGES_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/events.h"
|
||||
#include "common/str.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
class UIElement;
|
||||
|
||||
struct Message {};
|
||||
|
||||
struct FocusMessage : public Message {
|
||||
UIElement *_priorView = nullptr;
|
||||
FocusMessage() : Message() {}
|
||||
FocusMessage(UIElement *priorView) : Message(),
|
||||
_priorView(priorView) {}
|
||||
};
|
||||
|
||||
struct UnfocusMessage : public Message {};
|
||||
struct MouseEnterMessage : public Message {};
|
||||
struct MouseLeaveMessage : public Message {};
|
||||
|
||||
struct KeypressMessage : public Message, public Common::KeyState {
|
||||
KeypressMessage() : Message() {}
|
||||
KeypressMessage(const Common::KeyState &ks) :
|
||||
Message(), Common::KeyState(ks) {}
|
||||
};
|
||||
|
||||
struct MouseMessage : public Message {
|
||||
enum Button { MB_LEFT, MB_RIGHT, MB_MIDDLE };
|
||||
Button _button;
|
||||
Common::Point _pos;
|
||||
|
||||
MouseMessage() : Message(), _button(MB_LEFT) {}
|
||||
MouseMessage(Button btn, const Common::Point &pos) :
|
||||
Message(), _button(btn), _pos(pos) {}
|
||||
MouseMessage(Common::EventType type, const Common::Point &pos);
|
||||
};
|
||||
struct MouseDownMessage : public MouseMessage {
|
||||
MouseDownMessage() : MouseMessage() {}
|
||||
MouseDownMessage(Button btn, const Common::Point &pos) :
|
||||
MouseMessage(btn, pos) {}
|
||||
MouseDownMessage(Common::EventType type, const Common::Point &pos) :
|
||||
MouseMessage(type, pos) {}
|
||||
};
|
||||
struct MouseUpMessage : public MouseMessage {
|
||||
MouseUpMessage() : MouseMessage() {}
|
||||
MouseUpMessage(Button btn, const Common::Point &pos) :
|
||||
MouseMessage(btn, pos) {}
|
||||
MouseUpMessage(Common::EventType type, const Common::Point &pos) :
|
||||
MouseMessage(type, pos) {}
|
||||
};
|
||||
typedef MouseMessage MouseMoveMessage;
|
||||
|
||||
struct GameMessage : public Message {
|
||||
Common::String _name;
|
||||
int _value;
|
||||
Common::String _stringValue;
|
||||
|
||||
GameMessage() : Message(), _value(-1) {}
|
||||
GameMessage(const Common::String &name) : Message(),
|
||||
_name(name), _value(-1) {}
|
||||
GameMessage(const Common::String &name, int value) : Message(),
|
||||
_name(name), _value(value) {}
|
||||
GameMessage(const Common::String &name, const Common::String &value) :
|
||||
Message(), _name(name), _stringValue(value) {}
|
||||
};
|
||||
|
||||
struct ValueMessage : public Message {
|
||||
int _value;
|
||||
|
||||
ValueMessage() : Message(), _value(0) {}
|
||||
ValueMessage(int value) : Message(),
|
||||
_value(value) {}
|
||||
};
|
||||
|
||||
struct ActionMessage : public Message {
|
||||
int _action;
|
||||
ActionMessage() : Message(), _action(0) {
|
||||
}
|
||||
ActionMessage(int action) : Message(),
|
||||
_action(action) {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Xyzzy
|
||||
|
||||
#endif
|
||||
21
devtools/create_engine/files_events/module.mk
Normal file
21
devtools/create_engine/files_events/module.mk
Normal file
@@ -0,0 +1,21 @@
|
||||
MODULE := engines/xyzzy
|
||||
|
||||
MODULE_OBJS = \
|
||||
xyzzy.o \
|
||||
console.o \
|
||||
events.o \
|
||||
messages.o \
|
||||
metaengine.o \
|
||||
view.o \
|
||||
view1.o
|
||||
|
||||
# This module can be built as a plugin
|
||||
ifeq ($(ENABLE_XYZZY), DYNAMIC_PLUGIN)
|
||||
PLUGIN := 1
|
||||
endif
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
|
||||
# Detection objects
|
||||
DETECT_OBJS += $(MODULE)/detection.o
|
||||
81
devtools/create_engine/files_events/view.cpp
Normal file
81
devtools/create_engine/files_events/view.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xyzzy/view.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
void View::checkFocusedControl(const Common::Point &mousePos) {
|
||||
if (_focusedElement) {
|
||||
if (!_focusedElement->getBounds().contains(mousePos)) {
|
||||
_focusedElement->send(MouseLeaveMessage());
|
||||
_focusedElement = nullptr;
|
||||
}
|
||||
|
||||
} else {
|
||||
for (UIElement *child : _children) {
|
||||
if (child->getBounds().contains(mousePos)) {
|
||||
_focusedElement = child;
|
||||
child->send(MouseEnterMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UIElement *View::getElementAtPos(const Common::Point &pos) const {
|
||||
for (UIElement *child : _children) {
|
||||
if (child->getBounds().contains(pos))
|
||||
return child;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool View::msgFocus(const FocusMessage &msg) {
|
||||
_focusedElement = nullptr;
|
||||
return UIElement::msgFocus(msg);
|
||||
}
|
||||
|
||||
bool View::msgUnfocus(const UnfocusMessage &msg) {
|
||||
if (_focusedElement)
|
||||
_focusedElement->send(MouseLeaveMessage());
|
||||
|
||||
return UIElement::msgUnfocus(msg);
|
||||
}
|
||||
|
||||
bool View::msgMouseMove(const MouseMoveMessage &msg) {
|
||||
checkFocusedControl(msg._pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool View::msgMouseDown(const MouseDownMessage &msg) {
|
||||
UIElement *child = getElementAtPos(msg._pos);
|
||||
return child ? child->send(msg) : false;
|
||||
}
|
||||
|
||||
bool View::msgMouseUp(const MouseUpMessage &msg) {
|
||||
UIElement *child = getElementAtPos(msg._pos);
|
||||
return child ? child->send(msg) : false;
|
||||
}
|
||||
|
||||
} // namespace Xyzzy
|
||||
73
devtools/create_engine/files_events/view.h
Normal file
73
devtools/create_engine/files_events/view.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_VIEW_H
|
||||
#define XYZZY_VIEW_H
|
||||
|
||||
#include "xyzzy/events.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
/**
|
||||
* Base view class for screens and dialogs that appear on-screen.
|
||||
* The View class takes care of two important things:
|
||||
* 1) By default events get sent to all controls on a view until one
|
||||
* handles it. For mouse events, we instead want only the control the
|
||||
* mouse cursor is over to receive the events, saving the individual
|
||||
* controls from having to check if the mouse is within their bounds.
|
||||
* 2) Individual elements will get a Focus/Unfocus message as the
|
||||
* mouse enters and leaves them. This allows, for example, buttons
|
||||
* that have been pressed to de-select if the mouse leaves their bounds.
|
||||
*/
|
||||
class View : public UIElement {
|
||||
private:
|
||||
UIElement *_focusedElement = nullptr;
|
||||
|
||||
/**
|
||||
* Checks if a control is entered or left
|
||||
*/
|
||||
void checkFocusedControl(const Common::Point &mousePos);
|
||||
|
||||
/**
|
||||
* Check for an element at the given position
|
||||
*/
|
||||
UIElement *getElementAtPos(const Common::Point &pos) const;
|
||||
|
||||
public:
|
||||
View(const Common::String &name, UIElement *uiParent) :
|
||||
UIElement(name, uiParent) {
|
||||
}
|
||||
View(const Common::String &name) :
|
||||
UIElement(name) {
|
||||
}
|
||||
virtual ~View() {
|
||||
}
|
||||
|
||||
bool msgFocus(const FocusMessage &msg) override;
|
||||
bool msgUnfocus(const UnfocusMessage &msg) override;
|
||||
bool msgMouseMove(const MouseMoveMessage &msg) override;
|
||||
bool msgMouseDown(const MouseDownMessage &msg) override;
|
||||
bool msgMouseUp(const MouseUpMessage &msg) override;
|
||||
};
|
||||
|
||||
} // namespace Xyzzy
|
||||
|
||||
#endif
|
||||
64
devtools/create_engine/files_events/view1.cpp
Normal file
64
devtools/create_engine/files_events/view1.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/system.h"
|
||||
#include "graphics/paletteman.h"
|
||||
#include "xyzzy/view1.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
bool View1::msgFocus(const FocusMessage &msg) {
|
||||
Common::fill(&_pal[0], &_pal[256 * 3], 0);
|
||||
_offset = 128;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool View1::msgKeypress(const KeypressMessage &msg) {
|
||||
// Any keypress to close the view
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void View1::draw() {
|
||||
// Draw a bunch of squares on screen
|
||||
Graphics::ManagedSurface s = getSurface();
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
s.frameRect(Common::Rect(i, i, 320 - i, 200 - i), i);
|
||||
}
|
||||
|
||||
bool View1::tick() {
|
||||
// Cycle the palette
|
||||
++_offset;
|
||||
for (int i = 0; i < 256; ++i)
|
||||
_pal[i * 3 + 1] = (i + _offset) % 256;
|
||||
g_system->getPaletteManager()->setPalette(_pal, 0, 256);
|
||||
|
||||
// Below is redundant since we're only cycling the palette, but it demonstrates
|
||||
// how to trigger the view to do further draws after the first time, since views
|
||||
// don't automatically keep redrawing unless you tell it to
|
||||
if ((_offset % 256) == 0)
|
||||
redraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Xyzzy
|
||||
46
devtools/create_engine/files_events/view1.h
Normal file
46
devtools/create_engine/files_events/view1.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_VIEW1_H
|
||||
#define XYZZY_VIEW1_H
|
||||
|
||||
#include "xyzzy/view.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
class View1 : public View {
|
||||
private:
|
||||
byte _pal[256 * 3] = { 0 };
|
||||
int _offset = 0;
|
||||
|
||||
public:
|
||||
View1() : View("View1") {}
|
||||
virtual ~View1() {}
|
||||
|
||||
bool msgFocus(const FocusMessage &msg) override;
|
||||
bool msgKeypress(const KeypressMessage &msg) override;
|
||||
void draw() override;
|
||||
bool tick() override;
|
||||
};
|
||||
|
||||
} // namespace Xyzzy
|
||||
|
||||
#endif
|
||||
35
devtools/create_engine/files_events/views.h
Normal file
35
devtools/create_engine/files_events/views.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_VIEWS_H
|
||||
#define XYZZY_VIEWS_H
|
||||
|
||||
#include "xyzzy/view1.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
struct Views {
|
||||
View1 _view1;
|
||||
};
|
||||
|
||||
} // namespace Xyzzy
|
||||
|
||||
#endif
|
||||
76
devtools/create_engine/files_events/xyzzy.cpp
Normal file
76
devtools/create_engine/files_events/xyzzy.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xyzzy/xyzzy.h"
|
||||
#include "xyzzy/detection.h"
|
||||
#include "xyzzy/console.h"
|
||||
#include "common/scummsys.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/debug-channels.h"
|
||||
#include "common/events.h"
|
||||
#include "common/system.h"
|
||||
#include "engines/util.h"
|
||||
#include "graphics/paletteman.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
XyzzyEngine *g_engine;
|
||||
|
||||
XyzzyEngine::XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst),
|
||||
_gameDescription(gameDesc), _randomSource("Xyzzy") {
|
||||
g_engine = this;
|
||||
}
|
||||
|
||||
XyzzyEngine::~XyzzyEngine() {
|
||||
}
|
||||
|
||||
uint32 XyzzyEngine::getFeatures() const {
|
||||
return _gameDescription->flags;
|
||||
}
|
||||
|
||||
Common::String XyzzyEngine::getGameId() const {
|
||||
return _gameDescription->gameId;
|
||||
}
|
||||
|
||||
Common::Error XyzzyEngine::run() {
|
||||
// Initialize 320x200 paletted graphics mode
|
||||
initGraphics(320, 200);
|
||||
|
||||
// Set the engine's debugger console
|
||||
setDebugger(new Console());
|
||||
|
||||
runGame();
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
Common::Error XyzzyEngine::syncGame(Common::Serializer &s) {
|
||||
// The Serializer has methods isLoading() and isSaving()
|
||||
// if you need to specific steps; for example setting
|
||||
// an array size after reading it's length, whereas
|
||||
// for saving it would write the existing array's length
|
||||
int dummy = 0;
|
||||
s.syncAsUint32LE(dummy);
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
112
devtools/create_engine/files_events/xyzzy.h
Normal file
112
devtools/create_engine/files_events/xyzzy.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XYZZY_H
|
||||
#define XYZZY_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/system.h"
|
||||
#include "common/error.h"
|
||||
#include "common/fs.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "common/random.h"
|
||||
#include "common/serializer.h"
|
||||
#include "common/util.h"
|
||||
#include "engines/engine.h"
|
||||
#include "engines/savestate.h"
|
||||
#include "graphics/screen.h"
|
||||
|
||||
#include "xyzzy/detection.h"
|
||||
#include "xyzzy/events.h"
|
||||
|
||||
namespace Xyzzy {
|
||||
|
||||
struct XyzzyGameDescription;
|
||||
|
||||
class XyzzyEngine : public Engine, public Events {
|
||||
private:
|
||||
const ADGameDescription *_gameDescription;
|
||||
Common::RandomSource _randomSource;
|
||||
protected:
|
||||
// Engine APIs
|
||||
Common::Error run() override;
|
||||
|
||||
/**
|
||||
* Returns true if the game should quit
|
||||
*/
|
||||
bool shouldQuit() const override {
|
||||
return Engine::shouldQuit();
|
||||
}
|
||||
|
||||
public:
|
||||
XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc);
|
||||
~XyzzyEngine() override;
|
||||
|
||||
uint32 getFeatures() const;
|
||||
|
||||
/**
|
||||
* Returns the game Id
|
||||
*/
|
||||
Common::String getGameId() const;
|
||||
|
||||
/**
|
||||
* Gets a random number
|
||||
*/
|
||||
uint32 getRandomNumber(uint maxNum) {
|
||||
return _randomSource.getRandomNumber(maxNum);
|
||||
}
|
||||
|
||||
bool hasFeature(EngineFeature f) const override {
|
||||
return
|
||||
(f == kSupportsLoadingDuringRuntime) ||
|
||||
(f == kSupportsSavingDuringRuntime) ||
|
||||
(f == kSupportsReturnToLauncher);
|
||||
};
|
||||
|
||||
bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
|
||||
return true;
|
||||
}
|
||||
bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a serializer to allow implementing savegame
|
||||
* loading and saving using a single method
|
||||
*/
|
||||
Common::Error syncGame(Common::Serializer &s);
|
||||
|
||||
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
|
||||
Common::Serializer s(nullptr, stream);
|
||||
return syncGame(s);
|
||||
}
|
||||
Common::Error loadGameStream(Common::SeekableReadStream *stream) override {
|
||||
Common::Serializer s(stream, nullptr);
|
||||
return syncGame(s);
|
||||
}
|
||||
};
|
||||
|
||||
extern XyzzyEngine *g_engine;
|
||||
#define SHOULD_QUIT ::Xyzzy::g_engine->shouldQuit()
|
||||
|
||||
} // End of namespace Xyzzy
|
||||
|
||||
#endif // XYZZY_H
|
||||
10
devtools/create_engine/module.mk
Normal file
10
devtools/create_engine/module.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
MODULE := devtools/create_engine
|
||||
|
||||
MODULE_OBJS := \
|
||||
create_engine.o
|
||||
|
||||
# Set the name of the executable
|
||||
TOOL_EXECUTABLE := create_engine
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
Reference in New Issue
Block a user