Jump to content

Need help to update a dialog list


Flum
 Share

Recommended Posts

Could anyone tell me the best way to sort my champion list as soon as i move one from the right list to the left list. At this point i tried to work with the array.au3 without succes. Here is my code.

Global $sbselectform, $sbtargetlist, $sbtemplist1, $sbtemplist2 = "", $sbtemplist3, $sbtemplist2r, $sbaddbtn, $sbrembtn, $sbresetbtn, $sbokbtn, $sbmsg, $sbsourcelist, $sbsourcelistr, $sbchamplabel, $sbbanlabel

$sbsourcelist = 'Aatrox|Ahri|Akali|Alistar|Amumu|Anivia|Annie|Ashe|Blitzcrank|Brand|Caitlyn|Cassiopeia|Cho''Gath|Corki|Darius|Diana|Dr. Mundo|Draven|Elise|Evelynn|Ezreal|Fiddlesticks|Fiora|Fizz|Galio|Gangplank|Garen|Gragas|Graves|Hecarim|Heimerdinger|Irelia|Janna|Jarvan IV|Jax|Jayce|Jinx|Karma|Karthus|Kassadin|Katarina|Kayle|Kennen|Kha''Zix|Kog''Maw|LeBlanc|Lee Sin|Leona|Lissandra|Lucian|Lulu|Lux|Malphite|Malzahar|Maokai|Master Yi|Miss Fortune|Mordekaiser|Morgana|Nami|Nasus|Nautilus|Nidalee|Nocturne|Nunu|Olaf|Orianna|Pantheon|Poppy|Quinn|Rammus|Renekton|Rengar|Riven|Rumble|Ryze|Sejuani|Shaco|Shen|Shyvana|Singed|Sion|Sivir|Skarner|Sona|Soraka|Swain|Syndra|Talon|Taric|Teemo|Thresh|Tristana|Trundle|Tryndamere|Twisted Fate|Twitch|Udyr|Urgot|Varus|Vayne|Veigar|Vi|Viktor|Vladimir|Volibear|Warwick|Wukong|Xerath|Xin Zhao|Yasuo|Yorick|Zac|Zed|Ziggs|Zilean|Zyra|'
$sbtemplist2 = IniRead("banlist.ini", "Settings", "banlist", "")
If $sbtemplist2 <> "" Then
;~  dump($sbtemplist2)
    $sbtemplist3 = StringTrimRight($sbtemplist2, 1)
    Local $sbremlist = StringSplit($sbtemplist3, '|')
    For $iCount = 1 To UBound($sbremlist) - 1
        $sbsourcelist = StringReplace($sbsourcelist, $sbremlist[$iCount] & "|", "")
;~      dump($sbremlist[$iCount])
    Next
EndIf
$sbsourcelistr = $sbsourcelist
$sbtemplist2r = $sbtemplist2

$sbselectform = GUICreate("Ban list for Draft/Ranked mode", 335, 275, 227, 154)
$sbchamplabel = GUICtrlCreateLabel("Champion List", 15, 15, 129, 15)
$sbtemplist1 = GUICtrlCreateList("", 15, 32, 129, 227, 0x00200001)
GUICtrlSetData($sbtemplist1, $sbsourcelist)
$sbaddbtn = GUICtrlCreateButton(">>", 152, 40, 25, 25, 0)
$sbrembtn = GUICtrlCreateButton("<<", 152, 70, 25, 25, 0)
;~ $sbresetbtn = GUICtrlCreateButton("C", 152, 189, 25, 25, 0)
$sbokbtn = GUICtrlCreateButton("Ok", 152, 219, 25, 25, 0)
$sbbanlabel = GUICtrlCreateLabel("Ban List", 185, 15, 129, 15)
$sbtargetlist = GUICtrlCreateList("", 185, 32, 129, 227, 0x00200001)
GUICtrlSetData($sbtargetlist, $sbtemplist2)
GUICtrlSetState($sbokbtn, 256)
GUISetState(@SW_SHOW)
While 1
    $sbmsg = GUIGetMsg()
    Select
        Case $sbmsg = $sbaddbtn
            If GUICtrlRead($sbtemplist1) == "" Then
                MsgBox(0, "", "select from left list before adding...")
            Else
                If (UBound(StringSplit($sbtemplist2, '|')) - 1) <= 9 Then
                    $sbtemplist2 &= GUICtrlRead($sbtemplist1) & "|"
                    $sbsourcelist = sbmove($sbtemplist1, $sbtargetlist, $sbsourcelist, GUICtrlRead($sbtemplist1))
                Else
                    MsgBox(0, "", "max 9")
                EndIf
            EndIf
        Case $sbmsg = $sbrembtn
            If GUICtrlRead($sbtargetlist) == "" Then
                MsgBox(0, "", "select from right list before removing...")
            Else
                $sbsourcelist = $sbsourcelist & GUICtrlRead($sbtargetlist) & "|"
