- Joined
- Nov 11, 2006
- Messages
- 7,591
Integrating Tools Into JNGP
Introduction:
This quick guide will show you how to integrate a tool of your choice into JNGP, so that it may be executed from the toolbar. This tutorial covers:
- Adding a menu.
- Adding a menu entry.
- Executing the tool.
Many tools, such as GMSI, use this process for the convenience of the map maker.
Note: The latest compilation of JNGP has a new feature, "Custom Menu Settings", that will automate much of this process. The below information is still useful, but you may want to consider checking that feature out. Here is the main thread:
JassNewGen Pack
Requirements:
- JassNewGen Pack
- NotePad, or any text editing document that can save as .lua.
- A tool of your choice. I will be using BLP Lab as my example.
*Note: Some of the screenshots will be from my Mac.
Table of Contents:
Initial Preparations:
First, you must install the tool. Go to your JNGP folder.
Place whatever tool you are using into your JNGP folder.
Go to your JNGP folder. Open wehack.lua with a text editor. I recommend that you close JNGP Editor while you are modifying wehack.lua.
Adding a Menu:
wehack.lua is executed on startup, adding the toolbars to WE and executing the appropriate applications/dlls. This is where we will add the toolbar menus. A toolbar menu refers to an individual "button" in the toolbar, such as "File", "Edit", "View", etc.
The syntax to add a menu is relatively simple:
Lua:
varName = wehack.addmenu("Menu Name")
In my case, I will add a toolbar menu titled "External Programs". You can write essentially anywhere in the file, but the order in which you write it will determine where it is on the toolbar. If you place the code all the way at the top, then it will be placed before "Extensions", "UMSWE", "Grimoire", etc.
For that reason, I will place it at the end right before "isstartup = false":
I named the variable "extPrograms", and the title shown will be "External Programs". This is how it will look in the editor:
Adding a Menu Entry:
If you open JNGP with your current wehack.lua, you'll notice that nothing happens when you click it (aside from highlighting the text). This is because it doesn't have any menu entries! This is the general format of adding a menu entry:
Lua:
varName = MenuEntry:New( menu, "Menu Entry Title", callbackFunction )
The menu entry will be assigned to the variable represented by "varName". The "menu" is the menu you want to place it under. Mine will be extPrograms, since that is what I named my variable. The "Menu Entry Title" will be whatever you want to name your menu entry. I will name mine, "BLP Lab".
The final field is the callbackFunction. The function specified will be called when the menu entry is clicked. As such, we'll make a function to serve as the callback, right above the menu entry and such. This is how it will look like in the end:
Lua:
function blpLabStartup()
end
extPrograms = wehack.addmenu("External Programs")
blpLab = MenuEntry:New( extPrograms, "BLP Lab", blpLabStartup)
Again, this is written in Lua. If you are not familiar with the syntax, please refer to:
http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/lua-object-generation-191740/#V
After that code, this is what it will look like in the editor:
As an extra bonus, you can add what is known as a menu separator. This is just a line that separates one set of menu entries from the rest. Here is the syntax:
Lua:
wehack.addmenuseparator(menu)
Lua:
wehack.addmenuseparator(extPrograms)
Starting The Program:
Now we just need to make the program run. The line is:
Lua:
wehack.execprocess("path.exe")
Now, all we need to do is place the line above into the function "callback" that we specified. The path is simply the path to the program. The paths are relative to the jassnewgenpack folder unless otherwise specified. This is why I placed the tool into the JNGP folder itself. In my case, the path will be:
Lua:
wehack.execprocess("BLP Laboratory/blplab.exe")
If your program has no folder, then the path will be simply the name of the executable file. This is what our code will look like in the end:
Lua:
function blpLabStartup()
wehack.execprocess("BLP Laboratory/blplab.exe")
end
extPrograms = wehack.addmenu("External Programs")
blpLab = MenuEntry:New( extPrograms, "BLP Lab", blpLabStartup)
Now to test it. It should open the program:
Lua
You can also run Lua files through a menu entry. Instead of execprocess, just use:
Lua:
dofile("path.lua")
This will allow you to execute Lua through JNGP without copying and pasting the code. This will be very convenient if you have several maps that use the same Lua code.
Why?
- It is convenient.
- It is cool.
- More importantly, this tutorial will help those programs that are designed to be integrated into WE. If you have a tool that you think would be sensible to include in the JNGP package (the new ones by moyack), then just PM me.
F.A.Q.
- Q:
Why doesn't it work?
Lua is case sensitive. Make sure you have all your capitalizations in order. Also make sure you don't have any typos in the syntax. The code may run into an error, but it won't throw an error.
- Q:
Why doesn't it apply right away?
wehack.lua is ran on JNGP WE's startup. In order for it to apply, you have to close and reopen WE. I suppose you could add a menu entry to run a lua file with such changes, but I haven't tested it.
- Q:
How do I make entries that can be checkmarked (toggled on or off)?
The function format is:
Lua:varName = TogMenuEntry:New( menu, "Title", callback, default ) -- default should be either true or false
https://w3grimoire.svn.sourceforge.net/svnroot/w3grimoire/
(old)
Samples
I'll continually post sample addons that may prove useful for modding.
- View Output War3map.j - This will view the output war3map.j of the last saved map. When a vJASS script is saved, jasshelper will convert the code to vanilla JASS and place the contents under logs\outputwar3map.j. This option will allow you to start it up from the editor. Note that this only applies to the last map you saved (not necessarily the one you opened), and you may be prompted to associate the .j file with a certain program (choose notepad or some other text editor):
Lua:extPrograms = wehack.addmenu("External Programs") -- only add this if you do not have it already (it is the same menu from the tutorial) function viewOutputCode() -- updated for 1.5e if jh_isvexorian.checked then os.execute("logs\\outputwar3map.j") elseif jh_iscohadar.checked then os.execute("logs\\output_war3map.j") end -- os.execute("logs\\outputwar3map.j") -- ^ use this function for pre-1.5e and comment out the rest end outputj = MenuEntry:New( extPrograms, "View war3map.j", viewOutputCode )
Last edited: