#!/usr/bin/env wish
# mohave - Modified version of Dave Leo's "mohave" wrapper.
# License: GNU General Public License, version 2 (June 1991)
# Revision: 070401

#---------------------------------------------------------------------

# This script is based on the  February 24, 2007 release of Dave Leo's
# "mohave" wrapper. The most important changes are as follows:
#
#     a. The number of  backgrounds  has been  changed  [this distro's
#        version of the "mohave" dataset omits a few backgrounds]
#
#     b. The number of  tilesets has been changed  [this distro's ver-
#        sion of the "mohave" dataset omits a few tilesets]
#
#     c. The "layout" buttons have  been  moved up  [previously,  they
#        weren't visible on some displays]
#
#     d. The "play" button terminates  "mohave" after starting  "xmah-
#        jongg"
#
#     e. The "play" button  uses a  distro-specific  script  to  start
#        "xmahjongg"  [the script restarts  "mohave" after "xmahjongg"
#        exits]
#
#     f. The data-file directory paths have been modified.

#---------------------------------------------------------------------

# Mohave is a GUI front end for x-mahjongg.
# Mohave was written by legendary mahjongg afficionado 
# and man-about-town, Dave Leo, 
# in January 2007 and first posted at 
# [http://www.tikmark.com/Mohave/mohave.html] on Feb.06.2007
# Federal law prohibits use of this product.
# Ask your doctor if x-mahjongg is right for you.
#
#COPYRIGHT/LICENSE
#All source code is Copyright (C) 2007 by Dave Leo.
#This package is distributed under the GNU General Public License, Version
#2, or, at your discretion, any later version. The GNU General Public License
#is available via the Web at <http://www.gnu.org/copyleft/gpl.html>. The GPL
#is designed to allow you to alter and redistribute the package, as long as
#you do not remove that freedom from others.
#
#
#
 # window configure
 . configure -background #b3c0b3
 font create davesfont -family Courier -size 10 -weight normal
 . configure -padx 0 -pady 0
 #
 set frcolor #b3c0b3
 set textcolor #000000
 set buttoncolor #c0c0c0
 set buttforecolor #000000
 set pagecolor "rgb(200,205,195)"
 set buttonwidth 6
 set buttonheight 6
 set laybutts 8
 set padding 1
 set framepad 0
 set nexxtt 1
 set nexxttbg 1
 set tileset "mohaveset1"
 set bakk "bkgrd1"
 set scheme "dragon"
# ---------------------------------------------------------------------------------------------------
# redefine these directories as necessary for the version of xmahjongg
# on your computer
 set tiledir "/opt/xmahjongg/share/xmahjongg/tiles"
 set bkgrddir "/opt/xmahjongg/share/xmahjongg/backgrounds"
 set layoutdir "/opt/xmahjongg/share/xmahjongg/layouts"
 #
 # -----------------------------------------------------
frame .topframe \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -relief groove \
 -background $frcolor \
 -width 410
#
frame .midframe \
 -padx $framepad -pady $framepad\
 -borderwidth 0 \
 -background $frcolor \
 -width 451
frame .midframe2 \
 -padx $framepad -pady $framepad\
 -borderwidth 0 \
 -background $frcolor \
 -width 410
#
#
frame .bottomframe \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -relief groove \
 -background $frcolor \
 -width 410
frame .bottomframe2 \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -relief groove \
 -background $frcolor \
 -width 410
frame .bottomframe3 \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -relief groove \
 -background $frcolor \
 -width 410
frame .bottomframe4 \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -background $frcolor \
 -width 410
frame .bottomframe5 \
 -padx $framepad -pady $framepad\
 -borderwidth 2 \
 -background $frcolor \
 -width 410
