Advertisement
OgreVorbis

TES Morrowind Object Finder

Jun 15th, 2022
2,501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.98 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <GuiListView.au3>
  3. #include <GuiListBox.au3>
  4. #include <WindowsConstants.au3>
  5.  
  6. Local $idListBox
  7. Local $idButton
  8. Local $hLB
  9. Local $hWin
  10. Local $wasFound = 0
  11.  
  12. BuildGUI()
  13. Main()
  14. Do
  15.     $event = GUIGetMsg()
  16.     If $event = $idButton Then
  17.         Main()
  18.     EndIf
  19. Until $event = $GUI_EVENT_CLOSE
  20. GUIDelete()
  21.  
  22. Func BuildGUI()
  23.     ; Create GUI
  24.     GUICreate("TES Helper by OgreVorbis", 400, 332)
  25.     $idListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $WS_HSCROLL))
  26.     $idButton = GUICtrlCreateButton("Go Again!", 164, 300)
  27.     GUISetState(@SW_SHOW)
  28.     GUIRegisterMsg($WM_COMMAND, "ListBox_Clicked")
  29. EndFunc
  30.  
  31. Func ListBox_Clicked($hWnd, $iMsg, $wParam, $lParam)
  32.     #forceref $hWnd, $iMsg, $lParam
  33.  
  34.     $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
  35.     $iCode = BitShift($wParam, 16) ; Hi Word
  36.  
  37.     If $iCode = $LBN_DBLCLK And $iIDFrom = $idListBox Then
  38.         $iIndex = _GUICtrlListBox_GetCaretIndex($idListBox)
  39.         $sText = _GUICtrlListBox_GetText($idListBox, $iIndex)
  40.         $goThere = Int(StringLeft($sText, StringInStr($sText, " ") - 1))
  41.         _GUICtrlListView_SetItemSelected($hLB, -1, False) ; clear the selection
  42.         _GUICtrlListView_SetItemSelected($hLB, $goThere, True, True) ; set the selected item
  43.         ;ControlListView($hWin, "", $hLB, "SelectClear") - this is an alternate method, but junkier
  44.         ;ControlListView($hWin, "", $hLB, "Select", $goThere)
  45.         _GUICtrlListView_EnsureVisible($hLB, $goThere) ; scroll to it
  46.         WinActivate($hWin)
  47.     EndIf
  48. EndFunc
  49.  
  50. Func Main()
  51.     If WinExists("Object Window") Then
  52.         _GUICtrlListBox_ResetContent($idListBox)
  53.         $hWin = WinGetHandle("Object Window")
  54.         $hLB = ControlGetHandle($hWin, "", "List2")
  55.         Local $numItems = _GUICtrlListView_GetItemCount($hLB)
  56.         Local $title
  57.         Local $iD = -1
  58.         Local $sSearch = ""
  59.         $wasFound = 0
  60.         MsgBox(0, "Win", "Total objects in list = " & String($numItems))
  61.         $sSearch = InputBox("Search", "What object do you want to search for?")
  62.         If $sSearch = "" Then Return
  63.         ToolTip("Please wait. . .", @DesktopWidth / 2, @DesktopHeight / 2, "Searching", 1, 2)
  64.  
  65.         _GUICtrlListBox_BeginUpdate($idListBox)
  66.         $iD = _GUICtrlListView_FindInText($hLB, $sSearch, $iD, False)
  67.         $title = _GUICtrlListView_GetItemText($hLB, $iD, 0)
  68.         If $iD <> -1 Then
  69.             _GUICtrlListBox_AddString($idListBox, String($iD) & " " & $title)
  70.             $wasFound = $wasFound + 1
  71.         EndIf
  72.         While True
  73.             $iD = _GUICtrlListView_FindInText($hLB, $sSearch, $iD, False)
  74.             If $iD = -1 Then ExitLoop
  75.             $title = _GUICtrlListView_GetItemText($hLB, $iD, 0)
  76.             _GUICtrlListBox_AddString($idListBox, String($iD) & " " & $title)
  77.             $wasFound = $wasFound + 1
  78.         WEnd
  79.         _GUICtrlListBox_EndUpdate($idListBox)
  80.  
  81.         ToolTip("")
  82.         If $wasFound = 0 Then
  83.             MsgBox(16, "Nothing", "Nothing was found for this term.")
  84.         Else
  85.             MsgBox(64, "Results", "The search returned " & String($wasFound) & " results.")
  86.         EndIf
  87.     Else
  88.         MsgBox(16, "Fail", "TES must not be open or there is another problem :-(")
  89.         Exit
  90.     EndIf
  91. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement