HOWTO: Develop Custom EQ Windows with MQ2

General announcements relating to the modularized MacroQuest2 system.

Moderator: MacroQuest Developers

Lax
We're not worthy!
We're not worthy!
Posts: 3524
Joined: Thu Oct 17, 2002 1:01 pm
Location: ISBoxer
Contact:

HOWTO: Develop Custom EQ Windows with MQ2

Post by Lax » Wed Dec 03, 2003 5:17 am

You must derive your own class from CCustomWnd, similar to this example:

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]
};
Here's some explanation.

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;
	}
}
If you want to use a custom XML file, make sure to have the parts shown in red here (FindScreenPieceTemplate). This ensures the XML you're looking for was loaded, and it would most likely crash EQ without it if the XML was not loaded.

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]
}
voila! .. thats all it takes. When the UI is initially loaded, or reloaded via loadskin, the custom xml file will be loaded. The XML file MUST exist in the default skin directory, OR it will not be loaded by the MQ2 system. This is a safety feature, because if we tried to make it load EQ would crash with a ui error message box. So with that added, make sure if the user wants the custom window they put the xml in their default directory, and of course custom versions of the xml can be placed in custom ui directories.

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.
Lax Lacks
Master of MQ2 Disaster
Purveyor of premium, EULA-safe MMORPG Multiboxing Software
* Multiboxing with ISBoxer: Quick Start Video
* EQPlayNice, WinEQ 2.0

Plazmic
The One
The One
Posts: 800
Joined: Fri Jun 14, 2002 12:31 am
Contact:

Post by Plazmic » Wed Dec 03, 2003 6:24 pm

I can see a DPS plugin being developed around this...
- Plazmic

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Wed Dec 03, 2003 8:04 pm

Already being discussed :)

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Thu Dec 04, 2003 1:36 am

and a nice window with remote control buttons for my warrior pet
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Thu Dec 04, 2003 6:54 am

I want one that makes coffee :)