00001 00032 #include "llviewerprecompiledheaders.h" 00033 00034 #include "llfloaterhud.h" 00035 #include "llviewercontrol.h" 00036 #include "lluictrlfactory.h" 00037 #include "llwebbrowserctrl.h" 00038 #include "llalertdialog.h" 00039 00040 // statics 00041 LLFloaterHUD* LLFloaterHUD::sInstance = 0; 00042 std::string LLFloaterHUD::sTutorialUrl = ""; 00043 00047 #define super LLFloater /* superclass */ 00048 00049 // Default constructor 00050 LLFloaterHUD::LLFloaterHUD() 00051 : LLFloater("floater_hud"), 00052 mWebBrowser(0) 00053 { 00054 // Create floater from its XML definition 00055 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_hud.xml"); 00056 00057 // Don't grab the focus as it will impede performing in-world actions 00058 // while using the HUD 00059 setIsChrome(TRUE); 00060 00061 // Chrome doesn't show the window title by default, but here we 00062 // want to show it. 00063 setTitleVisible(true); 00064 00065 // Opaque background since we never get the focus 00066 setBackgroundOpaque(TRUE); 00067 00068 // Position floater based on saved location 00069 LLRect saved_position_rect = gSavedSettings.getRect("FloaterHUDRect"); 00070 reshape(saved_position_rect.getWidth(), saved_position_rect.getHeight(), FALSE); 00071 setRect(saved_position_rect); 00072 00073 mWebBrowser = getChild<LLWebBrowserCtrl>("floater_hud_browser" ); 00074 if (mWebBrowser) 00075 { 00076 // Open links in internal browser 00077 mWebBrowser->setOpenInExternalBrowser(false); 00078 00079 // This is a "chrome" floater, so we don't want anything to 00080 // take focus (as the user needs to be able to walk with 00081 // arrow keys during tutorial). 00082 mWebBrowser->setTakeFocusOnClick(false); 00083 00084 LLString language(gSavedSettings.getString("Language")); 00085 if(language == "default") 00086 { 00087 language = gSavedSettings.getString("SystemLanguage"); 00088 } 00089 00090 std::string url = sTutorialUrl + language + "/"; 00091 mWebBrowser->navigateTo(url); 00092 } 00093 00094 // Remember the one instance 00095 sInstance = this; 00096 } 00097 00098 // Get the instance 00099 LLFloaterHUD* LLFloaterHUD::getInstance() 00100 { 00101 if (!sInstance) 00102 { 00103 new LLFloaterHUD(); 00104 } 00105 return sInstance; 00106 } 00107 00108 // Destructor 00109 LLFloaterHUD::~LLFloaterHUD() 00110 { 00111 // Save floater position 00112 gSavedSettings.setRect("FloaterHUDRect", getRect() ); 00113 00114 // Clear out the one instance if it's ours 00115 if (sInstance == this) 00116 { 00117 sInstance = NULL; 00118 } 00119 } 00120 00121 // Show the HUD 00122 void LLFloaterHUD::show() 00123 { 00124 // do not build the floater if there the url is empty 00125 if (sTutorialUrl == "") 00126 { 00127 LLAlertDialog::showXml("TutorialNotFound"); 00128 return; 00129 } 00130 00131 // Create the instance if necessary 00132 LLFloaterHUD* hud = getInstance(); 00133 hud->open(); 00134 hud->setFrontmost(FALSE); 00135 } 00136 00137 void LLFloaterHUD::close() 00138 { 00139 if (sInstance) sInstance->close(); 00140 }