Difference between revisions of "Game chat box"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
Line 6: Line 6:
 
Editbox for chat input at bottom. Listbox for chat history at top.
 
Editbox for chat input at bottom. Listbox for chat history at top.
 
Both contained in frame window.
 
Both contained in frame window.
 +
This code is used after the system initialisation is done.
  
 
'''chat.layout'''
 
'''chat.layout'''

Revision as of 02:44, 6 July 2005

**4/7/05 - Work in progress**

File:ChatBox1.jpg


Editbox for chat input at bottom. Listbox for chat history at top. Both contained in frame window. This code is used after the system initialisation is done.

chat.layout

<?xml version="1.0" ?>
<GUILayout>
<Window Type="TaharezLook/FrameWindow" Name="/Chat">
	<Property Name="Position" Value="x:0.0 y:0.0" />
	<Property Name="Size" Value="w:0.25 h:0.25" />
	<Property Name="Alpha" Value="0.8" />
	<Window Type="DefaultWindow" Name="/Chat/Wnd"> 
		<Property Name="Alpha" Value="0.8" />
		<Property Name="Position" Value="x:0.0 y:0.00" />
		<Property Name="Size" Value="w:1 h:1" />
		<Window Type="TaharezLook/Listbox" Name="/Chat/Wnd/List">
			<Property Name="Position" Value="x:0.0 y:0.1" />
			<Property Name="Size" Value="w:1 h:0.77" />
		</Window>
	 	<Window Type="TaharezLook/Editbox" Name="/Chat/Wnd/Edit" >
			<Property Name="Position" Value="x:0.01 y:0.87" />
			<Property Name="Size" Value="w:0.98 h:0.12" />
  		</Window>
	</Window>
</Window>
</GUILayout>

#define

#define BIND_CEGUI_EVENT(window, event, method) window->subscribeEvent
(event, CEGUI::Event::Subscriber(&method, this)); 

Initialise()

mMainWindow = CEGUI::WindowManager::getSingleton().loadWindowLayout("chat.layout");
if (mMainWindow)
    getMainSheet()->addChildWindow(mMainWindow);
CEGUI::Window* pEditBoxWnd = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)
"/Chat/Wnd/Edit");
BIND_CEGUI_EVENT(pEditBoxWnd, CEGUI::Editbox::EventTextAccepted,
    ChatWidget::EditTextAccepted)
mEditBox = static_cast<CEGUI::Editbox*> (CEGUI::WindowManager::getSingleton()
    .getWindow("/Chat/Wnd/Edit"));
mListBox = static_cast<CEGUI::Listbox*> (CEGUI::WindowManager::getSingleton()
    .getWindow("/Chat/Wnd/List"));

getMainSheet() in this case returns the main default gui sheet (root) window

EditTextAccepted()

bool ChatWidget::EditTextAccepted(const CEGUI::EventArgs& args)
{
	//add text to list
	CEGUI::ListboxTextItem* item = new CEGUI::ListboxTextItem(mEditBox->getText());
	mListBox->addItem ( item );
	mListBox->ensureItemIsVisible(mListBox->getItemCount());
	//remove old text
	mEditBox->setText("");

	return true;
}