1 #######################################################################
2 # Micropolis.tcl, by Don Hopkins.
3 # Copyright (C) 2002 by Electronic Arts.
4 # This file defines the user interface of Micropolis.
5 # Modify at your own risk!
6 ########################################################################
7 # Micropolis, Unix Version. This game was released for the Unix platform
8 # in or about 1990 and has been modified for inclusion in the One Laptop
9 # Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
10 # you need assistance with this program, you may contact:
11 # http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or (at
16 # your option) any later version.
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details. You should have received a
22 # copy of the GNU General Public License along with this program. If
23 # not, see <http://www.gnu.org/licenses/>.
25 # ADDITIONAL TERMS per GNU GPL Section 7
27 # No trademark or publicity rights are granted. This license does NOT
28 # give you any right, title or interest in the trademark SimCity or any
29 # other Electronic Arts trademark. You may not distribute any
30 # modification of this program using the trademark SimCity or claim any
31 # affliation or association with Electronic Arts Inc. or its employees.
33 # Any propagation or conveyance of this program must include this
34 # copyright notice and these terms.
36 # If you convey this program (or any modifications of it) and assume
37 # contractual liability for the program to recipients of it, you agree
38 # to indemnify Electronic Arts for any liability that those contractual
39 # assumptions impose on Electronic Arts.
41 # You may not misrepresent the origins of this program; modified
42 # versions of the program must be marked as such and not identified as
43 # the original program.
45 # This disclaimer supplements the one included in the General Public
46 # License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
47 # PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
48 # OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
49 # SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
50 # DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
51 # INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
52 # FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
53 # RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
54 # USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
55 # INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
56 # MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
57 # UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
58 # WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
59 # CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
60 # ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
61 # JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
62 # WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
63 # CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
67 ########################################################################
69 ########################################################################
75 source $tk_library/wish.tcl
78 ########################################################################
80 ########################################################################
84 set State uninitialized
85 set CityName
"Micropolis"
88 set CityLibDir
$SimHome/cities
89 set CityDir
$CityLibDir
93 set BudgetPoliceFund
0
110 set AudioChannels
{mode edit fancy warning intercom
}
113 set BudgetTimerActive
0
115 set EvaluationsVisible
0
116 set SplashScreenDelay
5000
119 set ChatServer
"localhost"
121 set ChatConnection
{}
122 set NickName
"nickname"
123 set UserName
"username"
124 set ServerName
"servername"
125 set RealName
"realname"
126 set ChannelName
"#Micropolis"
130 set LocalHostName
"[exec hostname]"
138 set ShowingPicture
300
142 set VoteNames
{UseThisMap Ask Zone
}
143 set VotesForUseThisMap
{}
146 set VotesForBudget
{}
154 set EvaluationWindows
{}
156 set ScenarioWindows
{}
164 set HeadPanelWidth
360
165 set HeadPanelHeight
200
167 set MapPanelWidth
360
168 set MapPanelHeight
330
170 set NoticePanelWidth
360
171 set NoticePanelHeight
250
173 set SplashPanelWidth
1200
174 set SplashPanelHeight
900
176 set ScenarioPanelWidth
420
177 set ScenarioPanelHeight
440
186 {editor EditorWindows
}
189 {budget BudgetWindows
}
190 {evaluation EvaluationWindows
}
191 {scenario ScenarioWindows
}
192 {splash SplashWindows
}
195 {player PlayerWindows
}
196 {notice NoticeWindows
}
203 # 0 1 2 3 4 5 6 7 8 9 10 11 12 13
204 # type id callback param var x y w h normal over disabled checked checkedover
205 # ----------- --------------- --------------- ------- ------- --- --- --- --- ------- ---- -------- ------- -----------
206 set ScenarioButtons
{
207 { button load DoLoad
"" "" 70 238 157 90 "" @images
/button1hilite.xpm
"" }
208 { button generate DoGenerate
"" "" 62 392 157 90 "" @images
/button2hilite.xpm
"" }
209 { button quit DoQuit
"" "" 68 544 157 90 "" @images
/button3hilite.xpm
"" }
210 { button about DoAbout
"" "" 101 705 157 90 "" @images
/button4hilite.xpm
"" }
211 { checkbox easy DoLevel
0 "" 982 106 190 70 "" @images
/checkbox1hilite.xpm
"" @images
/checkbox1checked.xpm
@images
/checkbox1hilitechecked.xpm
}
212 { checkbox medium DoLevel
1 "" 982 176 190 70 "" @images
/checkbox2hilite.xpm
"" @images
/checkbox2checked.xpm
@images
/checkbox2hilitechecked.xpm
}
213 { checkbox hard DoLevel
2 "" 982 246 190 70 "" @images
/checkbox3hilite.xpm
"" @images
/checkbox3checked.xpm
@images
/checkbox3hilitechecked.xpm
}
214 { button left DoLeft
"" "" 540 375 50 50 "" @images
/lefthilite.xpm
@images
/leftdisabled.xpm
}
215 { button right DoRight
"" "" 841 375 50 50 "" @images
/righthilite.xpm
@images
/rightdisabled.xpm
}
216 { button play DoPlay
"" "" 625 376 180 50 "" @images
/playhilite.xpm
"" }
217 { button scenario1 DoPickScenario
"1" "" 310 451 209 188 "" @images
/scenario1hilite.xpm
"" }
218 { button scenario2 DoPickScenario
"2" "" 519 451 209 188 "" @images
/scenario2hilite.xpm
"" }
219 { button scenario3 DoPickScenario
"3" "" 727 450 209 188 "" @images
/scenario3hilite.xpm
"" }
220 { button scenario4 DoPickScenario
"4" "" 936 450 209 188 "" @images
/scenario4hilite.xpm
"" }
221 { button scenario5 DoPickScenario
"5" "" 310 639 209 188 "" @images
/scenario5hilite.xpm
"" }
222 { button scenario6 DoPickScenario
"8" "" 519 639 209 188 "" @images
/scenario6hilite.xpm
"" }
223 { button scenario7 DoPickScenario
"7" "" 728 638 209 188 "" @images
/scenario7hilite.xpm
"" }
224 { button scenario8 DoPickScenario
"6" "" 937 638 209 188 "" @images
/scenario8hilite.xpm
"" }
227 # Disabled until we handle mouse events on the map itself.
228 # { button map DoMap "" "" 516 30 396 338 "" @images/maphilite.xpm }
231 ########################################################################
237 {-*-dejavu lgc sans-medium-r-normal-
*-90-*}
240 {-*-dejavu lgc sans-medium-r-normal-
*-80-*}
243 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
246 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
249 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
252 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
255 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
258 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
261 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
266 ########################################################################
270 {Micropolis Overall Map
}
271 {Residential Zone Map
}
272 {Commercial Zone Map
}
273 {Industrial Zone Map
}
276 {Population Density Map
}
278 {Traffic Density Map
}
279 {Pollution Desity Map
}
283 {Police Coverage Map
}
289 leftframe.tools.palletres
290 leftframe.tools.palletcom
291 leftframe.tools.palletind
292 leftframe.tools.palletfire
293 leftframe.tools.palletquery
294 leftframe.tools.palletpolice
295 leftframe.tools.palletwire
296 leftframe.tools.palletbulldozer
297 leftframe.tools.palletrail
298 leftframe.tools.palletroad
299 leftframe.tools.palletchalk
300 leftframe.tools.palleteraser
301 leftframe.tools.palletstadium
302 leftframe.tools.palletpark
303 leftframe.tools.palletseaport
304 leftframe.tools.palletcoal
305 leftframe.tools.palletnuclear
306 leftframe.tools.palletairport
310 set EditorPalletImages
{
311 res com ind fire qry pol
312 wire dozr rail road chlk ersr
313 stad park seap coal nuc airp
317 set EditorPalletSounds
{
318 Res Com Ind Fire Query Police
319 Wire Bulldozer Rail Road Chalk Eraser
320 Stadium Park Seaport Coal Nuclear Airport
328 leftframe.right.money
329 leftframe.right.crime
330 leftframe.right.pollution
334 set GraphPalletImages
{
335 res com ind mony crim poll
339 set GraphYearPallets
{
340 leftframe.year.year10
341 leftframe.year.year120
345 set GraphYearPalletImages
{ 10 120 }
349 { {a
} {Residential Zone
} {$100}}
350 { {a
} {Commercial Zone
} {$100}}
351 { {an
} {Industrial Zone
} {$100}}
352 { {a
} {Fire Station
} {$500}}
353 { {a
} {Query
} {free
}}
354 { {a
} {Police Station
} {$500}}
356 { {a
} {Bulldozer
} {$1}}
359 { {a
} {Chalk
} {free
}}
360 { {an
} {Eraser
} {free
}}
361 { {a
} {Stadium
} {$5,000}}
363 { {a
} {Seaport
} {$3,000}}
364 { {a
} {Coal Power Plant
} {$3,000}}
365 { {a
} {Nuclear Power Plant
} {$5,000}}
366 { {an
} {Airport
} {$10,000}}
367 { {a
} {Network
} {$1,000}}
371 set DynamicDataNames
{
382 ########################################################################
384 ########################################################################
387 wm title .
{Micropolis Root
}
390 if {"[sim Platform]" == "msdos"} {
411 # The next three lines have no effect on the OLPC, where we don't provide
412 # the font in res (because it's already in the system fonts). These lines
413 # are for other systems that lack the font.
414 set FontPath
"[pwd]/res/dejavu-lgc"
415 system
"xset -fp $FontPath >&/dev/null"
416 system
"xset +fp $FontPath >&/dev/null"
419 ########################################################################
421 ########################################################################
424 proc Message
{id color title msg
{props
{}}} {
426 set Messages
($id) [list $color $title $msg $props]
430 Message
1 #7f7fff {DULLSVILLE, USA 1900} \
431 {Things haven't changed much around here in the last hundred years or so and the residents are beginning to get bored. They think Dullsville could be the next great city with the right leader.
433 It is your job to attract new growth and development
, turning Dullsville into a Metropolis within
30 years.
}
435 Message
2 #7f7fff {SAN FRANCISCO, CA. 1906} \
436 {Damage from the earthquake was minor compared to that of the ensuing fires
, which took days to control.
1500 people died.
438 Controlling the fires should be your initial concern. Then clear the rubble and start rebuilding. You have
5 years.
}
440 Message
3 #7f7fff {HAMBURG, GERMANY 1944} \
441 {Allied fire-bombing of German cities in WWII caused tremendous damage and loss of life. People living in the inner cities were at greatest risk.
443 You must control the firestorms during the bombing and then rebuild the city
after the war. You have
5 years.
}
445 Message
4 #7f7fff {BERN, SWITZERLAND 1965} \
446 {The roads here are becoming more congested every day
, and the residents are upset. They demand that you do something about it.
448 Some have suggested a mass transit system as the answer
, but this would require major rezoning in the downtown area. You have
10 years.
}
450 Message
5 #7f7fff {TOKYO, JAPAN 1957} \
451 {A large reptilian creature has been spotted heading
for Tokyo bay. It seems to be attracted to the heavy levels of industrial pollution there.
453 Try to control the fires
, then rebuild the industrial center. You have
5 years.
}
455 Message
6 #7f7fff {DETROIT, MI. 1972} \
456 {By
1970, competition from overseas and other economic factors pushed the once
"automobile capital of the world" into recession. Plummeting land values and unemployment then increased crime in the inner-city to chronic levels.
458 You have
10 years to reduce crime and rebuild the industrial base of the city.
}
460 Message
7 #7f7fff {BOSTON, MA. 2010} \
461 {A major meltdown is about to occur at one of the new downtown nuclear reactors. The area in the vicinity of the reactor will be severly contaminated by radiation
, forcing you to restructure the city around it.
463 You have
5 years to get the situation under control.
}
465 Message
8 #7f7fff {RIO DE JANEIRO, BRAZIL 2047} \
466 {In the mid-21st century
, the greenhouse effect raised
global temperatures
6 degrees F. Polar icecaps melted and raised sea levels worldwide. Coastal areas were devastated by flood and erosion.
468 You have
10 years to turn this swamp back into a city again.
}
470 Message
9 #ffa500 {Query Zone Status} \
478 {{view
{PanView
$v $QueryX $QueryY}}}
480 Message
10 #ff4f4f {POLLUTION ALERT!} \
481 {Pollution in your city has exceeded the maximum allowable amounts established by the Micropolis Pollution Agency. You are running the risk of grave ecological consequences.
483 Either clean up your act or
open a gas mask concession at city hall.
} \
484 {{view
{PanView
$v [sim PolMaxX
] [sim PolMaxY
]}}}
486 Message
11 #ff4f4f {CRIME ALERT!} \
487 {Crime in your city is our of hand. Angry mobs are looting and vandalizing the central city. The president will
send in the national guard soon
if you cannot control the problem.
} \
488 {{view
{PanView
$v [sim CrimeMaxX
] [sim CrimeMaxY
]}}}
490 Message
12 #ff4f4f {TRAFFIC WARNING!} \
491 {Traffic in this city is horrible. The city gridlock is expanding. The commuters are getting militant.
493 Either build more roads and rails or get a bulletproof limo.
} \
494 {{view
{PanView
$v [sim TrafMaxX
] [sim TrafMaxY
]}}}
496 Message
20 #ff4f4f {FIRE REPORTED!} \
497 "A fire has been reported!" \
498 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
500 Message
21 #ff4f4f {MONSTER ATTACK!} \
501 "A large reptilian creature has been spotted in the water. It seems to be attracted to areas of high pollution. There is a trail of destruction wherever it goes. \
502 All you can do is wait till he leaves, then rebuild from the rubble." \
503 {{view
{FollowView
$v monster
}}}
505 # XXX: write more text
506 Message
22 #ff4f4f {TORNADO ALERT!} \
507 {A tornado has been reported
! There's nothing you can do to stop it
, so you'd better prepare to clean up
after the disaster
!} \
508 {{view
{FollowView
$v tornado
}}}
510 # XXX: write more text
511 Message
23 #ff4f4f {EARTHQUAKE!} \
512 {A major earthquake has occurred
! Put out the fires as quickly as possible
, before they spread
, then reconnect the power
grid and rebuild the city.
} \
513 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
515 # XXX: write more text
516 Message
24 #ff4f4f {PLANE CRASH!} \
517 {A plane has crashed
!} \
518 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
520 # XXX: write more text
521 Message
25 #ff4f4f {SHIPWRECK!} \
522 {A ship has wrecked
!} \
523 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
525 # XXX: write more text
526 Message
26 #ff4f4f {TRAIN CRASH!} \
527 {A train has crashed
!} \
528 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
530 # XXX: write more text
531 Message
27 #ff4f4f {HELICOPTER CRASH!} \
532 {A helicopter has crashed
!} \
533 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
535 Message
30 #ff4f4f {FIREBOMBING REPORTED!} \
536 {Firebombs are falling
!!} \
537 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
539 Message
35 #7fff7f {TOWN} \
540 {Congratulations
, your village has grown to town status. You now have
2,000 citizens.
} \
541 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
543 Message
36 #7fff7f {CITY} \
544 {Your town has grown into a full sized city
, with a current population of
10,000. Keep up the good work
!} \
545 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
547 Message
37 #7fff7f {CAPITAL} \
548 {Your city has become a capital. The current population here is
50,000. Your political future looks bright.
} \
549 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
551 Message
38 #7fff7f {METROPOLIS} \
552 {Your capital city has now achieved the status of metropolis. The current population is
100,000. With your management skills
, you should seriously consider running
for governor.
} \
553 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
555 Message
39 #7fff7f {MEGALOPOLIS} \
556 {Congratulation
, you have reached the highest category of urban development
, the megalopolis.
558 If you manage to reach this level
, send us email at micropolis
@laptop.org or
send us a copy of your city. We might do something interesting with it.
} \
559 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
561 Message
40 #7fff7f {MEGALINIUM} \
562 {Congratulation
, you have reached the end of
time!
564 Because of the toroidal nature of the the Micropolis Space
/Time Continuum
, your city has wrapped back in
time to
1900!} \
565 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
567 # XXX: write more text
568 Message
41 #ff4f4f {HEAVY TRAFFIC!} \
570 reporting heavy traffic
!} \
571 {{view
{FollowView
$v helicopter
}}}
573 # XXX: write more text
574 Message
42 #ff4f4f {FLOODING REPORTED!} \
575 {Flooding has been been reported along the water's edge
!} \
576 {{view
{PanView
$v [sim FloodX
] [sim FloodY
]}}}
578 Message
43 #ff4f4f {NUCLEAR MELTDOWN!} \
579 {A nuclear meltdown has occured at your power plant. You are advised to avoid the area until the radioactive isotopes decay.
581 Many generations will confront this problem before it goes away
, so don't hold your breath.
} \
582 {{view
{PanView
$v [sim MeltX
] [sim MeltY
]}}}
585 Message
44 #ff4f4f {RIOTS!} \
586 {The citizens are rioting in the streets
, setting cars and houses on fire
, and bombing government buildings and businesses
!
588 All media coverage is blacked out
, while the fascist pigs beat the poor citizens into submission.
}
590 Message
46 #ff4f4f {NO SOUND SERVER!} \
591 {There is no sound server running on your X11 display
"%s". You won't hear any noise unless you run a sound server
, and turn the sound back on in the
"Options" menu.
}
593 Message
48 #7f7fff {Start a New City} \
594 {Build your very own city from the ground up
, starting with this map of uninhabited land.
}
596 Message
49 #7f7fff {Restore a Saved City} \
597 {This city was saved in the
file named
: %s
}
599 Message
100 #7fff7f {YOU'RE A WINNER!} \
600 {Your mayorial skill and city planning expertise have earned you the KEY TO THE CITY. Local residents will erect monuments to your glory and name their first-born children
after you. Why not run
for governor?
} \
601 {{middle
{@images
/key2city.xpm
}}}
603 Message
200 #ff4f4f {IMPEACHMENT NOTICE!} \
604 {The entire population of this city has finally had enough of your inept planning and incompetant management. An angry mob
-- led by your mother
-- has been spotted in the vicinity of city hall.
606 You should seriously consider taking an extended vacation
-- NOW.
(Or
read the manual and try again.
)}
608 Message
300 #ffd700 {About Micropolis} \
609 "Micropolis Version [sim Version] Copyright (C) 2007
611 Based on the Original Micropolis Concept and Design
613 TCL/Tk User Interface Designed and Created
614 by Don Hopkins, DUX Software.
615 Ported to Linux, Optimized and Adapted for OLPC
617 Licensed under the GNU General Public License,
618 version 3, with additional conditions."
621 ########################################################################
623 ########################################################################
626 option add
*CheckButton.relief flat
627 option add
*Dialog.cursor top_left_arrow
628 option add
*Entry.relief sunken
629 option add
*Frame.borderWidth
0
630 option add
*Listbox.relief sunken
631 option add
*Scrollbar.relief sunken
632 option add
*RadioButton.anchor w
633 option add
*RadioButton.relief flat
635 option add
*background
#b0b0b0
636 option add
*foreground
#000000
637 option add
*activeBackground
#d0d0d0
638 option add
*activeForeground
#000000
639 option add
*disabledForeground
""
640 option add
*selectBackground
#d0d0d0
641 option add
*selectForeground
#000000
642 #option add *selector #ffff80
643 option add
*selector
#bf0000
645 option add
*Scrollbar.Background
#b0b0b0
646 option add
*Scrollbar.Foreground
#d0d0d0
647 option add
*Interval.Background
#b0b0b0
648 option add
*Interval.Foreground
#000000
649 option add
*Interval.activeForeground
#d0d0d0
650 option add
*Interval.sliderForeground
#b0b0b0
651 option add
*Scale.activeForeground
#d0d0d0
652 option add
*Scale.sliderForeground
#b0b0b0
653 option add
*PieMenu.activeBackground
#b0b0b0
655 option add Mwm
*Micropolis.clientDecoration
-maximize
658 ########################################################################
660 ########################################################################
663 bind all
<Help
> {HandleHelp
%W
%x
%y
%X
%Y
}
664 bind all
<Shift-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
665 bind all
<Meta-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
666 bind all
<Shift-Meta-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
669 ########################################################################
671 ########################################################################
690 puts stderr
"$errorInfo"
698 proc NoFunction
{args
} {}
701 proc LinkWindow
{fromname to
} {
703 set WindowLinks
($fromname) $to
707 proc WindowLink
{fromname
} {
710 catch {set to
$WindowLinks($fromname)}
715 proc DeleteWindow
{sym name win
} {
716 set head
[WindowLink
$win.head
]
717 LinkWindow
$head.
$sym {}
719 set wins
[eval ident
"\$$name"]
720 set i
[lsearch $wins $win]
722 set $name [lreplace $wins $i $i]
728 proc Font
{win name
} {
729 global FontInfo FontCache HeadWindows
730 set scr
[winfo screen
$win]
733 set font $FontCache($scr,$name)
738 set label $FontCache($scr)
740 if {"$label" == ""} {
741 foreach head
$HeadWindows {
742 if {"[winfo screen $head]" == "$scr"} {
743 set label $head.fontlabel
744 label $label -text "X11 Sucks" -font fixed
745 set FontCache
($scr) $label
750 set fonts
[keylget FontInfo
$name]
751 foreach font $fonts {
752 #echo "Configuring font $font on $label"
753 if {[catch "$label config -font \"$font\""] == 0} {
766 set FontCache
($scr,$name) $font
772 proc Color
{win color mono
} {
773 if {[winfo screendepth
$win] == 1} {
781 ########################################################################
782 # Window Definition Functions
783 ########################################################################
786 proc MakeWindow.head
{{display
":0"}} {
788 source $ResourceDir/whead.tcl
793 proc MakeWindow.editor
{head
{display
":0"}} {
795 source $ResourceDir/weditor.tcl
800 proc MakeWindow.map
{head
{display
":0"}} {
802 source $ResourceDir/wmap.tcl
807 proc MakeWindow.graph
{head
{display
":0"}} {
809 source $ResourceDir/wgraph.tcl
814 proc MakeWindow.budget
{head
{display
":0"}} {
816 source $ResourceDir/wbudget.tcl
821 proc MakeWindow.evaluation
{head
{display
":0"}} {
823 source $ResourceDir/weval.tcl
828 proc MakeWindow.splash
{head
{display
":0"}} {
830 source $ResourceDir/wsplash.tcl
835 proc MakeWindow.scenario
{head
{display
":0"}} {
837 source $ResourceDir/wscen.tcl
842 proc MakeWindow.
file {head
{display
":0"}} {
844 source $ResourceDir/wfile.tcl
849 proc MakeWindow.ask
{head
{display
":0"}} {
851 source $ResourceDir/wask.tcl
856 proc MakeWindow.player
{head
{display
":0"}} {
858 source $ResourceDir/wplayer.tcl
863 proc MakeWindow.notice
{head
{display
":0"}} {
865 source $ResourceDir/wnotice.tcl
869 proc MakeWindow.help
{head
{display
":0"}} {
871 source $ResourceDir/whelp.tcl
875 proc MakeWindow.frob
{head
{display
":0"}} {
877 source $ResourceDir/wfrob.tcl
882 ########################################################################
884 ########################################################################
887 proc UIInitializeSound
{} {
891 proc UIShutDownSound
{} {
895 proc UIDoSoundOn
{win cmd
} {
896 global Sound SoundServers
898 set win
[WindowLink
[winfo toplevel $win].head
]
899 if {[lsearch $SoundServers $win] != -1} {
900 set cmd
"send -quick -server $win Sound sound $cmd"
902 # XXX: Lost a sound server...
910 proc UIDoSound
{cmd
} {
911 global Sound SoundServers
913 foreach win
$SoundServers {
914 set foo
"send -quick -server $win Sound $cmd"
916 # XXX: Lost a sound server...
924 proc KillSoundServers
{} {
926 foreach win
$SoundServers {
927 set foo
"send -quick -server $win Sound KillSoundServer"
934 proc UISetChannelVolume
{win chan vol
} {
935 UIDoSoundOn
$win "channel $chan -volume $vol"
939 proc EchoPlaySound
{soundspec
} {
940 # Temporary workaround to tell Python Sugar app to play sound.
943 echo PlaySound
[lindex $soundspec 0]
948 proc UIMakeSoundOn
{win chan sound
{opts
""}} {
949 # Send message to Python to play sound.
952 #UIDoSoundOn $win "play $sound -replay -channel $chan $opts"
956 proc UIStartSoundOn
{win chan sound
{opts
""}} {
957 # Send message to Python to play sound.
960 #UIDoSoundOn $win "play $sound -replay -channel $chan -repeat 100 $opts"
964 proc UIStopSoundOn
{win chan sound
{opts
""}} {
965 UIDoSoundOn
$win "stop $sound"
969 proc UIMakeSound
{chan sound
{opts
""}} {
970 # Send message to Python to play sound.
973 #UIDoSound "sound play $sound -replay -channel $chan $opts"
977 proc UIStartSound
{chan sound
{opts
""}} {
978 # Send message to Python to play sound.
981 #UIDoSound "sound play $sound -channel $chan -repeat 100 $opts"
985 proc UIStopSound
{chan sound
{opts
""}} {
986 UIDoSound
"sound stop $sound"
990 proc SetupSoundServer
{win
} {
995 proc AddSoundServer
{win
} {
997 set i
[lsearch $SoundServers $win]
999 set SoundServers
[linsert $SoundServers 0 $win]
1004 proc LostSoundServer
{win
} {
1005 DeleteSoundServer
$win
1006 # UIShowPictureOn [WindowLink $win.head] 46 [winfo screen $win]
1010 proc DeleteSoundServer
{win
} {
1012 set i
[lsearch $SoundServers $win]
1014 set SoundServers
[lreplace $SoundServers $i $i]
1019 proc UISoundOff
{} {
1023 proc MonsterSpeed
{} {
1024 return [expr "[sim Rand 40] + 70"]
1028 proc ExplosionPitch
{} {
1029 return [expr "[sim Rand 20] + 90"]
1034 return [expr "[sim Rand 20] + 90"]
1038 ########################################################################
1039 # Global Window Handlers
1042 proc WithdrawAll
{} {
1060 proc ShowInitial
{} {
1068 ########################################################################
1069 # Head Window Handlers
1072 proc PrepHead
{head
} {
1079 WithdrawHeadOf
$head
1083 after 1000 "WithdrawSplashOf $head"
1084 WithdrawHeadOf
$head
1085 ShowScenarioOf
$head
1089 WithdrawSplashOf
$head
1090 WithdrawScenarioOf
$head
1095 ReShowPictureOn
$head
1103 proc ShowHeadOf
{head
} {
1108 proc WithdrawHeadOf
{head
} {
1115 foreach win
$HeadWindows {
1121 proc WithdrawHeads
{} {
1123 foreach win
$HeadWindows {
1129 proc DeleteHeadWindow
{head
} {
1136 foreach win
$HeadWindows {
1142 proc InitHead
{win
} {
1143 set w
[WindowLink
$win.
text]
1144 $w configure
-state normal
1147 $w configure
-state disabled
1149 if {[sim MultiPlayerMode
]} {
1150 set w
[WindowLink
$win.
entry]
1161 proc InitAllHeadMenus
{} {
1164 foreach win
$HeadWindows {
1170 proc InitHeadMenus
{win
} {
1172 set m0
[WindowLink
$win.m0
]
1173 set m1
[WindowLink
$win.m1
]
1174 set m2
[WindowLink
$win.m2
]
1175 set m3
[WindowLink
$win.m3
]
1176 set m4
[WindowLink
$win.m4
]
1177 set b0
[WindowLink
$win.b0
]
1178 set b1
[WindowLink
$win.b1
]
1179 set b2
[WindowLink
$win.b2
]
1180 set b3
[WindowLink
$win.b3
]
1181 set b4
[WindowLink
$win.b4
]
1195 # When in multi player mode there is an extra menu
1196 # item to add another player, before the quit item,
1197 # so compensate for it here.
1198 if {[sim MultiPlayerMode
]} {
1203 $b0 config
-state normal
1204 $b2 config
-state disabled
1205 $b4 config
-state disabled
1210 # When in multi player mode there is an extra menu
1211 # item to add another player, before the quit item,
1212 # so compensate for it here.
1213 if {[sim MultiPlayerMode
]} {
1218 $b0 config
-state normal
1219 $b2 config
-state normal
1220 $b4 config
-state normal
1226 proc UIDisaster
{win cmd action
} {
1227 AskQuestion
[Color
$win #ff0000 #ffffff] "Cause a Disaster" \
1228 "Oh no! Do you really want to $action" \
1229 "{No way!} Disaster.No {WithdrawAsks}" \
1231 "{I guess so.} Disaster.Yes {WithdrawAsks ; $cmd}"
1235 proc CrushHead
{head
} {
1236 global SubWindows VoteNames
1238 foreach foo
$VoteNames {
1240 set votes
[eval ident
\$VotesFor$foo]
1241 set i
[lsearch $votes $head]
1243 set VotesFor
$foo [lreplace $votes $i $i]
1247 foreach foo
$SubWindows {
1248 set sym
[lindex $foo 0]
1249 set name
[lindex $foo 1]
1251 set wins
[eval ident
"\$$name"]
1253 if {[WindowLink
$win.head
] == $head} {
1254 DeleteWindow
$sym $name $win
1261 proc ChatDown
{win
} {
1283 global ChatConnection
1285 DoSendMessage
"Opening Connection to Chat Server $ChatServer socket $ChatSocket ..." status
1287 set ChatConnection
{}
1289 set ChatConnection
[connect
$ChatServer $ChatSocket]
1292 if {$ChatConnection == {}} then
{
1293 DoSendMessage
"Sorry, I could not open a connection to chat server $ChatServer socket $ChatSocket." status
1296 filehandler
$ChatConnection r
"ReceiveChat"
1307 puts $ChatConnection "USER $UserName $HostName $ServerName $RealName\r\n" nonewline
1308 puts $ChatConnection "NICK $NickName\r\n" nonewline
1309 puts $ChatConnection "JOIN $ChannelName\r\n" nonewline
1310 flush $ChatConnection
1315 proc ReceiveChat
{mode f
} {
1316 # DoSendMessage "ReceiveChat: MODE $mode F $f"
1320 if {[string first
{:} $msg]} {
1324 set from
[lindex $msg 0]
1325 set cmd
[string tolower
[lindex $msg 1]]
1329 if {($cmd == "privmsg") ||
1330 ($cmd == "notice")} then
{
1332 set chan
[lindex $msg 2]
1333 set i
[expr "[string length $from] + 1 + [string length $cmd] + 1 + [string length $chan] + 2"]
1334 set j
[expr "[string length $msg] - 2"]
1335 set line
[string range
$msg $i $j]
1336 set chan
[string range
$chan 1 [string length
$chan]]
1337 set from
[string range
$from 1 [expr "[string length $from] - 1"]]
1338 set from
[split $from {!}]
1339 set from
[lindex $from 0]
1340 DoSendMessage
"$from> $line"
1343 if {$handled == 0} {
1344 set msg
[string range
$msg \
1345 [expr "[string length $from] + 1"] \
1346 [expr "[string length $msg] - 2"]]
1352 proc SendChatMessage
{msg win
} {
1353 global ChatConnection ChannelName NickName
1359 if {[string range
$msg 0 0] == "/"} {
1360 set cmd
[string range
$msg 1 [string length
$msg]]
1361 DoSendMessage
"$NickName> \[$cmd\]"
1364 set cmd
"PRIVMSG $ChannelName :$msg\r\n"
1365 DoSendMessage
"$NickName> $msg"
1372 puts $ChatConnection $cmd nonewline
1373 flush $ChatConnection
1378 DoSendMessage
"IRC Broke the connection"
1388 global ChatConnection
1390 DoSendMessage
"Closing Connection to Chat Server." status
1393 puts $ChatConnection "QUIT\r\n" nonewline
1394 flush $ChatConnection
1395 $ChatConnection close
1398 set ChatConnection
{}
1403 proc DoEnterMessage
{win var
} {
1406 set msg
[eval ident
"\$\{$var\}"]
1408 if {$Chatting} then
{
1409 SendChatMessage
$msg $win
1417 proc DoEvalMessage
{win var
} {
1419 set command
[eval ident
"\$\{$var\}"]
1421 DoSendMessage
"Evaluating TCL: $command"
1422 catch {uplevel #0 $command} result
1423 DoSendMessage
"Result: $result"
1427 proc DoSendMessage
{msg
{tag
message}} {
1429 foreach win
$HeadWindows {
1430 appendWithTag
[WindowLink
$win.
text] $tag "$msg"
1435 proc UISetMessage
{msg
{tag status
}} {
1436 global DoMessages EditorWindows HeadWindows
1438 if {$DoMessages == 0} {
1442 foreach win
$EditorWindows {
1443 [WindowLink
$win.
message] configure
-text "$msg"
1446 foreach win
$HeadWindows {
1447 appendWithTag
[WindowLink
$win.
text] $tag "$msg"
1454 proc appendWithTag
{w tag
text} {
1458 set start
[$w index end
]
1459 $w configure
-state normal
1460 if {$start > $MaxLines} then
{
1461 $w delete
0.0 $ShrinkLines.0
1462 set start
[$w index end
]
1464 $w insert end
"${text}\n"
1465 $w tag add
$tag $start {end
- 1 char
}
1466 $w configure
-state disabled
1467 $w yview
-pickplace {end
- 1 char
}
1471 ########################################################################
1472 # Budget Window Handlers
1475 proc ShowBudgetOf
{head
} {
1476 set win
[WindowLink
$head.budget
]
1478 set win
[MakeWindow.budget
$head [winfo screen
$head]]
1487 proc ShowBudgets
{} {
1488 global HeadWindows BudgetsVisible
1489 set BudgetsVisible
1
1490 foreach win
$HeadWindows {
1496 proc WithdrawBudgets
{} {
1497 global BudgetWindows BudgetsVisible
1498 foreach win
$BudgetWindows {
1502 set BudgetsVisible
0
1506 proc BudgetContinue
{{win
""}} {
1507 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1509 if {([sim RoadFund
] != $BudgetRoadFund) ||
1510 ([sim FireFund
] != $BudgetFireFund) ||
1511 ([sim PoliceFund
] != $BudgetPoliceFund) ||
1512 ([sim TaxRate
] != $BudgetTaxRate)} {
1513 UISetMessage
"The budget was changed."
1515 UISetMessage
"The budget wasn't changed."
1523 proc BudgetReset
{{win
""}} {
1524 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1525 if {([sim RoadFund
] != $BudgetRoadFund) ||
1526 ([sim FireFund
] != $BudgetFireFund) ||
1527 ([sim PoliceFund
] != $BudgetPoliceFund) ||
1528 ([sim TaxRate
] != $BudgetTaxRate)} {
1529 UISetMessage
"The budget was reset."
1530 if {[sim Players
] > 1} {
1531 UIMakeSound edit Sorry
1534 UISetMessage
"The budget was reset."
1536 sim RoadFund
$BudgetRoadFund
1537 sim FireFund
$BudgetFireFund
1538 sim PoliceFund
$BudgetPoliceFund
1539 sim TaxRate
$BudgetTaxRate
1545 proc BudgetCancel
{{win
""}} {
1553 proc SetTaxRate
{rate
} {
1558 proc BudgetSetTaxRate
{rate
} {
1564 proc BudgetSetRoadFund
{percent
} {
1565 sim RoadFund
$percent
1570 proc BudgetSetFireFund
{percent
} {
1571 sim FireFund
$percent
1576 proc BudgetSetPoliceFund
{percent
} {
1577 sim PoliceFund
$percent
1582 proc UIShowBudgetAndWait
{} {
1583 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1584 if {$OldBudget == 0} {
1585 set BudgetRoadFund
[sim RoadFund
]
1586 set BudgetFireFund
[sim FireFund
]
1587 set BudgetPoliceFund
[sim PoliceFund
]
1588 set BudgetTaxRate
[sim TaxRate
]
1592 UISetMessage
"Pausing to set the budget ..."
1598 sim UpdateBudgetWindow
1602 proc ToggleBudgetTimer
{} {
1603 global BudgetTimerActive
1604 if {$BudgetTimerActive} {
1612 proc StopBudgetTimer
{} {
1613 global BudgetTimerActive
1614 set BudgetTimerActive
0
1619 proc StartBudgetTimer
{} {
1620 global BudgetTimerActive BudgetTimer BudgetTimeout
1622 set BudgetTimerActive
$me
1623 set BudgetTimer
$BudgetTimeout
1625 after 1000 TickBudgetTimer
$me
1629 proc RestartBudgetTimer
{} {
1630 global BudgetTimerActive
1631 if {$BudgetTimerActive} {
1638 proc UpdateBudgetTimer
{} {
1639 global BudgetWindows BudgetTimerActive BudgetTimer
1640 if {$BudgetTimerActive} {
1641 set text [format "Auto Cancel In %d Seconds (click to disable)" $BudgetTimer]
1643 set text [format "Enable Auto Cancel (currently disabled)"]
1645 foreach win
$BudgetWindows {
1646 set t
[WindowLink
$win.timer
]
1647 $t config
-text "$text"
1652 proc TickBudgetTimer
{me
} {
1653 global BudgetTimerActive BudgetTimer BudgetTimeout
1654 if {$BudgetTimerActive == $me} {
1656 if {$BudgetTimer < 0} {
1662 after 1000 TickBudgetTimer
$me
1668 proc FireBudgetTimer
{} {
1678 proc ToggleAutoBudget
{} {
1681 #echo "ToggleAutoBudget found on, clearing"
1684 #echo "ToggleAutoBudget found off, setting"
1690 proc UIUpdateBudget
{} {
1695 proc UpdateAutoBudget
{} {
1696 global BudgetWindows AutoBudget
1697 if {[sim AutoBudget
]} {
1698 set text "Disable Auto Budget (currently enabled)"
1700 set text "Enable Auto Budget (currently disabled)"
1702 #echo "UpdateAutoBudget $AutoBudget $text"
1703 foreach win
$BudgetWindows {
1704 set t
[WindowLink
$win.autobudget
]
1705 $t config
-text "$text"
1710 proc UISetBudget
{cashflow previous current collected taxrate
} {
1711 global BudgetWindows BudgetsVisible
1713 #echo "UISetBudgetValues $taxrate $BudgetsVisible"
1715 if {$BudgetsVisible} {
1717 foreach win
$BudgetWindows {
1718 set w
[WindowLink
$win.cashflow
]
1719 set old
[lindex [$w configure
-text] 4]
1720 if {$old != $cashflow} {
1721 $w configure
-text $cashflow
1723 set w
[WindowLink
$win.previous
]
1724 set old
[lindex [$w configure
-text] 4]
1725 if {$old != $previous} {
1726 $w configure
-text $previous
1728 set w
[WindowLink
$win.current
]
1729 set old
[lindex [$w configure
-text] 4]
1730 if {$old != $current} {
1731 $w configure
-text $current
1733 set w
[WindowLink
$win.collected
]
1734 set old
[lindex [$w configure
-text] 4]
1735 if {$old != $collected} {
1736 $w configure
-text $collected
1739 set w
[WindowLink
$win.taxrate
]
1741 if {$old != $taxrate} {
1745 set w
[WindowLink
$win.taxlabel
]
1746 set old
[lindex [$w configure
-text] 4]
1749 $w configure
-text $new
1755 foreach win
$HeadWindows {
1757 set w
[WindowLink
$win.taxrate
]
1759 if {$old != $taxrate} {
1760 # FIXME: this might not work if the slider is disabled in multi player mode.
1764 set w
[WindowLink
$win.taxlabel
]
1765 set old
[lindex [$w configure
-text] 4]
1766 set new
"Tax Rate: $taxrate%"
1768 $w configure
-text $new
1774 proc UISetBudgetValues
{roadgot roadwant roadpercent policegot policewant policepercent firegot firewant firepercent
} {
1775 global BudgetWindows BudgetsVisible
1777 if {$BudgetsVisible == 0} {
1781 foreach win
$BudgetWindows {
1782 set w
[WindowLink
$win.fire
].request
1783 set old
[lindex [$w configure
-text] 4]
1784 set new
"$firepercent% of $firewant = $firegot"
1786 $w configure
-text $new
1788 set w
[WindowLink
$win.fire
].fund
1790 if {$old != $firepercent} {
1794 set w
[WindowLink
$win.police
].request
1795 set old
[lindex [$w configure
-text] 4]
1796 set new
"$policepercent% of $policewant = $policegot"
1798 $w configure
-text $new
1800 set w
[WindowLink
$win.police
].fund
1802 if {$old != $policepercent} {
1803 $w set $policepercent
1806 set w
[WindowLink
$win.road
].request
1807 set old
[lindex [$w configure
-text] 4]
1808 set new
"$roadpercent% of $roadwant = $roadgot"
1810 $w configure
-text $new
1812 set w
[WindowLink
$win.road
].fund
1814 if {$old != $roadpercent} {
1821 proc ChangeBudget
{} {
1822 global VotesForBudget
1823 if {"$VotesForBudget" != ""} {
1830 proc InitVotesForBudget
{} {
1831 global VotesForBudget BudgetWindows
1832 set VotesForBudget
{}
1833 foreach win
$BudgetWindows {
1834 [WindowLink
$win.vote
] config
-relief raised
1836 UpdateVotesForBudget
1840 proc UpdateVotesForBudget
{} {
1841 global BudgetWindows
1842 UpdateVotesFor Budget
$BudgetWindows
1846 proc UpdateTaxRateSliders
{} {
1848 set players
[sim Players
]
1849 foreach win
$HeadWindows {
1850 set slider
[WindowLink
$win.taxrate
]
1851 #echo "UpdateTaxRateSliders players $players win $win slider $slider"
1852 if {$players == 1} {
1853 $slider configure
-state normal
1855 $slider configure
-state disabled
1861 ########################################################################
1862 # Evaluation Window Handlers
1865 proc ToggleEvaluationOf
{head
} {
1867 if {"$State" != "play"} {
1872 set win
[WindowLink
$head.evaluation
]
1874 set mapped
[winfo ismapped
$win]
1878 WithdrawEvaluationOf
$head
1880 ShowEvaluationOf
$head
1886 proc WithdrawEvaluationOf
{head
} {
1887 set win
[WindowLink
$head.evaluation
]
1894 proc ShowEvaluationOf
{head
} {
1895 set win
[WindowLink
$head.evaluation
]
1897 set win
[MakeWindow.evaluation
$head [winfo screen
$head]]
1901 set parent
[WindowLink
$win.parent
]
1902 #pack append [WindowLink $head.col2]\
1903 # $parent {top frame nw fill}
1904 pack append $parent\
1905 $win {top
frame nw fillx
}
1907 sim UpdateEvaluation
1911 proc WithdrawEvaluations
{} {
1912 global EvaluationWindows EvaluationsVisible
1913 foreach win
$EvaluationWindows {
1915 #set parent [WindowLink $win.parent]
1916 #pack unpack $parent
1919 set EvaluationsVisible
0
1923 proc EvaluationVisible
{w v
} {
1924 global EvaluationsVisible
1925 global [set var
$w.visible
]
1930 set EvaluationsVisible
[expr "$EvaluationsVisible + 1"]
1932 set EvaluationsVisible
[expr "$EvaluationsVisible - 1"]
1937 proc UISetEvaluation
{changed score ps0 ps1 ps2 ps3 pv0 pv1 pv2 pv3 pop delta assessed cityclass citylevel goodyes goodno title
} {
1938 global EvaluationWindows EvaluationsVisible CurrentDate
1940 set class
[string tolower
$cityclass]
1941 UISetMessage
"$CurrentDate: Score $score, $class population $pop."
1943 if {$EvaluationsVisible} {
1945 foreach win
$EvaluationWindows {
1947 global [set var
$win.visible
]
1948 set visible
[eval ident
"\$\{$var\}"]
1952 # TODO: set evaluation window and icon title
1953 #wm title $win "$title"
1954 #wm iconname $win "$title"
1956 set w
[WindowLink
$win.goodjob
]
1957 set old
[lindex [$w configure
-text] 4]
1958 set new
"$goodyes\n$goodno"
1960 $w configure
-text $new
1963 set w
[WindowLink
$win.problemnames
]
1964 set old
[lindex [$w configure
-text] 4]
1965 set new
"$ps0\n$ps1\n$ps2\n$ps3"
1967 $w configure
-text $new
1970 set w
[WindowLink
$win.problempercents
]
1971 set old
[lindex [$w configure
-text] 4]
1972 set new
"$pv0\n$pv1\n$pv2\n$pv3"
1974 $w configure
-text $new
1977 set w
[WindowLink
$win.stats
]
1978 set old
[lindex [$w configure
-text] 4]
1979 set new
"$pop\n$delta\n\n$assessed\n$cityclass\n$citylevel"
1981 $w configure
-text $new
1984 set w
[WindowLink
$win.score
]
1985 set old
[lindex [$w configure
-text] 4]
1986 set new
"$score\n$changed"
1988 $w configure
-text $new
1996 ########################################################################
1997 # File Window Handlers
2000 proc ShowFileOf
{head
} {
2001 set win
[WindowLink
$head.
file]
2003 set win
[MakeWindow.
file $head [winfo screen
$head]]
2013 foreach win
$HeadWindows {
2019 proc WithdrawFiles
{} {
2021 foreach win
$FileWindows {
2027 proc DoFileDialog
{win Message Path Pattern FileName ActionOk ActionCancel
} {
2028 ShowFileDialog
$win "$Path" "$Pattern"
2029 $win.message1 configure
-text "$Message"
2030 $win.path.path delete
0 end
2031 $win.path.path insert
0 $Path
2032 $win.
file.
file delete
0 end
2033 $win.
file.
file insert
0 "$FileName"
2034 $win.frame1.ok config
-command "
2035 $ActionOk \[$win.file.file get\] \[$win.path.path get\]
2037 $win.frame1.rescan config
-command "
2038 ShowFileDialog $win \[$win.path.path get\] $Pattern"
2039 $win.frame1.cancel config
-command "
2042 bind $win.files.files
"<Double-Button-1>" "\
2043 FileSelectDouble $win %W %y $Pattern \"
2044 $ActionOk \[$win.file.file get\] \[$win.path.path get\]\""
2045 bind $win.path.path
<Return
> "
2046 ShowFileDialog $win \[$win.path.path get\] $Pattern
2047 $win.file.file cursor 0
2048 focus $win.file.file"
2049 bind $win.
file.
file <Return
> "\
2050 $ActionOk \[$win.file.file get\] \[$win.path.path get]
2055 proc BindSelectOne
{win Y
} {
2056 set Nearest
[$win nearest
$Y]
2057 if {$Nearest >= 0} {
2058 $win select from
$Nearest
2059 $win select to
$Nearest
2064 proc FileSelect
{win widget Y
} {
2065 BindSelectOne
$widget $Y
2066 set Nearest
[$widget nearest
$Y]
2067 if {$Nearest >= 0} {
2068 set Path
[$win.path.path get
]
2069 set TmpEntry
[$widget get
$Nearest]
2070 if {[string compare
"/" [string index
$TmpEntry \
2071 [expr [string length
$TmpEntry]-1]]] == 0 ||
\
2072 [string compare
"@" [string index
$TmpEntry \
2073 [expr [string length
$TmpEntry]-1]]] == 0} {
2074 # handle directories, and symbolic links to directories
2075 set FileName
[string range
$TmpEntry 0 \
2076 [expr [string length
$TmpEntry]-2]]
2077 # whoops / or @ is part of the name
2078 if {[MiscIsDir
$Path/$FileName] != 1} {
2079 set FileName
$TmpEntry
2082 if {[string compare
"*" [string index
$TmpEntry \
2083 [expr [string length
$TmpEntry]-1]]] == 0} {
2084 # handle executable filenames
2085 set FileName
[string range
$TmpEntry 0 \
2086 [expr [string length
$TmpEntry]-2]]
2087 # whoops * is part of the name
2088 if {[file executable
$Path/$FileName] != 1} {
2089 set FileName
$TmpEntry
2092 # a ordinary filename
2093 set FileName
$TmpEntry
2096 # enter the selected filename into the filename field
2097 if {[MiscIsDir
$Path/$FileName] != 1} {
2098 $win.
file.
file delete
0 end
2099 $win.
file.
file insert
0 $FileName
2105 proc FileSelectDouble
{win widget Y Pattern Action
} {
2106 BindSelectOne
$widget $Y
2107 set Nearest
[$widget nearest
$Y]
2108 if {$Nearest >= 0} {
2109 set Path
[$win.path.path get
]
2110 set TmpEntry
[$widget get
$Nearest]
2111 if {[string compare
$TmpEntry "../"] == 0} {
2112 # go up one directory
2114 [string trimright
[string trimright
[string trim
$Path] /] @]
2115 if {[string length
$TmpEntry] <= 0} {
2118 set Path
[file dirname
$TmpEntry]
2119 $win.path.path delete
0 end
2120 $win.path.path insert
0 $Path
2121 ShowFileDialog
$win $Path $Pattern
2123 if {[string compare
"/" [string index
$TmpEntry \
2124 [expr [string length
$TmpEntry]-1]]] == 0 ||
\
2125 [string compare
"@" [string index
$TmpEntry \
2126 [expr [string length
$TmpEntry]-1]]] == 0} {
2127 # handle directorys, and symbolic links to directorys
2128 set FileName
[string range
$TmpEntry 0 \
2129 [expr [string length
$TmpEntry]-2]]
2130 # whoops / or @ is part of the name
2131 if {[MiscIsDir
$Path/$FileName] != 1} {
2132 set FileName
$TmpEntry
2135 if {[string compare
"*" [string index
$TmpEntry \
2136 [expr [string length
$TmpEntry]-1]]] == 0} {
2137 # handle executable filenames
2138 set FileName
[string range
$TmpEntry 0 \
2139 [expr [string length
$TmpEntry]-2]]
2140 # whoops * is part of the name
2141 if {[file executable
$Path/$FileName] != 1} {
2142 set FileName
$TmpEntry
2145 # a ordinary filename
2146 set FileName
$TmpEntry
2150 if {[MiscIsDir
$Path/$FileName] == 1} {
2151 if {[string compare
"/" [string index
$Path \
2152 [expr [string length
$Path]-1]]] == 0} {
2153 append Path
$FileName
2155 append Path
/ $FileName
2157 $win.path.path delete
0 end
2158 $win.path.path insert
0 $Path
2159 ShowFileDialog
$win $Path $Pattern
2161 # enter the selected filename into the filename field
2162 $win.
file.
file delete
0 end
2163 $win.
file.
file insert
0 "$FileName"
2164 if {[string length
$Action] > 0} {
2174 proc NameComplete
{win Type
} {
2179 if {[string compare
$Type path
] == 0} {
2180 set DirName
[file dirname
[$win.path.path get
]]
2181 set FileName
[file tail
[$win.path.path get
]]
2183 set DirName
[file dirname
[$win.path.path get
]/]
2184 set FileName
[file tail
[$win.
file.
file get
]]
2188 if {[MiscIsDir
$DirName] == 1} {
2189 catch "exec ls $DirName/" Result
2191 set ListLength
[llength $Result]
2193 while {$Counter < $ListLength} {
2194 if {[string length
$FileName] == 0} {
2195 if {$FoundCounter == 0} {
2196 set NewFile
[lindex $Result $Counter]
2199 set TmpFile1
$NewFile
2200 set TmpFile2
[lindex $Result $Counter]
2201 set Length1
[string length
$TmpFile1]
2202 set Length2
[string length
$TmpFile2]
2204 if {$Length1 > $Length2} {
2205 set Length1
$Length2
2207 while {$Counter1 < $Length1} {
2208 if {[string compare
[string index
$TmpFile1 $Counter1] \
2209 [string index
$TmpFile2 $Counter1]] == 0} {
2210 append NewFile
[string index
$TmpFile1 $Counter1]
2219 if {[regexp "^$FileName" [lindex $Result $Counter] \
2221 if {$FoundCounter == 0} {
2222 set NewFile
[lindex $Result $Counter]
2225 set TmpFile1
$NewFile
2226 set TmpFile2
[lindex $Result $Counter]
2227 set Length1
[string length
$TmpFile1]
2228 set Length2
[string length
$TmpFile2]
2230 if {$Length1 > $Length2} {
2231 set Length1
$Length2
2233 while {$Counter1 < $Length1} {
2234 if {[string compare
[string index
$TmpFile1 $Counter1] \
2235 [string index
$TmpFile2 $Counter1]] == 0} {
2236 append NewFile
[string index
$TmpFile1 $Counter1]
2250 if {$FoundCounter == 1} {
2251 if {[MiscIsDir
$DirName/$NewFile] == 1} {
2252 if {[string compare
$DirName "/"] == 0} {
2253 $win.path.path delete
0 end
2254 $win.path.path insert
0 "/[string trim [string trim $NewFile /] @]/"
2256 $win.path.path delete
0 end
2257 $win.path.path insert
0 "[string trimright $DirName /]/[string trim [string trim $NewFile /] @]/"
2260 $win.path.path delete
0 end
2261 $win.path.path insert
0 \
2262 "[string trim [string trimright $DirName /] @]/"
2263 $win.
file.
file delete
0 end
2264 $win.
file.
file insert
0 "$NewFile"
2267 if {[MiscIsDir
$DirName/$NewFile] == 1 ||
2268 [string compare
$Type path
] == 0} {
2269 $win.path.path delete
0 end
2270 $win.path.path insert
0 \
2271 "[string trimright $DirName /]/[string trim [string trim $NewFile /] @]"
2273 $win.path.path delete
0 end
2274 $win.path.path insert
0 "$DirName"
2275 if {[string length
$NewFile] > 0} {
2276 $win.
file.
file delete
0 end
2277 $win.
file.
file insert
0 "$NewFile"
2284 proc ShowFileDialog
{win Path Pattern
} {
2286 set Path
[lindex [split $Path] 0]
2287 if {[$win.files.files size
] > 0} {
2288 $win.files.files delete
0 end
2291 if {[catch "exec ls -F $Path" Result
]} {
2294 if {[string match
$Result "* not found"]} {
2297 set ElementList
[lsort $Result]
2300 if {[string compare
$Path "/"]} {
2301 $win.files.files insert end
"../"
2305 foreach Counter
$ElementList {
2307 if {[string match
$Pattern $Counter] == 1} {
2308 if {[string compare
$Counter "../"] &&
2309 [string compare
$Counter "./"]} {
2310 $win.files.files insert end
$Counter
2313 set fn
$Path/[string trim
[string trim
[string trim
$Counter /] @] *]
2314 if {[MiscIsDir
$fn]} {
2315 $win.files.files insert end
$Counter
2323 proc MiscIsDir
{PathName
} {
2325 if {[file isdirectory
$PathName] == 1} {
2328 catch "file type $PathName" Type
2329 if {[string compare
$Type link
] == 0} {
2330 set LinkName
[file readlink
$PathName]
2331 catch "file type $LinkName" Type
2332 while {[string compare
$Type link
] == 0} {
2333 set LinkName
[file readlink
$LinkName]
2335 return [file isdirectory
$LinkName]
2342 proc busy
{win cmds
} {
2344 set list [winfo children
$win]
2346 while {$list != ""} {
2349 set class
[winfo class
$w]
2350 set cursor
[lindex [$w config
-cursor] 4]
2351 if {[winfo toplevel $w] == $w} {
2352 lappend busy
[list $w $cursor]
2354 set next
[concat $next [winfo children
$w]]
2360 catch {[lindex $w 0] config
-cursor watch
}
2365 set error [catch {uplevel eval [list $cmds]} result
]
2368 catch {[lindex $w 0] config
-cursor [lindex $w 1]}
2379 ########################################################################
2380 # Editor Window Handlers
2382 proc ShowEditorOf
{head
} {
2383 global EditorWindows
2385 foreach win
$EditorWindows {
2386 if {[WindowLink
$win.head
] == $head} {
2387 set parent
[WindowLink
$win.parent
]
2388 #pack append [WindowLink $head.col2]\
2389 # $parent {top frame nw expand fill}
2390 pack append $parent\
2391 $win {top
frame nw expand fill
}
2405 proc NewEditorOf
{head
} {
2406 set win
[MakeWindow.editor
$head [winfo screen
$head]]
2408 set parent
[WindowLink
$win.parent
]
2409 pack append $parent\
2410 $win {top
frame nw expand fill
}
2417 proc ShowEditors
{} {
2419 foreach win
$HeadWindows {
2425 proc WithdrawEditors
{} {
2426 global EditorWindows
2427 foreach win
$EditorWindows {
2428 #set parent [WindowLink $win.parent]
2429 #pack unpack $parent
2435 proc InitEditors
{} {
2436 global EditorWindows
2437 foreach win
$EditorWindows {
2443 proc InitEditor
{win
} {
2444 set e
[WindowLink
$win.view
]
2445 UISetToolState
$win 7
2450 global $e.TrackState
2451 set $e.TrackState
{}
2455 proc SetEditorAutoGoto
{win val
} {
2456 global AutoGoto.
$win
2457 set AutoGoto.
$win $val
2458 set e
[WindowLink
$win.view
]
2463 proc SetEditorControls
{win val
} {
2464 global Controls.
$win
2465 set Controls.
$win $val
2467 pack append $win $win.leftframe
{left
frame center filly
}
2469 pack unpack
$win.leftframe
2474 proc SetEditorOverlay
{win val
} {
2476 set Overlay.
$win $val
2477 set e
[WindowLink
$win.view
]
2482 proc SetEditorDynamicFilter
{win val
} {
2483 global DynamicFilter.
$win
2484 set DynamicFilter.
$win $val
2485 set e
[WindowLink
$win.view
]
2486 $e DynamicFilter
$val
2487 if {$val == 1} then
{
2488 ShowFrobOf
[WindowLink
$win.head
]
2493 proc SetEditorSkip
{win val
} {
2494 set e
[WindowLink
$win.view
]
2499 proc EditorToolDown
{mod w x y
} {
2500 global [set var
$w.TrackState
]
2504 case
[$w ToolState
] in
\
2506 UIMakeSoundOn
$w edit Rumble
"-repeat 4"
2514 set $var [list constrain_start
$x $y]
2515 $w ToolConstrain
$x $y
2520 EditorTool ToolDown
$w $x $y
2525 proc EditorToolDrag
{w x y
} {
2526 EditorTool ToolDrag
$w $x $y
2531 proc EditorToolUp
{w x y
} {
2532 global [set var
$w.TrackState
]
2535 case
[$w ToolState
] in
\
2537 UIStopSoundOn
$w edit
1
2543 EditorTool ToolUp
$w $x $y
2545 $w ToolConstrain
-1 -1
2552 proc EditorTool
{action w x y
} {
2553 global [set var
$w.TrackState
]
2554 set state
[eval ident
"\$\{$var\}"]
2555 case
[lindex $state 0] in
\
2557 set x0
[lindex $state 1]
2558 set y0
[lindex $state 2]
2559 set dx
[expr "$x - $x0"]
2560 set dy
[expr "$y - $y0"]
2561 if [expr "($dx > 16) || ($dx < -16)"] then
{
2562 $w ToolConstrain
-1 $y0
2565 if [expr "($dy > 16) || ($dy < -16)"] then
{
2566 $w ToolConstrain
$x0 -1
2575 proc StartChalk
{w
} {
2576 sim CollapseMotion
0
2580 proc StopChalk
{w
} {
2581 sim CollapseMotion
1
2585 proc EditorPanDown
{mod w x y
} {
2586 global [set var
$w.TrackState
]
2590 set $var [list constrain_start
$x $y]
2591 $w ToolConstrain
$x $y
2596 EditorTool PanStart
$w $x $y
2600 proc EditorPanDrag
{w x y
} {
2601 EditorTool PanTo
$w $x $y
2605 proc EditorPanUp
{w x y
} {
2608 EditorTool PanTo
$w $x $y
2609 $w ToolConstrain
-1 -1
2615 proc EditorKeyDown
{w k
} {
2620 proc EditorKeyUp
{w k
} {
2625 proc BindEditorButtons
{win
} {
2626 set w
[WindowLink
$win.top
]
2628 bind $win <1> "CancelPie $win ; EditorToolDown none %W %x %y"
2629 bind $win <B1-Motion
> {EditorToolDrag
%W
%x
%y
}
2630 bind $win <ButtonRelease-1
> {EditorToolUp
%W
%x
%y
}
2632 bind $win <Control-1
> "CancelPie $win ; EditorToolDown constrain %W %x %y"
2633 bind $win <Control-B1-Motion
> {EditorToolDrag
%W
%x
%y
}
2634 bind $win <Control-ButtonRelease-1
> {EditorToolUp
%W
%x
%y
}
2636 bind $win <2> "CancelPie $win ; EditorPanDown none %W %x %y"
2637 bind $win <B2-Motion
> {EditorPanDrag
%W
%x
%y
}
2638 bind $win <ButtonRelease-2
> {EditorPanUp
%W
%x
%y
}
2640 bind $win <Control-2
> "CancelPie $win ; EditorPanDown constrain %W %x %y"
2641 bind $win <Control-B2-Motion
> {EditorPanDrag
%W
%x
%y
}
2642 bind $win <Control-ButtonRelease-2
> {EditorPanUp
%W
%x
%y
}
2644 InitPie
$win $w.toolpie
2648 proc UISetFunds
{funds
} {
2650 foreach win
$HeadWindows {
2651 [WindowLink
$win.funds
] configure
-text "$funds"
2656 proc UISetDate
{date month year
} {
2660 set CurrentDate
"$date"
2662 foreach win
$HeadWindows {
2663 [WindowLink
$win.date
] Set
$month $year
2668 proc SetPriority
{index
} {
2694 proc UISetDemand
{r c i
} {
2695 global HeadWindows DemandRes DemandCom DemandInd
2701 if {$r <= 0} then
{set ry0
32} else {set ry0
24}
2702 set ry1
[expr "$ry0 - $r"]
2703 if {$c <= 0} then
{set cy0
32} else {set cy0
24}
2704 set cy1
[expr "$cy0 - $c"]
2705 if {$i <= 0} then
{set iy0
32} else {set iy0
24}
2706 set iy1
[expr "$iy0 - $i"]
2708 foreach win
$HeadWindows {
2709 set can
[WindowLink
$win.demand
]
2710 # $can coords r 8 $ry0 14 $ry1
2711 # $can coords c 17 $cy0 23 $cy1
2712 # $can coords i 26 $iy0 32 $iy1
2713 $can coords r
49 $ry0 55 $ry1
2714 $can coords c
58 $cy0 64 $cy1
2715 $can coords i
67 $iy0 73 $iy1
2720 proc UISetOptions
{autobudget autogoto autobulldoze disasters sound animation messages notices
} {
2721 global AutoBudget AutoGoto AutoBulldoze Disasters Sound
2722 set AutoBudget
$autobudget
2723 set AutoGoto
$autogoto
2724 set AutoBulldoze
$autobulldoze
2725 set Disasters
$disasters
2727 set DoAnimation
$animation
2728 set DoMessages
$messages
2729 set DoNotices
$notices
2733 proc UIDidToolRes
{win x y
} {
2734 UIMakeSoundOn
$win edit O
"-speed 140"
2738 proc UIDidToolCom
{win x y
} {
2739 UIMakeSoundOn
$win edit A
"-speed 140"
2743 proc UIDidToolInd
{win x y
} {
2744 UIMakeSoundOn
$win edit E
"-speed 140"
2748 proc UIDidToolFire
{win x y
} {
2749 UIMakeSoundOn
$win edit O
"-speed 130"
2753 proc UIDidToolQry
{win x y
} {
2754 UIMakeSoundOn
$win edit E
"-speed 200"
2758 proc UIDidToolPol
{win x y
} {
2759 UIMakeSoundOn
$win edit E
"-speed 130"
2763 proc UIDidToolWire
{win x y
} {
2764 UIMakeSoundOn
$win edit O
"-speed 120"
2768 proc UIDidToolDozr
{win x y
} {
2769 UIMakeSoundOn
$win edit Rumble
2773 proc UIDidToolRail
{win x y
} {
2774 UIMakeSoundOn
$win edit O
"-speed 100"
2778 proc UIDidToolRoad
{win x y
} {
2779 UIMakeSoundOn
$win edit E
"-speed 100"
2783 proc UIDidToolChlk
{win x y
} {
2787 proc UIDidToolEraser
{win x y
} {
2791 proc UIDidToolStad
{win x y
} {
2792 UIMakeSoundOn
$win edit O
"-speed 90"
2796 proc UIDidToolPark
{win x y
} {
2797 UIMakeSoundOn
$win edit A
"-speed 130"
2801 proc UIDidToolSeap
{win x y
} {
2802 UIMakeSoundOn
$win edit E
"-speed 90"
2806 proc UIDidToolCoal
{win x y
} {
2807 UIMakeSoundOn
$win edit O
"-speed 75"
2811 proc UIDidToolNuc
{win x y
} {
2812 UIMakeSoundOn
$win edit E
"-speed 75"
2816 proc UIDidToolAirp
{win x y
} {
2817 UIMakeSoundOn
$win edit A
"-speed 50"
2821 proc UISetToolState
{w state
} {
2822 global EditorPallets EditorPalletImages ToolInfo
2823 set win
[WindowLink
$w.top
]
2824 #echo "UISETTOOLSTATE w $w win $win $state"
2825 ExclusivePallet
$state $win $EditorPallets ic
$EditorPalletImages \
2826 raised sunken
{NoFunction
}
2828 set c1
[WindowLink
$w.cost1
]
2830 set info [lindex $ToolInfo $state]
2831 set cost1
[lindex $info 1]
2832 set cost2
[lindex $info 2]
2833 $c1 configure
-text "$cost1"
2834 [WindowLink
$w.cost2
] configure
-text "$cost2"
2839 proc UIShowZoneStatus
{zone density value crime pollution growth x y
} {
2840 global QueryX QueryY
2841 set QueryX
[expr "8 + 16 * $x"]
2842 set QueryY
[expr "8 + 16 * $y"]
2843 UIShowPicture
9 [list $zone $density $value $crime $pollution $growth]
2847 ########################################################################
2848 # Map Window Handlers
2851 proc ShowMapOf
{head
} {
2854 foreach win
$MapWindows {
2855 if {"[WindowLink $win.head]" == "$head"} {
2856 global MapPanelWidth MapPanelHeight
2857 #place configure $win -x 0 -y 0 -width $MapPanelWidth -height $MapPanelHeight
2858 #[WindowLink $win.parent] configure -width $MapPanelWidth -height $MapPanelHeight
2859 set parent
[WindowLink
$win.parent
]
2860 pack append [WindowLink
$head.w2
] \
2861 $win {top
frame nw expand fill
}
2874 proc NewMapOf
{head
} {
2875 set win
[MakeWindow.map
$head [winfo screen
$head]]
2876 global MapPanelWidth MapPanelHeight
2877 #place configure $win -x 0 -y 0 -width $MapPanelWidth -height $MapPanelHeight
2878 #[WindowLink $win.parent] configure -width $MapPanelWidth -height $MapPanelHeight
2879 set parent
[WindowLink
$win.parent
]
2880 #pack append [WindowLink $head.col1]\
2881 # $parent {top frame nw fillx}
2882 pack append [WindowLink
$head.w2
] \
2883 $win {top
frame nw expand fill
}
2890 foreach win
$HeadWindows {
2896 proc WithdrawMaps
{} {
2898 foreach win
$MapWindows {
2907 foreach win
$MapWindows {
2913 proc InitMap
{win
} {
2918 proc EnableMaps
{} {
2920 foreach win
$MapWindows {
2926 proc EnableMap
{win
} {
2927 [WindowLink
$win.view
] ShowEditors
1
2928 [WindowLink
$win.zones
] config
-state normal
2929 [WindowLink
$win.overlays
] config
-state normal
2933 proc DisableMaps
{} {
2935 foreach win
$MapWindows {
2941 proc DisableMap
{win
} {
2942 [WindowLink
$win.view
] ShowEditors
0
2943 [WindowLink
$win.zones
] config
-state disabled
2944 [WindowLink
$win.overlays
] config
-state disabled
2948 proc SetMapState
{win state
} {
2949 set m
[WindowLink
$win.view
]
2951 if {$state == 14} then
{
2952 ShowFrobOf
[WindowLink
$win.head
]
2957 proc MapPanDown
{w x y
} {
2962 proc MapPanDrag
{w x y
} {
2967 proc MapPanUp
{w x y
} {
2974 proc UISetMapState
{w state
} {
2976 #set win [winfo toplevel $w]
2977 set win
[WindowLink
$w.win
]
2978 set m
[WindowLink
$win.view
]
2979 set title
[lindex $MapTitles $state]
2981 # TODO: set map text field header to title
2982 #wm title $win "$title"
2983 #wm iconname $win "$title"
2985 global [set var MapState.
$win]
2989 {6 8 9 10 11 12 13} {
2990 [WindowLink
$win.legend
] config
-bitmap "@images/legendmm.xpm"
2993 [WindowLink
$win.legend
] config
-bitmap "@images/legendpm.xpm"
2996 [WindowLink
$win.legend
] config
-bitmap "@images/legendn.xpm"
3002 ########################################################################
3003 # Graph Window Handlers
3006 proc ToggleGraphOf
{head
} {
3008 if {"$State" != "play"} {
3013 set win
[WindowLink
$head.graph
]
3015 set mapped
[winfo ismapped
$win]
3019 WithdrawGraphOf
$head
3027 proc WithdrawGraphOf
{head
} {
3028 set win
[WindowLink
$head.graph
]
3035 proc ShowGraphOf
{head
} {
3036 set win
[WindowLink
$head.graph
]
3038 set win
[MakeWindow.graph
$head [winfo screen
$head]]
3042 set parent
[WindowLink
$win.parent
]
3043 pack append $parent\
3044 $win {top
frame nw fillx
}
3050 proc WithdrawGraphs
{} {
3052 foreach win
$GraphWindows {
3059 proc InitGraphs
{} {
3061 foreach win
$GraphWindows {
3067 proc InitGraph
{win
} {
3068 UISetGraphState
$win 1 1 1 1 1 1 0
3072 proc UISetGraphState
{win t0 t1 t2 t3 t4 t5 range
} {
3073 set g
[WindowLink
$win.graphview
]
3074 GraphPalletMask
$win [expr "$t0 + ($t1<<1) + ($t2<<2) + ($t3<<3) + ($t4<<4) + ($t5<<5)"]
3075 GraphYearPallet
$win $range
3079 ########################################################################
3080 # Splash Window Handlers
3083 proc ShowSplashOf
{head
} {
3084 set win
[WindowLink
$head.splash
]
3086 set win
[MakeWindow.splash
$head [winfo screen
$head]]
3088 set splashscreen
[WindowLink
$win.splashscreen
]
3090 catch {$splashscreen config
-bitmap "@images/splashscreen.xpm"; set success 1}
3093 global SplashScreenDelay
3094 after $SplashScreenDelay "UIPickScenarioMode"
3101 proc WithdrawSplashOf
{head
} {
3102 set win WindowLink
$head.splash
]
3107 proc ShowSplashes
{} {
3109 foreach win
$HeadWindows {
3115 proc WithdrawSplashes
{} {
3116 global SplashWindows
3117 foreach win
$SplashWindows {
3119 set splashscreen
[WindowLink
$win.splashscreen
]
3120 $splashscreen config
-bitmap ""
3125 proc InitSplashes
{} {
3129 proc InitSplash
{win
} {
3133 proc DeleteSplashWindow
{win
} {
3138 ########################################################################
3139 # Scenario Window Handlers
3142 proc ShowScenarioOf
{head
} {
3143 set win
[WindowLink
$head.scenario
]
3145 set win
[MakeWindow.scenario
$head [winfo screen
$head]]
3147 # TODO: load background bitmap
3152 proc WithdrawScenarioOf
{head
} {
3153 set win WindowLink
$head.scenario
]
3158 proc ShowScenarios
{} {
3160 foreach win
$HeadWindows {
3166 proc WithdrawScenarios
{} {
3167 global ScenarioWindows
3168 foreach win
$ScenarioWindows {
3170 # TODO: flush background bitmap
3175 proc InitScenarios
{} {
3176 global MapHistory MapHistoryNum
3177 if {$MapHistoryNum < 1} {
3182 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3187 global ScenarioWindows
3188 foreach win
$ScenarioWindows {
3190 #[WindowLink $win.previous] config -state $prev
3191 #[WindowLink $win.next] config -state $next
3196 proc InitScenario
{win
} {
3197 global MapHistory MapHistoryNum
3198 if {$MapHistoryNum < 1} {
3204 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3211 #[WindowLink $win.previous] config -state $prev
3212 #[WindowLink $win.next] config -state $next
3214 LinkWindow
$win.scenarioTarget
-1
3215 LinkWindow
$win.scenarioTargetDown
-1
3217 global ScenarioButtons
3219 set len
[llength $ScenarioButtons]
3221 set data
[lindex $ScenarioButtons $i]
3222 set type
[lindex $data 0]
3223 set id
[lindex $data 1]
3227 LinkWindow
$win.
$id.over
0
3228 LinkWindow
$win.
$id.enabled
1
3229 LinkWindow
$win.
$id.checked
0
3230 #echo "SETTING WIN $win ID $id"
3232 set i
[expr "$i + 1"]
3235 UpdateLevelSelection
$win
3236 UpdateLeftRightEnabled
$win
3240 proc UpdateLevelSelection
{win
} {
3241 #echo UpdateLevelSelection
3243 if {$GameLevel == 0} then
{
3244 LinkWindow
$win.easy.checked
1
3245 LinkWindow
$win.medium.checked
0
3246 LinkWindow
$win.hard.checked
0
3248 if {$GameLevel == 1} then
{
3249 LinkWindow
$win.easy.checked
0
3250 LinkWindow
$win.medium.checked
1
3251 LinkWindow
$win.hard.checked
0
3253 if {$GameLevel == 2} then
{
3254 LinkWindow
$win.easy.checked
0
3255 LinkWindow
$win.medium.checked
0
3256 LinkWindow
$win.hard.checked
1
3259 UpdateScenarioButtonID
$win easy
3260 UpdateScenarioButtonID
$win medium
3261 UpdateScenarioButtonID
$win hard
3266 proc UpdateLeftRightEnabled
{win
} {
3267 #echo UpdateLeftRightEnabled
3269 global MapHistory MapHistoryNum
3270 if {$MapHistoryNum < 1} {
3271 LinkWindow
$win.left.enabled
0
3273 LinkWindow
$win.left.enabled
1
3276 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3277 LinkWindow
$win.right.enabled
0
3279 LinkWindow
$win.right.enabled
1
3282 UpdateScenarioButtonID
$win left
3283 UpdateScenarioButtonID
$win right
3287 proc UpdateScenarioButtonID
{win id
} {
3289 global ScenarioButtons
3291 set len
[llength $ScenarioButtons]
3293 set data
[lindex $ScenarioButtons $i]
3295 if {$id == [lindex $data 1]} then
{
3296 UpdateScenarioButton
$win $data
3300 set i
[expr "$i + 1"]
3305 proc UpdateScenarioButton
{win data
} {
3306 set type
[lindex $data 0]
3307 set id
[lindex $data 1]
3308 set over
[WindowLink
$win.
$id.over
]
3309 set enabled
[WindowLink
$win.
$id.enabled
]
3310 set checked
[WindowLink
$win.
$id.checked
]
3311 #echo "WIN $win TYPE $type ID $id OVER $over ENABLED $enabled CHECKED $checked"
3315 set bm
[lindex $data 13]
3317 set bm
[lindex $data 12]
3321 set bm
[lindex $data 10]
3323 set bm
[lindex $data 9]
3327 set bm
[lindex $data 11]
3330 [WindowLink
$win.
canvas] itemconfig
$id -bitmap $bm
3334 proc DoEnterCityName
{win
} {
3338 proc InitVotesForUseThisMap
{} {
3339 # TODO: Disabled for new scenario window.
3342 global VotesForUseThisMap ScenarioWindows
3343 set VotesForUseThisMap
{}
3344 foreach win
$ScenarioWindows {
3345 [WindowLink
$win.vote
] config
-relief raised
3347 UpdateVotesForUseThisMap
3351 proc UpdateVotesForUseThisMap
{} {
3352 global ScenarioWindows
3353 UpdateVotesFor UseThisMap
$ScenarioWindows
3357 proc UIUseThisMap
{} {
3358 global CityName GameLevel Scenario
3360 # special handling for scenarios?
3361 if {$GameLevel != -1} {
3362 sim GameLevel
$GameLevel
3364 sim CityName
$CityName
3367 if {$Scenario != -1} {
3368 UIShowPicture
$Scenario
3373 proc HandleScenarioDown
{win x y
} {
3374 #echo HandleScenarioDown $win $x $y
3375 HandleScenarioMove
$win $x $y
3376 set w
[WindowLink
$win.w
]
3377 set target
[WindowLink
$w.scenarioTarget
]
3378 LinkWindow
$w.scenarioTargetDown
$target
3382 proc HandleScenarioUp
{win x y
} {
3383 #echo HandleScenarioUp $win $x $y
3384 HandleScenarioMove
$win $x $y
3385 global ScenarioButtons
3386 set w
[WindowLink
$win.w
]
3387 set target
[WindowLink
$w.scenarioTarget
]
3388 set targetDown
[WindowLink
$w.scenarioTargetDown
]
3389 if {($target != -1) &&
3390 ($target == $targetDown)} {
3391 set data
[lindex $ScenarioButtons $target]
3392 set type
[lindex $data 0]
3393 set id
[lindex $data 1]
3394 set callback
[lindex $data 2]
3395 set param
[lindex $data 3]
3396 set var
[lindex $data 4]
3397 set xx
[lindex $data 5]
3398 set yy
[lindex $data 6]
3399 set ww
[lindex $data 7]
3400 set hh
[lindex $data 8]
3401 set normal
[lindex $data 9]
3402 set over
[lindex $data 10]
3403 set disabled
[lindex $data 11]
3404 if {$type == "button"} {
3405 #echo callback $callback w $w param $param
3406 eval "$callback $w {$param}"
3408 if {$type == "checkbox"} {
3409 #echo checkbox callback $callback w $w param $param
3410 eval "$callback $w {$param}"
3417 proc HandleScenarioMove
{win x y
} {
3418 #echo HandleScenarioMove $win $x $y
3419 global ScenarioButtons
3420 set w
[WindowLink
$win.w
]
3421 set target
[WindowLink
$w.scenarioTarget
]
3424 set len
[llength $ScenarioButtons]
3426 set data
[lindex $ScenarioButtons $i]
3427 set type
[lindex $data 0]
3428 set id
[lindex $data 1]
3429 set callback
[lindex $data 2]
3430 set param
[lindex $data 3]
3431 set var
[lindex $data 4]
3432 set xx
[lindex $data 5]
3433 set yy
[lindex $data 6]
3434 set ww
[lindex $data 7]
3435 set hh
[lindex $data 8]
3437 set enabled
[WindowLink
$w.
$id.enabled
]
3438 set checked
[WindowLink
$w.
$id.checked
]
3440 #echo "ID $id ENABLED $enabled CHECKED $checked w $w id $id"
3442 if {($enabled != 0) &&
3444 ($x < ($xx + $ww)) &
3446 ($y < ($yy + $hh))} {
3451 set i
[expr "$i + 1"]
3454 if {$found != $target} {
3457 if {$target != -1} {
3459 #echo OUT $w $found $xx $yy $normal
3460 LinkWindow
$w.scenarioTarget
-1
3462 set targetdata
[lindex $ScenarioButtons $target]
3463 set targetid
[lindex $targetdata 1]
3464 LinkWindow
$w.
$targetid.over
0
3465 UpdateScenarioButton
$w $targetdata
3470 #echo IN $w $found $xx $yy $over
3471 LinkWindow
$w.scenarioTarget
$found
3472 LinkWindow
$w.
$id.over
1
3474 if {$target != -1} {
3475 set targetdata
[lindex $ScenarioButtons $target]
3476 set targetid
[lindex $targetdata 1]
3477 LinkWindow
$w.
$targetid.over
0
3478 UpdateScenarioButton
$w $targetdata
3481 UpdateScenarioButton
$w $data
3487 proc DoLoad
{win param
} {
3488 #echo DOLOAD $win $param
3493 proc DoGenerate
{win param
} {
3494 #echo DOGENERATE $win $param
3499 proc DoQuit
{win param
} {
3500 #echo DOQUIT $win $param
3505 proc DoAbout
{win param
} {
3506 #echo DOABOUT $win $param
3507 MakeHistory
"DoLoadCity cities/about.cty"
3511 proc DoMap
{win param
} {
3512 #echo DOMAP $win $param
3516 proc DoLevel
{win param
} {
3517 #echo DOLEVEL $win $param
3518 DoSetGameLevel
$param
3522 proc DoLeft
{win param
} {
3523 #echo DOLEFT $win $param
3528 proc DoRight
{win param
} {
3529 #echo DORIGHT $win $param
3534 proc DoPlay
{win param
} {
3535 #echo DOPLAY $win $param
3540 proc DoPickScenario
{win param
} {
3541 #echo DOPICKSCENARIO $win $param
3542 UILoadScenario
$param
3546 ########################################################################
3547 # Undo/Redo Facility
3550 proc InitHistory
{} {
3552 global MapHistoryNum
3554 set MapHistoryNum
-1
3558 proc MakeHistory
{cmd
} {
3560 set len
[llength $MapHistory]
3562 ($cmd != [lindex $MapHistory [expr $len-1]])} {
3563 lappend MapHistory
$cmd
3571 proc GotoHistory
{i
} {
3573 global MapHistoryNum
3574 InitVotesForUseThisMap
3575 if {$i != $MapHistoryNum} {
3576 set MapHistoryNum
$i
3577 set cmd
[lindex $MapHistory $i]
3580 if {$MapHistoryNum == 0} {
3585 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3591 global ScenarioWindows
3592 foreach win
$ScenarioWindows {
3593 UpdateLeftRightEnabled
$win
3599 proc NextHistory
{} {
3601 global MapHistoryNum
3602 set len
[llength $MapHistory]
3603 set i
[expr "$MapHistoryNum + 1"]
3610 proc PrevHistory
{} {
3612 global MapHistoryNum
3613 set i
[expr "$MapHistoryNum - 1"]
3620 ########################################################################
3621 # Ask Window Handlers
3623 proc ShowAskOf
{head
} {
3624 set win
[WindowLink
$head.ask
]
3626 set win
[MakeWindow.ask
$head [winfo screen
$head]]
3636 foreach win
$HeadWindows {
3642 proc WithdrawAsks
{} {
3644 foreach win
$AskWindows {
3650 proc WithdrawAskOf
{win
} {
3651 set ask
[WindowLink
$win.ask
]
3658 proc AskQuestion
{color title
text left middle right
} {
3660 foreach win
$HeadWindows {
3661 AskQuestionOn
$win $color $title $text $left $middle $right
3666 proc AskQuestionOn
{head color title
text left middle right
} {
3669 set win
[WindowLink
$head.ask
]
3670 set t
[WindowLink
$win.title
]
3671 $t configure
-text $title
3672 $t configure
-background $color
3674 set t
[WindowLink
$win.
text]
3675 $t configure
-state normal
3677 $t insert end
"${text}\n"
3678 $t configure
-state disabled
3680 set bf
[WindowLink
$win.
frame]
3681 set l
[WindowLink
$win.left
]
3682 set m
[WindowLink
$win.middle
]
3683 set r
[WindowLink
$win.vote
]
3684 set rf
[WindowLink
$win.voteframe
]
3688 -text [lindex $left 0] \
3689 -command [format [lindex $left 2] $head]
3690 SetHelp
$l [lindex $left 1]
3691 pack append $bf $l {left
frame center
}
3696 if {$middle != ""} {
3698 -text [lindex $middle 0] \
3699 -command [format [lindex $middle 2] $head]
3700 SetHelp
$m [lindex $middle 1]
3701 pack append $bf $m {left
frame center expand
}
3707 set notify
[format [lindex $right 2] $head]
3708 set preview
[format [lindex $right 3] $head]
3709 set cmd
[list DoVote
$win Ask
$notify $preview]
3711 -text [lindex $right 0] \
3713 SetHelp
$r [lindex $right 1]
3714 pack append $bf $rf {right
frame center
}
3723 proc BindVotingButton
{win but name
} {
3724 set w
[WindowLink
$win.top
]
3726 bind $but <Any-Enter
> "VoteButtonEnter $win $but"
3727 bind $but <Any-Leave
> "VoteButtonLeave $win $but"
3728 bind $but <1> "VoteButtonDown $win $but $name"
3729 bind $but <ButtonRelease-1
> "VoteButtonUp $win $but $name"
3730 bind $but <2> "VoteButtonDown $win $but $name"
3731 bind $but <ButtonRelease-2
> "VoteButtonUp $win $but $name"
3732 bind $but <3> "VoteButtonDown $win $but $name"
3733 bind $but <ButtonRelease-3
> "VoteButtonUp $win $but $name"
3737 proc VoteButtonEnter
{win but
} {
3739 set screen
[winfo screen
$but]
3740 if {[lindex [$but config
-state] 4] != "disabled"} {
3741 $but config
-state active
3742 set tk_priv
(window
@$screen) $but
3744 set tk_priv
(window
@$screen) ""
3749 proc VoteButtonLeave
{win but
} {
3751 if {[lindex [$but config
-state] 4] != "disabled"} {
3752 $but config
-state normal
3754 set screen
[winfo screen
$but]
3755 set tk_priv
(window
@$screen) ""
3759 proc VoteButtonDown
{win but name
} {
3761 set screen
[winfo screen
$but]
3762 set rel
[lindex [$but config
-relief] 4]
3763 set tk_priv
(relief
@$screen) $rel
3764 if {[lindex [$but config
-state] 4] != "disabled"} {
3765 set head
[WindowLink
$win.head
]
3766 if {[IsVotingFor
$head $name]} {
3767 $but config
-relief raised
3769 $but config
-relief sunken
3775 proc VoteButtonUp
{win but name
} {
3777 set screen
[winfo screen
$but]
3778 $but config
-relief $tk_priv(relief
@$screen)
3779 if {($but == $tk_priv(window
@$screen))
3780 && ([lindex [$but config
-state] 4] != "disabled")} {
3781 uplevel #0 [list $but invoke]
3782 set head
[WindowLink
$win.head
]
3783 if {[IsVotingFor
$head $name]} {
3784 $but config
-relief sunken
3786 $but config
-relief raised
3792 proc PressVoteButton
{win but name
} {
3794 uplevel #0 [list $but invoke]
3795 set head
[WindowLink
$win.head
]
3796 if {[IsVotingFor
$head $name]} {
3797 $but config
-relief sunken
3799 $but config
-relief raised
3804 proc IsVotingFor
{win name
} {
3805 global VotesFor
$name
3806 set votes
[eval ident
"\$\{VotesFor$name\}"]
3807 if {[lsearch $votes $win] == -1} {
3815 proc DoVote
{win name notify preview
} {
3816 global VotesFor
$name
3817 set votes
[eval ident
"\$\{VotesFor$name\}"]
3819 set win
[WindowLink
$win.head
]
3820 set i
[lsearch $votes $win]
3822 lappend VotesFor
$name $win
3824 set VotesFor
$name [lreplace $votes $i $i]
3827 set votes
[eval ident
"\$\{VotesFor$name\}"]
3828 if {[llength $votes] >= [NeededVotes
]} {
3836 proc UpdateVotesFor
{name wins
} {
3837 global VotesFor
$name
3838 set votes
[eval llength "\$\{VotesFor$name\}"]
3839 set needed
[NeededVotes
]
3842 set head
[WindowLink
$win.head
]
3843 if {[IsVotingFor
$head $name]} {
3844 set border
[expr "($needed - $votes) * 1"]
3845 set pad
[expr "6 - $border"]
3846 [WindowLink
$win.vote
] config
-padx $pad -pady $pad
3847 [WindowLink
$win.voteframe
] config
-borderwidth $border
3849 set border
[expr "($needed - $votes - 1) * 1"]
3850 set pad
[expr "6 - $border"]
3851 [WindowLink
$win.vote
] config
-padx $pad -pady $pad
3852 [WindowLink
$win.voteframe
] config
-borderwidth $border
3858 proc InitVotesForAsk
{} {
3859 global VotesForAsk AskWindows
3861 foreach win
$AskWindows {
3862 [WindowLink
$win.vote
] config
-relief raised
3869 proc UpdateVotesForAsk
{} {
3871 UpdateVotesFor Ask
$AskWindows
3875 ########################################################################
3876 # Player Window Handlers
3878 proc ShowPlayerOf
{head
} {
3879 set win
[WindowLink
$head.player
]
3881 set win
[MakeWindow.player
$head [winfo screen
$head]]
3889 proc ShowPlayers
{} {
3891 foreach win
$HeadWindows {
3897 proc WithdrawPlayers
{} {
3898 global PlayerWindows
3899 foreach win
$PlayerWindows {
3905 proc UpdatePlayers
{} {
3906 # TODO: Disabled for new scenario window.
3909 global HeadWindows PlayerWindows
3912 foreach win
$HeadWindows {
3913 set server
[winfo screen
$win]
3914 # if {[string first : $server] == 0} {
3915 # set server "[exec hostname]:0"
3917 lappend players
$server
3920 sim Players
[llength $players]
3922 foreach win
$PlayerWindows {
3923 set list [WindowLink
$win.players
]
3925 eval "$list insert 0 $players"
3928 UpdateVotesForUseThisMap
3930 UpdateVotesForBudget
3931 UpdateTaxRateSliders
3935 proc UIShowPlayer
{win
} {
3940 proc DoNewPlayer
{win
} {
3941 set field
[WindowLink
$win.display
]
3942 set dpy
[$field get
]
3947 if {[AddPlayer
$dpy] != ""} {
3953 ########################################################################
3954 # Notice Window Handlers
3957 proc ShowNoticeOf
{head
} {
3958 set win
[WindowLink
$head.notice
]
3960 set win
[MakeWindow.notice
$head [winfo screen
$head]]
3962 global NoticePanelWidth NoticePanelHeight
3963 #place configure $win -x 0 -y 0 -width $NoticePanelWidth -height $NoticePanelHeight
3964 pack append [WindowLink
$head.w3
] \
3965 $win {bottom
frame sw expand fill
}
3970 proc ShowNotices
{} {
3972 foreach win
$HeadWindows {
3978 proc WithdrawNotices
{} {
3979 global NoticeWindows
3980 foreach win
$NoticeWindows {
3987 proc ReShowPictureOn
{{head
""}} {
3988 global ShowingPicture ShowingParms
3989 UIShowPictureOn
$head $ShowingPicture $ShowingParms
3993 proc UIShowPicture
{id
{parms
""}} {
3994 UIShowPictureOn
"" $id $parms
3998 proc UIShowPictureOn
{where id
{parms
""}} {
3999 global DoNotices Messages ShowingPicture ShowingParms
4000 if {$DoNotices == 0} {
4004 set ShowingPicture
$id
4005 set ShowingParms
$parms
4006 set msg
$Messages($id)
4007 set color
[lindex $msg 0]
4008 set title
[lindex $msg 1]
4009 set body
[lindex $msg 2]
4011 set cmd
"format {$body} $parms"
4012 set body
[uplevel #0 $cmd]
4014 set props
[lindex $msg 3]
4015 if {"$where" == ""} {
4017 set where
$HeadWindows
4019 foreach head
$where {
4020 NoticeMessageOn
$head "$title" $color "$body" Medium
$props
4025 proc NoticeMessageOn
{head title color
text font props
} {
4027 set win
[WindowLink
$head.notice
]
4029 set t
[WindowLink
$win.title
]
4030 $t configure
-text $title -background $color
4032 set t
[WindowLink
$win.
text]
4033 $t configure
-state normal
-font [Font
$head $font]
4035 $t insert end
"${text}\n"
4036 $t configure
-state disabled
4039 catch {set left
[keylget props left
]}
4040 set l
[WindowLink
$win.left
]
4042 $l config
-bitmap $left
4043 place $l -in $t -anchor sw
-relx .05 -rely .95
4049 catch {set middle
[keylget props middle
]}
4050 set m
[WindowLink
$win.middle
]
4051 if {$middle != ""} {
4052 $m config
-bitmap $middle
4053 place $m -in $t -anchor s
-relx .5 -rely .95
4059 catch {set right
[keylget props right
]}
4060 set r
[WindowLink
$win.right
]
4062 $r config
-bitmap $right
4063 place $r -in $t -anchor se
-relx .95 -rely .95
4069 catch {set view
[keylget props view
]}
4070 set vf
[WindowLink
$win.viewframe
]
4072 set v
[WindowLink
$win.view
]
4073 set bg
[WindowLink
$win.background
]
4077 pack append $bg $vf {left
frame center fill
}
4078 pack append $bg $t {right
frame center fill expand
}
4085 proc UIPopUpMessage
{msg
} {
4090 proc ComeToMe
{view
} {
4091 set win
[winfo toplevel $view]
4094 set x
[expr "[lindex $xy 0] >>4"]
4095 set y
[expr "[lindex $xy 1] >>4"]
4101 proc ComeTo
{win x y
} {
4102 global EditorWindows
4103 set head
[WindowLink
$win.head
]
4106 foreach ed
$EditorWindows {
4107 if {"[WindowLink $ed.head]" == "$head"} {
4109 set view
[WindowLink
$ed.view
]
4110 if {[$view AutoGoto
]} {
4111 lappend myautoeds
$ed
4115 if {[llength $myautoeds]} {
4116 UIAutoGotoOn
$x $y $myautoeds
4118 if {[llength $myeds]} {
4119 UIAutoGotoOn
$x $y $myeds
4125 proc FollowView
{view id
} {
4129 if {[sim DoAnimation
]} {
4130 set head
[WindowLink
[winfo toplevel $view].head
]
4131 global EditorWindows
4132 foreach win
$EditorWindows {
4133 if {"[WindowLink $win.head]" == "$head"} {
4134 set s
[[WindowLink
$win.view
] Skip
]
4135 set skips
[min
$skips $s]
4139 if {$skips == 999999} {
4149 proc PanView
{view x y
} {
4155 ########################################################################
4156 # Help Window Handlers
4159 proc ShowHelpOf
{head
} {
4160 set win
[WindowLink
$head.help
]
4162 set win
[MakeWindow.help
$head [winfo screen
$head]]
4172 foreach win
$HeadWindows {
4178 proc WithdrawHelps
{} {
4180 foreach win
$HelpWindows {
4186 ########################################################################
4187 # Frob Window Handlers
4190 proc ShowFrobOf
{head
} {
4191 set win
[WindowLink
$head.frob
]
4193 set win
[MakeWindow.frob
$head [winfo screen
$head]]
4204 foreach win
$HeadWindows {
4210 proc WithdrawFrobs
{} {
4212 foreach win
$FrobWindows {
4218 proc UISetDynamic
{i min max
} {
4219 sim DynamicData
[expr "$i*2"] $min
4220 sim DynamicData
[expr "$i*2+1"] $max
4224 ########################################################################
4231 source $ResourceDir/help.tcl
4234 proc HandleHelp
{win x y rootx rooty
} {
4235 global HelpLoaded HelpWidgets Messages
4237 if {$HelpLoaded == 0} {
4243 set head
[WindowLink
[winfo toplevel $win].head
]
4246 catch {set id
$HelpWidgets($win)}
4250 set list [split $win .
]
4251 set len
[expr "[llength $list] - 2"]
4252 set list [lrange $list 0 $len]
4253 if {[llength $list] <= 1} {
4257 set win
[join $list .
]
4259 if [info exists Messages
($id)] {
4260 UIShowHelpOn
$head $id
4262 UIShowHelpOn
$head Window
4267 proc UIShowHelpOn
{win id
{parms
""}} {
4268 global Messages ShowingPicture ShowingParms ResourceDir
4269 set head
[WindowLink
$win.head
]
4270 set msg
$Messages($id)
4271 set color
[lindex $msg 0]
4272 set title
[lindex $msg 1]
4273 set body
[lindex $msg 2]
4275 set cmd
"format {$body} $parms"
4276 set body
[uplevel #0 $cmd]
4278 set props
[lindex $msg 3]
4281 set win
[WindowLink
$head.help
]
4283 set t
[WindowLink
$win.title
]
4284 $t configure
-text $title -background $color
4286 set t
[WindowLink
$win.
text]
4287 $t configure
-state normal
-font [Font
$head Large
]
4289 $t insert end
"${body}\n"
4290 FormatHTML
$ResourceDir/doc
/$id.html
$t
4291 $t configure
-state disabled
4295 proc FormatHTML
{filename text} {
4298 set f
[open $filename]
4305 while {[gets $f line
] >= 0} {
4306 if {"$line" == "</body>"} {
4309 if {([string index
$line 0] == "#") ||
([string length
$line] == 0)} {
4312 $text insert end
"$line\n"
4321 proc SetHelp
{win id
} {
4323 set HelpWidgets
($win) $id
4327 proc Help
{id title
{msg
{}} {props
{}}} {
4328 Message
$id #7f7fff $title $msg $props
4331 ########################################################################
4335 # Set up the bindings to pop up $pie when the right button is clicked in $win
4336 proc InitPie
{win pie
} {
4337 bind $win <Motion
> {}
4338 bind $win <3> "PieMenuDown $win $pie $pie Initial %X %Y"
4339 bind $win <B3-Motion
> {}
4340 bind $win <B3-ButtonRelease
> {}
4344 # Set up the bindings to continue tracking $pie
4345 # Get this: we keep the tracking machine state in the bindings!
4346 proc ActivatePie
{win root pie state
} {
4347 bind $win <Motion
> "PieMenuMotion $win $root $pie $state %X %Y"
4348 bind $win <3> "PieMenuDown $win $root $pie $state %X %Y"
4349 bind $win <B3-Motion
> "PieMenuMotion $win $root $pie $state %X %Y"
4350 bind $win <B3-ButtonRelease
> "PieMenuUp $win $root $pie $state %X %Y"
4354 # Cancel and reset a pie menu
4355 proc CancelPie
{win
} {
4356 set binding
[bind $win <3>]
4357 set root
[lindex $binding 2]
4358 set pie
[lindex $binding 3]
4359 set state
[lindex $binding 4]
4360 if {"$state" != "Initial"} {
4361 catch {$root ungrab
$win}
4364 UIMakeSoundOn
$win fancy Oop
4370 # Handle pie menu button down
4371 proc PieMenuDown
{win root pie state x y
} {
4374 ActivatePie
$win $root $pie FirstDown
4376 catch {$root grab $win}
4379 PreviewPieMenu
$win $pie $x $y
4383 TrackPieMenu
$pie $x $y
4384 ActivatePie
$win $root $pie SecondDown
4390 PreviewPieMenu
$win $pie $x $y
4391 ActivatePie
$win $root $pie SecondDown
4396 SecondDown
{ # error
4403 # Handle pie menu button motion
4404 proc PieMenuMotion
{win root pie state x y
} {
4407 TrackPieMenu
$pie $x $y
4415 TrackPieMenu
$pie $x $y
4429 # Handle pie menu button up
4430 proc PieMenuUp
{win root pie state x y
} {
4433 TrackPieMenu
$pie $x $y
4434 set active
[$pie index active
]
4435 if {$active == "none"} {
4437 catch {$root grab $win}
4438 ActivatePie
$win $root $pie ClickedUp
4440 set label [lindex [$pie entryconfig
$active -label] 4]
4441 set submenu
[lindex [$pie entryconfig
$active -piemenu] 4]
4442 UIMakeSoundOn
$win mode
$label
4443 if {$submenu == {}} {
4444 set reward
[$pie pending
]
4445 catch {$root ungrab
$win}
4449 sim Funds
[expr "[sim Funds] + 5"]
4450 UIMakeSoundOn
$win fancy Aaah
4452 eval [lindex [$pie entryconfig
$active -command] 4]
4457 $submenu activate none
4459 PreviewPieMenu
$win $submenu $x $y
4460 catch {$root grab $win}
4461 ActivatePie
$win $root $submenu SelectedUp
4466 TrackPieMenu
$pie $x $y
4467 set active
[$pie index active
]
4468 if {$active == "none"} {
4471 set label [lindex [$pie entryconfig
$active -label] 4]
4472 set submenu
[lindex [$pie entryconfig
$active -piemenu] 4]
4473 UIMakeSoundOn
$win mode
$label
4474 if {$submenu == {}} {
4475 set reward
[$pie pending
]
4476 catch {$root ungrab
$win}
4480 sim Funds
[expr "[sim Funds] + 5"]
4481 UIMakeSoundOn
$win fancy Aaah
4483 eval [lindex [$pie entryconfig
$active -command] 4]
4488 $submenu activate none
4490 PreviewPieMenu
$win $submenu $x $y
4491 catch {$root grab $win}
4492 ActivatePie
$win $root $submenu SelectedUp
4502 SelectedUp
{ # error
4509 # Track the selected item
4510 proc TrackPieMenu
{pie x y
} {
4511 $pie activate
@$x,$y
4515 proc PreviewPieMenu
{win pie x y
} {
4516 set preview
[lindex [$pie config
-preview] 4]
4517 if {"$preview" != ""} {
4518 set rx
[winfo rootx
$win]
4519 set ry
[winfo rooty
$win]
4520 set x
[expr "$x - $rx"]
4521 set y
[expr "$y - $ry"]
4522 eval [format $preview $x $y]
4527 ########################################################################
4531 proc ExclusivePallet
{state parent children prefix images inactive active cmd
} {
4532 #echo "ExclusivePallet state $state parent $parent children $children prefix $prefix images $images inactive $inactive active $active cmd $cmd"
4534 foreach child
$children {
4535 set name
[lindex $images $i]
4536 if {$i == $state} then
{
4537 $parent.
$child config
\
4538 -bitmap "@images/${prefix}${name}hi.xpm" \
4541 $parent.
$child config
\
4542 -bitmap "@images/${prefix}${name}.xpm" \
4547 eval [concat $cmd $state]
4551 proc NonExclusivePallet
{mask parent children prefix images
4552 inactive active cmd
} {
4554 foreach child
$children {
4555 set name
[lindex $images $i]
4556 if {$mask & (1<<$i)} then
{
4557 $parent.
$child config
\
4558 -bitmap "@images/${prefix}${name}hi.xpm" \
4561 $parent.
$child config
\
4562 -bitmap "@images/${prefix}${name}.xpm" \
4567 eval [concat $cmd $mask]
4571 proc EditorPallet
{win state
} {
4572 global EditorPalletSounds
4573 UIMakeSoundOn
$win mode
[lindex $EditorPalletSounds $state]
4574 EditorSetTool
$win $state
4578 proc EditorSetTool
{win state
} {
4579 global EditorPallets
4580 global EditorPalletImages
4581 ExclusivePallet
$state $win $EditorPallets ic
$EditorPalletImages \
4582 flat raised
"$win.centerframe.view ToolState"
4586 proc GraphPallet
{win state
} {
4587 set mask
[[WindowLink
$win.graphview
] Mask
]
4588 set mask
[expr "$mask ^ (1<<$state)"]
4589 GraphPalletMask
$win $mask
4593 proc GraphPalletMask
{win mask
} {
4595 global GraphPalletImages
4596 NonExclusivePallet
$mask $win $GraphPallets gr
$GraphPalletImages \
4597 flat flat
"SetGraphState $win"
4601 proc GraphYearPallet
{win state
} {
4602 global GraphYearPallets
4603 global GraphYearPalletImages
4604 ExclusivePallet
$state $win $GraphYearPallets gr
$GraphYearPalletImages \
4605 flat flat
"SetGraphYearState $win"
4609 proc SetGraphYearState
{win state
} {
4610 set graph
[WindowLink
$win.graphview
]
4619 proc SetGraphState
{win mask
} {
4621 set graph
[WindowLink
$win.graphview
]
4626 ########################################################################
4629 proc sim_butEnter
{w
} {
4631 set screen
[winfo screen
$w]
4632 set tk_priv
(window
@$screen) $w
4636 proc sim_butLeave
{w
} {
4638 set screen
[winfo screen
$w]
4639 set tk_priv
(window
@$screen) ""
4643 proc sim_butDown
{w
} {
4645 set screen
[winfo screen
$w]
4646 set pict
[lindex [$w config
-bitmap] 4]
4647 set tk_priv
(relief
@$screen) $pict
4648 $w config
-bitmap [lindex [split $pict .
] 0]hi.xpm
4653 proc sim_butUp
{w
} {
4655 set screen
[winfo screen
$w]
4656 $w config
-bitmap $tk_priv(relief
@$screen)
4658 if {$w == $tk_priv(window
@$screen)} {
4659 uplevel #0 [list $w invoke]
4664 proc BindSimButton
{w
} {
4665 bind $w <Any-Enter
> {sim_butEnter
%W
}
4666 bind $w <Any-Leave
> {sim_butLeave
%W
}
4667 bind $w <1> {sim_butDown
%W
}
4668 bind $w <ButtonRelease-1
> {sim_butUp
%W
}
4669 bind $w <2> {sim_butDown
%W
}
4670 bind $w <ButtonRelease-2
> {sim_butUp
%W
}
4671 bind $w <3> {sim_butDown
%W
}
4672 bind $w <ButtonRelease-3
> {sim_butUp
%W
}
4676 ########################################################################
4677 # Internal Callbacks
4680 proc UIStartMicropolis
{homedir resourcedir hostname
} {
4681 global HomeDir ResourceDir HostName HeadWindows
4682 set HomeDir
$homedir
4683 set ResourceDir
$resourcedir
4684 set HostName
$hostname
4689 foreach display
[sim Displays
] {
4690 if {"[AddPlayer $display]" == ""} {
4691 echo Couldn't add a player on
$display ...
4695 if {"$HeadWindows" == ""} {
4696 echo Micropolis is exiting because it couldn't connect to any players.
4702 proc UISelectCity
{win
} {
4703 AskQuestion
[Color
$win #ff0000 #ffffff] "Choose Another City" \
4704 "Do you want to abandon this city and choose another one?" \
4705 "{Keep playing.} SelectCity.No {RejectPlan}" \
4707 "{Another city!} SelectCity.Yes {UIPickScenarioMode}"
4711 proc UIQuit
{head
} {
4712 if {[sim Players
] == 1} {
4713 set l
"{Keep playing.} Quit.No {RejectPlan}"
4715 set r
"{I quit!} Quit.IQuit {DoReallyQuit %s}"
4717 set l
"{Keep playing.} Quit.No {RejectPlan}"
4718 set m
"{I quit!} Quit.IResign {DoIResign %s}"
4719 set r
"{Everyone quit!} Quit.AllQuit {DoReallyQuit %s}"
4721 AskQuestion
[Color
$head #ff0000 #ffffff] "Quit Playing Micropolis" \
4722 "Do you want to quit playing Micropolis?" \
4727 proc DoIResign
{head
} {
4729 set display
[winfo screen
$head]
4731 DecRefDisplay
$display
4732 UISetMessage
"The player on X11 Display $display has resigned."
4734 if {([sim Players
] == 0) ||
4735 ([llength $VotesForAsk] >= [sim Players
])} {
4741 proc DoReallyQuit
{head
} {
4747 proc UISplashMode
{} {
4757 proc UIPickScenarioMode
{} {
4766 InitVotesForUseThisMap
4771 proc ForcePickScenarioMode
{} {
4773 if {"$State" != "scenario"} {
4779 proc UIGenerateCityNow
{} {
4780 global CityName GameLevel
4781 sim CityName NowHere
4787 proc UIGenerateNewCity
{} {
4788 global CityName GameLevel
4789 if {$GameLevel == -1} {
4792 MakeHistory
"DoNewCity NowHere $GameLevel [sim Rand] [sim TreeLevel] [sim LakeLevel] [sim CurveLevel] [sim CreateIsland]"
4796 proc DoNewCity
{name level
{r
""} {tl
-1} {ll
-1} {cl
-1} {ci
-1}} {
4802 sim CreateIsland
$ci
4806 sim GenerateSomeCity
$r
4809 sim GameLevel
$level
4814 proc UIDidGenerateNewCity
{} {
4819 proc IncRefDisplay
{display
} {
4820 global DisplayRegistry
4821 if ![info exists DisplayRegistry
($display)] {
4822 set DisplayRegistry
($display) 0
4824 incr DisplayRegistry
($display)
4828 proc DecRefDisplay
{display
} {
4829 global DisplayRegistry
4830 incr DisplayRegistry
($display) -1
4831 if {$DisplayRegistry($display) <= 0} {
4832 CloseDisplay
$display
4837 proc CloseDisplay
{display
} {
4841 proc DoStopMicropolis
{} {
4847 proc AddPlayer
{display
} {
4848 set i
[string first
: $display]
4852 set display
"$display:0"
4856 echo Adding a player on
$display ...
4858 set head
[MakeWindow.head
$display]
4860 if {"$head" != ""} {
4861 set display
[winfo screen
$head]
4862 IncRefDisplay
$display
4864 UISetMessage
"Added a player on X11 Display \"$display\"."
4867 UISetMessage
"Couldn't add a player on X11 Display \"$display\"!"
4877 proc DropFireBombs
{} {
4885 proc UIMakeMonster
{} {
4886 sim MakeMonster
[sim Rand
120] [sim Rand
100]
4909 proc TogglePause
{} {
4912 if {"$State" != "play" ||
[sim Speed
]} {
4921 proc SetSpeedTime
{time} {
4927 proc MakeRunningSound
{} {
4930 if {"$State" == "play" && [sim Speed
]} {
4931 UIMakeSound edit Boing
"-speed 1[sim Speed]0"
4933 UIMakeSound edit Boing
"-speed 90"
4938 proc SayDemands
{} {
4939 global DemandRes DemandCom DemandInd
4941 set r
[expr "100 + ($DemandRes * $slope)"]
4942 set c
[expr "100 + ($DemandCom * $slope)"]
4943 set i
[expr "100 + ($DemandInd * $slope)"]
4944 after 020 "UIMakeSound edit O \"-speed $r\""
4945 after 220 "UIMakeSound edit A \"-speed $c\""
4946 after 440 "UIMakeSound edit E \"-speed $i\""
4950 proc UISaveCity
{win
} {
4952 set SaveCityWin
$win
4957 proc UISaveCityAs
{{win
""}} {
4959 if {"$win" == ""} {set win
$SaveCityWin}
4960 set SaveCityWin
$win
4963 set file [ShowFileOf
$win]
4964 DoFileDialog
$file "Choose a File to Save the City" $CityDir "*.cty" "" \
4965 "UIDoReallySaveCity" ""
4969 proc UIDoReallySaveCity
{name path
} {
4971 if {![string match
*.cty
$name]} {
4975 sim SaveCityAs
$path/$name
4979 proc UIDidSaveCity
{} {
4980 DoSendMessage
"Saved the city in \"[sim CityFileName]\"." status
4984 proc UIDidntSaveCity
{msg
} {
4985 DoSendMessage
$msg alert
4986 UIMakeSound warning Sorry
"-speed 85"
4990 proc UILoadScenario
{scen
} {
4991 MakeHistory
"DoScenario $scen"
4995 proc DoScenario
{scen
} {
4998 sim LoadScenario
$scen
5003 proc UIDidLoadScenario
{} {
5007 proc UIStartScenario
{id
} {
5016 proc UIPlayNewCity
{} {
5022 proc UIStartLoad
{} {
5027 proc UIReallyStartGame
{} {
5033 proc UIPlayGame
{} {
5040 SetPriority
$Priority
5048 proc UISetSpeed
{speed
} {
5051 if {"$State" == "play"} {
5052 UISetMessage
[lindex {
5055 {Time flows medium.
}
5063 proc UIUpdateRunning
{} {
5064 global HeadWindows Time State
5066 if {($State == "play") && $Time} {
5067 set pict
"@images/micropolisg.xpm"
5069 set pict
"@images/micropoliss.xpm"
5072 foreach win
$HeadWindows {
5073 set can
[WindowLink
$win.demand
]
5074 $can itemconfig micropolis
-bitmap $pict
5079 proc DoSetGameLevel
{level
} {
5080 sim GameLevel
$level
5084 proc UISetGameLevel
{level
} {
5086 set GameLevel
$level
5087 global ScenarioWindows
5088 foreach win
$ScenarioWindows {
5089 UpdateLevelSelection
$win
5094 proc UISetCityName
{name
} {
5095 global EditorWindows
5098 set title
"Micropolis Editor on $name"
5099 foreach win
$EditorWindows {
5100 # TODO: set editor window and icon title
5101 #wm title $win "$title"
5102 #wm iconname $win "$title"
5107 proc UILoadCity
{win
} {
5108 # if changed, r-u-sure?
5110 set file [ShowFileOf
$win]
5111 DoFileDialog
$file "Choose a City to Load" $CityDir "*.cty" "" \
5116 proc UIDoLoadCity
{name path
} {
5119 if {![string match
*.cty
$name]} {
5122 MakeHistory
"DoLoadCity $path/$name"
5126 proc DoLoadCity
{filename} {
5127 sim LoadCity
$filename
5130 proc UIDidLoadCity
{} {
5131 global State GameLevel Scenario
5134 if {$State == "play"} {
5137 UIShowPicture
49 [sim CityFileName
]
5142 proc UIDidntLoadCity
{msg
} {
5143 DoSendMessage
$msg alert
5144 UIMakeSound warning Sorry
"-speed 85"
5145 UIShowPicture
49 [sim CityFileName
]
5164 proc UIDidPan
{w x y
} {
5165 if {[$w ToolMode
] == 1} {
5166 EditorToolDrag
$w $x $y
5172 proc UIDidStopPan
{win
} {
5173 UIMakeSoundOn
$win fancy Skid
"-volume 25"
5178 proc UIEarthQuake
{} {
5182 proc UIAutoGoto
{x y
{except
{}}} {
5183 global EditorWindows
5185 set x
[expr "$x * 16 + 8"]
5186 set y
[expr "$y * 16 + 8"]
5187 foreach win
$EditorWindows {
5188 if {"$win" != "$except"} {
5189 set view
[WindowLink
$win.view
]
5190 if {[$view AutoGoto
]} {
5192 $view AutoGoal
$x $y
5202 proc UIAutoGotoOn
{x y eds
} {
5203 set x
[expr "$x * 16 + 8"]
5204 set y
[expr "$y * 16 + 8"]
5206 [WindowLink
$win.view
] AutoGoal
$x $y
5212 proc DoLeaveGame
{head
} {
5216 proc UILoseGame
{} {
5227 proc DoPendTool
{view tool x y
} {
5228 global HeadWindows ToolInfo VotesForAsk
5230 set win
[WindowLink
$view.top
]
5231 set head
[WindowLink
$win.head
]
5233 if {($tool == [sim PendingTool
]) &&
5234 ($x == [sim PendingX
]) &&
5235 ($y == [sim PendingY
])} {
5236 if {[lsearch $VotesForAsk $head] != -1} {
5237 # you can only vote once
5238 UIMakeSound edit Oop
5240 UIMakeSound edit Boing
5241 set ask
[WindowLink
$head.ask
]
5242 PressVoteButton
$ask [WindowLink
$ask.vote
] Ask
5245 UIAutoGoto
$x $y $win
5247 UIMakeSound edit Boing
5248 set info [lindex $ToolInfo $tool]
5249 set a
[lindex $info 0]
5250 set name
[lindex $info 1]
5251 set cost
[lindex $info 2]
5252 set title
"Build $a $name"
5253 set question
"Do you support the plan to build $a $name for $cost?"
5254 AskQuestion
[Color
$win #00ff00 #ffffff] "$title" \
5256 "{Veto plan.} Plan.Veto
5258 "{Goto plan.} Plan.Goto
5259 {ComeTo %s $x $y}" \
5260 "{Support plan!} Plan.Support
5261 {SupportPlan $view %s $tool $x $y}
5262 {PreviewSupportPlan $view %s $tool $x $y}"
5263 set VotesForAsk
$head
5264 set ask
[WindowLink
$head.ask
]
5265 [WindowLink
$ask.vote
] config
-relief sunken
5269 sim PendingTool
$tool
5272 sim Votes
[llength $VotesForAsk]
5277 proc RejectPlan
{} {
5279 if {[sim Players
] > 1} {
5280 UIMakeSound edit Sorry
5286 proc NeededVotes
{} {
5288 set players
[sim Players
]
5289 set needed
[expr "$players - $FreeVotes"]
5290 return [max
0 $needed]
5294 proc SupportPlan
{view h tool x y
} {
5296 sim Votes
[llength $VotesForAsk]
5299 $view DoTool
$tool $x $y
5302 UIMakeSound edit Aaah
5306 proc PreviewSupportPlan
{view h tool x y
} {
5308 sim Votes
[llength $VotesForAsk]
5312 proc SugarStartUp
{uri
} {
5316 # TODO: Load the city file at the given URI, or configure according to URI parameters.
5320 proc SugarNickName
{nick
} {
5321 global SugarNickName
5322 set SugarNickName
$nick
5326 proc SugarActivate
{} {
5327 global SugarActivated
5328 set SugarActivated
1
5332 proc SugarDeactivate
{} {
5333 global SugarActivated
5334 set SugarActivated
0
5338 proc SugarShare
{} {
5344 proc SugarBuddyAdd
{key nick color address
} {
5346 set buddy
[list $key $nick $color $address]
5347 lappend SugarBuddies
$buddy
5351 proc SugarBuddyDel
{key nick color address
} {
5353 set buddy
[list $key $nick $color $address]
5354 set i
[lsearch $wins $win]
5356 set SugarBuddies
[lreplace $wins $i $i]
5366 ########################################################################