Posts Tagged Visual Studio
Visual Studio addon for World of Warcraft released!!!
Recently, released addon for VS2008, which allowing creation of addins for WoW (yes, this is an addon to create addons – confusing a bit ;-) ). So, as a hardly addicted WoW player and professional programmer, I felt a personal duty to test it and see what is all about. Prior to this addin, WoW addins were done primarily using Notepad (although there is an entire community of developers who advancing to abandon Visual Studio and develop using notepad – I’m not sure it is a good idea). With the VS WoW addon it is easier than ever to create addons for WoW. It takes an advantage of powerful VS designer and providing many components to create any GUI you want, such as frames, buttons and text boxes. It has an Intellisense support for almost every function you have in your disposal (later I will talk about this “almost”). Personally I love Visual Studio, and I think many WoW developers will appriciate this wonderful tool.
Ok, enough talking – lets do some example! Initially my task was to create Orcish - Human translator. In WoW Alliance cannot understand Horde talking, and vice versa. So, many times killing started because of misunderstanding
What I really wanted to do, is to create addin, which will translate from Orcish to Human. Sounds easy - all I need to do is register somehow to ‘new message’ event in chat window, pass message text to translating function, and print translated text back to the chat window. Unfortunately, for now I not able to translate Orcish, and according to this article i doubt I ever will. Therefore I just printing the original text – echo addin. Here are the steps to create this addin:
-
Install WoW addin for Visual Studio – get it from here. I installed it successfully with VS2008 Express Edition (free version of VS which is available on www.microsoft.com).
-
Create new project – Basic WoW Addon. It creates for you Frame.xml and Frame.lua. Xml file describes GUI, and lua file holds all logic behind.
-
Double click on xml file will open VS designer. You can drag and drop components from toolbox on the left. The designer will generate all xml for you – no coding needed.
-
As far as I know, you can catch events only from GUI objects such as frames. For this purpose, we will use frame which was generated by wizard on project creation.
-
Locate it in designer and click on it left click. Properties grid on the right should appear.
-
Locate ‘name’ property and change it to ‘_invisibleFrame’.
-
Locate ‘hidden’ property and set it to True.
-
Locate OnLoad property. Name it ‘OnLoad()’ and press Create. Stub for this method will be created in the lua file.
-
Inside it, write the following code:
function OnLoad()
this:RegisterEvent(“CHAT_MSG_SAY”);
end
-
CHAT_MSG_SAY – is event which is fired on new ’say’ message. How I know that? Well, this is the part about “almost” of Intellisense. It is not provides support for events, and you have to discover name of the right event on your own. I used Internet, and found it in 2 minutes. It missing many other things, as you will see soon.
-
Now we need to catch fired event. Go back to designer. In property grid, locate ‘OnEvent’ property. Name it ‘_invisibleFrame_OnEvent()’ and press Create button.
-
About event mechanics: WoW has 8 predefined variables for holding event arguments (maybe not only) – arg1, arg2, … arg8. If some event has arguments, they stored in these variables. As I discovered, CHAT_MSG_SAY event has 3 arguments: arg1 is text of the message, arg2 is the name of speaking person, arg3 says if the language is Common or Orcish. All other args are nil. This addin meant to be translator, therefore I had to check speaking language – I want translate only Orcish:
function _invisibleFrame_OnEvent()
if(event == “CHAT_MSG_SAY”) then
if(arg3 == “Orcish”) then
local translated = Translate(arg1);
AddMessage(translated);
end
end
end -
Translate function have to translate text (for now it returns original text). AddMessage function prints specified text in the chat window. Here these 2 functions:
function AddMessage(msg, r, g, b)
if ( not msg ) then
msg = ” {NIL Value Passed}”;
end
msg = “Translated : “..msg;
if ( not r ) then
r, g, b = 0.64, 0.21, 0.93;
end
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b);
end
end
function Translate(orcishText)
return orcishText;
end
-
DEFAULT_CHAT_FRAME is another example of what you can’t find with Intellisense. I searched for function to print my text to chat window, and finally found this one in other addin.
That’s all! After you building solution, it will itself deploy your addin in WoW folder. In general, I very impressed with the work done by developers of this addin. Creating complex UI was never easy as now, and there is no need to mess with xml. Neverless it’s Intellisense needs future improvements, I think this is an awesome tool with great potential, and hope this project will continue evolve.
3 comments February 3, 2008