12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12 ■ Interacting with Widgets 225<strong>Creating</strong> an EditBoxThe most prevalent edit box in the default user interface is the one that appearswhen you press Enter: the chat edit box. Using it you can input comm<strong>and</strong>s,type messages to friends, or even run Lua code. The edit box you use <strong>for</strong>BagBuddy won’t have all <strong>of</strong> these features because all it needs to do is accepttext from the user.You must exercise caution when working with an EditBox,whetheryouarecreating it in Lua or XML. It has an odd property that causes it to automaticallytake the keyboard’s focus when it is displayed <strong>and</strong> doesn’t (by default) have away to relinquish this control. As a result, if you don’t pay attention you couldwind up needing to restart your client to regain control <strong>of</strong> the keyboard.You can, however, set a property (via an XML attribute or Lua) <strong>and</strong> a framescript to provide better behavior. Open BagBuddy.xml <strong>and</strong> add the followingdefinition be<strong>for</strong>e the tag in the BagBuddy definition, but after thecode <strong>for</strong> the previous <strong>and</strong> next buttons:self:ClearFocus()BagBuddy_Update()The important part <strong>of</strong> this code is the autoFocus attribute being set to false.This ensures that the edit box won’t automatically try to steal the keyboardwhenever it is shown. It’s not enough, however, to ensure that there is aneasy way to get the keyboard’s focus away from the EditBox. Forthisyousetan OnEscapePressed script. This script h<strong>and</strong>ler fires anytime the edit box hasfocus <strong>and</strong> the player presses the escape key. Because most people are usedto pressing escape to clear the focus from an input box, whether it be on theWeb or in <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>, it’s a good behavior to emulate. The h<strong>and</strong>lerbody simply calls the self:ClearFocus() method. This method is specific tothe EditBox type, <strong>and</strong> simply releases control <strong>of</strong> the keyboard so it can be usedelsewhere.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!