Skip to content

Commit

Permalink
Rework EngineGUI to utilize its new engine interface.
Browse files Browse the repository at this point in the history
That way it's easier to communicate with it without having to dynamically hook the module on demand, plus the interface class allows for creation of other EngineGUI interfaces that don't utilize MFC.
  • Loading branch information
DreamyCecil committed Jun 13, 2024
1 parent 0c066e3 commit 3217027
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 121 deletions.
41 changes: 6 additions & 35 deletions Sources/Engine/Base/ReplaceFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include <Engine/Base/ListIterator.inl>

#define FILTER_TEX "Textures (*.tex)\0*.tex\0"
#define FILTER_MDL "Models (*.mdl)\0*.mdl\0"
#define FILTER_ANI "Animations (*.ani)\0*.ani\0"
#define FILTER_END "\0"

BOOL _bFileReplacingApplied;

#ifndef NDEBUG
#define ENGINEGUI_DLL_NAME "EngineGUID.dll"
#else
#define ENGINEGUI_DLL_NAME "EngineGUI.dll"
#endif

extern INDEX wed_bUseBaseForReplacement;

static CTFileName CallFileRequester(char *achrTitle, char *achrSelectedFile, char *pFilter)
{
#if SE1_WIN
typedef CTFileName FileRequester_t(
char *pchrTitle,
char *pchrFilters,
char *pchrRegistry,
char *pchrDefaultFileSelected);

HMODULE hGUI = GetModuleHandleA(ENGINEGUI_DLL_NAME);
if (hGUI==NULL) {
WarningMessage(TRANS("Cannot load %s:\n%s\nCannot replace files!"),
ENGINEGUI_DLL_NAME, GetWindowsError(GetLastError()));
return CTString("");
}
FileRequester_t *pFileRequester = (FileRequester_t *)OS::GetLibSymbol(hGUI, "FileRequester");
if (pFileRequester==NULL) {
WarningMessage(TRANS("Error in %s:\nFileRequester() function not found\nCannot replace files!"),
ENGINEGUI_DLL_NAME);
// [Cecil] No API available
if (_pEngineGuiApi == NULL) {
WarningMessage(TRANS("Engine GUI is unavailable! Cannot replace files!"));
return CTString("");
}

return pFileRequester( achrTitle, pFilter, "Replace file directory", achrSelectedFile);

#else
// [Cecil] TODO: Make sure this function has a purpose on anything but Windows
return CTString("");
#endif
}
// [Cecil] Call file requester from the API
return _pEngineGuiApi->ReplaceFileRequester(achrTitle, pFilter, "Replace file directory", achrSelectedFile);
};

BOOL GetReplacingFile(CTFileName fnSourceFile, CTFileName &fnReplacingFile,
char *pFilter)
Expand Down
3 changes: 0 additions & 3 deletions Sources/Engine/Entities/EntityProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <Engine/Templates/Stock_CEntityClass.h>
#include <Engine/Templates/StaticArray.cpp>

#define FILTER_ALL "All files (*.*)\0*.*\0"
#define FILTER_END "\0"

#define PROPERTY(offset, type) ENTITYPROPERTY(this, offset, type)

/////////////////////////////////////////////////////////////////////
Expand Down
87 changes: 33 additions & 54 deletions Sources/EngineGui/EngineGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,43 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#endif

