Fandom

HammerWiki

Examples

6,449pages on
this wiki
Add New Page
Comments0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Window Label Button Example:Edit

The following is the example of a window that has a label and a button. This example was posted on the previous wiki compliments of Medikage. To view this example copy the code into 3 separate files and place them into a folder called HelloWorldGui. Then take the HelloWorldGui folder and place it in the Warhammer addon folder.



Mod File: Save as HelloWorldGui.mod

<?xml version="1.0" encoding="UTF-8"?>
<ModuleFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <UiMod name="HelloWorldGui" version="1.0" date="01/10/2009" >
        <Author name="medikage" email="medikage@gmail.com" />
        <Description text="Demonstrates how to create a window that will display some text and a button turn itself off" />
        <VersionSettings gameVersion="1.3.3" windowsVersion="1.0"/>
        <Dependencies>
      <Dependency name="EASystem_WindowUtils" />
      <Dependency name="LibSlash" />
        </Dependencies>
        <Files>
            <File name="HelloWorldGui.lua" />
      <File name="HelloWorldGui.xml" />
        </Files>     
        <OnInitialize>
            <CallFunction name="HelloWorldGui.Initialise" />
        </OnInitialize>
        <OnUpdate/>
        <OnShutdown/>
    </UiMod>
</ModuleFile>

Lua file: Save as HelloWorldGui.lua

HelloWorldGui = {}
 
function HelloWorldGui.Initialise()
   -- Register the slash command.  Now when the user types "/helloworld" the HelloWorld.Slash 
   -- function will be actioned. 
   LibSlash.RegisterSlashCmd("helloworld", HelloWorldGui.Slash)

   -- Create the window and then hide it.  
   CreateWindow("HelloWorldGui", true)
   WindowSetShowing("HelloWorldGui", false)

   -- Apply text to the label and button so they are not blank.
   LabelSetText("HelloWorldGuiLabel", L"Hello, World!")
   ButtonSetText("HelloWorldGuiButton", L"Close")

   -- Register the window with the LayoutEditor so that it can be moved and resized via the 
   -- Settings/Layout Editor screen. Note: You will need to have the SaveSettings="true" option 
   -- set in the <Window> XML tag if you want these changes to persist beyond game closure.
   LayoutEditor.RegisterWindow ( "HelloWorldGui"             -- Window Name
                               , L"HelloWorldGui"            -- Window Display Name
                               , L"GUI Demonstration Window" -- Window Description
                               , false                       -- Allow Size Width
                               , false                       -- Allow Size Height
                               , true                        -- Allow Hiding
                               , nil                         -- Allowable Anchor List
                               )
end

function HelloWorldGui.CloseWindow()
   --When the button is clicked, hide the HelloWorldGui window.
   WindowSetShowing("HelloWorldGui",false)
end

function HelloWorldGui.Slash()
   --When the user types "/helloworld", show the HelloWorldGui window
   WindowSetShowing("HelloWorldGui",true)
end

XML File: Save as HelloWorldGui.xml

<Interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Interface.xsd">
<Scripts>
    <Script file="HelloWorldGui.lua" />
  </Scripts>
  <Windows>
<Window name="HelloWorldGui" inherits="EA_Window_Default" layer="secondary" movable="true" savesettings="false">
<Size>
        <AbsPoint x="280" y="150"/>
      </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="$parentLabel" font="font_chat_text" textalign="center">          
          <Size><AbsPoint x="200" y="40" /></Size>
          <Anchors>
            <Anchor point="topleft" relativePoint="topleft" relativeTo="$parent">
<AbsPoint x = "40" y = "40"/>
            </Anchor>
          </Anchors>
<Color r="255" g="204" b="102" />
        </Label>
<Button name="$parentButton" inherits="EA_Button_DefaultResizeable" textalign="center">
          <Anchors>
            <Anchor point="bottom" relativePoint="bottom" relativeTo="$parent">
              <AbsPoint x = "" y = "-20"/>
            </Anchor>
          </Anchors>
<EventHandlers>
            <EventHandler event="OnLButtonUp" function="HelloWorldGui.CloseWindow"/>
          </EventHandlers>
        </Button>
      </Windows>
    </Window>
  </Windows>
</Interface>

Also on Fandom

Random Wiki