coloredstacksdn5

Note: To toggle between 6max and full ring, Ctrl+left-click on one of the colored boxes. To hide the boxes for a certain range, make the color white (since all pixels of that color are made transparent).

This script needs RolandsFunctions.

Note : ColoredStacks is only compatible with PartyPoker !

Note: You need to have FPHG running!

;------------ ColoredStacks v1.06 ---------------

; date: 7:55 PM Monday, April 02, 2007
; by Roland

#NoEnv
#SingleInstance force
#Include %a_scriptDir%
#Include Functions.ahk

SetWorkingDir %a_scriptDir%

OnExit HandleExit

SetTitleMatchMode 3
DetectHiddenWindows On

IsCompiled()
CheckAHKVersion("1.0.46.09")

ini = Stacks.ini
version = ColoredStacks v1.06

IfNotExist %ini%        
  FileAppend, % Colors_(), %ini% ;just what I plugged in

IniWrite, Dummy.exe, %ini%, General, exe

Install()

TrayMenu()

SetTimer, Tables, 1000
return

Tables:
list := TableIDListParty(LobbyIDParty())
Loop, Parse, list, `,
        {
                IfWinExist ColoredStacksGui%a_loopfield% ahk_classAutoHotkeyGUI ;if we alrady have one
                        continue
                Run "AutoHotkey.exe" "/f" "_Colored_Stacks_.ahk" "%a_loopfield%"        ;pass the id as parameter
                WinWait ColoredStacksGui%a_loopfield%,, 20              ;wait for the gui to exist
        }
return

;notifies every instance to update settings
SettingsChange() {
Critical
SetTitleMatchMode 1
WinGet, list, list, ColoredStacksGui ahk_classAutoHotkeyGUI
Loop %list% {
                thisID := list%a_index%
                PostMessage, 0x5556,,,, ahk_id%thisID%  ;post exit msg
        }
}

;shut down every instance
HandleExit:
Critical
SetTitleMatchMode 1
WinGet, list, list, ColoredStacksGui ahk_classAutoHotkeyGUI
Loop %list% {
        thisID := list%a_index%
        PostMessage, 0x5555,,,, ahk_id%thisID%  ;post exit msg
}
ExitApp

Conf:
Thread NoTimers
Gui +Lastfound +Toolwindow
Hotkey, IfWinActive, % "ahk_id" WinExist()
Hotkey, tab, Tab
Gui, Margin, 5, 5
Gui, Font,, Comic Sans MS
IniRead, totalRanges, %ini%, Ranges, totalRanges, 10
Gui, Add, Text, Section, Upper bound:
Loop % totalRanges {
                IniRead, u, %ini%, Upper, upper%a_index%, % a_index * 20
                Gui, Add, Edit, vu%a_index% xs wp h20, % u
        }
Gui, Add, Text, ys Section, Color:
Loop % totalRanges {
                IniRead, lv%a_index%, %ini%, Colors, color%a_index%
                c := lv%a_index%
                Gui, Add, ListView, 
                        (
                        vlv%a_index% xs -Hdr r1 -Multi -Tabstop
                        w150 Background%c% 
                        Altsubmit gConfColor
                        ), 1|2
        }
IniRead, trans, %ini%, General, trans, 80
Gui, Add, Text, x5 Section, Transparency:
Gui, Add, Edit, vtrans wp h20, %trans%
;Gui, Add, Text, ys, PartyGaming exe:
;IniRead, exe, %ini%, General, exe, %a_space%
;Gui, Add, Edit, vexe wp+25 h20 Section, %exe%
;Gui, Add, Button, h20 ys gConfExe, ...
Gui, Add, Button, x5 h20 Section +default, &Submit
Gui, Add, Button, ys h20, &Cancel
Gui Show,, Ranges and Colors
return

Tab:
GuiControlGet, f, focusV
StringTrimLeft, n, f, 1
If ( n != totalRanges ) {
        SendPlay {tab}
        return
}
GuiControl, Focus, u1
SendPlay ^{a}
return

ButtonSubmit:
Gui Submit
Loop % totalRanges {
                IniWrite, % u%a_index%, %ini%, Upper, upper%a_index%
                IniWrite, % lv%a_index%, %ini%, Colors, color%a_index%
        }
IniWrite, %trans%, %ini%, General, trans
IniWrite, %exe%, %ini%, General, exe
Gui Destroy
SettingsChange()
return

ButtonCancel:
GuiClose:
GuiEscape:
Gui Destroy
return

ConfColor:
If ( a_guiControlEvent != "normal" )
        return
c := ColorPicker()
If ( c="" )
        return
GuiControl, +Background%c%, % a_guiControl
%a_guiControl% = %c%
return

ConfExe:
Gui +OwnDialogs
FileSelectFile, f, 1, %a_programFiles%\PartyGaming
        , Please select the PartyGaming executable:, *.exe
If ( f="" )
        return
GuiControl,, exe, % f
return

TrayMenu() {
global
Menu, Tray, NoStandard
Menu, Tray, DeleteAll
Menu, Tray, Add, &Help, Help
Menu, Tray, Default, &Help
Menu, Tray, Add
Menu, Tray, Add, &About, About
Menu, Tray, Add
Menu, Tray, Add, &Settings, Conf
Menu, Tray, Add
Menu, Tray, Add, E&xit, Exit
Menu, Tray, Tip, %version%
}

Help:
Run % Web() "http://www.overcards.com/wiki/moin.cgi/ColoredStacks"
return

About:
TrayTip, %version%, Author: Roland`nE-mail: Roland@overcards.com,,1
return

