Difference between revisions of "NDCommunityToolsTestTool"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
Line 1: Line 1:
 
<p style="width:60%;margin: 0 auto">[[NewDawnHome|[Main]]][[NDCustomCommunityTools|[Community Tools]]]</p>
 
<p style="width:60%;margin: 0 auto">[[NewDawnHome|[Main]]][[NDCustomCommunityTools|[Community Tools]]]</p>
<p style="color: #DDDD88;font-size: 24px;width:60%;margin: 0 auto">Equipment Editor</p>
+
<p style="color: #DDDD88;font-size: 24px;width:60%;margin: 0 auto">Testing Tool</p>
<p style="width: 60%;margin: 0 auto">The equipment editor allows you to easily modify equipment so you can do testing without the heavy mess of dealing with template file editing. It also has the ability to create the template file for you and put it directly into your mods/ModName/templates directory. Join me in the video below as I cover the file structure, code and a simple walk through of how to use the equipment editor</p>
+
<p style="width: 60%;margin: 0 auto">This script is easy to attach to any item. Use the /info command on any item. Attach this module to it in the Info UI window. This script upon being attached will add 3 contenxt (right click) options to the item you targeted.</p>
<p style="color: #DDDD88;font-size: 20px;width:60%;margin: 0 auto">Download & Installation</p>
 
 
<div style="width: 60%;margin: 0 auto">
 
<div style="width: 60%;margin: 0 auto">
 +
* Open Window - this is used to open the ShowTestWindow() function
 +
* Reload Modules - this will reload the test_scripting.lua file
 +
* Test Function - this will run any code put in the TestCode Function
 +
</div>
 +
<div style="width: 60%;margin: 0 auto">
 +
* Save the following as test_scripting.lua in any editor you use.
 +
CODE
 +
--- Attach this file by typing /info and targeting any item
 +
--- Then in the texfield type in test_scripting and add the module
 +
--- Then use this file to test out UI parts, or function info.
 +
--- There are 3 contet menu options to speed up testing.
 +
--- this is the testwindow
 +
function ShowTestWindow(user,controlobject)
 +
local dynamicWindow = DynamicWindow("DynamicWindowHandler","",300,300,-150,-150,"TransparentDraggable","Center")
 +
dynamicWindow:AddImage(1,1,"HueSwatch",300,300,"Simple","252525")
 +
DrawCloseButton(271,5,dynamicWindow)
 +
 +
--test dynamic window code here
 +
 +
user:OpenDynamicWindow(dynamicWindow,controlobject)
 +
end
 +
 +
--- this is the dynamic window you wish to place the close button on
 +
function DrawCloseButton(x,y,dynamicwindow)
 +
dynamicwindow:AddImage(x,y,"HueSwatch",24,24,"Sliced","AA0000")
 +
dynamicwindow:AddImage(x+2,y+2,"HueSwatch",20,20,"Sliced","770000")
 +
dynamicwindow:AddButton(x,y,"CloseButton","",24,24,"[FF7700]Close\n[FFFF00]closes this dynamic window.","",true,"Invisible")
 +
end
 +
 +
--- this will handle the response to your dynamic window
 +
RegisterEventHandler(EventType.DynamicWindowResponse,"DynamicWindowHandler",
 +
function (user,buttonId,fieldData)
 +
 +
if(buttonId == "CloseButton") then
 +
user:SystemMessage("I clicked the close button","info")
 +
end
 +
-- handle dynamic window responses here
 +
 +
end)
 +
 +
--- this will handle the context menu and double click of the attached object
 +
RegisterEventHandler(EventType.Message, "UseObject", function(user, usedType)
 +
    if(usedType=="Open Window") then
 +
    ShowTestWindow(user,this)
 +
    end
 +
    if(usedType=="Refresh Modules") then
 +
ReloadModule(GetCurrentModule())
 +
    end
 +
    if(usedType=="Test Code") then
 +
TestCodeFunction()
 +
    end
 +
end)
 +
 +
function TestCodeFunction()
 +
-- test code here
 +
end
 +
 +
-- this will handle when the module gets attached to the object
 +
RegisterEventHandler(EventType.ModuleAttached, GetCurrentModule(), function()
 +
AddUseCase(this,"Open Window",true,"IsGod")
 +
AddUseCase(this,"Refresh Modules",false,"IsGod")
 +
AddUseCase(this,"Test Code",false,"IsGod")
 +
end)
 +
</div>

Revision as of 06:49, 13 December 2019

[Main][Community Tools]

Testing Tool

This script is easy to attach to any item. Use the /info command on any item. Attach this module to it in the Info UI window. This script upon being attached will add 3 contenxt (right click) options to the item you targeted.

  • Open Window - this is used to open the ShowTestWindow() function
  • Reload Modules - this will reload the test_scripting.lua file
  • Test Function - this will run any code put in the TestCode Function
  • Save the following as test_scripting.lua in any editor you use.

CODE

--- Attach this file by typing /info and targeting any item
--- Then in the texfield type in test_scripting and add the module
--- Then use this file to test out UI parts, or function info.
--- There are 3 contet menu options to speed up testing.
--- this is the testwindow 
function ShowTestWindow(user,controlobject)
	local dynamicWindow = DynamicWindow("DynamicWindowHandler","",300,300,-150,-150,"TransparentDraggable","Center")
	dynamicWindow:AddImage(1,1,"HueSwatch",300,300,"Simple","252525")
	DrawCloseButton(271,5,dynamicWindow)

	--test dynamic window code here

	user:OpenDynamicWindow(dynamicWindow,controlobject)
end	

--- this is the dynamic window you wish to place the close button on
function DrawCloseButton(x,y,dynamicwindow)
	dynamicwindow:AddImage(x,y,"HueSwatch",24,24,"Sliced","AA0000")
	dynamicwindow:AddImage(x+2,y+2,"HueSwatch",20,20,"Sliced","770000")
	dynamicwindow:AddButton(x,y,"CloseButton","",24,24,"[FF7700]Close\n[FFFF00]closes this dynamic window.","",true,"Invisible")
end

--- this will handle the response to your dynamic window
RegisterEventHandler(EventType.DynamicWindowResponse,"DynamicWindowHandler",
function (user,buttonId,fieldData)
	
	if(buttonId == "CloseButton") then
		user:SystemMessage("I clicked the close button","info")
	end
	-- handle dynamic window responses here

end)

--- this will handle the context menu and double click of the attached object
RegisterEventHandler(EventType.Message, "UseObject", function(user, usedType) 
    if(usedType=="Open Window") then
    	ShowTestWindow(user,this)
    end
    if(usedType=="Refresh Modules") then
		ReloadModule(GetCurrentModule())
    end
    if(usedType=="Test Code") then
		TestCodeFunction()
    end
end)

function TestCodeFunction()
	-- test code here
end

-- this will handle when the module gets attached to the object
RegisterEventHandler(EventType.ModuleAttached, GetCurrentModule(), function() 
	AddUseCase(this,"Open Window",true,"IsGod")
	AddUseCase(this,"Refresh Modules",false,"IsGod")
	AddUseCase(this,"Test Code",false,"IsGod")
end)