在游戏的程序里,界面的实现往往是比较复杂的。因为在游戏里,没有
WINDOWS的组件可以使用,也没有其合适的组件可以使用,所有界面的显示都需要从最原始的方式来实现,这样工作量非常庞大。下面就来分析第二生里实现UI的类厂,它的声明代码如下:
#001class LLUICtrlFactory
#002{
#003public:
构造函数。
#004
LLUICtrlFactory();
#005
// do not call!needs to be public so run-time can clean up the singleton
析构函数。
#006
virtual ~LLUICtrlFactory() {}
#007
查找到界面布局的
XML路径。
#008
void setupPaths();
#009
创建浮动的界面层。
#010
void buildFloater(LLFloater* floaterp, const LLString &filename,
#011
const LLCallbackMap::map_t* factory_map = NULL, BOOL open = TRUE);
创建控制板的界面层。
#012
BOOL buildPanel(LLPanel* panelp, const LLString &filename,
#013
const LLCallbackMap::map_t* factory_map = NULL);
#014
删除控制板的界面层。
#015
void removePanel(LLPanel* panelp) { mBuiltPanels.erase(panelp->getHandle()); }
删除浮动的界面层。
#016
void removeFloater(LLFloater* floaterp) { mBuiltFloaters.erase(floaterp->getHandle()); }
#017
创建界面菜单。
#018
class LLMenuGL *buildMenu(const LLString &filename, LLView* parentp);
创建光滑的菜单。
#019
class LLPieMenu *buildPieMenu(const LLString &filename, LLView* parentp);
#020
保存界面布局到
XML文件。
#021
// Does what you want for LLFloaters and LLPanels
#022
// Returns 0 on success
#023
S32 saveToXML(LLView* viewp, const LLString& filename);
#024
#025
重新建立界面布局。
#026
// Rebuilds all currently built panels.
#027
void rebuild();
#028
获取控件的类型。
#029
static EWidgetType getWidgetType(const LLString& ctrl_type);
通过类型获取控件的名称。
#030
static LLString getWidgetType(EWidgetType ctrl_type);
获取控件的颜色。
#031
static BOOL getAttributeColor(LLXMLNodePtr node, const LLString& name, LLColor4& color);
#032
下面通过名称来创建控件。
#033
// specific typed getters
#034
static class LLButton* getButtonByName( const LLPanel* panelp, const
#035LLString& name);
#036
static class LLCheckBoxCtrl* getCheckBoxByName( const LLPanel* panelp, const LLString& name);
#037
static class LLComboBox* getComboBoxByName( const LLPanel* panelp, const LLString& name);
#038
static class LLIconCtrl* getIconByName( const LLPanel* panelp, const LLString& name);
#039
static class LLLineEditor* getLineEditorByName( const LLPanel* panelp, const LLString& name);
#040
static class LLRadioGroup* getRadioGroupByName( const LLPanel* panelp, const LLString& name);
#041
static class LLScrollListCtrl* getScrollListByName( const LLPanel* panelp, const LLString& name);
#042
static class LLSliderCtrl* getSliderByName( const LLPanel* panelp, const LLString& name);
#043
static class LLSlider* getSliderBarByName( const LLPanel* panelp, const
#044LLString& name);
#045
static class LLSpinCtrl* getSpinnerByName( const LLPanel* panelp, const LLString& name);
#046
static class LLTextBox* getTextBoxByName( const LLPanel* panelp, const
#047LLString& name);
#048
static class LLTextEditor* getTextEditorByName( const LLPanel* panelp, const LLString& name);
#049
static class LLTabContainer* getTabContainerByName(const LLPanel* panelp, const LLString& name);
#050
static class LLScrollableContainerView* getScrollableContainerByName(const LLPanel* panelp, const LLString& name);
#051
static class LLPanel* getPanelByName( const LLPanel*
#052panelp, const LLString& name);
#053
static class LLMenuItemCallGL* getMenuItemCallByName(const LLPanel* panelp, const LLString& name);
#054
static class LLScrollingPanelList*getScrollingPanelList(const LLPanel* panelp, const LLString& name);
#055
static class LLMultiSliderCtrl* getMultiSliderByName( const LLPanel* panelp, const LLString& name);
#056
static class LLMultiSlider* getMultiSliderBarByName(const LLPanel* panelp, const LLString& name);
#057
#058
// interface getters
#059
static LLCtrlListInterface* getListInterfaceByName( const LLPanel* panelp, const LLString& name);
#060
static LLCtrlSelectionInterface* getSelectionInterfaceByName(const LLPanel* panelp, const LLString& name);
#061
static LLCtrlScrollInterface* getScrollInterfaceByName(const LLPanel* panelp, const LLString& name);
#062
通过名称创建控制板。
#063
LLPanel* createFactoryPanel(LLString name);
#064
根据
XML节点创建一个窗口。
#065
virtual LLView* createCtrlWidget(LLPanel *parent, LLXMLNodePtr node);
#066
virtual void createWidget(LLPanel *parent, LLXMLNodePtr node);
#067
#068
template <class T> T* createDummyWidget(const LLString& name)
#069
{
#070
return NULL;
#071
//static LLPanel dummy_panel;
#072
//LLXMLNodePtr new_node_ptr = new LLXMLNode(T::getWidgetTag(), FALSE);
#073
//return createWidget(&dummy_panel, new_node_ptr);
#074
}
#075
注册创建的回调函数。
#076
// Creator library
#077
typedef LLView* (*creator_function_t)(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
#078
void registerCreator(LLString ctrlname, creator_function_t function);
#079
通过名称获取
XML根节点。
#080
static bool getLayeredXMLNode(const LLString &filename, LLXMLNodePtr& root);
#081
#082protected:
#083
#084
template<class T>
#085
class LLUICtrlCreator
#086
{
#087
public:
#088
static void registerCreator(LLString name, LLUICtrlFactory *factory)
#089
{
#090
factory->registerCreator(name, T::fromXML);
#091
}
#092
};
#093
#094private:
#095
#096
typedef std::map<LLHandle<LLPanel>, LLString> built_panel_t;
#097
built_panel_t mBuiltPanels;
#098
typedef std::map<LLHandle<LLFloater>, LLString> built_floater_t;
#099
built_floater_t mBuiltFloaters;
#100
#101
std::deque<const LLCallbackMap::map_t*> mFactoryStack;
#102
#103
static const LLString sUICtrlNames[];
#104
#105
typedef std::map<LLString, creator_function_t> creator_list_t;
#106
creator_list_t mCreatorFunctions;
#107
static std::vector<LLString> mXUIPaths;
#108 };