]> git.zerfleddert.de Git - micropolis/blobdiff - res/micropolis.tcl
use old forking player when SDL_mixer is not available
[micropolis] / res / micropolis.tcl
index ff1ad9b0acd3a6501d4fb05d9f2f664a8dc80110..5704330d82f25288932aad3c8d640c3ff0559ad5 100644 (file)
@@ -97,6 +97,7 @@ set DemandCom 0
 set DemandInd 0
 set Priority 2
 set Time 3
+set Pause 0
 set AutoGoto 1
 set AutoBudget 1
 set Disasters 1
@@ -412,8 +413,12 @@ sim ResetDynamic
 # the font in res (because it's already in the system fonts).  These lines
 # are for other systems that lack the font.
 set FontPath "[pwd]/res/dejavu-lgc"
-system "xset -fp $FontPath >&/dev/null"
-system "xset +fp $FontPath >&/dev/null"
+system "xset -fp \"$FontPath\" >/dev/null 2>&1"
+system "xset +fp \"$FontPath\" >/dev/null 2>&1"
+
+# Ignore SIGCHLD for spawned sound-player childs, this should lead to them
+# being reaped by init
+signal ignore SIGCHLD
 
 
 ########################################################################
@@ -484,7 +489,7 @@ Either clean up your act or open a gas mask concession at city hall.} \
 {{view {PanView $v [sim PolMaxX] [sim PolMaxY]}}}
 
 Message 11 #ff4f4f {CRIME ALERT!} \
-{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.} \
+{Crime in your city is out 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.} \
 {{view {PanView $v [sim CrimeMaxX] [sim CrimeMaxY]}}}
 
 Message 12 #ff4f4f {TRAFFIC WARNING!} \