Exit:
ExitApp

Colors_() {
c =
(
[Colors]
color1=00FF00
color2=80FF00
color3=FFFF00
color4=FF0000
color5=FF8040
color6=ED7700
color7=800000
color8=0080C0
color9=005580
color10=0000A0
)
return c
}

Install() {
FileDelete, _Colored_Stacks_.ahk
FileRead, code, %a_scriptName%
name = ColoredStacks
start =
(
############## %name% ##############
)
StringTrimLeft, code, code, InStr(code, start) - 2
StringTrimRight, code, code, 4
FileAppend, %code%, _Colored_Stacks_.ahk
}

/*
;############## ColoredStacks ##############

#NoEnv
#NoTrayIcon             
#SingleInstance off
#Include %a_scriptDir%
#Include Functions.ahk

SetWorkingDir %a_scriptDir%

SetBatchLines -1                ;only to spped-up the launch

OnExit HandleExit

OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x204, "WM_RBUTTONDOWN")
OnMessage(0x5555, "ExitMsg")    
OnMessage(0x5556, "Settings")   ;gets sent when the user hits Submit in conf Gui

format = txt    ;can be changed to hhf when testing with FPHG

ini = Stacks.ini

Settings()

;"fr" for fullRing - whatever
frX = 475,651,693,646,458,216,41,5,47,222
frY = 69,124,218,369,394,394,352,223,103,69
StringSplit, frX, frX, `,
StringSplit, frY, frY, `,

timer = 1000    

targetID = %1%  ;the command line param 

myScreenName := MyScreenName(targetID)
gameType := gameTypeParty(WinGetTitle(targetID))
 
Gui +Lastfound +AlwaysOnTop +Toolwindow
Gui, Color, White               ;figured noone would want white
WinSet, TransColor, White %trans%
Gui -Caption
Loop 10 {
        Gui, Add, Progress, vp%a_index% BackgroundWhite ;initially transparent
        ;remove the border (this style might get lost when moving/showing ctrls later; we'd have to do this again)
        Control, ExStyle, -0x20000, msctls_progress32%a_index%          
}
Gui Show, Hide, ColoredStacksGui%targetID%      ;a hopefully unique title...

6max = 0
WinWaitStatic(targetID, 2000, 5000)             ;wait until PartyPlanner's done moving it etc.
        If ( WinMinMax(targetID) != -1 ) {
        ;this makes the pixel search thing somewhat reliable
        WinSet, AlwaysOnTop, On, ahk_id%targetID%       
        6max := Is6max(targetID)                
        WinSet, AlwaysOnTop, Off, ahk_id%targetID%
} 

SetBatchLines 30                ;we can set this even higher probably, please experiment

SetTimer, ShowHide, %timer%
return

;------------ end of auto-execute section ---------------

;------ Settings -------

Settings() {
global
Critical
IniRead, totalRanges, %ini%, Ranges, totalRanges, 10
Loop % totalRanges {
                IniRead, upper%a_index%, %ini%, Upper, upper%a_index%, % a_index * 10 
                IniRead, color%a_index%, %ini%, Colors, color%a_index%
        }
IniRead, trans, %ini%, General, trans, 80
IniRead, exe, %ini%, General, exe, Dummy.exe
Gui +Lastfound
WinSet, TransColor, White %trans%
}

;------- ShowHide ---------

ShowHide:
If ! WinExist("ahk_id" targetID)                ;if the table was closed, exit
        exitApp
If ( WinMinMax(WinExist("a"))   ;active window maximised, target minimized...
        || WinMinMax(WinExist("ahk_id" targetID)) = -1) {
                        Gui Hide
                        xp = -32000
                } else {
                        Gui +AlwaysOnTop     
                        WinGetPos, x, y, w, h, ahk_id%targetID%
                        If ( x != xp || y != yp || w != wp )    {       ;target was moved/resized
                                xp = %x%                ;set these to the new coords
                                yp = %y%
                                wp = %w%
                                Gui, Show, % "x" x+3 "y" y+26 "w" w-6 "h" h-29 "NoActivate"
                                cw := Floor( 101 / ( 796 - 3 ) * ( w - 3 ) )    ;width of the controls
                                ch := Floor( 35 / ( 579 - 26 ) * ( h - 26 ) )   ;height of the control
                                Loop 10 {
                                        x := Floor( ( ( frX%a_index% - 3 ) / ( 796 - 3 ) ) * ( w - 3 ) )        ;x-position
                                        y := Floor( ( ( frY%a_index% - 26 ) / ( 579 - 26 ) ) * ( h - 26 ) ) ;y-position
                                        GuiControl, Move, p%a_index%, x%x% y%y%  w%cw% h%ch%    ;move it
                                }
                        }
        }
handID := HandID(targetID) ;re-do colors after every hand
If ( handID != handID_p ) {
                ColorStacks()
                handID_p = %handID% 
        }
return

;--------- ColorStacks ----------

ColorStacks() {
global
Thread NoTimers
;returns the full path of the file where the hh for %targetID% resides (also works for FPHG)
file := HHFile(targetID, exe)
hh := HH(file, lastHandID(targetID))    ;grabs the hhs
;fills several arrays with names relative to seats, stacks relative to names etc
SeatsStacksNames(hh, targetID)  
bb := GetBBParty(targetID, GameTypeParty(WinGetTitle(targetID)))      ;get the bb
Loop 10 {
                thisP := p(a_index, 6max)       ;have to convert in case 6max
                If ( sn%a_index%%TargetID% = "" 
                                || sn%a_index%%TargetID% = myScreenName ) {     ;if no player, hide ctrl and skip rest of loop
                                GuiControl, Hide, p%thisP%
                                continue
                        }
                GuiControl, Show, p%thisP%      ;show in case it was hidden
                invested := InvestedLastHand(hh, sn%a_index%%targetID%)       ;$ won/lost on last hand
                stack := Round( ( stack%a_index%%targetID% - invested ) / bb )  ;stack in BBs
                If ( ! stack )  ;if stack couldn't be determined, hide ctrl
                        GuiControl, Hide, p%thisP%
                If ( 6max && IsIn(a_index, "2,4,7,9") ) ;if we're 6max, hide these ctrls
                        GuiControl, Hide, p%a_index%
                c := Color(stack)       ;get the new color
                GuiControl, +Background%c%, p%thisP%    ;set the color
        }
}

;-------- Color ------------

Color(bb) {
global
Loop % totalRanges {
        lower := a_index - 1    ;lower bound is prev upper bound
        If ( ! upper%lower% )
                upper%lower% = 0
        If IsBetween(bb, upper%lower%, upper%a_index%) 
                return % color%a_index%   ;if it's in this range, return this color
        }
return % color%totalRanges%
}

;--------- Toggle6max ---------

Toggle6max() {
global
Convert(6max)
6max :=  1 - 6max
ColorStacks()
}

;--------- p ----------

;converts seat positions for 6max
p(p, 6max) {
If ( ! 6max )
        return p
If ( p = 1 )
        return 1
If ( p = 2 )
        return 3
If ( p = 3 )
        return 5
If ( p = 4 ) 
        return 6
If ( p = 5 )
        return 8 
If ( p = 6 )
        return 10
}

;------- Convert --------

;convert to 6max / fullring
Convert(show) {
local seats
seats = 2,4,7,9
Loop, Parse, Seats, `,
        GuiControl, Show%show%, p%a_loopfield%
return 
}

;--------- WM_LBUTTONDOWN ---------

;CTRL+LBUTTON toggles 6max, otherwise click
WM_LBUTTONDOWN() {
If ( GetKeyState("Ctrl") ) {    
                Toggle6max()
                return
        }
GuiControl, Hide, %a_guiControl%
Click
GuiControl, Show, %a_guiControl%
}

;--------- WM_RBUTTONDOWN ---------

;just click
WM_RBUTTONDOWN() {
GuiControl, Hide, %a_guiControl%
Click R
GuiControl, Show, %a_guiControl%
}

;--------- HandleExit ---------

HandleExit:
exitApp

/*

CategoryAutoHotKey

ColoredStacks (last edited 2008-03-06 18:05:39 by MogobuTheFool)