chiark / gitweb /
where-vessels: decode codes and abbrevs for the user
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 13 Dec 2009 13:55:24 +0000 (13:55 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 13 Dec 2009 13:55:32 +0000 (13:55 +0000)
yarrg/where-vessels

index 9ec3b35fc8ee8b139abcd94286672cce43df76af..81341a0f43002e5b3190be8e27704cb1f03834df 100755 (executable)
@@ -244,7 +244,7 @@ proc display-note-infos {} {
 #---------- vessel properties ----------
 
 proc vesselclasses-init {} {
-    global vc_game2code vc_code2abbrev vc_abbrev2full
+    global vc_game2code vc_code2abbrev vc_code2full
     foreach {game code abbrev full} {
        smsloop         am      sl      Sloop
        lgsloop         bm      ct      Cutter
@@ -260,7 +260,7 @@ proc vesselclasses-init {} {
     } {
        set vc_game2code($game) $code
        set vc_code2abbrev($code) $abbrev
-       set vc_abbrev2full($abbrev) $full
+       set vc_code2full($code) $full
     }
 }
 
@@ -268,19 +268,57 @@ proc code2abbrev {code} {
     global vc_code2abbrev
 
     manyset [split $code _] inport class subclass lockown xabbrev
-    manyset [split $lockown ""] lock own
+    manyset [split $lockown ""] lock notown
 
     set abbrev {}
     append abbrev [lindex {? {}} $inport]
     append abbrev $vc_code2abbrev($class)
     append abbrev $subclass
     append abbrev [lindex {* + -} $lock]
-    append abbrev [lindex {- = ?} [regsub {\D} $own 2]]
+    append abbrev [lindex {= - ?} [regsub {\D} $notown 2]]
     append abbrev $xabbrev
 
     debug "CODE2ABBREV $code $abbrev"
     return $abbrev
 }
+
+proc show-report {islandname code} {
+    global vc_code2full
+
+    .report.island configure -text $islandname
+    glset report_code $code
+    glset report_abbrev [code2abbrev $code]
+
+    manyset [split $code _] inport classcode subclass lockown xabbrev
+    manyset [split $lockown ""] lock notown
+    
+    report-set inport [lindex {{At Sea} {In port}} $inport]
+    report-set class $vc_code2full($classcode)
+
+    switch -exact $subclass {
+       {} { report-set subclass {Ordinary} }
+       F { report-set subclass {"Frost class"} }
+       default { report-set subclass "Subclass \"$subclass\"" }
+    }
+
+    report-set lock [lindex {
+       {Battle ready} {Unlocked} {Locked}
+    } $lock]
+
+    switch -exact $notown {
+       0 { report-set own "Yours" }
+       1 { report-set own "Other pirate's" }
+       U { report-set own "Owner not known" }
+       M { report-set own "Missing from notes" }
+       default { report-set own "?? $notown" }
+    }
+
+    if {[string length $xabbrev]} {
+       report-set xabbrev "Notes flags: $xabbrev"
+    } else {
+       report-set xabbrev "No flags in notes"
+    }
+}
     
 #---------- loading and parsing the clipboard (vessel locations) ----------
 
@@ -326,22 +364,22 @@ proc vessel {vin} {
        }
        if {[string length $owner]} {
            if {![string compare $owner $pirate]} {
-               set own 1
+               set notown 0
            } else {
-               set own 0
+               set notown 1
            }
        } else {
-           set own U
+           set notown U
        }
        append abbrev $xabbrev
        set notes_used($vid) 1
 
     } else {
-       set own M
+       set notown M
        lappend note_missings [list $island $realname $vid]
     }
 
-    lappend codel "$lock$own" $xabbrev
+    lappend codel "$lock$notown" $xabbrev
     lappend newnotes [list $vid $realname $owner $xabbrev]
     set kk "$island [join $codel _]"
     upvar #0 count($kk) k
@@ -495,6 +533,8 @@ proc draw {} {
        set bbox [$canvas bbox $id]
        set bid [eval $canvas create rectangle $bbox -fill white]
        $canvas lower $bid $id
+       $canvas bind $id <ButtonPress> [list show-report $islandname $code]
+       $canvas bind $bid <ButtonPress> [list show-report $islandname $code]
        manyset $bbox dummy dummy dummy y
 #      debug "NEW Y $y"
     }
@@ -647,14 +687,21 @@ proc reparse {base varname old fulldesc okshow noneshow parse ok} {
 proc widgets-setup {} {
     global canvas debug pirate ocean
 
+    wm geometry . 1024x480
+    wm title . "where-vessels - $pirate on the $ocean ocean"
+
+    #----- map -----
+
     frame .f -border 1 -relief groove
     set canvas .f.c
     canvas $canvas
     pack $canvas -expand 1 -fill both
     pack .f -expand 1 -fill both -side left
 
+    #----- control panel -----
+
     frame .ctrl
-    pack .ctrl -side right
+    pack .ctrl -side left -anchor n
 
     debug "BBOX [$canvas bbox all]"
 
@@ -681,10 +728,43 @@ proc widgets-setup {} {
        
     pack .ctrl.notes -side top -pady 2
 
-    wm geometry . 1024x480
-    wm title . "where-vessels - $pirate on the $ocean ocean"
+    #----- decoding etc. report -----
+
+    frame .report
+    pack .report -side left -anchor n
+
+    label .report.island -text { }
+
+    frame .report.abbrev -background black
+    glset report_abbrev {         }
+    entry .report.abbrev.abbrev -state readonly \
+       -textvariable report_abbrev \
+       -borderwidth 0 -relief flat -width 0 \
+       -highlightbackground white \
+       -readonlybackground white -foreground black
+    pack .report.abbrev.abbrev -side left -padx 1 -pady 1
+
+    frame .report.code
+    label .report.code.lab -text Code:
+    glset report_code { }
+    entry .report.code.code -state readonly -textvariable report_code -width 15
+    pack .report.code.lab .report.code.code -side left
+    frame .report.details -bd 2 -relief groove -padx 2 -pady 2
+
+    listbox .report.list -height 5
+
+    pack .report.island .report.abbrev .report.details \
+       .report.list .report.code -side top
+    pack configure .report.details -fill x
+
+    foreach sw {inport class subclass lock own xabbrev} {
+       label .report.details.$sw -text { }
+       pack .report.details.$sw -side top -anchor w
+    }
 }
 
+proc report-set {sw val} { .report.details.$sw configure -text $val }
+
 proc zoom {extail} {
     global scale canvas
     set nscale [expr "\$scale $extail"]