;~              Local $sbremlist = StringSplit($sbsourcelist, '|')
;~              _ArraySort($sbremlist)
;~              $sbsourcelist = ""
;~              For $iCount = 1 To UBound($sbremlist) - 1
;~                  $sbsourcelist &= $sbremlist[$iCount] & "|"
;~              Next



                $sbtemplist2 = sbmove($sbtargetlist, $sbtemplist1, $sbtemplist2, GUICtrlRead($sbtargetlist))
            EndIf
;~      Case $sbmsg = $sbresetbtn
;~          GUICtrlDelete($sbtemplist1)
;~          GUICtrlDelete($sbtargetlist)
;~          $sbtemplist1 = GUICtrlCreateList("", 15, 32, 129, 227, 0x00200001)
;~          GUICtrlSetData($sbtemplist1, $sbsourcelistr)
;~          $sbtargetlist = GUICtrlCreateList("", 185, 32, 129, 227, 0x00200001)
;~          GUICtrlSetData($sbtargetlist, $sbtemplist2r)
        Case $sbmsg = $sbokbtn
            IniWrite("banlist.ini", "Settings", "banlist", $sbtemplist2)


;~          MsgBox(64, "boob", $sbtargetlist)
            ExitLoop
        Case $sbmsg = -3
            ExitLoop
        Case Else
    EndSelect
WEnd

Func sbmove($sbmove1, $sbmove2, $sbmove3, $sbmove4)
    Local $sbmove5 = StringSplit($sbmove3, '|'), $sbmove6 = ''
    For $iCount = 1 To UBound($sbmove5) - 1
        If $sbmove5[$iCount] <> $sbmove4 And $sbmove5[$iCount] <> '' Then
            $sbmove6 &= $sbmove5[$iCount] & '|'
        EndIf
    Next
    GUICtrlSetData($sbmove1, '')
    GUICtrlSetData($sbmove1, $sbmove6)
    GUICtrlSetData($sbmove2, $sbmove4)
    Return $sbmove6
EndFunc   ;==>sbmove

Func dump($a)
    MsgBox(0, "", $a)
EndFunc   ;==>dump


Func _ArraySort(ByRef $avArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0)
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    Local $iUBound = UBound($avArray) - 1
    If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
    If $iStart < 0 Then $iStart = 0
    If $iStart > $iEnd Then Return SetError(2, 0, 0)
    Switch UBound($avArray, 0)
        Case 1
            __ArrayQuickSort1D($avArray, $iStart, $iEnd)
            If $iDescending Then _ArrayReverse($avArray, $iStart, $iEnd)
        Case 2
            Local $iSubMax = UBound($avArray, 2) - 1
            If $iSubItem > $iSubMax Then Return SetError(3, 0, 0)
            If $iDescending Then
                $iDescending = -1
            Else
                $iDescending = 1
            EndIf
            __ArrayQuickSort2D($avArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax)
        Case Else
            Return SetError(4, 0, 0)
    EndSwitch
    Return 1
