• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • RaptureAtkUnitManager.GetRawControls

    Discussion in 'Community Developer Forum' started by Wheredidigo, May 27, 2015.

    1. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      Mastahg,

      I have the following code which I'm using to information about RemoteWindows onto a Winforms Form to make it easy to gather information about those windows while devs are trying to write OrderBotProfiles.

      Code:
      private void RemoteWindowsGrid()
      {
      	var remoteWindowTabIndex = tabControl1.TabPages.IndexOfKey("tabRemoteWindows");
      	var remoteWindowTabPage = tabControl1.TabPages[remoteWindowTabIndex];
      	var remoteWindowsTabControl = new TabControl { Dock = DockStyle.Fill };
      
      	foreach (var window in RaptureAtkUnitManager.GetRawControls.OrderBy(x => x.Name))
      	{
      		var thisWindowName = window.GetType().Name;
      		var props =
      			window.GetType()
      				.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public |
      							   BindingFlags.NonPublic);
      		if (!remoteWindowsTabControl.TabPages.ContainsKey(thisWindowName))
      		{
      			var tabPage = new TabPage { Name = thisWindowName, Text = thisWindowName, Dock = DockStyle.Fill};
      			var propertyDataGrid = new DataGridView
      			{
      				Name = thisWindowName + "DataGrid",
      				ColumnCount = props.Count() + 1,
      				Dock = DockStyle.Fill
      			};
      			propertyDataGrid.Columns[0].Name = window.Name;
      			for (int i = 1; i <= props.Count(); i++)
      			{
      				propertyDataGrid.Columns[i].Name = props[i - 1].Name;
      			}
      			tabPage.Controls.Add(propertyDataGrid);
      			remoteWindowsTabControl.TabPages.Add(tabPage);
      		}
      		var row = props.Select(x => x.GetValue(window, null)).ToArray();
      		var insertRow = new object[row.Length + 1];
      		insertRow[0] = window.Name;
      		Array.Copy(row, 0, insertRow, 1, row.Length);
      		var dg = (DataGridView)remoteWindowsTabControl.TabPages[thisWindowName].Controls[thisWindowName + "DataGrid"];
      		dg.Rows.Add(insertRow);
      	}
      	remoteWindowTabPage.Controls.Add(remoteWindowsTabControl);
      }
      
      This should dynamically build me tabs for each different type of control it gets back, but everything is coming back as an AtkAddonControl instead of the different types(ie: SelectString, SelectIconString, SelectYesNo, etc...)
      Can you tell me if I'm using something incorrectly?

      Also, if I were to just put a var y = SelectString.IsOpen; at the very top of that method...even when I do have the SelectString window open, it is showing false when I debug the code. The weird part is that if I do a Log(SelectString.IsOpen); in the Console, it returns false. Can you shed some light on what it's doing behind the scenes to make sure it has the correct data?

      Here is a sample of what the form looks like right now with that method:

      [​IMG]
       
    2. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,343
      Likes Received:
      383
      Trophy Points:
      83
      Only windows that have a custom implementation will return something other then AtkAddonControl.

      As for why its not showing the right value its probably because you are running on a sepreate thread from the mainbot thread and the information is being cached. Look at questdevtools code for examples of what todo, and rebornconsole for pulsing pulsator. Running code in another thread is nonsupported behavior really so its up to you.
       
    3. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,343
      Likes Received:
      383
      Trophy Points:
      83
      Actually getrawcontrols only ever returns a atkaddoncontrol. All the functions in classes selectstring etc are static and there isn't any table that contains them.

      Edit:
      I'd also recommend against just enumerating their fields as well, much of that code is expected to be run inside a framelock and if it isnt it will be terribly slow.
       
    4. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      I appreciate the response. I know this goes against all coding standards....but I'm not worried about it being terribly slow. Basically, the point of it will be that you walk up and interact with something in game, you then go to the ExDevTools UI and click Refresh button, and then my code will go through and determine what type of window is open and then give you all of the information regarding that specific type of window. It's a only run once kind of thing specifically when you want it to, so I'm not worried if it takes a little longer to load because it's not happening on every pulse. I was just hoping there would be something that has a list of all of those static classes and I could just filter on IsOpen on them.

      Since GetRawControls and Controls both only ever return an AtkAddonControl, is there really any point to having the RaptureAtkUnitManager? I'm not sure what you could actually do with it.

      Thanks
       
    5. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,343
      Likes Received:
      383
      Trophy Points:
      83
      It's used internally by those static methods.

      Edit:
      you could also use reflection to find all the types that inherit atkaddoncontrol, and when I saw slow, i mean really really slow, and some stuff just won't work properly either.
       

    Share This Page