using System; using System.Diagnostics; using System.Globalization; using LavishScriptAPI; using MRBot.IsxEq2.AbilityEffect; using MRBot.IsxEq2.Helpers; namespace MRBot.IsxEq2.UI { /// /// This DataType includes all of the data available to ISXEQ2 that is related /// to UI Elements such as buttons, icons, checkboxes, UI Text, composites and others. /// public class EQ2Widget : LavishScriptObject { #region Constructor /// /// Constructor /// /// LS Object public EQ2Widget(LavishScriptObject copy) : base(copy) { } /// /// Constructor - Constructs a EQ2Window object based on the LavishScript object EQ2Window /// public EQ2Widget() : base(LavishScript.Objects.GetObject("EQ2Widget")) { } #endregion #region Members /// /// If the result of a GetProperty call is a boolean value, then it will return "TRUE" or "FALSE". /// Otherwise, it will return a string unless an additional argument is provided as follows /// public string GetProperty(string name) { Trace.WriteLine(String.Format("EQ2UIElement:GetProperty({0})", name)); return this.GetStringFromLSO("GetProperty", name); } /// /// Retrieves the specified Child. This data member only works for Composite UI element types. /// This data member uses two arguments. The first is the 'type' the element, which can be /// either "Button", "Icon", "Text", "CheckBox", "Page", "DataSourceContainer", or "Composite". /// The second argument is the index location of the child within the composite's children array. /// This number will be between 1 and NumChildren. /// /// type /// index /// EQ2UIElement public EQ2Widget Child(ElementType type, int index) { Trace.WriteLine(String.Format("EQ2UIElement:Child({0}, {1})", type.ToString(), index.ToString(CultureInfo.InvariantCulture))); return new EQ2Widget(this.GetMember("ChildType", type.ToString(), index.ToString(CultureInfo.InvariantCulture))); } /// /// Retrieves the ChildType at the specified index. /// This data member only works for Composite UI element types. /// This data member uses one argument. This argument is a /// number between 1 and NumChildren representing the location in the composite's children array. /// /// index /// ElementType public ElementType ChildType(int index) { Trace.WriteLine(String.Format("EQ2UIElement:ChildType({0})", index.ToString(CultureInfo.InvariantCulture))); switch (this.GetStringFromLSO("ChildType", index.ToString(CultureInfo.InvariantCulture))) { case "Button": return ElementType.Button; case "Icon": return ElementType.Icon; case "Text": return ElementType.Text; case "CheckBox": return ElementType.CheckBox; case "Page": return ElementType.Page; case "DataSourceContainer": return ElementType.DataSourceContainer; case "Composite": return ElementType.Composite; case "DynamicData": return ElementType.DynamicData; case "TextBox": return ElementType.TextBox; case "List": return ElementType.List; case "VolumePage": return ElementType.VolumePage; case "DataSource": return ElementType.DataSource; default: return ElementType.Unknown; } } /// /// Retrieves the dynamic data UI element at the specified path /// /// path /// EQ2UIElement public EQ2Widget GetDynamicData(string path) { Trace.WriteLine(String.Format("EQ2UIElement:GetDynamicData({0})", path)); return new EQ2Widget(this.GetMember("GetDynamicData", path)); } /// /// Returns true if the element is checked. This data member only works for Checkbox and DynamicData UI element types. /// public bool IsChecked { get { Trace.WriteLine(String.Format("EQ2UIElement:IsChecked")); return this.GetBoolFromLSO("IsChecked"); } } /// /// This data member has only been tested to work with 'button' types thus far. /// public bool IsEnabled { get { Trace.WriteLine(String.Format("EQ2UIElement:IsEnabled")); return this.GetBoolFromLSO("IsEnabled"); } } /// /// This member is an exact replica of IsChecked. /// This data member only works for Checkbox and DynamicData UI element types. /// public bool IsSet { get { Trace.WriteLine(String.Format("EQ2UIElement:IsSet")); return this.GetBoolFromLSO("IsSet"); } } /// /// Cache of Label /// private string _label; /// /// Label. This data member only works for Checkbox, Text, DynamicData, and Button UI element types. /// public string Label { get { Trace.WriteLine(String.Format("EQ2UIElement:Label")); return _label ?? (_label = this.GetStringFromLSO("Text")); } } /// /// Number of children. This data member only works for Composite UI element types. /// public int NumChildren { get { Trace.WriteLine(String.Format("EQ2UIElement:NumChildren")); return this.GetIntFromLSO("NumChildren"); } } /// /// Parent /// public EQ2Widget Parent { get { Trace.WriteLine(String.Format("EQ2UIElement:Parent")); return new EQ2Widget(this.GetMember("Parent")); } } /// /// ProgressBar completion. For ProgressBar types only. /// public float Percent { get { Trace.WriteLine(String.Format("EQ2UIElement:Percent")); return this.GetFloatFromLSO("Percent"); } } /// /// Highlighted list row. "List" types only. /// public int RowHighlighted { get { Trace.WriteLine(String.Format("EQ2UIElement:RowHighlighted")); return this.GetIntFromLSO("RowHighlighted"); } } /// /// Cache of ShortLabel /// private string _shortLabel; /// /// Short Label. This data member only works for DynamicData UI element types. /// public string ShortLabel { get { Trace.WriteLine(String.Format("EQ2UIElement:ShortLabel")); return _shortLabel ?? (_shortLabel = this.GetStringFromLSO("ShortLabel")); } } /// /// Cache of Text /// private string _text; /// /// Text. This data member only works for Checkbox, Text, DynamicData, and Button UI element types. /// public string Text { get { Trace.WriteLine(String.Format("EQ2UIElement:Text")); return _text ?? (_text = this.GetStringFromLSO("Text")); } } /// /// Returns the ability associated with the icon. For Icons only. /// public Ability ToAbility { get { Trace.WriteLine(String.Format("EQ2UIElement:ToAbility")); return new Ability(this.GetMember("ToAbility")); } } /// /// Element Type /// public ElementType Type { get { Trace.WriteLine(String.Format("EQ2UIElement:Type")); switch (this.GetStringFromLSO("Type")) { case "Button": return ElementType.Button; case "Icon": return ElementType.Icon; case "Text": return ElementType.Text; case "CheckBox": return ElementType.CheckBox; case "Page": return ElementType.Page; case "DataSourceContainer": return ElementType.DataSourceContainer; case "Composite": return ElementType.Composite; case "DynamicData": return ElementType.DynamicData; case "TextBox": return ElementType.TextBox; case "List": return ElementType.List; case "VolumePage": return ElementType.VolumePage; case "DataSource": return ElementType.DataSource; default: return ElementType.Unknown; } } } #endregion #region Methods /// /// Adds text to textbox. This should work for pretty much any "text entry" box in the EQ2 UI. /// Only works for Textbox type eq2uielements. /// /// text /// call success public bool SetProperty(string propertyName, string value) { Trace.WriteLine(String.Format("EQ2UIElement:SetProperty({0},{1})", propertyName, value)); return this.ExecuteMethod("SetProperty", propertyName, value); } /// /// Clicks a button. Only works for Button type eq2uielements. /// /// call success public bool ClickButton() { Trace.WriteLine(String.Format("EQ2UIElement:ClickButton()")); return this.ExecuteMethod("ClickButton"); } /// /// Performs a double left click of the eq2uielement. /// /// call success public bool DoubleLeftClick() { Trace.WriteLine(String.Format("EQ2UIElement:DoubleLeftClick()")); return this.ExecuteMethod("DoubleLeftClick"); } /// /// Highlights the specified row in the list /// /// row /// call success public bool HighlightRow(int row) { Trace.WriteLine(String.Format("EQ2UIElement:HighlightRow({0})", row.ToString(CultureInfo.InvariantCulture))); return this.ExecuteMethod("HighlightRow", row.ToString(CultureInfo.InvariantCulture)); } /// /// LeftClicks the eq2uielement /// /// call success public bool LeftClick() { Trace.WriteLine(String.Format("EQ2UIElement:LeftClick()")); return this.ExecuteMethod("LeftClick"); } /// /// RightClicks the eq2uielement /// /// public bool RightClick() { Trace.WriteLine(String.Format("EQ2UIElement:RightClick()")); return this.ExecuteMethod("RightClick"); } #endregion #region Enums /// /// UI Element Types /// public enum ElementType { /// /// Element Type Button /// Button, /// /// Element Type Text /// Text, /// /// Element Type TextBox /// TextBox, /// /// Element Type CheckBox /// CheckBox, /// /// Element Type Page /// Page, /// /// Element Type Composite /// Composite, /// /// Element Type Icon /// Icon, /// /// Element Type DataSourceContainer /// DataSourceContainer, /// /// Element Type DynamicData /// DynamicData, /// /// Element Type Volume Page /// VolumePage, /// /// Element Type DataSource /// DataSource, /// /// Element Type Lists /// List, /// /// Element Type Unknown /// Unknown } #endregion } }