Ticket #1540: disableAtlasButtonIfNotAvailable.patch

File disableAtlasButtonIfNotAvailable.patch, 4.0 KB (added by Adrián Chaves, 11 years ago)

Patch to disable the Scenario Editor button if Atlas cannot be loaded.

  • binaries/data/mods/public/gui/pregame/mainmenu.xml

    diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.xml b/binaries/data/mods/public/gui/pregame/mainmenu.xml
    index 837f6bf..3dcbbb2 100644
    a b Status: $status.  
    281281                >
    282282                    Scenario Editor
    283283                    <action on="Press">
    284                         closeMenu();
    285284                        <![CDATA[
    286                             // Start Atlas
    287                             if (Engine.AtlasIsAvailable())
     285                        closeMenu();
     286                        if (Engine.AtlasIsAvailable())
    288287                            Engine.RestartInAtlas();
    289                             else
    290                             messageBox(400, 200, "The scenario editor is not available or failed to load.", "Error", 2);
     288                        else
     289                            messageBox(400, 200, "The scenario editor is not available or failed to load. See the game logs for additional information.", "Error", 2);
    291290                        ]]>
    292291                    </action>
    293292                </object>
  • source/ps/DllLoader.cpp

    diff --git a/source/ps/DllLoader.cpp b/source/ps/DllLoader.cpp
    index 4a68cc9..051ab3d 100644
    a b  
    2222#include "lib/timer.h"
    2323#include "lib/posix/posix_dlfcn.h"
    2424#include "ps/CStr.h"
    25 #include "ps/CLogger.h"
    2625
    2726#if OS_MACOSX
    2827# include "lib/sysdep/os/osx/osx_bundle.h"
    static void* LoadAnyVariant(const CStr& name, std::stringstream& errors)  
    133132}
    134133
    135134
    136 DllLoader::DllLoader(const char* name)
    137     : m_Name(name), m_Handle(0)
     135DllLoader::DllLoader(const char* name, CLogger::ELogMethod loadErrorLogMethod)
     136    : m_Name(name), m_Handle(0), m_loadErrorLogMethod(loadErrorLogMethod)
    138137{
    139138}
    140139
    bool DllLoader::LoadDLL()  
    161160        m_Handle = LoadAnyVariant(m_Name, errors);
    162161        if(!m_Handle)   // (only report errors if nothing worked)
    163162        {
    164             LOGERROR(L"DllLoader: %hs", errors.str().c_str());
     163            logLoadError(errors.str().c_str());
    165164            m_Handle = HANDLE_UNAVAILABLE;
    166165        }
    167166    }
    void DllLoader::LoadSymbolInternal(const char* name, void** fptr) const  
    192191        throw PSERROR_DllLoader_SymbolNotFound();
    193192}
    194193
     194void DllLoader::logLoadError(const char* errors)
     195{
     196    if (m_loadErrorLogMethod == CLogger::Normal)
     197    {
     198        LOGMESSAGE(L"DllLoader: %hs", errors);
     199    }
     200    else if (m_loadErrorLogMethod == CLogger::Warning)
     201    {
     202        LOGWARNING(L"DllLoader: %hs", errors);
     203    }
     204    else /*(m_loadErrorLogMethod == CLogger::Error)*/
     205    {
     206        LOGERROR(L"DllLoader: %hs", errors);
     207    }
     208}
     209
    195210void DllLoader::OverrideLibdir(const char* libdir)
    196211{
    197212    g_Libdir = libdir;
  • source/ps/DllLoader.h

    diff --git a/source/ps/DllLoader.h b/source/ps/DllLoader.h
    index 963c135..7d994b6 100644
    a b  
    1919#define INCLUDED_DLLLOADER
    2020
    2121#include "ps/Errors.h"
     22#include "ps/CLogger.h"
    2223
    2324ERROR_GROUP(DllLoader);
    2425ERROR_TYPE(DllLoader, DllNotLoaded);
    public:  
    3334     * @param name base name of the library (from which we'll derive
    3435     *  "name.dll", "libname_dbg.so", etc). Pointer must remain valid for
    3536     *  this object's lifetime (which is fine if you just use a string literal).
     37     * @param loadErrorLogMethod Allows to customize how the DllLoader reports loading errors. For example, thanks to
     38     * this parameter it is possible to handle a failed Atlas load gracefully on the UI side, without printing an error
     39     * or warning, but still logging the message, just in case.
    3640     */
    37     DllLoader(const char* name);
     41    DllLoader(const char* name, CLogger::ELogMethod loadErrorLogMethod = CLogger::Error);
    3842
    3943    ~DllLoader();
    4044
    private:  
    7882    // casting from users.
    7983    void LoadSymbolInternal(const char* name, void** fptr) const;
    8084
     85    void logLoadError(const char* errors);
     86
    8187    const char* m_Name;
    8288    void* m_Handle;
     89    CLogger::ELogMethod m_loadErrorLogMethod;
    8390};
    8491
    8592template <typename T>
  • source/ps/GameSetup/Atlas.cpp

    diff --git a/source/ps/GameSetup/Atlas.cpp b/source/ps/GameSetup/Atlas.cpp
    index 6787931..ce000cd 100644
    a b  
    2626// Atlas (map editor) integration
    2727//----------------------------------------------------------------------------
    2828
    29 DllLoader atlas_dll("AtlasUI");
     29DllLoader atlas_dll("AtlasUI", CLogger::Normal);
    3030
    3131enum AtlasRunFlags
    3232{