1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
|
/* Copyright (c) 1996--1999 Geoff Pike. */
/* All rights reserved. */
/* Floater is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* This software is provided "as is" and comes with absolutely no */
/* warranties. Geoff Pike is not liable for damages under any */
/* circumstances. Support is not provided. Use at your own risk. */
/* Personal, non-commercial use is allowed. Attempting to make money */
/* from Floater or products or code derived from Floater is not allowed */
/* without prior written consent from Geoff Pike. Anything that remotely */
/* involves commercialism, including (but not limited to) systems that */
/* show advertisements while being used and systems that collect */
/* information on users that is later sold or traded require prior */
/* written consent from Geoff Pike. */
gset newstyle_matrix 0
proc redrawmatrixcards {} {}
proc togglepassedcard {suit card} {
global togglepassedaction
if [info exists togglepassedaction([string toupper $suit$card])] \
{catch $togglepassedaction([string toupper $suit$card])}
}
proc removecardfromhand {suit card} {
global removecard
if [info exists removecard([string toupper $suit$card])] \
{catch $removecard([string toupper $suit$card])}
}
#ifndef TEXT
proc tpcard {w} {
// talkmsg "tpcard: $w"
if ![string match *ello* [$w config -fg]] {
$w config -fg yellow
// talkmsg "tpcard: $w set to yellow"
} else {
$w config -fg black
// talkmsg "tpcard: $w set to black"
}
}
#endif
#ifdef TEXT
// remove a card from a player's hand
proc rmcard {x y suit card} {
set f "$x $y"
anchor $f
set suit [string toupper $suit]
if {$suit == "S"} {rmcard2 $f $suit $card} {down_and_anchor}
if {$suit == "H"} {rmcard2 $f $suit $card} {down_and_anchor}
if {$suit == "D"} {rmcard2 $f $suit $card} {down_and_anchor}
if {$suit == "C"} {rmcard2 $f $suit $card}
}
proc rmcard2 {f suit card} {
global cursuit
right 2 // move over suit symbol and space
set w [set "cursuit($f$suit)" [zap $card $cursuit($f$suit)]]
str "$w "
}
// find the first occurence of char in text and remove it
proc zap {char text} {
set i [string first $char $text]
if {$i < 0} { // shouldn't happen
return $text
} elseif {$i == 0} {
return [string range $text 1 end]
} else {
incr i -1
set j [expr $i + 2]
// this still works (empirically) if j is beyond the end of the string
return "[string range $text 0 $i][string range $text $j end]"
}
}
#endif
// proc suit creates one row of buttons to show one suit on the screen
proc suit {f cards suit} {
#ifdef TEXT
global cursuit removecard
set suit [string toupper $suit]
set cards [string toupper $cards]
str "$suit $cards"
down_and_anchor
set "cursuit($f$suit)" $cards
for {set i [expr [string length $cards] - 1]} {$i >= 0} {incr i -1} {
set card [string index $cards $i]
set removecard([string toupper $suit$card]) "rmcard $f $suit $card"
}
#else
global buttoncardoptions buttonsuitoptions removecard togglepassedaction
set buttons {}
for {set i [expr [string length $cards] - 1]} {$i >= 0} {incr i -1} {
set card [string index $cards $i]
set comm "-command \"command $suit$card\""
set newbutton [eval "button $f.$suit.$suit$card \
$buttoncardoptions -text $card $comm"]
refont $newbutton cardfont
set buttons [linsert $buttons 0 $newbutton]
set removecard([string toupper $suit$card]) "destroy $newbutton"
set togglepassedaction([string toupper $suit$card]) "tpcard $newbutton"
}
// if {$buttons == {}} {
// set buttons [eval "label $f.$suit.void $buttoncardoptions -text -"]
// }
refont [eval "label $f.$suit.suit $buttonsuitoptions -text [$suit]"] suitfont
eval "pack $f.$suit.suit $buttons -side left"
#endif
}
// proc hand creates the frames and buttons to show a hand on the screen
// f is a frame; s, d, h, and c are suit holdings
proc hand {f s h d c} {
#ifndef TEXT
global framesuitoptions
// either create the 5 frames or, if they exist, empty them out
if [winfo exists $f.name] {
foreach i {name s h d c} {
foreach child [winfo children $f.$i] {
catch {destroy $child}
}
}
} else {
catch {destroy $f.name $f.s $f.h $f.d $f.c}
frame $f.name
frame $f.s
frame $f.h
frame $f.d
frame $f.c
pack $f.name -side top -anchor w
eval "pack $f.s $f.h $f.d $f.c -side top -anchor w $framesuitoptions"
}
#else
global handwidth
anchor $f
clearrect $handwidth 4
#endif
suit $f $s s
suit $f $h h
suit $f $d d
suit $f $c c
}
#if 0
// proc hand creates the frames and buttons to show a hand on the screen
// f is a frame; s, d, h, and c are suit holdings
proc hand {f s h d c} {
#ifndef TEXT
global framesuitoptions
catch {destroy $f.name $f.s $f.h $f.d $f.c}
frame $f.name
frame $f.s
frame $f.h
frame $f.d
frame $f.c
pack $f.name -side top -anchor w
eval "pack $f.s $f.h $f.d $f.c -side top -anchor w $framesuitoptions"
#else
global handwidth
anchor $f
clearrect $handwidth 4
#endif
suit $f $s s
suit $f $h h
suit $f $d d
suit $f $c c
}
#endif /* 0 */
#ifndef TEXT
// We want pack propagation off most of the time for .play
// But occasionally we'll turn it on for a little while to allow important
// changes to happen. This is a disgusting hack.
proc prop_on {} {
// pack prop .play true
// after 250 pack prop .play false
// after 2000 prop_on
}
#endif
// Show a full deal
// (this wrecks & rebuilds frames and whatnot, destroying any display of the
// players' names)
proc fulldeal {s h d c LHOs LHOh LHOd LHOc \
Ps Ph Pd Pc RHOs RHOh RHOd RHOc} {
global mframe
hand $mframe(self) $s $h $d $c
hand $mframe(pard) $Ps $Ph $Pd $Pc
hand $mframe(lho) $LHOs $LHOh $LHOd $LHOc
hand $mframe(rho) $RHOs $RHOh $RHOd $RHOc
}
gset tricktimeOK 1
// causes tricktimeOK to be 0 for the next tricktime milliseconds
// tricktimeOK should be 1 when this is called
proc startshowtricktimer {} {
global tricktime tricktimeOK
set tricktimeOK 0
after $tricktime set tricktimeOK 1
}
// this is for erasing the last trick 5 seconds after the double dummy
// display at the end of a hand
proc delayedclearmatrix {} {
global needtoerase
set needtoerase 1
after 5000 clearmatrixtimer
}
proc clearmatrixtimer {} {
global needtoerase
if $needtoerase {erasebidplay all}
}
// Erase a bid or play from the matrix
// who should be lho, rho, pard, self, or all
proc erasebidplay {who} {
global tricktimeOK
while {!$tricktimeOK} {
update
after 100
}
if {$who == "all"} {
global needtoerase
set needtoerase 0
erasebidplay lho
erasebidplay rho
erasebidplay pard
erasebidplay self
} else {
#ifdef TEXT
global matrixtext
anchor $matrixtext($who)
clearrect 2 1
#else
set path .play.middle.box.$who
catch {pack forget $path.suit $path.card}
#endif
}
}
// display (in the matrix) a card played
// suit is one of s, d, h, c
// card is one of 2 ... A
proc showplay {player suit card} {
#ifdef TEXT
global matrixtext
anchor $matrixtext($player)
if {$suit == "?"} {
str "? "
} else {
str $suit$card
}
#else
global cardfont suitfont
set path .play.middle.box.$player
catch {pack forget $path.suit $path.card} c
if {$c != ""} {
// something went wrong -- we must create suit and card buttons
refont [label $path.suit -font $suitfont -borderwidth 0] suitfont
refont [label $path.card -font $cardfont -borderwidth 0] cardfont
}
pack $path.suit $path.card -side left
if {$suit != "?"} {
eval "$path.suit configure -text [$suit] -font $suitfont"
refont $path.suit suitfont
} else {
$path.suit configure -text ""
}
$path.card configure -text [string toupper $card]
#endif
}
// display (in the matrix) a card played
// level is in 1 ... 7
// strain is n, s, h, d, c, x, xx, or p
// (if strain is x, xx, or p, then level is ignored)
proc showbid {player level strain} {
// debugmsg "showbid $player $level $strain"
#ifdef TEXT
global matrixtext
anchor $matrixtext($player)
if {$strain == "-"} {
str " "
} elseif {$strain == "?"} {
str "? "
} elseif {$level > 0} {
str "$level$strain "
} else {
str "$strain "
}
#else
drawbid .play.middle.box.$player $level $strain
#endif
}
#ifdef TEXT
proc drawbid {x y level strain} {
global auctionx auctiony auctionbot
// debugmsg "drawbid $x $y $level $strain"
if {[expr $auctiony + $y + 2] <= $auctionbot} {
anchor "[expr $auctionx + 1 + 4 * $x] [expr $auctiony + $y + 2]"
// convert level & strain to a two character string
if {$strain == "x"} {
set s "X "
} elseif {$strain == "xx"} {
set s "XX"
} elseif {$strain == "p"} {
set s "P "
} elseif {$strain == "-"} {
set s " "
} elseif {$strain == "?"} {
set s "? "
} else {
set s $level$strain
}
clearrect 2 1
if {$s != " "} {str [string toupper $s]}
}
}
#else
proc drawbid {path level strain} {
global NTtext NTfont cardfont suitfont \
passtext passfont doubletext doublefont redoubletext redoublefont
// debugmsg "drawbid $path $level $strain"
catch {pack forget $path.suit $path.card} c
if {$c != ""} {
// something went wrong -- we must create strain and level buttons
refont [label $path.suit -font $suitfont -borderwidth 0] suitfont
refont [label $path.card -font $cardfont -borderwidth 0] cardfont
}
pack $path.card $path.suit -side left
if {$strain == "n"} {
$path.suit configure -text $NTtext -font $NTfont -fg black
refont $path.suit NTfont
$path.card configure -text $level
} elseif {$strain == "x"} {
$path.suit configure -text $doubletext -font $doublefont -fg red
refont $path.suit doublefont
$path.card configure -text ""
} elseif {$strain == "xx"} {
$path.suit configure -text $redoubletext -font $redoublefont -fg blue
refont $path.suit redoublefont
$path.card configure -text ""
} elseif {$strain == "p"} {
$path.suit configure -text $passtext -font $passfont -fg black
refont $path.suit passfont
$path.card configure -text ""
} elseif {$strain == "-"} {
$path.suit configure -text ""
$path.card configure -text ""
} elseif {$strain == "?"} {
$path.suit configure -text ""
$path.card configure -text "?"
} else {
eval "$path.suit configure -text [$strain] -font $suitfont"
refont $path.suit suitfont
$path.card configure -text $level
}
}
#endif
// Display a player's name above his cards
// player should be lho, rho, pard, or self
proc setname {player compassdir name} {
#ifdef TEXT
global namepos namewidth
anchor $namepos($player)
if {[string first "(" $name] == -1} {set name "$name ($compassdir)"}
if {[string length $name] > $namewidth} {
set name [string range $name 0 [expr $namewidth - 1]]
}
if {$player == "self" || $player == "pard"} {
rightjustify $name $namewidth
} else {
clearrect $namewidth 1
}
str $name
#else
global namefont mframe playername position
set playername($player) $name
set position($player) $compassdir
set f $mframe($player).name.label
if {[string first "(" $name] == -1} {set name "$name ($compassdir)"}
catch {$f configure -text $name} c
if {$c != ""} {
// configure didn't work -- try creating widget
refont [label $f -font $namefont -text $name] namefont
pack $f -pady 0
}
#endif
}
|