World of Warcraft programming Book Reading Notes (10)

Source: Internet
Author: User
Tags custom graphics blizzard

Chapter 2 plug-in Analysis

Plug-ins are actually a collection of files. These files are stored on the client and loaded and run on the client. The available World of Warcraft custom plug-ins are already very rich. This chapter focuses on how the plug-ins are made up and explains each part.

9.1 develop your own plug-in folder

To load the game and apply a plug-in, you need to put it in the folder specified by World of Warcraft. If you have run World of Warcraft, there will be an interface folder under the directory of the World of Warcraft game, this folder also contains an Addons folder, and the plug-in should be placed in the Addons folder.

9.1.1 blizzard plug-in

By default, blizzard uses many plug-ins to design the user interface. These plug-ins are loaded only when the client needs them.

Each blizzard plug-in has a file with the. Pub extension in its directory. It is a method of game identifier plug-in reliability. Blizzard plug-ins are considered as security plug-ins. Chapter 17th will introduce relevant knowledge in detail.

1.9.2 custom plug-in

Both custom plug-ins and blizzard plug-ins are placed under the Addons folder, but they follow different plug-ins in different organization forms, with different types of files and different naming methods.

9.2 plug-in components and files

Files contained in each plug-in are different, but some parts of each plug-in are the same. The following describes various files that may be contained in the plug-in.

9.2.1 content table file (. TOC)

TOC files must be included in each plug-in. They must be named in the plug-in folder. For example, the folder name is myaddons, and its TOC file name is myaddons. TOC. The TOC file mainly provides some important information (such as the title, description, and author information) to help load specific plug-in files. The following is an example:

# Interface: 20300

# Title: My addon name

# Notes: This is mysample addon

 

Myaddon. xml

Myaddon. Lua

There are many tags starting with # In the TOC document. Each tag occupies one line. The label name is before the colon, and the label value is after the colon. After the tag is a list of files to be loaded by the plug-in

1. ## interface:

This tag provides a version number in the plug-in selection window, so that the World of Warcraft client can identify whether your plug-in is compatible with it. If not compatible, the following two errors are displayed:

L plug-in expired -- this is because your # interface version is different from the game Client Version. This is just a warning. You can select "load expired plug-ins" to solve this problem. Normally, the plug-ins will work normally after being loaded.

L incompatible -- this is because the API of the game client has greatly changed and this plug-in cannot be loaded. To run the plug-in correctly, you need to modify the plug-in.

Listing the plug-in as "expired" does not mean a significant error. It may be that the interface label in the. TOC file is not updated to the latest interface number. This situation reminds you to update the plug-in to the latest version. It can help you get the latest bug fixes and functions. The latest version provides better technical support from plug-in authors.

The version number after the interface is generally determined by the version number of the World of Warcraft client. For example, the version number of the interface 2.3.0 is 20300, which can be queried by other available plug-ins. obtain the TOC file (speak silently: I personally think this is the easiest way .)

In the lower left corner of the role selection window of the World of Warcraft game, you can see a "plug-in management" button. Click this button to bring up a dialog box for plug-in management, you can see the above-mentioned "Expiration" or "incompatible" prompt.

2. ## title

This is the name of the plug-in you saw in World of Warcraft. This name is usually the same as the folder Name of the plug-in. Of course, if you do not want players to easily recognize the location where your plug-in is stored, you can also get a name that is irrelevant to the plug-in folder name.

This name can be localized. You only need to add the country code after # title. For example:

# Title-zhcn: Treatment assistant Grid

This is the plug-in name displayed in simplified Chinese. Another example:

# Title-zhtw: Governance Assistant Grid

This is the plug-in name displayed in Traditional Chinese.

3. ## notes

This is a tag that describes the Plugin in detail. You can provide more help information about the plug-in here. It can also be localized like the title tag (add the country location code later, to display the language used by the corresponding country), for example:

# Notes: a modular, lightweight and screen-estate saving grid of Party/Raid unit Frames

# Notes-zhcn: lightweight modular team framework

# Notes-zhtw: Excellent zookeeper framework function

4. ## dependencies and ## requireddeps