@@ -937,21 +942,11 @@ proc UISetChannelVolume {win chan vol} {
 
 
 proc EchoPlaySound {soundspec} {
-  # Temporary workaround to tell Python Sugar app to play sound.
-  global Sound
-  if {$Sound} {
-    echo PlaySound [lindex $soundspec 0]
-    signal ignore SIGCHLD
-    exec play res/sounds/[string tolower [lindex $soundspec 0]].wav &
-  }
 }
 
 
 proc UIMakeSoundOn {win chan sound {opts ""}} {
-  # Send message to Python to play sound.
-  EchoPlaySound $sound
-
-  #UIDoSoundOn $win "play $sound -replay -channel $chan $opts"
+  playsound $chan $sound $opts
 }
 
 
@@ -963,16 +958,8 @@ proc UIStartSoundOn {win chan sound {opts ""}} {
 }
 
 
-proc UIStopSoundOn {win chan sound {opts ""}} {
-  UIDoSoundOn $win "stop $sound"
-}
-
-
 proc UIMakeSound {chan sound {opts ""}} {
-  # Send message to Python to play sound.
-  EchoPlaySound $sound
-
-  #UIDoSound "sound play $sound -replay -channel $chan $opts"
+  playsound $chan $sound $opts
 }
 
 
@@ -984,11 +971,6 @@ proc UIStartSound {chan sound {opts ""}} {
 }
 
 
-proc UIStopSound {chan sound {opts ""}} {
-  UIDoSound "sound stop $sound"
-}
-
-
 proc SetupSoundServer {win} {
   AddSoundServer $win
 }
@@ -2043,13 +2025,13 @@ proc DoFileDialog {win Message Path Pattern FileName ActionOk ActionCancel} {
       wm withdraw $win"
   bind $win.files.files "<Double-Button-1>" "\
     FileSelectDouble $win %W %y $Pattern \"
-       $ActionOk \[$win.file.file get\] \[$win.path.path get\]\""
+       $ActionOk {\[$win.file.file get\]} {\[$win.path.path get\]}\""
   bind $win.path.path <Return> "
     ShowFileDialog $win \[$win.path.path get\] $Pattern
     $win.file.file cursor 0
     focus $win.file.file"
   bind $win.file.file <Return> "\
-    $ActionOk \[$win.file.file get\] \[$win.path.path get]
+    $ActionOk \[$win.file.file get\] \[$win.path.path get\]
     wm withdraw $win"
 }
 
@@ -2285,18 +2267,18 @@ proc NameComplete {win Type} {
 
 proc ShowFileDialog {win Path Pattern} {
   busy $win {
-    set Path [lindex [split $Path] 0]
+    #set Path [lindex [split $Path] 0]
     if {[$win.files.files size] > 0} {
       $win.files.files delete 0 end
     }
     # read directory
-    if {[catch "exec ls -F $Path" Result]} {
+    if {[catch "exec ls -F \"$Path\"" Result]} {
       set ElementList {}
     }
     if {[string match $Result "* not found"]} {
       set ElementList {}
     }
-    set ElementList [lsort $Result]
+    set ElementList [lsort [split $Result "\n"]]
 
     # insert ..
     if {[string compare $Path "/"]} {
@@ -2536,7 +2518,7 @@ proc EditorToolUp {w x y} {
 
   case [$w ToolState] in \
     7 { # bulldozer
-     UIStopSoundOn $w edit 1
+      stopdozer
     } \
     10 { # chalk
       StopChalk $w
@@ -3101,8 +3083,10 @@ proc ShowSplashOf {head} {
 
 
 proc WithdrawSplashOf {head} {
-  set win WindowLink $head.splash]
-  wm withdraw $win
+  set win [WindowLink $head.splash]
+  if {$win != {}} {
+    wm withdraw $win
+  }
 }
 
 
@@ -3152,8 +3136,10 @@ proc ShowScenarioOf {head} {
 
 
 proc WithdrawScenarioOf {head} {
-  set win WindowLink $head.scenario]
-  wm withdraw $win
+  set win [WindowLink $head.scenario]
+  if {$win != {}} {
+    wm withdraw $win
+  }
 }
 
 
@@ -3305,12 +3291,33 @@ proc UpdateScenarioButtonID {win id} {
 
 
 proc UpdateScenarioButton {win data} {
+  global Messages
+
   set type [lindex $data 0]
   set id [lindex $data 1]
   set over [WindowLink $win.$id.over]
   set enabled [WindowLink $win.$id.enabled]
   set checked [WindowLink $win.$id.checked]
   #echo "WIN $win TYPE $type ID $id OVER $over ENABLED $enabled CHECKED $checked"
+  if {$over} {
+    if {[lindex ${data} 2] == "DoPickScenario"} {
+      catch {text $win.desc \
+       -borderwidth 2 \
+       -relief flat \
+       -wrap word \
+       -state normal \
+       -font [Font $win Large]}
+      
+      $win.desc configure -state normal
+      $win.desc delete 0.0 end
+      $win.desc insert end "[lindex $Messages([lindex ${data} 3]) 1]\n\n[lindex $Messages([lindex ${data} 3]) 2]"
+      $win.desc configure -state disabled
+      
+      place $win.desc -x 232 -y 170 -width 280 -height 285
+    }
+  } else {
+    catch {destroy $win.desc}
+  }
   if {$enabled} {
     if {$checked} {
       if {$over} {
@@ -3544,6 +3551,10 @@ proc DoPickScenario {win param} {
   UILoadScenario $param
 }
 
+proc DeleteScenarioWindow {win} {
+  UIQuit $win
+}
+
 
 ########################################################################
 # Undo/Redo Facility
@@ -4909,12 +4920,14 @@ proc oops {} {
 
 
 proc TogglePause {} {
-  global State
+  global State Pause
 
   if {"$State" != "play" || [sim Speed]} {
     sim Speed 0
+    set Pause 1
   } else {
     sim Speed 3
+    set Pause 0
   }
   MakeRunningSound
 }
@@ -5121,7 +5134,7 @@ proc UIDoLoadCity {name path} {
   if {![string match *.cty $name]} {
     set name $name.cty
   }
-  MakeHistory "DoLoadCity $path/$name"
+  MakeHistory "DoLoadCity {$path/$name}"
 }
 
 
@@ -5216,8 +5229,14 @@ proc DoLeaveGame {head} {
 
 
 proc UILoseGame {} {
-  UIPickScenarioMode
+  global Messages
   UIShowPicture 200
+  sim Pause
+  AskQuestion [Color . #ff0000 #ffffff] [lindex $Messages(200) 1] \
+    [lindex $Messages(200) 2] \
+    ""\
+    ""\
+    "{Ok} SelectCity.Yes {UIPickScenarioMode}"
 }
 
 
Impressum, Datenschutz