#!/usr/local/bin/wish -f
# Above line may need to be modified. Find your "wish" with
# 'which wish'
#***************************************************************
# RIFT Tk
# A reduced version of Rift v. 0.7
# TCL/TK Dynamic Load Utility for Unix Rift
# Copyright 1996, Bob Jamison
# All rights reserved (typical!)
#
#***************************************************************
load "./rifttcl.so" Rifttcl

wm title . "Rift - The Internet Quake Tool"

set fontfix  -*-Courier-Medium-R-Normal--*-120-*-*-*-*-*-*
set fontnorm -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
#***************************************************************
# COMMANDS
#***************************************************************
proc rmsg {msg} {
  .f.txt delete 0.0 end
  .f.txt insert end  $msg
}

proc rift_config {} {
  exec nedit rift.cfg
}

proc rift_editlist {} {
  exec nedit rift.dat
}

proc rift_refresh {} {
  rmsg "Polling servers"
  riftUpdate
  .f.r.list delete 0 end
  for { set i 0 } { $i < 100 } { incr i } {
    set s [riftListGet $i]
    if { $s == "" } break
    .f.r.list insert end $s
    }
}

proc rift_launch {} {
  set l [.f.r.list curselection]
  if { $l == "" } {
    rmsg "Nothing Selected"
    return
    }
  set s [.f.r.list get $l]
  scan $s "%s %s %s" a b c
  rmsg "Trying $b"
  riftLaunch $c
}

proc rift_helpreadme {} {
  exec nedit riftnote.txt
}

proc rift_helpabout {} {
  tk_dialog .about "About Rift" \
    "Can't be killed by conventional weapons!\nVersion 0.7\n1996, Bob Jamison"  \
    "@rift.xbm" 0 Ok
}

proc rift_startup {} {
  riftInit
  rmsg "Loading configuration"
  riftCfg
  rmsg "Loading local list"
  riftLoad
  rmsg "Reverse DNS"
  riftGetrev
  rift_refresh
}

#***************************************************************
# GUI
#***************************************************************
proc ScrolledListbox { parent args } {
global fontfix
  set font $fontfix
  # Create listbox attached to scrollbars, pass thru $args
  frame $parent
  eval {listbox $parent.list \
      -yscrollcommand [list $parent.sy set] \
      -xscrollcommand [list $parent.sx set]} $args
  # Create scrollbars attached to the listbox
  scrollbar $parent.sx -orient horizontal \
      -command [list $parent.list xview]
  scrollbar $parent.sy -orient vertical \
      -command [list $parent.list yview]
  # Arrange them in the parent frame
  pack $parent.sx -side bottom -fill x
  pack $parent.sy -side right -fill y
  pack $parent.list -side left -fill both -expand true
}

proc create_gui {} {
global fontnorm fontfix
  #************************ Menus
  set font $fontnorm
  frame .menuBar
  pack .menuBar -side top -fill x
  #***********File menu
  menubutton .menuBar.file -text File -menu .menuBar.file.m -underline 0
  menu .menuBar.file.m
  .menuBar.file.m add command -label "Refresh" -command "rift_refresh" -underline 0
  .menuBar.file.m add command -label "Quit" -command "exit" -underline 0
  pack .menuBar.file -side left
  #***********Launch menu
  menubutton .menuBar.launch -text Launch -menu .menuBar.launch.m -underline 0
  menu .menuBar.launch.m
  .menuBar.launch.m add command -label "Launch" -command "rift_launch" -underline 0
  pack .menuBar.launch -side left
  #***********Edit menu
  menubutton .menuBar.edit -text Edit -menu .menuBar.edit.m -underline 0
  menu .menuBar.edit.m
  .menuBar.edit.m add command -label "Rift Config" -command "rift_config" -underline 0
  .menuBar.edit.m add command -label "Local list"  -command "rift_editlist" -underline 0
  pack .menuBar.edit -side left
  #***********Help menu
  menubutton .menuBar.help -text Help -menu .menuBar.help.m -underline 0
  menu .menuBar.help.m
  .menuBar.help.m add command -label "Readme" -command "rift_helpreadme" -underline 0
  .menuBar.help.m add command -label "About"  -command "rift_helpabout"  -underline 0
  pack .menuBar.help -side right

  #*************************** Rest of GUI
  frame .f -width 300 -height 200
  pack .f
  text .f.txt -width 35 -height 1
  pack .f.txt
  ScrolledListbox .f.r -width 50 -height 10 -setgrid 1
  pack .f.r
}


create_gui

after 4000 rift_startup

#***************************************************************
# END OF FILE
#***************************************************************