#
# -----------------------------------file menu items 
#menubutton .topframe.file -text "File" -menu .topframe.file.menu\
#	-background #c0c0c0\
#	-relief groove \
#	-font davesfont
#menu .topframe.file.menu
#
#.topframe.file.menu add command -label "Play"\
#	-font davesfont \
#	-command { global tileset;
#	exec xmahjongg --bg $bakk --tileset $tileset &
#	}
#
#.topframe.file.menu add command -label "Exit"\
#	-font davesfont \
#	 -command {
#	set exitanswer [tk_messageBox -icon question -message "are you sure?" \
#	-parent . \
#	-title "Exit?" -type yesno];
#	if {$exitanswer ==yes} then { clipboard clear;
#	exit}
#	}
#
# -----------------------------create images for buttons -------------------------------
# need to create images before they can appear in buttons

# Replace 28 here with max. "mohaveset" image number plus one
for {set jkl 1} {$jkl < 28} {incr jkl} {
image create photo tileset$jkl.gif -file $tiledir/mohaveset$jkl.gif
}

# Replace 20 here with max. "bkgrd" image number plus one
for {set abc 1} {$abc < 20} {incr abc} {
image create photo bkgrd$abc.gif -file $bkgrddir/bkgrd$abc.gif
}
#
image create photo arena.gif -file $layoutdir/arena.gif
image create photo boar.gif -file $layoutdir/boar.gif
image create photo ceremo.gif -file $layoutdir/ceremo.gif
image create photo dragon.gif -file $layoutdir/dragon.gif
image create photo hare.gif -file $layoutdir/hare.gif
image create photo hrglass.gif -file $layoutdir/hrglass.gif
image create photo ox.gif -file $layoutdir/ox.gif
image create photo ram.gif -file $layoutdir/ram.gif
image create photo rooster.gif -file $layoutdir/rooster.gif
image create photo snake.gif -file $layoutdir/snake.gif

# -----------------------------create buttons ------------------------------------------

# Replace 27 here with max. "mohaveset" image number
button .topframe.nextiles \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "tiles>" \
 -padx $padding -pady $padding \
 -command {global nexxtt;
	incr nexxtt +1;
	if {$nexxtt > 27} then {set nexxtt 1};
	.midframe.settiles configure -image tileset$nexxtt.gif;
	set tileset mohaveset$nexxtt;
	global tileset;
 }

# Replace 27 here with max. "mohaveset" image number
button .topframe.prevtiles \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "<tiles" \
 -padx $padding -pady $padding \
 -command {global nexxtt;
	incr nexxtt -1;
	if {$nexxtt < 1} then {set nexxtt 27};
	.midframe.settiles configure -image tileset$nexxtt.gif;
	set tileset mohaveset$nexxtt;
	global tileset;
 }

# Replace 19 here with max. "bkgrd" image number
button .topframe.nextbg \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "bkgrd>" \
 -padx $padding -pady $padding \
 -command {global nexxttbg;
	incr nexxttbg +1;
	if {$nexxttbg > 19} then {set nexxttbg 1};
	.midframe.bg1 configure -image bkgrd$nexxttbg.gif;
	.midframe.bg2 configure -image bkgrd$nexxttbg.gif;
	set bakk bkgrd$nexxttbg;
	global bakk;
 }

# Replace 19 here with max. "bkgrd" image number
button .topframe.prevbg \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "<bkgrd" \
 -padx $padding -pady $padding \
 -command {global nexxttbg;
	incr nexxttbg -1;
	if {$nexxttbg < 1} then {set nexxttbg 19};
	.midframe.bg1 configure -image bkgrd$nexxttbg.gif;
	.midframe.bg2 configure -image bkgrd$nexxttbg.gif;
	set bakk bkgrd$nexxttbg;
	global bakk;
 }
button .topframe.play \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "play" \
 -padx $padding -pady $padding \
 -command { global tileset;
	exec runjongg xmahjongg --bg $bakk --tileset $tileset --layout $scheme &
    clipboard clear
    exit
	 }
