00001 #include "gui_manager.hpp"
00002 #include "gui_out.hpp"
00003 #include "gui_event.hpp"
00004 #include "gui_uiobject.hpp"
00005 #include "gui_frame.hpp"
00006 #include "gui_eventmanager.hpp"
00007
00008 #include <xml_document.hpp>
00009 #include <luapp_state.hpp>
00010 #include <luapp_exception.hpp>
00011
00012 namespace gui
00013 {
00014 void manager::parse_xml_file_(const std::string& sFile, addon* pAddOn)
00015 {
00016 xml::document mDoc(sFile, "interface/ui.def", gui::out);
00017 if (mDoc.check())
00018 {
00019 xml::block* pElemBlock;
00020 foreach_block (pElemBlock, mDoc.get_main_block())
00021 {
00022 if (pElemBlock->get_name() == "Script")
00023 {
00024 std::string sFile = pAddOn->sDirectory + "/" + pElemBlock->get_attribute("file");
00025
00026 try { pLua_->do_file(sFile); }
00027 catch (lua::exception& e)
00028 {
00029 std::string sError = e.get_description();
00030
00031 gui::out << gui::error << sError << std::endl;
00032
00033 event mEvent("LUA_ERROR");
00034 mEvent.add(sError);
00035 pEventManager_->fire_event(mEvent);
00036 }
00037 }
00038 else if (pElemBlock->get_name() == "Include")
00039 {
00040 this->parse_xml_file_(pAddOn->sDirectory + "/" + pElemBlock->get_attribute("file"), pAddOn);
00041 }
00042 else
00043 {
00044 uiobject* pUIObject = create_uiobject(pElemBlock->get_name());
00045
00046 if (!pUIObject)
00047 return;
00048
00049 try
00050 {
00051 frame* pFrame = dynamic_cast<frame*>(pUIObject);
00052
00053 if (pFrame)
00054 {
00055 pFrame->set_addon(get_current_addon());
00056 pFrame->parse_block(pElemBlock);
00057 pFrame->notify_loaded();
00058 }
00059 else
00060 {
00061
00062 gui::out << gui::warning << "gui::manager : " "Creating texture or font_string at root "
00063 "level is forbidden. Skipped." << std::endl;
00064 delete pUIObject;
00065 }
00066 }
00067 catch (const exception& e)
00068 {
00069 delete pUIObject;
00070 gui::out << gui::error << e.get_description() << std::endl;
00071 }
00072 catch (...)
00073 {
00074 delete pUIObject;
00075 throw;
00076 }
00077 }
00078 }
00079 }
00080 }
00081 }