class CEngineGUI
{
public:
/* Functions used by application for getting and setting registry keys concerning modes */
ENGINEGUI_API void GetFullScreenModeFromRegistry( CTString strSectionName, CDisplayMode &dm, GfxAPIType &gat);
ENGINEGUI_API void SetFullScreenModeToRegistry( CTString strSectionName, CDisplayMode dm, GfxAPIType gat);
/* Call select mode dialog */
ENGINEGUI_API void SelectMode( CDisplayMode &dm, GfxAPIType &gat);
// [Cecil] Define Engine GUI interface
class ENGINEGUI_API CEngineGUI : public IEngineGUI {
public:
// Functions used by application for getting and setting registry keys concerning modes
virtual void GetFullScreenModeFromRegistry(CTString strSectionName, CDisplayMode &dm, GfxAPIType &gat);
virtual void SetFullScreenModeToRegistry( CTString strSectionName, CDisplayMode dm, GfxAPIType gat);

/* Call create texture dialog */
ENGINEGUI_API CTFileName CreateTexture( CTFileName fnTexFileToRecreate = CTString(""),
CDynamicArray<CTFileName> *pafnCreatedTextures=NULL);
// Call select mode dialog
virtual void SelectMode(CDisplayMode &dm, GfxAPIType &gat);

/* Predefined registry key names */
#define KEY_NAME_REQUEST_FILE_DIR "Request file directory"
#define KEY_NAME_DETAIL_TEXTURE_DIR "Detail texture directory"
#define KEY_NAME_BASE_TEXTURE_DIR "Base texture directory"
#define KEY_NAME_CREATE_TEXTURE_DIR "Create texture directory"
#define KEY_NAME_CREATE_ANIMATED_TEXTURE_DIR "Create animated texture directory"
#define KEY_NAME_CREATE_EFFECT_TEXTURE_DIR "Create effect texture directory"
#define KEY_NAME_BACKGROUND_TEXTURE_DIR "Background texture directory"
#define KEY_NAME_REPLACE_TEXTURE_DIR "Replace texture directory"
#define KEY_NAME_SCREEN_SHOT_DIR "Screen shots directory"
// Call create texture dialog
virtual CTFileName CreateTexture(CTFileName fnTexFileToRecreate = CTString(""),
CDynamicArray<CTFileName> *pafnCreatedTextures = NULL);

/* Predefined file filters for file requester */
#define FILTER_ALL "All files (*.*)\0*.*\0"
#define FILTER_PICTURES "Pictures (*.pcx;*.tga)\0*.pcx;*.tga\0"
#define FILTER_3DOBJ "3D object\0*.lwo;*.obj;*.3ds\0"
#define FILTER_LWO "Lightwave object (*.lwo)\0*.lwo\0"
#define FILTER_OBJ "Alias Wavefront Object (*.obj)\0*.obj\0"
#define FILTER_3DS "3DS object (*.3ds)\0*.3ds\0"
#define FILTER_SCR "Scripts (*.scr)\0*.scr\0"
#define FILTER_PCX "PCX files (*.pcx)\0*.pcx\0"
#define FILTER_TGA "TGA files (*.tga)\0*.tga\0"
#define FILTER_TEX "Textures (*.tex)\0*.tex\0"
#define FILTER_TBN "Thumbnails (*.tbn)\0*.tbn\0"
#define FILTER_MDL "Models (*.mdl)\0*.mdl\0"
#define FILTER_WLD "Worlds (*.wld)\0*.wld\0"
#define FILTER_WAV "Sounds (*.wav)\0*.wav\0"
#define FILTER_ANI "Animations (*.ani)\0*.ani\0"
#define FILTER_TXT "Text files (*.txt)\0*.txt\0"
#define FILTER_LST "List files (*.lst)\0*.lst\0"
#define FILTER_TGA "TGA files (*.tga)\0*.tga\0"
#define FILTER_SMC "SMC files (*.smc)\0*.smc\0"
#define FILTER_END "\0"
/* File requester with thumbnail display */
ENGINEGUI_API CTFileName FileRequester( char *pchrTitle="Choose file",
char *pchrFilters=FILTER_ALL FILTER_END,
char *pchrRegistry=KEY_NAME_REQUEST_FILE_DIR,
CTString strDefaultDir="", CTString strFileSelectedByDefault="",
CDynamicArray<CTFileName> *pafnCreatedTextures=NULL,
BOOL bIfOpen=TRUE);
// File requester with thumbnail display
virtual CTFileName FileRequester(
const char *pchrTitle = "Choose file",
const char *pchrFilters = FILTER_ALL FILTER_END,
const char *pchrRegistry = KEY_NAME_REQUEST_FILE_DIR,
CTString strDefaultDir = "",
CTString strFileSelectedByDefault = "",
CDynamicArray<CTFileName> *pafnCreatedTextures = NULL,
BOOL bIfOpen = TRUE);

/* Call browse texture requester */
ENGINEGUI_API CTFileName BrowseTexture(CTFileName fnDefaultSelected=CTString(""),
char *pchrIniKeyName=KEY_NAME_REQUEST_FILE_DIR,
char *pchrWindowTitle="Choose texture",
BOOL bIfOpen=TRUE);
// [Cecil] Simplified requester for replacing files
virtual CTFileName ReplaceFileRequester(
const char *pchrTitle,
const char *pchrFilters,
const char *pchrRegistry,
const char *pchrFileSelectedByDefault);

// Call browse texture requester
virtual CTFileName BrowseTexture(
CTFileName fnDefaultSelected = CTString(""),
const char *pchrIniKeyName = KEY_NAME_REQUEST_FILE_DIR,
const char *pchrWindowTitle = "Choose texture",
BOOL bIfOpen = TRUE);
};

// global engine gui handling object
Expand Down
37 changes: 19 additions & 18 deletions Sources/EngineGui/FileRequester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ UINT_PTR APIENTRY FileOpenRequesterHook( HWND hdlg, UINT uiMsg, WPARAM wParam, L
}

CTFileName CEngineGUI::FileRequester(
char *pchrTitle/*="Choose file"*/,
char *pchrFilters/*=FILTER_ALL FILTER_END*/,
char *pchrRegistry/*="KEY_NAME_REQUEST_FILE_DIR"*/,
CTString strDefaultDir/*=""*/,
CTString strFileSelectedByDefault/*=""*/,
CDynamicArray<CTFileName> *pafnSelectedFiles/*=NULL*/,
BOOL bIfOpen/*=TRUE*/)
const char *pchrTitle,
const char *pchrFilters,
const char *pchrRegistry,
CTString strDefaultDir,
CTString strFileSelectedByDefault,
CDynamicArray<CTFileName> *pafnSelectedFiles,
BOOL bIfOpen)
{
_pDrawPort = NULL;
_pViewPort = NULL;
Expand Down Expand Up @@ -317,21 +317,22 @@ CTFileName CEngineGUI::FileRequester(
return CTString( "");
}

// [Cecil] Export via C API
extern "C" ENGINEGUI_API CTFileName FileRequester(
char *pchrTitle,
char *pchrFilters,
char *pchrRegistry,
char *pchrFileSelectedByDefault)
// [Cecil] Simplified requester for replacing files
CTFileName CEngineGUI::ReplaceFileRequester(
const char *pchrTitle,
const char *pchrFilters,
const char *pchrRegistry,
const char *pchrFileSelectedByDefault)
{
return _EngineGUI.FileRequester(pchrTitle, pchrFilters, pchrRegistry, "", pchrFileSelectedByDefault);
return FileRequester(pchrTitle, pchrFilters, pchrRegistry, "", pchrFileSelectedByDefault);
}


CTFileName CEngineGUI::BrowseTexture(CTFileName fnDefaultSelected/*=""*/,
char *pchrIniKeyName/*=KEY_NAME_REQUEST_FILE_DIR*/,
char *pchrWindowTitle/*="Choose texture"*/,
BOOL bIfOpen/*=TRUE*/)
CTFileName CEngineGUI::BrowseTexture(
CTFileName fnDefaultSelected,
const char *pchrIniKeyName,
const char *pchrWindowTitle,
BOOL bIfOpen)
{
return FileRequester( pchrWindowTitle, FILTER_TEX FILTER_END, pchrIniKeyName,
"Textures\\", fnDefaultSelected, NULL, bIfOpen);
Expand Down
2 changes: 1 addition & 1 deletion Sources/SeriousSkaStudio/DlgClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ void CDlgClient::OnBtBrowseTexture()
// browse texture
//CDynamicArray<CTFileName> afnTexture;
CTFileName fnTexture = _EngineGUI.FileRequester( "Open texture files",
FILTER_TEXTURE, "Open directory", "Models\\", "", NULL);
FILTER_TEX, "Open directory", "Models\\", "", NULL);
if(fnTexture=="") {
return;
}
Expand Down
9 changes: 0 additions & 9 deletions Sources/SeriousSkaStudio/SeriousSkaStudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// CSeriousSkaStudioApp:
// See SeriousSkaStudio.cpp for the implementation of this class
//
#define FILTER_ASCII "ASCII files (*.aal,*.asl,*.aml)\0*.aal;*.aml;*.asl\0"
#define FILTER_MESH "Mesh ASCII files (*.am)\0*.am;\0"
#define FILTER_SKELETON "Skeleton ASCII files (*.as)\0*.as;\0"
#define FILTER_ANIMATION "Animation ASCII files (*.aa)\0*.aa;\0"
#define FILTER_TEXTURE "Texture files (*.tex)\0*.tex;\0"
#define FILTER_MESH_LIST "Mesh list files (*.aml)\0*.aml;\0"
#define FILTER_SKELETON_LIST "Skeleton list files (*.asl)\0*.asl;\0"
#define FILTER_ANIMSET_LISTS "AnimSet list files (*.aal)\0*.aal;\0"

#define STRETCH_BUTTON_INDEX 22

#define NT_MODELINSTANCE 0
Expand Down
2 changes: 1 addition & 1 deletion Sources/SeriousSkaStudio/SeriousSkaStudioView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ void CSeriousSkaStudioView::BrowseTexture(CTString strTextureDir)
CSeriousSkaStudioDoc *pDoc = GetDocument();
CDynamicArray<CTFileName> afnTexture;
_EngineGUI.FileRequester( "Open texture files",
FILTER_TEXTURE,
FILTER_TEX,
strTextureDir.ConstData(), strTextureDir, "", &afnTexture);

// return if no files selected
Expand Down

0 comments on commit 3217027

Please sign in to comment.