Both functions share the same effect. They are a list of other plug-ins that indicate that the plug-in must be dependent on. If the plug-in this list is disabled or cannot be loaded for some reason, it cannot be loaded. The "dependency plug-in disabled" prompt is displayed in the plug-in manager. The statement is as follows:

# Requireddeps: DBM-core

The above is the TOC code of a plug-in our commonly used "leader warning". Leader warning is a plug-in group composed of multiple plug-ins, almost all plug-ins depend on the core plug-in DBM-core. Therefore, you can find the above tag in the TOC file of all plug-ins.

This tag also provides an additional function: to determine the loading sequence of the plug-in (speak silently: the dependent plug-in will be loaded first, so if there are some conflicts related to the loading order of your plug-in, you can take the initiative to modify their TOC to add dependencies to them ).

5. ## optionaldeps

The optionaldeps label is generally an extension function library or plug-in that can be called by some plug-ins. When the extension function library exists, the functions called by the plug-in can be implemented. However, even if the extension function library does not exist, the plug-in should work properly. These plug-ins also need to provide methods to implement the main functions without relying on the above function libraries to ensure the normal operation of the plug-ins.

6. ## loadondemand

Starting from version 1.7, plug-ins can be loaded when needed, rather than when players enter the game for the first time. If this option is enabled, the plug-in can only be loaded by other plug-ins later. This label prevents plug-ins with certain special functions from being loaded when entering the game, thus effectively saving memory.

The tag value can only be 1 or 0. 1 indicates loading as needed.

7. ## loadswith

After version 1.9, combined with the loadondemand tag, this tag can be automatically loaded after a plug-in (usually a blizzard UI module, such as blizzard_auctionui) is loaded.

8. ## defaultstate

The defaultstate label is used to determine whether the plug-in is enabled by default during installation. If the value is set to disabled, the player must manually enable the plug-in on the character selection page. If this label is not set, the default value is enabled.

9. ## savedvariables

Since plug-in version 2150, savedvariables has become the best way to store data between processes. To save the information, the plug-in can only define one Lua variable and list the variable name in the # savedvariables label of the TOC file. When the game is closed, the system stores the variable content in an external file. When the game restarts, the variable is read again. The variable type can be string, number, or table.

10. ## savedvariablespercharacter

The savedvariablespercharacter label works in the same way as the savedvariables label. The difference is that the variables saved by the savedvariables label are only under the role of a specific character. This tag uses only the name of a person to differentiate roles. However, you can use the server name and name to differentiate roles (in current version (3.2.2 ), the variable file saved by this tag is located under World of Warcraft \ WTF \ ACCOUNT \ User ID \ Server Name \ character name ).

9.2.2 Lua script file

The TOC file can list every Lua file (including files in subdirectories ). These files are loaded, parsed, and executed by the game client in the order listed in the TOC file.

The Lua file is usually used to define the behavior of the plug-in. You can also use it to dynamically create a window (Chapter 16)

9.2.3 XML file

Within a single plug-in (or within framexml), file loading is carried out linearly in the order defined in the. TOC file. The first file defined in TOC is parsed and executed first, followed by the second file, followed by the third file, and so on. Every time an XML file is executed with the <script file = "X"/> element, the Referenced File X is parsed and executed, after the processing is complete, the subsequent elements are processed.

9.2.4 media files

Game client plug-ins can also contain custom graphics, sounds, fonts, and so on, to provide you with different audio-visual styles. These files are contained in the plug-in's own folder. The complete path name must be used to indicate the address.

1. Music

The World of Warcraft client can recognize MP3 and WAV Files.

If you have a sound file named mysound.pdf and it is stored in interface \ Addons \ mysound \ mysound.pdf, you can run the following command in the game to play the audio file:

/Run playsoundfile ("interface \ Addons \ mysound \ mysound.pdf ")

2. Graphics

World of Warcraft supports two different graphic formats-BLP and TGA. They also meet the following requirements:

L The file height and width must be greater than or equal to 2 pixels and smaller than 512 pixels.

L The file height and width are an integer multiple of 2, but the width and height can be different (that is, the image can be square or rectangular)

Chapter 20 describes how to create a custom image file.

