2 # show your vessels on a map
4 # This is part of ypp-sc-tools, a set of third-party tools for assisting
5 # players of Yohoho Puzzle Pirates.
7 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
23 # are used without permission. This program is not endorsed or
24 # sponsored by Three Rings.
32 #---------- general utilities ----------
37 if {$debug} { puts "DEBUG $m" }
41 puts stderr "where-vessels: bad usage: $m"
50 #---------- expecting certain errors ----------
52 proc errexpect-setline {lno line} {
53 glset errexpect_lno $lno
54 glset errexpect_line $line
57 proc errexpect-error {m} {
58 global errexpect_line errexpect_lno
59 error $m "$errexpect_line\n" [list YARRG-ERREXPECT $errexpect_lno]
62 proc errexpect-arrayget {arrayvar key} {
64 upvar 1 ${arrayvar}($key) v
65 if {[info exists v]} { return $v }
66 errexpect-error "undefined $key"
69 proc errexpect-arrayget-boolean {arrayvar key} {
70 switch -exact [uplevel 1 [list errexpect-arrayget $arrayvar $key]] {
73 default { errexpect-error "unexpected $key" }
77 proc errexpect-catch {code} {
78 global errorInfo errorCode
82 debug "ERREXPECT CATCH |$rc|$rv|$errorCode|$errorInfo|"
83 if {$rc==1 && ![string compare YARRG-ERREXPECT [lindex $errorCode 0]]} {
84 return [list 1 $rv [lindex $errorCode 1] $errorInfo]
88 return -code $rc -errorinfo $errorInfo -errorcode $errorCode $rv
92 #---------- argument parsing ----------
96 if {$ai >= [llength $argv]} {
97 badusage "option [lindex $argv [expr {$ai-1}]] needs a value"
99 set v [lindex $argv $ai]
104 set notes_loc vessel-notes
105 set scraper {./yppedia-ocean-scraper --chart}
112 while {[regexp {^\-} [set arg [lindex $argv $ai]]]} {
114 switch -exact -- $arg {
116 --pirate { glset pirate [string totitle [nextarg]] }
117 --ocean { glset ocean [string totitle [nextarg]] }
118 --clipboard-file { load-clipboard-file [nextarg] }
119 --local-html-dir { lappend scraper --local-html-dir=[nextarg] }
120 --notes { glset notes_loc [nextarg] }
121 --debug { incr debug }
122 default { badusage "unknown option $arg" }
125 set argv [lrange $argv $ai end]
126 if {[llength $argv]} { badusage "non-option args not allowed" }
129 proc argdefaults {} {
130 global ocean notes_loc pirate scraper
131 if {![info exists ocean] || ![info exists pirate]} {
132 set cmd {./yarrg --find-window-only --quiet}
133 if {[info exists ocean]} { lappend cmd --ocean $ocean }
134 if {[info exists pirate]} { lappend cmd --pirate $pirate }
135 manyset [split [eval exec $cmd] " "] ocean pirate
136 if {![llength $ocean] || ![llength $pirate]} {
137 error "$ocean $pirate ?"
140 lappend scraper $ocean
144 #---------- loading and parsing the vessel notes ----------
147 global notes_loc notes_data
148 if {[regexp {^\w+\:} $notes_loc]} {
150 debug "FETCHING NOTES $notes_loc"
151 set req [::http::geturl $notes_loc]
152 switch -glob [::http::status $req].[::http::ncode $req] {
154 ok.* { error "retrieving vessel-notes: [::http::code $req]" }
155 * { error "Retrieving vessel-notes: [::http::error $req]" }
157 set newdata [::http::data $req]
160 debug "READING NOTES $notes_loc"
161 set vn [open $notes_loc]
162 set newdata [read $vn]
165 set notes_data $newdata
168 proc parse-notes {} {
169 global notes_data notes
170 catch { unset notes }
173 foreach l [split $notes_data "\n"] {
175 errexpect-setline $lno $l
176 set l [string trim $l]
177 if {![string length $l]} continue
178 if {[regexp {^\#} $l]} continue
179 if {![regexp -expanded \
180 {^ (\d+) (?: \s+([^=]*?) )? \s* =
182 (?: \s+ (\S+) )?)? $} \
183 $l dummy vid vname owner note]} {
184 errexpect-error "badly formatted"
186 set vname [string trim $vname]
187 if {[info exists notes($vid)]} {
188 errexpect-error "duplicate vesselid $vid"
190 set notes($vid) [list $lno $vname $owner $note]
194 proc note-info {lno vid name island description} {
196 lappend note_infos [list $lno $vid $name $island $description]
199 proc display-note-infos {} {
200 global note_infos note_missings notes
202 set nmissing [llength $note_missings]
203 debug "display-note-infos $nmissing [array size notes]"
205 if {[llength $note_infos]} {
206 set tiny "[llength $note_infos] warning(s)"
207 } elseif {$nmissing && [array size notes]} {
208 set tiny "$nmissing missing"
215 foreach info $note_infos {
216 manyset $info lno vid name island description
217 append infodata "vessel"
218 append infodata " $vid"
219 if {[string length $name]} { append infodata " $name" }
220 if {[string length $island]} { append infodata " ($island)" }
221 append infodata ": " $description "\n"
225 if {[string length $infodata]} { append infodata "\n" }
226 append infodata "$nmissing vessel(s) not mentioned in notes:\n"
228 foreach info [lsort $note_missings] {
229 manyset $info island name vid
230 if {[string compare $island $last_island]} {
231 append infodata "# $island:\n"
232 set last_island $island
234 append infodata [format "%-9d %-29s =\n" $vid $name]
238 parser-control-failed-core .cp.ctrl.notes notes \
241 "[llength $note_infos] warning(s);\
242 $nmissing vessel(s) missing" \
243 "Full description of warnings and missing vessels:" \
247 #---------- vessel properties ----------
249 proc vesselclasses-init {} {
250 global vc_game2code vc_code2abbrev vc_code2full vc_codes
255 longship dm ls Longship
256 baghlah em bg Baghlah
257 merchbrig fm mb {Merchant Brig}
258 warbrig gm wb {War Brig}
260 merchgal jm mg {Merchant Galleon}
261 warfrig im wf {War Frigate}
262 grandfrig km gf {Grand Frigate}
265 foreach {game code abbrev full} $vcl {
266 lappend vc_codes $code
267 set vc_game2code($game) $code
268 set vc_code2abbrev($code) $abbrev
269 set vc_code2full($code) $full
274 foreach a {battle borrow dot} {
275 foreach b {ours dot query} {
276 load-icon-combine $a $b
281 proc load-icon {icon} {
282 image create bitmap icon/$icon -file icons/$icon.xbm
285 proc load-icon-combine {args} {
287 set delim "pnmcat -lr "
289 append cmd $delim " <(xbmtopbm icons/$icon.xbm)"
290 set delim " <(pbmmake -white 1 1)"
292 append cmd " | pbmtoxbm"
293 debug "load-icon-combine $cmd"
294 image create bitmap icon/[join $args +] -data [exec bash -c $cmd]
297 proc code-lockown2icon {lockown} {
298 manyset [split $lockown ""] lock notown
300 lindex {battle borrow dot} $lock
302 lindex {ours dot query} $notown
306 proc canvas-horiz-stack {xvar xoff y bind type args} {
308 upvar 1 canvas canvas
309 set id [eval $canvas create $type [expr {$x+$xoff}] $y $args]
310 set bbox [$canvas bbox $id]
311 set x [lindex $bbox 2]
312 $canvas bind $id <ButtonPress> $bind
316 proc code2canvas {code canvas x yvar qty qtylen bind} {
317 global vc_code2abbrev
320 manyset [split $code _] inport class subclass lockown xabbrev
324 set imy [expr {$y+2}]
326 if {!$inport} { incr qtylen -1 }
327 if {$qtylen<=0} { set qtylen {} }
328 set qty [format "%${qtylen}s" $qty]
330 set qtyid [canvas-horiz-stack stackx 0 $y $bind \
331 text -anchor nw -font fixed -text $qty]
334 canvas-horiz-stack stackx 0 $imy $bind \
335 image -anchor nw -image icon/atsea
339 canvas-horiz-stack stackx -1 $imy $bind \
340 image -anchor nw -image icon/$vc_code2abbrev($class)
342 if {[string length $subclass]} {
343 canvas-horiz-stack stackx 0 $y $bind \
344 text -anchor nw -font fixed -text \
349 canvas-horiz-stack stackx 0 $imy $bind \
350 image -anchor nw -image [code-lockown2icon $lockown]
353 if {[string length $xabbrev]} {
354 canvas-horiz-stack stackx 0 $y $bind \
355 text -anchor nw -font fixed -text \
359 set bbox [$canvas bbox $qtyid]
360 set ny [lindex $bbox 3]
361 set bid [$canvas create rectangle \
366 $canvas lower $bid $qtyid
368 $canvas bind $bid <ButtonPress> $bind
371 proc show-report-decode {code} {
374 manyset [split $code _] inport classcode subclass lockown xabbrev
375 manyset [split $lockown ""] lock notown
377 report-set inport [lindex {{At Sea} {In port}} $inport]
378 report-set class $vc_code2full($classcode)
380 switch -exact $subclass {
381 {} { report-set subclass {Ordinary} }
382 F { report-set subclass {"Frost class"} }
383 default { report-set subclass "Subclass \"$subclass\"" }
386 report-set lock [lindex {
387 {Battle ready} {Unlocked} {Locked}
390 switch -exact $notown {
391 0 { report-set own "Yours" }
392 1 { report-set own "Other pirate's" }
393 2 { report-set own "Owner unknown" }
394 default { report-set own "?? $notown" }
397 if {[string length $xabbrev]} {
398 report-set xabbrev "Notes flags: $xabbrev"
400 report-set xabbrev "No flags in notes"
404 #---------- filtering ----------
408 proc filter-values/size {} { global vc_codes; return $vc_codes }
409 proc filter-icon/size {code} {
410 upvar #0 vc_code2abbrev($code) abb
413 proc filter-default/size {code} { return 1 }
414 proc filter-says-yes/size {codel} {
415 set sizecode [lindex $codel 1]
416 upvar #0 filter_size($sizecode) yes
420 proc filter-values/lockown {} {
423 lappend vals "$lv$ov"
428 proc filter-icon/lockown {lockown} { return [code-lockown2icon $lockown] }
429 proc filter-default/lockown {lockown} {
430 return [regexp {^[01]|^2[^1]} $lockown]
432 proc filter-says-yes/lockown {codel} {
433 set lockown [lindex $codel 3]
434 upvar #0 filter_lockown($lockown) yes
438 proc filter-validate/xabbre {re} {
442 regsub {^.*:\s*} $emsg {} emsg
443 regsub {^.*(.{30})$} $emsg {\1} emsg
448 proc filter-says-yes/xabbre {codel} {
450 set xabbrev [lindex $codel 4]
451 return [regexp -- $filter_xabbre $xabbrev]
454 proc filter-tickbox-flip {fil} {
455 upvar #0 filter_$fil vars
456 set values [filter-values/$fil]
457 foreach val $values {
458 set vars($val) [expr {!$vars($val)}]
463 proc make-tickbox-filter {fil label rows inrow} {
464 upvar #0 filter_$fil vars
465 set fw [make-filter tickbox $fil $label frame]
466 set values [filter-values/$fil]
467 set nvalues [llength $values]
469 set inrow [expr {($nvalues + $rows) / $rows}]
471 set noicons [catch { info args filter-icon/$fil }]
472 for {set ix 0} {$ix < $nvalues} {incr ix} {
473 set val [lindex $values $ix]
474 set vars($val) [filter-default/$fil $val]
475 checkbutton $fw.$ix -variable filter_${fil}($val) \
476 -font fixed -command redraw-needed
478 $fw.$ix configure -image [filter-icon/$fil $val] -height 16
480 $fw.$ix configure -text [filter-map/$fil $val]
482 grid configure $fw.$ix -sticky sw \
483 -row [expr {$ix / $inrow}] \
484 -column [expr {$ix % $inrow}]
486 button $fw.invert -text flip -command [list filter-tickbox-flip $fil] \
488 grid configure $fw.invert -sticky se \
489 -row [expr {$rows-1}] \
490 -column [expr {$inrow-1}]
493 proc entry-filter-changed {fw fil n1 n2 op} {
495 upvar #0 filter_$fil realvar
496 upvar #0 filterentered_$fil entryvar
497 global def_background
498 debug "entry-filter-changed $fw $fil $entryvar"
500 set error [filter-validate/$fil $entryvar]
501 if {[string length $error]} {
502 $fw.error configure -text $error -foreground white -background red
504 $fw.error configure -text { } -background $def_background
505 set realvar $entryvar
509 puts stderr "FILTER CHECK ERROR $emsg $errorInfo"
513 proc make-entry-filter {fil label def} {
514 global filterentered_$fil
515 upvar #0 filter_$fil realvar
517 set fw [make-filter entry $fil $label frame]
518 entry $fw.entry -textvariable filterentered_$fil
520 glset def_background [$fw.error cget -background]
521 trace add variable filterentered_$fil write \
522 [list entry-filter-changed $fw $fil]
523 pack $fw.entry $fw.error -side top -anchor w
526 proc make-filter {kind fil label ekind} {
528 label .filter.lab_$fil -text $label -justify left
531 set nfilters [llength $filters]
532 grid configure .filter.lab_$fil -row $nfilters -column 0 -sticky nw -pady 4
533 grid configure .filter.$fil -row $nfilters -column 1 -sticky w -pady 3
537 proc make-filters {} {
538 make-tickbox-filter size Size 2 0
539 make-tickbox-filter lockown "Lock/\nowner" 2 6
540 make-entry-filter xabbre "Flags\n regexp" {}
543 proc filterstyle-changed {n1 n2 op} {
545 debug "filterstyle-changed $filterstyle"
549 proc filters-say-yes {code} {
550 global filters filterstyle
551 debug "filters-say-yes $code"
552 set codel [split $code _]
553 set lockown [lindex $codel 3]
554 switch -exact $filterstyle {
556 1 { return [filter-default/lockown $lockown] }
557 2 { return [regexp {^.0} $lockown] }
559 default { error $filterstyle }
562 foreach fil $filters {
563 if {![filter-says-yes/$fil $codel]} { return 0 }
568 #---------- loading and parsing the clipboard (vessel locations) ----------
571 global pirate notes_used note_missings newnotes
575 lappend codel [errexpect-arrayget-boolean vi inPort]
577 set gameclass [errexpect-arrayget vi vesselClass]
578 upvar #0 vc_game2code($gameclass) class
579 if {![info exists class]} { errexpect-error "unexpected vesselClass"}
582 set subclass [errexpect-arrayget vi vesselSubclass]
583 switch -exact $subclass {
584 null { lappend codel {} }
585 icy { lappend codel F }
586 default { lappend codel ($subclass) }
589 switch -exact [errexpect-arrayget vi isLocked]/[ \
590 errexpect-arrayget vi isBattleReady] {
591 true/false { set lock 2 }
592 false/false { set lock 1 }
593 false/true { set lock 0 }
594 default { errexpect-error "unexpected isLocked/isBattleReady" }
597 set vid [errexpect-arrayget vi vesselId]
598 upvar #0 notes($vid) note
599 set realname [errexpect-arrayget vi vesselName]
600 set island [errexpect-arrayget vi islandName]
604 if {[info exists note]} {
605 manyset $note lno notename owner xabbrev
606 if {[string compare -nocase $realname $notename]} {
607 note-info $lno $vid $realname $island \
608 "notes say name is $notename"
610 if {[string length $owner]} {
611 if {![string compare $owner $pirate]} {
619 append abbrev $xabbrev
620 set notes_used($vid) 1
624 lappend note_missings [list $island $realname $vid]
627 lappend codel "$lock$notown" $xabbrev
628 lappend newnotes [list $vid $realname $owner $xabbrev]
629 set kk "$island [join $codel _]"
630 upvar #0 found($kk) k
631 lappend k [list $vid $realname $owner]
633 debug "CODED $kk $vid $realname"
637 proc parse-clipboard {} {
638 global clipboard found notes notes_used newnotes
640 catch { unset found }
641 catch { unset notes_used }
643 glset note_missings {}
647 set itemre { (\w+) = ([^=]*) }
648 set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
652 foreach l [split $clipboard "\n"] {
654 errexpect-setline $lno $l
655 if {![string length $l]} continue
658 if {![regexp -expanded $manyitemre $l dummy \
659 thiskey thisval rhs]} {
660 errexpect-error "badly formatted"
662 set vi($thiskey) $thisval
663 if {![string length $rhs]} break
664 regsub {^, } $rhs {} rhs
670 if {[llength $newnotes]} {
671 foreach vid [lsort [array names notes]] {
672 if {![info exists notes_used($vid)]} {
673 manyset $notes($vid) lno notename
674 note-info $lno $vid $notename {} \
675 "vessel in notes no longer found"
681 proc load-clipboard-file {fn} {
683 glset clipboard [read $f]
688 #---------- loading and parsing the chart ----------
692 debug "FETCHING CHART"
693 set chart [eval exec $scraper [list | perl -we {
698 yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
699 sub { sprintf "%d %d", @_; },
700 sub { printf "archlabel %d %d %s\n", @_; },
701 sub { printf "island %s %s\n", @_; },
702 sub { printf "league %s %s %s.\n", @_; },
703 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
705 STDOUT->error and die $!;
714 return [expr {$c * $scale}]
717 proc chart-got/archlabel {args} { }
718 proc chart-got/island {x y args} {
719 # debug "ISLE $x $y $args"
720 global canvas isleloc
721 set isleloc($args) [list $x $y]
723 # $canvas create oval \
724 # [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
725 # [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
727 $canvas create text [coord $x] [coord $y] \
728 -text $args -anchor s
730 proc chart-got/league {x1 y1 x2 y2 kind} {
731 # debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
733 set l [$canvas create line \
734 [coord $x1] [coord $y1] \
735 [coord $x2] [coord $y2]]
736 if {![string compare $kind .]} {
737 $canvas itemconfigure $l -dash .
741 proc redraw-needed {} {
743 debug "REDRAW NEEDED"
744 if {[info exists redraw_after]} return
745 set redraw_after [after 250 draw]
749 global chart found isleloc canvas redraw_after islandnames
751 catch { after cancel $redraw_after }
752 catch { unset redraw_after }
756 foreach l [split $chart "\n"] {
757 # debug "CHART-GOT $l"
758 set proc [lindex $l 0]
759 eval chart-got/$proc [lrange $l 1 end]
763 set lastislandname {}
764 foreach key [lsort [array names found]] {
765 set c [llength $found($key)]
766 # debug "SHOWING $key $c"
767 regexp {^(.*) (\S+)$} $key dummy islandname code
769 if {![filters-say-yes $code]} continue
771 if {[string compare $lastislandname $islandname]} {
772 manyset $isleloc($islandname) x y
775 set lastislandname $islandname
776 lappend islandnames $islandname
780 if {$c > 1} { set qty [format %d $c] } else { set qty {} }
781 code2canvas $code $canvas $x y $qty 2 \
782 [list show-report $islandname $code]
786 panner::updatecanvas-bbox .cp.ctrl.pan
792 #---------- parser error reporting ----------
794 proc parser-control-create {w base invokebuttontext etl_title} {
796 button $w.do -text $invokebuttontext -command invoke_$base -pady 3
798 frame $w.resframe -width 120 -height 32
799 button $w.resframe.res -text {} -anchor nw \
800 -padx 1 -pady 1 -borderwidth 0 -justify left
801 glset deffont_$base [$w.resframe.res cget -font]
802 place $w.resframe.res -relx 0.5 -y 0 -anchor n
805 pack $w.resframe -side top -expand y -fill both
810 wm title $eb "where-vessels - $etl_title"
811 wm protocol $eb WM_DELETE_WINDOW [list wm withdraw $eb]
813 label $eb.title -text $etl_title
814 pack $eb.title -side top
816 button $eb.close -text Close -command [list wm withdraw $eb]
817 pack $eb.close -side bottom
819 frame $eb.emsg -bd 2 -relief groove
820 label $eb.emsg.lab -anchor nw -text "Error:"
821 text $eb.emsg.text -height 1
822 pack $eb.emsg.text -side bottom -fill x
823 pack $eb.emsg.lab -side left
825 pack $eb.emsg -side top -pady 2 -fill x
827 frame $eb.text -bd 2 -relief groove
828 pack $eb.text -side bottom -pady 2 -fill both -expand y
830 label $eb.text.lab -anchor nw
832 text $eb.text.text -width 85 \
833 -xscrollcommand [list $eb.text.xscroll set] \
834 -yscrollcommand [list $eb.text.yscroll set]
835 $eb.text.text tag configure error \
836 -background red -foreground white
838 scrollbar $eb.text.xscroll -orient horizontal \
839 -command [list $eb.text.text xview]
840 scrollbar $eb.text.yscroll -orient vertical \
841 -command [list $eb.text.text yview]
843 grid configure $eb.text.lab -row 0 -column 0 -sticky w -columnspan 2
844 grid configure $eb.text.text -row 1 -column 0 -sticky news
845 grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
846 grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
847 grid rowconfigure $eb.text 0 -weight 0
848 grid rowconfigure $eb.text 1 -weight 1
849 grid rowconfigure $eb.text 2 -weight 0
850 grid columnconfigure $eb.text 0 -weight 1
851 grid columnconfigure $eb.text 1 -weight 0
854 proc parser-control-ok-core {w base background show} {
855 debug "parser-control-ok-core $w $base $background $show"
856 upvar #0 deffont_$base deffont
857 $w.resframe.res configure \
858 -background $background -disabledforeground black -font $deffont \
859 -state disabled -command {} \
862 proc parser-control-ok {w base show} {
863 parser-control-ok-core $w $base green $show
865 proc parser-control-none {w base show} {
866 parser-control-ok-core $w $base blue $show
868 proc parser-control-failed-core {w base foreground background smallfont
869 tiny summary fulldesc fulldata} {
870 debug "parser-control-failed-core $w $base $summary $fulldesc"
871 upvar #0 deffont_$base deffont
874 $eb.emsg.text delete 0.0 end
875 $eb.emsg.text insert end $summary
877 $eb.text.lab configure -text $fulldesc
878 $eb.text.text delete 0.0 end
879 $eb.text.text insert end $fulldata
881 regsub -all {.{18}} $tiny "&\n" ewrap
889 $w.resframe.res configure \
890 -background $background -foreground $foreground -font $font \
891 -state normal -command [list wm deiconify $eb] \
895 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
898 set line [lindex [split $ei "\n"] 0]
899 debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
901 parser-control-failed-core $w $base \
903 "err: [string trim $emsg]: \"$line\"" \
904 "at line $lno: $emsg" \
907 $eb.text.text tag add error $lno.0 $lno.end
908 $eb.text.text see $lno.0
910 proc parser-control-failed-unexpected {w base emsg ei} {
912 parser-control-failed-core $w $base \
914 $emsg $emsg "Details and stack trace:" $ei
917 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
918 upvar #0 $varname var
919 manyset [errexpect-catch {
921 if {[string length [string trim $var]]} {
922 parser-control-ok .cp.ctrl.$base $base $okshow
924 parser-control-none .cp.ctrl.$base $base $noneshow
926 }] failed emsg lno ei
928 parser-control-failed-expected .cp.ctrl.$base $base \
929 $emsg $lno $ei $fulldesc $var
937 #---------- island names selection etc. ----------
939 proc islandnames-update {} {
941 .islands.count configure -text [format "ships at %d island(s)" \
942 [llength $islandnames]]
945 proc islandnames-select {} {
946 .islands.clip configure -relief sunken -state disabled
947 selection own -command islandnames-deselect .islands.clip
949 proc islandnames-deselect {} {
950 .islands.clip configure -relief raised -state normal
953 proc islandnames-handler {offset maxchars} {
955 return [string range [join $islandnames ", "] \
956 $offset [expr {$offset+$maxchars-1}]]
959 #---------- main user interface ----------
961 proc widgets-setup {} {
962 global canvas debug pirate ocean filterstyle
964 wm geometry . 1024x600
965 wm title . "where-vessels - $pirate on the $ocean ocean"
969 frame .f -border 1 -relief groove
972 pack $canvas -expand 1 -fill both
973 pack .f -expand 1 -fill both -side left
975 #----- control panels and filter -----
978 frame .filter -relief groove -bd 2 -padx 1
979 frame .islands -pady 2
980 pack .cp .filter .islands -side top
983 trace add variable filterstyle write filterstyle-changed
986 label .filter.title.title -text Show
987 pack .filter.title.title -side left
988 for {set fing 0} {$fing < 4} {incr fing} {
989 radiobutton .filter.title.f$fing \
990 -variable filterstyle -value $fing \
991 -text [lindex {All Useable Mine These:} $fing]
992 pack .filter.title.f$fing -side left
995 grid configure .filter.title -row 0 -column 0 -columnspan 2
997 #----- control panel -----
1000 pack .cp.ctrl -side left -anchor n
1002 debug "BBOX [$canvas bbox all]"
1004 panner::canvas-scroll-bbox .f.c
1005 panner::create .cp.ctrl.pan .f.c 120 120 $debug
1007 pack .cp.ctrl.pan -side top -pady 0 -padx 5
1009 pack .cp.ctrl.zoom -side top
1011 button .cp.ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2} -pady 0
1012 button .cp.ctrl.zoom.in -text + -font {Courier 16} -command {zoom *2} -pady 0
1013 pack .cp.ctrl.zoom.out .cp.ctrl.zoom.in -side left
1015 parser-control-create .cp.ctrl.acquire \
1017 "Clipboard parsing error" \
1019 pack .cp.ctrl.acquire -side top -pady 2
1021 parser-control-create .cp.ctrl.notes \
1022 notes "Reload notes" \
1023 "Vessel notes loading report" \
1025 pack .cp.ctrl.notes -side top -pady 2
1027 #----- island name count and copy -----
1029 label .islands.count
1030 button .islands.clip -text "copy island names" -pady 2 -padx 2 \
1031 -command islandnames-select
1032 selection handle .islands.clip islandnames-handler
1033 pack .islands.count .islands.clip -side left
1035 #----- decoding etc. report -----
1038 pack .cp.report -side left -anchor n
1040 label .cp.report.island -text { }
1042 canvas .cp.report.abbrev -width 1 -height 15
1044 frame .cp.report.code
1045 label .cp.report.code.lab -text Code:
1046 glset report_code { }
1047 entry .cp.report.code.code -state readonly \
1048 -textvariable report_code -width 15
1049 pack .cp.report.code.lab .cp.report.code.code -side left
1050 frame .cp.report.details -bd 2 -relief groove -padx 2 -pady 2
1052 listbox .cp.report.list -height 5
1054 pack .cp.report.island .cp.report.abbrev .cp.report.details \
1055 .cp.report.list -side top
1056 #pack .cp.report.code -side top
1057 pack configure .cp.report.details -fill x
1059 foreach sw {inport class subclass lock own xabbrev} {
1060 label .cp.report.details.$sw -text { }
1061 pack .cp.report.details.$sw -side top -anchor w
1065 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
1067 proc show-report {islandname code} {
1068 .cp.report.island configure -text $islandname
1070 .cp.report.abbrev delete all
1072 code2canvas $code .cp.report.abbrev 5 y {} 0 {}
1073 manyset [.cp.report.abbrev bbox all] minx dummy maxx dummy
1074 .cp.report.abbrev configure -width [expr {$maxx-$minx+4}]
1076 glset report_code $code
1077 show-report-decode $code
1079 set kk "$islandname $code"
1080 upvar #0 found($kk) k
1082 .cp.report.list delete 0 end
1085 manyset $entry vid name owner
1086 lappend owned($owner) $name
1089 foreach owner [lsort [array names owned]] {
1090 if {[string length $owner]} {
1091 set owndesc "$owner's"
1093 set owndesc "Owner unknown"
1095 .cp.report.list insert end "$owndesc:"
1096 foreach name $owned($owner) {
1097 .cp.report.list insert end " $name"
1102 proc zoom {extail} {
1104 set nscale [expr "\$scale $extail"]
1105 debug "ZOOM $scale $nscale"
1106 if {$nscale < 1 || $nscale > 200} return
1111 proc invoke_acquire {} {
1112 global clipboard errorInfo
1116 set clipboard [clipboard get]
1118 parser-control-failed-unexpected .cp.ctrl.acquire acquire \
1119 $emsg "fetching clipboard:\n\n$errorInfo"
1124 clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
1132 proc invoke_notes {} {
1133 global notes_data errorInfo notes_loc
1139 parser-control-failed-unexpected .cp.ctrl.notes notes \
1140 $emsg "loading $notes_loc:\n\n$errorInfo"
1145 notes_data $old "Vessel notes:" "loaded ok" { no notes } {
1154 #---------- main program ----------
1159 httpclientsetup where-vessels
1165 if {[catch { parse-clipboard } emsg]} {
1166 puts stderr "$emsg\n$errorInfo"
1169 after idle invoke_notes