Changes

Jump to navigation Jump to search
Line 154: Line 154:  
You can add buttons to the bottom main HUD by calling '''AddBottomButton'''(string panel, string name, string desc, Sprite icon). If you want your own Icon you need to instantiate a Sprite with a texture that you load using ParentMod.LoadTexture or in the ModMeta's initialize method.
 
You can add buttons to the bottom main HUD by calling '''AddBottomButton'''(string panel, string name, string desc, Sprite icon). If you want your own Icon you need to instantiate a Sprite with a texture that you load using ParentMod.LoadTexture or in the ModMeta's initialize method.
   −
You can load in UIs using xml files with an html like structure. Example:  
+
You can load in UIs using xml files with an html like structure using '''WindowManager.GenerateUI'''(List<XMLParser.XMLNode> nodes, GameObject parent, object callback). Example:  
 
  <window MinSize="0,0" NonLocTitle="Test window">
 
  <window MinSize="0,0" NonLocTitle="Test window">
 
  <scrollview anchor="fill" position="4,4" size="-8,-8">
 
  <scrollview anchor="fill" position="4,4" size="-8,-8">
Line 166: Line 166:  
  </scrollview>
 
  </scrollview>
 
  </window>
 
  </window>
 +
This will create a window with a scroll view containing a label, a button and a combobox automatically laid out vertically. Please note that attributes, e.g. position="4,4" are case sensitive!
 +
 +
To position an element you can use the '''anchor''' attribute to decide where the element should be anchored to in the element it is sitting in. The anchor is basically a box that contains the element formatted as x,y,width,height, where all values should be between 0-1, representing 0-100% in the parent element. An anchor of (0,0,0,0) is just the top left corner of the element and (0,0,1,1) is an anchor that fills the entire element, since width and height is 1=100%. '''position''' is the x, y pixel offset from the top left of the anchor. '''size''' or '''width''' and '''height''' is the pixel offset from the bottom right corner of the anchor. '''anchor''' can be formatted as either '''#,#,#,#''', '''middle,center''', '''bottom,right''', '''top'''(to fill the entire top), '''left''' to the fill the left side or '''fill''' to fill the entire element. Note that in the scroll view I'm using anchor="fill" position="4,4" size="-8,-8", because I want it to fill the parent window with a 4 pixel margin, so I have to decrease the size by 4 x 4 = 8, which is why size is -8,-8.
 +
 +
You can also use the '''id''' attribute to reference the element in your code after the UI has been loaded.
 +
 +
The game will try to find a corrosponding variable to set for the element for any other attributes you use (Rememeber case sensivity). Some elements, like the button and combo have event variable, i.e. onClick and OnSelectedChanged (use visual studio's code lookup feature to see what is possible), these can be set to function calls that will be called directly on an object you set when creating the UI, i.e. the  onClick="ShowMessage(Hehe)" part. Here's an example of how you would create and use this UI:
 +
var elements = WindowManager.GenerateUI(ParentMod.LoadFullXMLFile("UI.xml"), null, this)["lab"];
 +
var label = (Text)elements["lab"];
 +
Debug.log(label.text);
 +
public void ShowMessage(string x)
 +
{
 +
WindowManager.Instance.ShowMessageBox(x, true, DialogWindow.DialogType.Information);
 +
}
 +
 +
Note that the '''parent''' parameter of '''GenerateUI''' call is null, because all the UI will be added as a child to the parent object, but since we are spawning a window, this is not necessary to define. and I'm using '''this''' for the callback parameter, so when you click the button, the method '''ShowMessage''' from this current class will be called.
    
== Networking ==
 
== Networking ==

Navigation menu