Nui short template

From NWN Lexicon
Jump to navigationJump to search

Short Template

This is a short template for building a NUI. An example usage of this template, would be to make small working code examples.

See Nui_template for how to use (same usage, just change function names).

#include "nw_inc_nui"


const string NUI_TEMPLATE_SHORT_WINDOW_ID = "nui_template_short";

void NUI_TemplateShort_NewWindow(object oPlayer);
void NUI_TemplateShort_Update(object oPlayer, int nToken);
void NUI_TemplateShort_Events();


void NUI_TemplateShort_Events()
{
	object oPlayer	 = NuiGetEventPlayer();
	int nToken		 = NuiGetEventWindow();
	string sEvent	 = NuiGetEventType();
	string sElement	 = NuiGetEventElement();
	int nIndex		 = NuiGetEventArrayIndex();
	string sWindowId = NuiGetWindowId(oPlayer, nToken);

	if (sWindowId != NUI_TEMPLATE_SHORT_WINDOW_ID)
	{
		return;
	}
}


void NUI_TemplateShort_Update(object oPlayer, int nToken)
{
	if (nToken == 0)
	{
		return;
	}
}

void NUI_TemplateShort_NewWindow(object oPlayer)
{
	int nToken = NuiFindWindow(oPlayer, NUI_TEMPLATE_SHORT_WINDOW_ID);
	if (nToken != 0)
	{
		NuiDestroy(oPlayer, nToken);
	}

	/////////////////////////////////////////
	// Build the main root pane here
	json jRoot = JsonArray();

	json jRow;
	// Build the first row
	{
		jRow  = JsonArray();
		jRow  = JsonArrayInsert(jRow, NuiSpacer());
		jRow  = NuiRow(jRow);
		jRoot = JsonArrayInsert(jRoot, jRow);
	}

	///////////////////////////////////////////
	// Build final group
	jRoot = NuiCol(jRoot);

	/////////////////////////////////////////
	// Create new window here
	json jNuiWindow = NuiWindow(jRoot, NuiBind("windowtitle"), NuiBind("geometry"), NuiBind("resizable"), NuiBind("collapsed"), NuiBind("closable"), NuiBind("transparent"), NuiBind("border"), NuiBind("acceptinput"));
	nToken			= NuiCreate(oPlayer, jNuiWindow, NUI_TEMPLATE_WINDOW_ID);

	NuiSetBind(oPlayer, nToken, "windowtitle", JsonString("NUI Template"));
	float fX	  = -1.0f;
	float fY	  = -1.0f;
	float fWidth  = 512.0f;
	float fHeight = 512.0f;

	NuiSetBind(oPlayer, nToken, "geometry", NuiRect(fX, fY, fWidth, fHeight));

	NuiSetBind(oPlayer, nToken, "collapsed", JsonBool(FALSE));
	NuiSetBind(oPlayer, nToken, "resizable", JsonBool(TRUE));
	NuiSetBind(oPlayer, nToken, "closable", JsonBool(TRUE));
	NuiSetBind(oPlayer, nToken, "transparent", JsonBool(FALSE));
	NuiSetBind(oPlayer, nToken, "border", JsonBool(TRUE));
	NuiSetBind(oPlayer, nToken, "acceptinput", JsonBool(TRUE));

	// Update values after window is up
	NUI_TemplateShort_Update(oPlayer);
}