9.3 localize your plug-ins

9.3.1 available local languages

Table 9-2 available client local languages

Local language code

Corresponding Language

Dede

German

Enus

American English

Engb

English

Eses

Spanish

Frfr

French

Kokr

Korean

Zhcn

Simplified Chinese

Zhtw

Traditional Chinese

9.3.2 reason for localization

When a player plays a game, if the language of the custom plug-in is the same as that of the player, the player can easily respond instantly. If it is not his own language, it is difficult for a player to convert the language in a short time even if he has a high reading ability.

In addition, most players are willing and able to help the author with localization. If the plug-in is well designed, the localized update of the plug-in will become very easy.

9.3.3 encourage players' suggestions

Players often propose some localization file solutions to the author. The following are some methods that make the author easier to localize:

L provides a constant set or a list to facilitate translation search, rather than just strings.

Write the written information of the plug-in into the readme.txt file, or on your own official website.

L provide some annotations to indicate the meaning of the relevant information so that users can easily translate.

9.3.4 implement Localization

This section describes a recommended execution solution that allows you to easily update local files.

1. Add a file for each Local Language

Add a new localization file for the local language you translate. If there is no translation, create a file for the basic local language in the plug-in you developed. For example, localization. zhcn. Lua, and add this file to the first line of the file list in the. TOC file to ensure that it can be loaded immediately.

2. Create a global table containing all output strings

If the plug-in we created is myaddons, we will create a global table named myaddonslocalization in localization. zhcn. Lua.

Myaddonslocalization = {};

Myaddonslocalization ["frames_locked"] = "the framework is locked"

Myaddonslocalization ["frames_unlocked"] = "the framework has been unlocked"

3. Add a new local language

You can create another file (such as localization. enus. Lua) to add a new language. These files should appear in the file table of the. TOC file, followed by the localization. zhcn. Lua file.

If getlocale () = "enus" then

If not myaddonlocalization then

Myaddonlocalization = {}

End

Myaddonslocalization ["frames_locked"] = "frameshave been locked"

Myaddonslocalization ["frames_unlocked"] = "frames have been unlocked"

End

The first if is used to ensure that all output strings are English only when the local language of the user is English, the second if clause is used to ensure that the global table can be created even in the case of an accident.

Now, the information displayed on an American client is in English rather than simplified Chinese.

9.4 create a plug-in framework

10th ~ Chapter 11 will introduce a series of examples of using XML. For the next two chapters, we will teach you a basic plug-in framework, so that you do not have to repeat some things for each example.

9.4.1 name the plug-in (create directory)

Please create a folder named wowxmlexample, which should be located in the following directory in your world of warcraft Folder:

Worldof Warcraft \ interface \ Addons \ wowxmlexample

The next two chapters will teach you how to create all new things.

9.4.2 create a. TOC File

If no TOC file exists, the plug-in does not work. Therefore, use the following code to create a TOC file (File Name: wowxmlexample. TOC ):

# Interface: 30200

# Title: wowxmlexample

# Title-zhcn: XML sample plug-in

# Description: exampleaddon for World of Warcraft Programming

 

Wowxmlexample. xml

Speaking silently: I have changed the above version number to the latest version number, but it is not guaranteed that it will be available in the future for version such as catastrophic events.

9.4.3 create a. xml file

Use the following code to create the wowxmlexample. xml file in the plug-in directory:

<Uixmlns = "http://www.blizzard.com/wow/ui"

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

Xsi: schemalocation = "http://www.blizzard.com/wow/ui/

.. \ Framexml \ UI. XSD ">

</UI>

The above Code cannot be typed incorrectly (case sensitive. In addition, pay attention to the carriage return position). Check carefully. Later, we will write the code we need in the <UI> tag.

9.5 use external library

We recommend that you first learn how to use the World of Warcraft API and XML to write some basic plug-ins. Appendix E contains a list of major libraries and frameworks, as well as their details. (Speak silently: You can also be in the Workshop)

Conclusion 9.6

This chapter describes the basic components contained in a plug-in, including content file tables, XML definitions, and Lua scripts. In addition, the plug-in can contain and use specific types of media files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.