API:Hello World Saved Settings
From TheWarWiki
WAR API Help
This is a simple example of how to create settings that will be persist beyond warhammer closing down. The settings will be set and displayed via a GUI.
Note: You will need to have the libslash addon installed as you will need to enter a slash command to open the window.
Create a folder called HelloWorldSS in your Warhammer Online - Age of Reckoning\Interface\AddOns\ folder.
Make a new file, HelloWorldSS.mod in the HelloWorldSS folder. This file contains the setup information about the mod which is utilised by the warhammer interpreter.
Populate the file with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<ModuleFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UiMod name="HelloWorldSS" version="1.0" date="01/10/2009" >
<Author name="medikage" email="medikage@gmail.com" />
<Description text="Demonstrates how to create settings that will persist beyond warhammer closing down." />
<VersionSettings gameVersion="1.3.3" windowsVersion="1.0"/>
<Dependencies>
<Dependency name="EASystem_WindowUtils" />
<Dependency name="LibSlash" />
</Dependencies>
<Files>
<File name="HelloWorldSS.lua" />
<File name="HelloWorldSS.xml" />
</Files>
<!-- This tag tells warhammer that there are persistent settings for this addon -->
<SavedVariables>
<SavedVariable name="HelloWorldSS.Settings" />
</SavedVariables>
<OnInitialize>
<CallFunction name="HelloWorldSS.Initialise" />
</OnInitialize>
<OnUpdate/>
<OnShutdown/>
</UiMod>
</ModuleFile>
Now make a new file, HelloWorldSS.xml in the HelloWorldSS folder. This file will contain all of the visual component characteristics including name, relationships, inheritance, positioning, size and hooks between UI events and functions.
Note: For a more detailed description of the visual elements and how they work, look at Hello World Gui example
Populate the file with the following contents:
<Interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Interface.xsd">
<Scripts>
<Script file="HelloWorldSS.lua" />
</Scripts>
<Windows>
<Window name="HelloWorldSS" inherits="EA_Window_Default" layer="secondary" movable="true" savesettings="false">
<Size>
<AbsPoint x="300" y="300"/>
</Size>
<Anchors>
<Anchor point="center" relativePoint="center"/>
</Anchors>
<Windows>
<Window name="$parentBackground" inherits="EA_Window_DefaultBackgroundFrame" handleinput="true" >
<Anchors>
<Anchor point="topleft" relativePoint="topleft" relativeTo="$parent" />
<Anchor point="bottomright" relativePoint="bottomright" relativeTo="$parent"/>
</Anchors>
</Window>
<Label name="$parentLabel1" font="font_chat_text" textalign="center">
<Size><AbsPoint x="260" y="40" /></Size>
<Anchors>
<Anchor point="topleft" relativePoint="topleft" relativeTo="$parent">
<AbsPoint x = "20" y = "20"/>
</Anchor>
</Anchors>
</Label>
<EditBox name="$parentEditBox1" inherits="EA_EditBox_DefaultFrame" scrolling="none" maxChars="50">
<Size><AbsPoint x="260" y="30" /></Size>
<TextOffset x="4" y="3" />
<Anchors>
<Anchor point = "bottomleft" relativePoint = "topleft" relativeTo = "$parentLabel1">
<AbsPoint x = "" y = "5"/>
</Anchor>
</Anchors>
</EditBox>
<Label name="$parentLabel2" font="font_chat_text" textalign="center">
<Size><AbsPoint x="260" y="40" /></Size>
<Anchors>
<Anchor point = "bottomleft" relativePoint = "topleft" relativeTo = "$parentEditBox1">
<AbsPoint x = "" y = "20"/>
</Anchor>
</Anchors>
</Label>
<EditBox name="$parentEditBox2" inherits="EA_EditBox_DefaultFrame" scrolling="none" maxChars="50">
<Size><AbsPoint x="260" y="30" /></Size>
<TextOffset x="4" y="3" />
<Anchors>
<Anchor point = "bottomleft" relativePoint = "topleft" relativeTo = "$parentLabel2">
<AbsPoint x = "" y = "5"/>
</Anchor>
</Anchors>
</EditBox>
<Button name="$parentSaveButton" inherits="EA_Button_DefaultResizeable" textalign="center">
<Anchors>
<Anchor point="bottomleft" relativePoint="bottomleft" relativeTo="$parent">
<AbsPoint x = "15" y = "-20"/>
</Anchor>
</Anchors>
<EventHandlers>
<EventHandler event="OnLButtonUp" function="HelloWorldSS.SaveSettings"/>
</EventHandlers>
</Button>
<Button name="$parentCloseButton" inherits="EA_Button_DefaultResizeable" textalign="center">
<Anchors>
<Anchor point="bottomright" relativePoint="bottomright" relativeTo="$parent">
<AbsPoint x = "-15" y = "-20"/>
</Anchor>
</Anchors>
<EventHandlers>
<EventHandler event="OnLButtonUp" function="HelloWorldSS.CloseWindow"/>
</EventHandlers>
</Button>
</Windows>
</Window>
</Windows>
</Interface>
Now make a new file, HelloWorldSS.lua in the HelloWorldSS folder. This file contains all of the LUA code.
Populate the file with the following contents:
HelloWorldSS = {}
function HelloWorldSS.Initialise()
-- The first time the addon is loaded you will need to create the persistent settings yourself.
-- Therefore check to see if they exists and if not create them with some default values.
if (not HelloWorldSS.Settings) then
HelloWorldSS.Settings = {}
HelloWorldSS.Settings.SavedText1 = ""
HelloWorldSS.Settings.SavedText2 = ""
end
-- Register the slash command.
-- Now when the user types "/helloworldss" the HelloWorldSS.Slash function will be actioned.
LibSlash.RegisterSlashCmd("helloworldss", HelloWorldSS.Slash)
-- Create the window and then hide it.
CreateWindow("HelloWorldSS", true)
WindowSetShowing("HelloWorldSS",false)
-- Apply static text to the labels and buttons so they are not blank.
LabelSetText("HelloWorldSSLabel1", L"Type value for setting 1 below:")
LabelSetText("HelloWorldSSLabel2", L"Type value for setting 2 below:")
ButtonSetText("HelloWorldSSSaveButton", L"Save")
ButtonSetText("HelloWorldSSCloseButton", L"Close")
-- Apply the text that is stored in the persistent Settings to the edit boxes.
TextEditBoxSetText("HelloWorldSSEditBox1", HelloWorldSS.Settings.SavedText1)
TextEditBoxSetText("HelloWorldSSEditBox2", HelloWorldSS.Settings.SavedText2)
end
function HelloWorldSS.CloseWindow()
-- When the close button is clicked, hide the HelloWorldSS window.
WindowSetShowing("HelloWorldSS",false)
end
function HelloWorldSS.SaveSettings()
-- When the save button is clicked, store the text in the edit boxes to the persistent variables.
HelloWorldSS.Settings.SavedText1 = TextEditBoxGetText("HelloWorldSSEditBox1")
HelloWorldSS.Settings.SavedText2 = TextEditBoxGetText("HelloWorldSSEditBox2")
end
function HelloWorldSS.Slash()
-- When the user types "/helloworldss", show the HelloWorldSS window
WindowSetShowing("HelloWorldSS",true)
end
That's it. Start up warhammer, enable the mod and then type /helloworldss to see your new window. Type some values into the edit boxes and click the button labeled "Save" to store the text in the persistent variables. Click the button labeled "Close" to hide the window again. Now restart your game, logon with the same character and type /helloworldss again. You will notice that the text you entered previously is now displayed in the edit boxes.
You can play with this further by logging in as a different character, using the same profile to see if the settings are persistent for the profile. Alternatively log on with a character that is using a different profile to see if the edit boxes are once again blank and can store completely different values.