EndFunc   ;==>_ArraySort

Func _ArrayReverse(ByRef $avArray, $iStart = 0, $iEnd = 0)
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, 0)
    Local $vTmp, $iUBound = UBound($avArray) - 1
    If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
    If $iStart < 0 Then $iStart = 0
    If $iStart > $iEnd Then Return SetError(2, 0, 0)
    For $i = $iStart To Int(($iStart + $iEnd - 1) / 2)
        $vTmp = $avArray[$i]
        $avArray[$i] = $avArray[$iEnd]
        $avArray[$iEnd] = $vTmp
        $iEnd -= 1
    Next
    Return 1
EndFunc   ;==>_ArrayReverse

Func __ArrayQuickSort1D(ByRef $avArray, ByRef $iStart, ByRef $iEnd)
    If $iEnd <= $iStart Then Return
    Local $vTmp
    If ($iEnd - $iStart) < 15 Then
        Local $vCur
        For $i = $iStart + 1 To $iEnd
            $vTmp = $avArray[$i]
            If IsNumber($vTmp) Then
                For $j = $i - 1 To $iStart Step -1
                    $vCur = $avArray[$j]
                    If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop
                    $avArray[$j + 1] = $vCur
                Next
            Else
                For $j = $i - 1 To $iStart Step -1
                    If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop
                    $avArray[$j + 1] = $avArray[$j]
                Next
            EndIf
            $avArray[$j + 1] = $vTmp
        Next
        Return
    EndIf
    Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)
    Do
        If $fNum Then
            While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        Else
            While (StringCompare($avArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While (StringCompare($avArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        EndIf
        If $L <= $R Then
            $vTmp = $avArray[$L]
            $avArray[$L] = $avArray[$R]
            $avArray[$R] = $vTmp
            $L += 1
            $R -= 1
        EndIf
    Until $L > $R
    __ArrayQuickSort1D($avArray, $iStart, $R)
    __ArrayQuickSort1D($avArray, $L, $iEnd)
EndFunc   ;==>__ArrayQuickSort1D

Func __ArrayQuickSort2D(ByRef $avArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax)
    If $iEnd <= $iStart Then Return
    Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $fNum = IsNumber($vPivot)
    Do
        If $fNum Then
            While ($iStep * ($avArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($avArray[$L][$iSubItem])) Or (Not IsNumber($avArray[$L][$iSubItem]) And $iStep * StringCompare($avArray[$L][$iSubItem], $vPivot) < 0)
                $L += 1
            WEnd
            While ($iStep * ($avArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($avArray[$R][$iSubItem])) Or (Not IsNumber($avArray[$R][$iSubItem]) And $iStep * StringCompare($avArray[$R][$iSubItem], $vPivot) > 0)
                $R -= 1
            WEnd
        Else
            While ($iStep * StringCompare($avArray[$L][$iSubItem], $vPivot) < 0)
                $L += 1
            WEnd
            While ($iStep * StringCompare($avArray[$R][$iSubItem], $vPivot) > 0)
                $R -= 1
            WEnd
        EndIf
        If $L <= $R Then
            For $i = 0 To $iSubMax
                $vTmp = $avArray[$L][$i]
                $avArray[$L][$i] = $avArray[$R][$i]
                $avArray[$R][$i] = $vTmp
            Next
            $L += 1
            $R -= 1
        EndIf
    Until $L > $R
    __ArrayQuickSort2D($avArray, $iStep, $iStart, $R, $iSubItem, $iSubMax)
    __ArrayQuickSort2D($avArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax)
EndFunc   ;==>__ArrayQuickSort2D
Link to comment
Share on other sites

Add this to your List creation function: $LBS_SORT, it sorts the list automatically

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Add this to your List creation function: $LBS_SORT, it sorts the list automatically

 

I did try out the 0x0002 ($LBS_SORT) when creating the list. But i just found out i added it as extended style. Facepalm

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...