#
button .topframe.exitb \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -width $buttonwidth \
 -text "exit" \
 -padx $padding -pady $padding \
 -command {set exitanswer [tk_messageBox -icon question -message "are you sure?" \
	-parent . \
	-title "Exit?" -type yesno];
	if {$exitanswer ==yes} then { clipboard clear;
	exit}
	 }
#
label .midframe.settiles \
 -background black \
 -foreground black \
 -font davesfont \
 -image tileset1.gif \
 -relief groove \
 -borderwidth 3 \
 -padx $padding -pady $padding 
label .midframe2.setlayout \
 -background black \
 -foreground black \
 -font davesfont \
 -image arena.gif \
 -relief groove \
 -borderwidth 3 \
 -padx $padding -pady $padding 
label .midframe.bg1 \
 -background black \
 -foreground black \
 -relief groove \
 -font davesfont \
 -padx $padding -pady $padding \
 -borderwidth 3 \
 -width 405\
 -height 50 \
 -image bkgrd1.gif 
label .midframe.bg2 \
 -background black \
 -foreground black \
 -relief groove \
 -font davesfont \
 -padx $padding -pady $padding \
 -borderwidth 3 \
 -width 405\
 -height 50 \
 -image bkgrd1.gif 
# ------------------------------------------------------------------------------------
#button .bottomframe.layout1 \
# -background $buttoncolor \
# -foreground $buttforecolor \
# -font davesfont \
# -padx $padding -pady $padding \
# -width $buttonwidth \
# -height $buttonheight \
# -text "layout1" \
# -command {
# }
button .bottomframe.arena \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "arena" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "arena";
	.midframe2.setlayout configure -image arena.gif;
	 }
button .bottomframe.boar \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "boar" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "boar";
	.midframe2.setlayout configure -image boar.gif;
	 }
button .bottomframe.ceremo \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "ceremo" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "ceremonial";
	.midframe2.setlayout configure -image ceremo.gif;
	 }
button .bottomframe.dragon \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "dragon" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "dragon";
	.midframe2.setlayout configure -image dragon.gif;
	 }
button .bottomframe.hare \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "hare" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "hare";
	.midframe2.setlayout configure -image hare.gif;
	 }
button .bottomframe2.hrglass \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "hglass" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "hourglass";
	.midframe2.setlayout configure -image hrglass.gif;
	 }
button .bottomframe2.ox \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "ox" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "ox";
	.midframe2.setlayout configure -image ox.gif;
	 }
button .bottomframe2.ram \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "ram" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "ram";
	.midframe2.setlayout configure -image ram.gif;
	 }
button .bottomframe2.rooster \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "roost" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "rooster";
	.midframe2.setlayout configure -image rooster.gif;
	 }
button .bottomframe2.snake \
 -background $buttoncolor \
 -foreground $buttforecolor \
 -font davesfont \
 -text "snake" \
 -padx $padding -pady $padding \
 -command { global scheme;
	set scheme "snake";
	.midframe2.setlayout configure -image snake.gif;
	 }
# ------------------------------------------------------------------------------------
#

pack configure .topframe.prevtiles \
.topframe.nextiles .topframe.prevbg \
.topframe.nextbg .topframe.play .topframe.exitb -expand 1 -fill x -side left -anchor n
#
pack .bottomframe.arena .bottomframe.boar .bottomframe.ceremo \
.bottomframe.dragon .bottomframe.hare -expand 1 -fill x -side left -anchor w
#
pack .bottomframe2.hrglass .bottomframe2.ox .bottomframe2.ram \
.bottomframe2.rooster .bottomframe2.snake -expand 1 -fill x -side left
#
pack .midframe.bg1 .midframe.settiles .midframe.bg2 -anchor w
pack .midframe2.setlayout -anchor w
#
pack .topframe .bottomframe .bottomframe2 .midframe .midframe2 -expand 1 -fill x -anchor w
