diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index d275679097..f2c05c6d65 100644 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -64,7 +64,7 @@ void CButton::SetupText() debug_assert(m_GeneratedTexts.size()>=1); CStr font; - if (GUI::GetSetting(this, "font", font) != PS_OK || font.empty()) + if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) // Use the default if none is specified // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! font = "default"; diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index 26fec6f185..2ec8fadf7e 100644 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -69,7 +69,7 @@ void CCheckBox::SetupText() debug_assert(m_GeneratedTexts.size()>=1); CStr font; - if (GUI::GetSetting(this, "font", font) != PS_OK || font.empty()) + if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) // Use the default if none is specified // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! font = "default"; diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 2ed4d79a46..90b7c66a82 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -272,7 +272,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev) pNearest->m_MouseHovering = true; } } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { UNUSED2(e); debug_warn("CGUI::HandleEvent error"); @@ -431,7 +431,7 @@ void CGUI::Process() { GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_PREPROCESS); } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { return; } @@ -469,7 +469,7 @@ void CGUI::Process() } } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { return; } @@ -479,7 +479,7 @@ void CGUI::Process() { GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_POSTPROCESS); } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { return; } @@ -501,7 +501,7 @@ void CGUI::Draw() // meaning all hidden objects won't call Draw (nor will it recurse its children) GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::Draw); } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { UNUSED2(e); glPopMatrix(); @@ -545,7 +545,7 @@ void CGUI::Destroy() { it->second->Destroy(); } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { UNUSED2(e); debug_warn("CGUI::Destroy error"); @@ -587,9 +587,9 @@ void CGUI::AddObject(IGUIObject* pObject) // Loaded GUI::RecurseObject(0, pObject, &IGUIObject::HandleMessage, SGUIMessage(GUIM_LOAD)); } - catch (PS_RESULT e) + catch (PSERROR_GUI&) { - throw e; + throw; } } @@ -604,10 +604,10 @@ void CGUI::UpdateObjects() // Fill freshly GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects ); } - catch (PS_RESULT e) + catch (PSERROR_GUI&) { // Throw the same error - throw e; + throw; } // Else actually update the real one @@ -1313,7 +1313,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec ManuallySetZ = true; // Try setting the value - if (object->SetSetting(pFile->GetAttributeString(attr.Name), (CStr)attr.Value, true) != PS_OK) + if (object->SetSetting(pFile->GetAttributeString(attr.Name), (CStr)attr.Value, true) != PSRETURN_OK) { ReportParseError("(object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName().c_str(), pFile->GetAttributeString(attr.Name).c_str(), CStr(attr.Value).c_str()); @@ -1442,9 +1442,9 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec else pParent->AddChild(object); } - catch (PS_RESULT e) + catch (PSERROR_GUI& e) { - ReportParseError(e); + ReportParseError(e.what()); } } diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index fd81226820..603233fdaf 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -283,7 +283,7 @@ private: * This function is atomic, meaning if it throws anything, it will * have seen it through that nothing was ultimately changed. * - * @throws PS_RESULT that is thrown from IGUIObject::AddToPointersMap(). + * @throws PSERROR_GUI that is thrown from IGUIObject::AddToPointersMap(). */ void UpdateObjects(); @@ -293,8 +293,7 @@ private: * XML files. Why? Because it enables the GUI to * be much more encapsulated and safe. * - * @throws Rethrows PS_RESULT from IGUIObject::SetGUI() and - * IGUIObject::AddChild(). + * @throws Rethrows PSERROR_GUI from IGUIObject::AddChild(). */ void AddObject(IGUIObject* pObject); diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index 26f6920f6c..997565d636 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -92,7 +92,7 @@ void CList::SetupText() m_GeneratedTexts.clear(); CStr font; - if (GUI::GetSetting(this, "font", font) != PS_OK || font.empty()) + if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) // Use the default if none is specified // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. font = "default"; diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp index e89f7a1691..75d8f42e6b 100644 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -69,7 +69,7 @@ void CText::SetupText() debug_assert(m_GeneratedTexts.size()>=1); CStr font; - if (GUI::GetSetting(this, "font", font) != PS_OK || font.empty()) + if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) // Use the default if none is specified // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. font = "default"; diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index 780e197e00..de4ebceb38 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -65,7 +65,7 @@ void CTooltip::SetupText() debug_assert(m_GeneratedTexts.size()==1); CStr font; - if (GUI::GetSetting(this, "font", font) != PS_OK || font.empty()) + if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) font = "default"; float buffer_zone = 0.f; diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp index 12f07743e9..33f8ba65ec 100644 --- a/source/gui/GUITooltip.cpp +++ b/source/gui/GUITooltip.cpp @@ -84,10 +84,10 @@ const double CooldownTime = 0.25; // TODO: Don't hard-code this value static bool GetTooltip(IGUIObject* obj, CStr&style) { if (obj && obj->SettingExists("tooltip_style") - && GUI::GetSetting(obj, "tooltip_style", style) == PS_OK) + && GUI::GetSetting(obj, "tooltip_style", style) == PSRETURN_OK) { CStr text; - if (GUI::GetSetting(obj, "tooltip", text) == PS_OK) + if (GUI::GetSetting(obj, "tooltip", text) == PSRETURN_OK) { if (text.empty()) { @@ -125,7 +125,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in CStr usedObjectName; - if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK + if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && !usedObjectName.empty()) { usedobj = gui->FindObjectByName(usedObjectName); @@ -145,20 +145,20 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* GUI::SetSetting(usedobj, "hidden", false); // Store mouse position inside the CTooltip - if (GUI::SetSetting(usedobj, "_mousepos", pos) != PS_OK) + if (GUI::SetSetting(usedobj, "_mousepos", pos) != PSRETURN_OK) debug_warn("Failed to set tooltip mouse position"); } // Retrieve object's 'tooltip' setting CStr text; - if (GUI::GetSetting(obj, "tooltip", text) != PS_OK) + if (GUI::GetSetting(obj, "tooltip", text) != PSRETURN_OK) debug_warn("Failed to retrieve tooltip text"); // shouldn't fail // Do some minimal processing ("\n" -> newline, etc) text = text.UnescapeBackslashes(); // Set tooltip's caption - if (usedobj->SetSetting("caption", text) != PS_OK) + if (usedobj->SetSetting("caption", text) != PSRETURN_OK) debug_warn("Failed to set tooltip caption"); // shouldn't fail // Make the tooltip object regenerate its text @@ -179,7 +179,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui) } CStr usedObjectName; - if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK + if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && !usedObjectName.empty()) { IGUIObject* usedobj = gui->FindObjectByName(usedObjectName); diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index 3f73fd9858..4120c5f499 100644 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -222,10 +222,8 @@ public: //-------------------------------------------------------- ERROR_GROUP(GUI); -ERROR_TYPE(GUI, ReferenceNameTake); ERROR_TYPE(GUI, NullObjectProvided); ERROR_TYPE(GUI, InvalidSetting); -ERROR_TYPE(GUI, InvalidValueSyntax); ERROR_TYPE(GUI, OperationNeedsGUIObject); ERROR_TYPE(GUI, NameAmbiguity); ERROR_TYPE(GUI, ObjectNeedsName); diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index 24e904b759..ccdd00e0e0 100644 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -26,6 +26,9 @@ GUI utilities extern int g_yres; +#include "ps/CLogger.h" +#define LOG_CATEGORY "gui" + template <> bool __ParseString(const CStr& Value, bool &Output) @@ -307,17 +310,21 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, const SGUIMes //-------------------------------------------------------------------- template -PS_RESULT GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value) +PSRETURN GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value) { - if (pObject == NULL) - throw PSERROR_GUI_NullObjectProvided(); + debug_assert(pObject != NULL); std::map::const_iterator it = pObject->m_Settings.find(Setting); if (it == pObject->m_Settings.end()) - return PS_FAIL; + { + LOG(CLogger::Warning, LOG_CATEGORY, "setting %s was not found on object %s", + Setting.c_str(), + pObject->GetPresentableName().c_str()); + return PSRETURN_GUI_InvalidSetting; + } if (it->second.m_pSetting == NULL) - return PS_FAIL; + return PSRETURN_GUI_InvalidSetting; #ifndef NDEBUG CheckType(pObject, Setting); @@ -326,28 +333,32 @@ PS_RESULT GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setti // Get value Value = (T*)(it->second.m_pSetting); - return PS_OK; + return PSRETURN_OK; } template -PS_RESULT GUI::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value) +PSRETURN GUI::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value) { T* v; - PS_RESULT ret = GetSettingPointer(pObject, Setting, v); - if (ret == PS_OK) + PSRETURN ret = GetSettingPointer(pObject, Setting, v); + if (ret == PSRETURN_OK) Value = *v; return ret; } template -PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, +PSRETURN GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage) { - if (pObject == NULL) - throw PSERROR_GUI_NullObjectProvided(); + debug_assert(pObject != NULL); if (!pObject->SettingExists(Setting)) - throw PSERROR_GUI_InvalidSetting(); + { + LOG(CLogger::Warning, LOG_CATEGORY, "setting %s was not found on object %s", + Setting.c_str(), + pObject->GetPresentableName().c_str()); + return PSRETURN_GUI_InvalidSetting; + } #ifndef NDEBUG CheckType(pObject, Setting); @@ -376,14 +387,14 @@ PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, if (!SkipMessage) HandleMessage(pObject, SGUIMessage(GUIM_SETTINGS_UPDATED, Setting)); - return PS_OK; + return PSRETURN_OK; } // Instantiate templated functions: #define TYPE(T) \ - template PS_RESULT GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \ - template PS_RESULT GUI::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \ - template PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage); + template PSRETURN GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \ + template PSRETURN GUI::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \ + template PSRETURN GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage); #define GUITYPE_IGNORE_CGUISpriteInstance #include "GUItypes.h" @@ -391,5 +402,5 @@ PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, // you attempt to retrieve a sprite using GetSetting, since that copies the sprite // and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer // instead. (This is mainly useful to stop me accidentally using the wrong function.) -template PS_RESULT GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value); -template PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value, const bool& SkipMessage); +template PSRETURN GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value); +template PSRETURN GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value, const bool& SkipMessage); diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h index af04f620fb..6cf0d1bb74 100644 --- a/source/gui/GUIutil.h +++ b/source/gui/GUIutil.h @@ -112,7 +112,7 @@ public: // Like GetSetting (below), but doesn't make a copy of the value // (so it can be modified later) - static PS_RESULT GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); + static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); /** * Retrieves a setting by name from object pointer @@ -121,7 +121,7 @@ public: * @param Setting Setting by name * @param Value Stores value here, note type T! */ - static PS_RESULT GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); + static PSRETURN GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); /** * Sets a value by name using a real datatype as input. @@ -134,7 +134,7 @@ public: * @param Value Sets value to this, note type T! * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true */ - static PS_RESULT SetSetting(IGUIObject *pObject, const CStr& Setting, + static PSRETURN SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool &SkipMessage=false); #ifdef g_GUI @@ -142,7 +142,7 @@ public: * Adapter that uses the singleton g_GUI * Can safely be removed. */ - static PS_RESULT GetSetting( + static PSRETURN GetSetting( const CStr& Object, const CStr& Setting, T &Value) { @@ -158,12 +158,12 @@ public: * @param Setting Setting by name * @param Value Stores value here, note type T! */ - static PS_RESULT GetSetting( + static PSRETURN GetSetting( const CGUI &GUIinstance, const CStr& Object, const CStr& Setting, T &Value) { if (!GUIinstance.ObjectExists(Object)) - throw PSERROR_GUI_NullObjectProvided(); + return PSRETURN_GUI_NullObjectProvided; // Retrieve pointer and call sibling function const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object); @@ -176,7 +176,7 @@ public: * Adapter that uses the singleton g_GUI * Can safely be removed. */ - static PS_RESULT SetSetting( + static PSRETURN SetSetting( const CStr& Object, const CStr& Setting, const T &Value, const bool& SkipMessage=false) { return SetSetting(g_GUI, Object, Setting, Value, SkipMessage); @@ -195,13 +195,13 @@ public: * @param Setting Setting by name * @param Value Sets value to this, note type T! */ - static PS_RESULT SetSetting( + static PSRETURN SetSetting( CGUI &GUIinstance, const CStr& Object, const CStr& Setting, const T &Value, const bool& SkipMessage=false) { if (!GUIinstance.ObjectExists(Object)) - throw PSERROR_GUI_NullObjectProvided(); + return PSRETURN_GUI_NullObjectProvided; // Retrieve pointer and call sibling function @@ -294,7 +294,7 @@ private: * @param pObject Top object, this is where the iteration starts * @param pFunc Function to recurse * @param Argument Argument for pFunc of type T - * @throws PS_RESULT Depends on what pFunc might throw. PS_RESULT is standard. + * @throws PSERROR Depends on what pFunc might throw. PSERROR is standard. * Itself doesn't throw anything. */ static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument) diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index dab0e9576e..7840190ba9 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -27,6 +27,9 @@ IGUIObject #include "gui/scripting/JSInterface_IGUIObject.h" #include "gui/scripting/JSInterface_GUITypes.h" +#include "ps/CLogger.h" +#define LOG_CATEGORY "gui" + extern int g_xres, g_yres; @@ -122,15 +125,13 @@ void IGUIObject::AddChild(IGUIObject *pChild) //UpdateObjects(); pChild->GetGUI()->UpdateObjects(); } - catch (PS_RESULT e) + catch (PSERROR_GUI&) { // If anything went wrong, reverse what we did and throw // an exception telling it never added a child m_Children.erase( m_Children.end()-1 ); - - // We'll throw the same exception for easier - // error handling - throw e; + + throw; } } // else do nothing @@ -251,16 +252,16 @@ bool IGUIObject::SettingExists(const CStr& Setting) const { \ type _Value; \ if (!GUI::ParseString(Value, _Value)) \ - return PS_FAIL; \ + return PSRETURN_GUI_UnableToParse; \ \ GUI::SetSetting(this, Setting, _Value, SkipMessage); \ } -PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage) +PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage) { if (!SettingExists(Setting)) { - return PS_FAIL; + return LogInvalidSettings(Setting); } // Get setting @@ -271,25 +272,31 @@ PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const b #include "GUItypes.h" else { - return PS_FAIL; + // Why does it always fail? + //return PS_FAIL; + return LogInvalidSettings(Setting); } - return PS_OK; + return PSRETURN_OK; } #undef TYPE -PS_RESULT IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const +PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const { if (!SettingExists(Setting)) - throw PSERROR_GUI_InvalidSetting(); + { + return LogInvalidSettings(Setting); + } if (m_Settings.find(Setting) == m_Settings.end()) - return PS_FAIL; + { + return LogInvalidSettings(Setting); + } Type = m_Settings.find(Setting)->second.m_Type; - return PS_OK; + return PSRETURN_OK; } @@ -414,7 +421,7 @@ void IGUIObject::CheckSettingsValidity() { GUI::RecurseObject(0, this, &IGUIObject::UpdateMouseOver, NULL); } - catch (PS_RESULT) + catch (PSERROR_GUI&) { } } @@ -425,7 +432,7 @@ void IGUIObject::CheckSettingsValidity() HandleMessage(GUIM_SETTINGS_UPDATED); ScriptEvent("update"); } - catch (PS_RESULT) + catch (PSERROR_GUI&) { } } @@ -553,3 +560,10 @@ bool IGUIObject::IsRootObject() const { return (GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject); } + +PSRETURN IGUIObject::LogInvalidSettings(const CStr8 &Setting) const +{ + LOG(CLogger::Warning, LOG_CATEGORY, "IGUIObject: setting %s was not found on an object", + Setting.c_str()); + return PSRETURN_GUI_InvalidSetting; +} diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index f28fec7bbe..60820ba448 100644 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -77,6 +77,8 @@ struct JSObject; // Error declarations //-------------------------------------------------------- +ERROR_TYPE(GUI, UnableToParse); + //-------------------------------------------------------- // Declarations //-------------------------------------------------------- @@ -184,8 +186,8 @@ public: * * @param ObjectMap Adds this to the map_pObjects. * - * @throws PS_NEEDS_NAME Name is missing - * @throws PS_NAME_AMBIGUITY Name is already taken + * @throws PSERROR_GUI_ObjectNeedsName Name is missing + * @throws PSERROR_GUI_NameAmbiguity Name is already taken */ void AddToPointersMap(map_pObjects &ObjectMap); @@ -203,7 +205,7 @@ public: * * @param pChild Child to add * - * @throws PS_RESULT from CGUI::UpdateObjects(). + * @throws PSERROR_GUI from CGUI::UpdateObjects(). */ void AddChild(IGUIObject *pChild); @@ -268,18 +270,18 @@ public: * @param Setting Setting by name * @param Value Value to set to * - * @return PS_RESULT (PS_OK if successful) + * @return PSERROR (PSRETURN_OK if successful) */ - PS_RESULT SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false); + PSRETURN SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false); /** * Retrieves the type of a named setting. * * @param Setting Setting by name * @param Type Stores an EGUISettingType - * @return PS_RESULT (PS_OK if successful) + * @return PSRETURN (PSRETURN_OK if successful) */ - PS_RESULT GetSettingType(const CStr& Setting, EGUISettingType &Type) const; + PSRETURN GetSettingType(const CStr& Setting, EGUISettingType &Type) const; /** * Set the script handler for a particular object-specific action @@ -334,7 +336,7 @@ protected: /** * Draws the object. * - * @throws PS_RESULT if any. But this will mostlikely be + * @throws PSERROR if any. But this will mostlikely be * very rare since if an object is drawn unsuccessfully * it'll probably only output in the Error log, and not * disrupt the whole GUI drawing. @@ -493,6 +495,13 @@ private: // as parent. bool IsRootObject() const; + /** + * Logs an invalid setting search and returns the correct return result + * + * @return the error result + */ + PSRETURN LogInvalidSettings(const CStr& Setting) const; + // Variables protected: diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp index 45b5cb6782..768cc86100 100644 --- a/source/gui/scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -109,7 +109,7 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval { // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; - if (e->GetSettingType(propName, Type) != PS_OK) + if (e->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid GUIObject property '%s'", propName.c_str()); return JS_FALSE; @@ -311,7 +311,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; - if (e->GetSettingType(propName, Type) != PS_OK) + if (e->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid setting '%s'", propName.c_str()); return JS_TRUE; @@ -427,7 +427,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval { if (JSVAL_IS_STRING(*vp)) { - if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK) + if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; @@ -464,7 +464,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval { if (JSVAL_IS_STRING(*vp)) { - if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK) + if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; diff --git a/source/ps/Errors.cpp b/source/ps/Errors.cpp index 94e6036aad..9f9d25d041 100644 --- a/source/ps/Errors.cpp +++ b/source/ps/Errors.cpp @@ -34,13 +34,12 @@ class PSERROR_File_ReadFailed : public PSERROR_File { public: PSRETURN getCode() class PSERROR_File_UnexpectedEOF : public PSERROR_File { public: PSRETURN getCode() const; }; class PSERROR_File_WriteFailed : public PSERROR_File { public: PSRETURN getCode() const; }; class PSERROR_GUI_InvalidSetting : public PSERROR_GUI { public: PSRETURN getCode() const; }; -class PSERROR_GUI_InvalidValueSyntax : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_GUI_JSOpenFailed : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_GUI_NameAmbiguity : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_GUI_NullObjectProvided : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_GUI_ObjectNeedsName : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_GUI_OperationNeedsGUIObject : public PSERROR_GUI { public: PSRETURN getCode() const; }; -class PSERROR_GUI_ReferenceNameTake : public PSERROR_GUI { public: PSRETURN getCode() const; }; +class PSERROR_GUI_UnableToParse : public PSERROR_GUI { public: PSRETURN getCode() const; }; class PSERROR_Game_World_MapLoadFailed : public PSERROR_Game_World { public: PSRETURN getCode() const; }; class PSERROR_I18n_Script_SetupFailed : public PSERROR_I18n_Script { public: PSRETURN getCode() const; }; class PSERROR_Renderer_VBOFailed : public PSERROR_Renderer { public: PSRETURN getCode() const; }; @@ -74,13 +73,12 @@ extern const PSRETURN PSRETURN_File_ReadFailed = 0x04000004; extern const PSRETURN PSRETURN_File_UnexpectedEOF = 0x04000005; extern const PSRETURN PSRETURN_File_WriteFailed = 0x04000006; extern const PSRETURN PSRETURN_GUI_InvalidSetting = 0x05000001; -extern const PSRETURN PSRETURN_GUI_InvalidValueSyntax = 0x05000002; -extern const PSRETURN PSRETURN_GUI_JSOpenFailed = 0x05000003; -extern const PSRETURN PSRETURN_GUI_NameAmbiguity = 0x05000004; -extern const PSRETURN PSRETURN_GUI_NullObjectProvided = 0x05000005; -extern const PSRETURN PSRETURN_GUI_ObjectNeedsName = 0x05000006; -extern const PSRETURN PSRETURN_GUI_OperationNeedsGUIObject = 0x05000007; -extern const PSRETURN PSRETURN_GUI_ReferenceNameTake = 0x05000008; +extern const PSRETURN PSRETURN_GUI_JSOpenFailed = 0x05000002; +extern const PSRETURN PSRETURN_GUI_NameAmbiguity = 0x05000003; +extern const PSRETURN PSRETURN_GUI_NullObjectProvided = 0x05000004; +extern const PSRETURN PSRETURN_GUI_ObjectNeedsName = 0x05000005; +extern const PSRETURN PSRETURN_GUI_OperationNeedsGUIObject = 0x05000006; +extern const PSRETURN PSRETURN_GUI_UnableToParse = 0x05000007; extern const PSRETURN PSRETURN_Game_World_MapLoadFailed = 0x06040001; extern const PSRETURN PSRETURN_I18n_Script_SetupFailed = 0x07030001; extern const PSRETURN PSRETURN_Renderer_VBOFailed = 0x08000001; @@ -158,20 +156,18 @@ extern const PSRETURN MASK__PSRETURN_File_WriteFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_WriteFailed = 0x04000006; extern const PSRETURN MASK__PSRETURN_GUI_InvalidSetting = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_InvalidSetting = 0x05000001; -extern const PSRETURN MASK__PSRETURN_GUI_InvalidValueSyntax = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_InvalidValueSyntax = 0x05000002; extern const PSRETURN MASK__PSRETURN_GUI_JSOpenFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_JSOpenFailed = 0x05000003; +extern const PSRETURN CODE__PSRETURN_GUI_JSOpenFailed = 0x05000002; extern const PSRETURN MASK__PSRETURN_GUI_NameAmbiguity = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_NameAmbiguity = 0x05000004; +extern const PSRETURN CODE__PSRETURN_GUI_NameAmbiguity = 0x05000003; extern const PSRETURN MASK__PSRETURN_GUI_NullObjectProvided = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_NullObjectProvided = 0x05000005; +extern const PSRETURN CODE__PSRETURN_GUI_NullObjectProvided = 0x05000004; extern const PSRETURN MASK__PSRETURN_GUI_ObjectNeedsName = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_ObjectNeedsName = 0x05000006; +extern const PSRETURN CODE__PSRETURN_GUI_ObjectNeedsName = 0x05000005; extern const PSRETURN MASK__PSRETURN_GUI_OperationNeedsGUIObject = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_OperationNeedsGUIObject = 0x05000007; -extern const PSRETURN MASK__PSRETURN_GUI_ReferenceNameTake = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_GUI_ReferenceNameTake = 0x05000008; +extern const PSRETURN CODE__PSRETURN_GUI_OperationNeedsGUIObject = 0x05000006; +extern const PSRETURN MASK__PSRETURN_GUI_UnableToParse = 0xffffffff; +extern const PSRETURN CODE__PSRETURN_GUI_UnableToParse = 0x05000007; extern const PSRETURN MASK__PSRETURN_Game_World_MapLoadFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Game_World_MapLoadFailed = 0x06040001; extern const PSRETURN MASK__PSRETURN_I18n_Script_SetupFailed = 0xffffffff; @@ -224,13 +220,12 @@ PSRETURN PSERROR_File_ReadFailed::getCode() const { return 0x04000004; } PSRETURN PSERROR_File_UnexpectedEOF::getCode() const { return 0x04000005; } PSRETURN PSERROR_File_WriteFailed::getCode() const { return 0x04000006; } PSRETURN PSERROR_GUI_InvalidSetting::getCode() const { return 0x05000001; } -PSRETURN PSERROR_GUI_InvalidValueSyntax::getCode() const { return 0x05000002; } -PSRETURN PSERROR_GUI_JSOpenFailed::getCode() const { return 0x05000003; } -PSRETURN PSERROR_GUI_NameAmbiguity::getCode() const { return 0x05000004; } -PSRETURN PSERROR_GUI_NullObjectProvided::getCode() const { return 0x05000005; } -PSRETURN PSERROR_GUI_ObjectNeedsName::getCode() const { return 0x05000006; } -PSRETURN PSERROR_GUI_OperationNeedsGUIObject::getCode() const { return 0x05000007; } -PSRETURN PSERROR_GUI_ReferenceNameTake::getCode() const { return 0x05000008; } +PSRETURN PSERROR_GUI_JSOpenFailed::getCode() const { return 0x05000002; } +PSRETURN PSERROR_GUI_NameAmbiguity::getCode() const { return 0x05000003; } +PSRETURN PSERROR_GUI_NullObjectProvided::getCode() const { return 0x05000004; } +PSRETURN PSERROR_GUI_ObjectNeedsName::getCode() const { return 0x05000005; } +PSRETURN PSERROR_GUI_OperationNeedsGUIObject::getCode() const { return 0x05000006; } +PSRETURN PSERROR_GUI_UnableToParse::getCode() const { return 0x05000007; } PSRETURN PSERROR_Game_World_MapLoadFailed::getCode() const { return 0x06040001; } PSRETURN PSERROR_I18n_Script_SetupFailed::getCode() const { return 0x07030001; } PSRETURN PSERROR_Renderer_VBOFailed::getCode() const { return 0x08000001; } @@ -278,13 +273,12 @@ const char* GetErrorString(PSRETURN code) case 0x04000005: return "File_UnexpectedEOF"; case 0x04000006: return "File_WriteFailed"; case 0x05000001: return "GUI_InvalidSetting"; - case 0x05000002: return "GUI_InvalidValueSyntax"; - case 0x05000003: return "GUI_JSOpenFailed"; - case 0x05000004: return "GUI_NameAmbiguity"; - case 0x05000005: return "GUI_NullObjectProvided"; - case 0x05000006: return "GUI_ObjectNeedsName"; - case 0x05000007: return "GUI_OperationNeedsGUIObject"; - case 0x05000008: return "GUI_ReferenceNameTake"; + case 0x05000002: return "GUI_JSOpenFailed"; + case 0x05000003: return "GUI_NameAmbiguity"; + case 0x05000004: return "GUI_NullObjectProvided"; + case 0x05000005: return "GUI_ObjectNeedsName"; + case 0x05000006: return "GUI_OperationNeedsGUIObject"; + case 0x05000007: return "GUI_UnableToParse"; case 0x06040001: return "Game_World_MapLoadFailed"; case 0x07030001: return "I18n_Script_SetupFailed"; case 0x08000001: return "Renderer_VBOFailed"; @@ -326,13 +320,12 @@ void ThrowError(PSRETURN code) case 0x04000005: throw PSERROR_File_UnexpectedEOF(); break; case 0x04000006: throw PSERROR_File_WriteFailed(); break; case 0x05000001: throw PSERROR_GUI_InvalidSetting(); break; - case 0x05000002: throw PSERROR_GUI_InvalidValueSyntax(); break; - case 0x05000003: throw PSERROR_GUI_JSOpenFailed(); break; - case 0x05000004: throw PSERROR_GUI_NameAmbiguity(); break; - case 0x05000005: throw PSERROR_GUI_NullObjectProvided(); break; - case 0x05000006: throw PSERROR_GUI_ObjectNeedsName(); break; - case 0x05000007: throw PSERROR_GUI_OperationNeedsGUIObject(); break; - case 0x05000008: throw PSERROR_GUI_ReferenceNameTake(); break; + case 0x05000002: throw PSERROR_GUI_JSOpenFailed(); break; + case 0x05000003: throw PSERROR_GUI_NameAmbiguity(); break; + case 0x05000004: throw PSERROR_GUI_NullObjectProvided(); break; + case 0x05000005: throw PSERROR_GUI_ObjectNeedsName(); break; + case 0x05000006: throw PSERROR_GUI_OperationNeedsGUIObject(); break; + case 0x05000007: throw PSERROR_GUI_UnableToParse(); break; case 0x06040001: throw PSERROR_Game_World_MapLoadFailed(); break; case 0x07030001: throw PSERROR_I18n_Script_SetupFailed(); break; case 0x08000001: throw PSERROR_Renderer_VBOFailed(); break;