Code: Select all
class CTestWnd : public CCustomWnd
{
public:
CTestWnd():CCustomWnd([color=green]"TipWindow"[/color])
{
[color=red]CloseButton=(CButtonWnd*)GetChildItem(CXStr("CloseButton"));
SetWndNotification(CTestWnd);[/color]
}
~CTestWnd()
{
}
[color=red]
int WndNotification(CXWnd *pWnd, unsigned int Message, void *unknown)
{
if (pWnd==(CXWnd*)CloseButton)
{
if (Message==XWM_LCLICK)
pXWnd()->Show(0,0);
else
DebugSpew("CloseButton message %Xh / %d",Message,Message);
}
return CSidlScreenWnd::WndNotification(pWnd,Message,unknown);
};
CButtonWnd *CloseButton;
[/color]
};
The part in GREEN shows what you need to change in order for it to be based on your own custom XML.. if you want it based on the tip window for example, you would just change it to say TipWindow. This is the "Screen Item" from the XML file -- <Screen item = "TipWindow">.
The part in RED shows what you'd need to do in order to have custom functional buttons. GetChildItem finds that piece in the window, this is the ScreenID from the XML file -- <ScreenID>CloseButton</ScreenID>. SetWndNotification sets up your WndNotification function so you get it instead of it going higher in the chain. You can always return CSidlScreenWnd::WndNotification(pWnd,Message,unknown); and not worry about it. In WndNotification, the pWnd parameter given is the pointer to the window being clicked (in this case, the close button seen on the tip window). Having the CloseButton data member means we dont have to GetChildItem every time WndNotification is called (this is why we store it when the window is created). Anyway, then the message number says if it's being left clicked, right clicked, etc. Right now the only one I've checked the code for is left click, which is XWM_LCLICK. Others will be filled in soon (feel free to figure it out and pm me a list).
Now for the setup
Code: Select all
CTestWnd *MyWnd=0;
.
.
.
PLUGIN_API VOID OnCleanUI(VOID)
{
DebugSpewAlways("MQ2WndTest::OnCleanUI()");
if (MyWnd)
{
delete MyWnd;
MyWnd=0;
}
}
.
.
.
PLUGIN_API VOID SetGameState(DWORD GameState)
{
// DebugSpewAlways("MQ2WndTest::SetGameState()");
if (GameState==GAMESTATE_INGAME && !MyWnd)
{
[color=red] if (pSidlMgr->FindScreenPieceTemplate("TestWindow"))[/color]
MyWnd=new CTestWnd;
}
}
PLUGIN_API VOID OnReloadUI()
{
// DebugSpewAlways("MQ2WndTest::OnReloadUI()");
if (!MyWnd)
{
[color=red] if (pSidlMgr->FindScreenPieceTemplate("TestWindow"))[/color]
MyWnd=new CTestWnd;
}
}
Finally, in order to use a custom XML file, it's very easy to set it up:
Code: Select all
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing MQ2WndTest");
// Add commands, macro parameters, hooks, etc.
// AddCommand("/mycommand",MyCommand);
// AddParm("$myparm(x)",MyParm);
[color=red] AddXMLFile("MQUI_TestWnd.xml");[/color]
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down MQ2WndTest");
// Remove commands, macro parameters, hooks, etc.
// RemoveParm("$myparm(x)");
// RemoveCommand("/mycommand");
[color=red] RemoveXMLFile("MQUI_TestWnd.xml");[/color]
}
Now some quick notes:
- The window is shown automatically by the system when created. You can hide the window by calling pXWnd()->Show(0,0);
- You can access CSidlScreenWnd member functions directly
- You can access CXWnd member functions using pXWnd()->function();
- Controls from the XML will ALWAYS show up, but you need to make them functional yourself by trapping the clicks in your class's WndNotification.
- You do not need to use CButtonWnd* as the variable for your stored control pointers, you can make it CSidlScreenWnd* or CXWnd* if you want, and it might be useful to use CEditWnd* etc in the near future.
- You do not need to have any of the red code that was shown inside the CTestWnd example class. It can be almost completely empty, but make sure to have the constructor and deconstructor as shown.


donations for this month's patches.