File: RPGEdDressing.tcl

package info (click to toggle)
roleplaying 2.0-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 16,620 kB
  • ctags: 1,039
  • sloc: tcl: 7,155; cpp: 2,709; ansic: 2,227; makefile: 559; sh: 330; csh: 3
file content (478 lines) | stat: -rw-r--r-- 15,702 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#* 
#* ------------------------------------------------------------------
#* Role PlayingDB V2.0 by Deepwoods Software
#* ------------------------------------------------------------------
#* RPGEdDressing.tcl - Dressing Editor
#* Created by Robert Heller on Fri Aug 21 08:41:33 1998
#* ------------------------------------------------------------------
#* Modification History: 
#* $Log: RPGEdDressing.tcl,v $
#* Revision 1.4  2000/02/11 00:30:25  heller
#* Change MacOS type code GIF => GIFf
#*
#* Revision 1.3  1999/07/13 01:29:16  heller
#* Fix documentation: spelling, punctuation, etc.
#*
#* Revision 1.2  1998/12/30 15:10:51  heller
#* Add in comments
#*
#* Revision 1.1  1998/12/28 01:57:59  heller
#* Initial revision
#*
#* ------------------------------------------------------------------
#* Contents:
#* ------------------------------------------------------------------
#*  
#*     Role Playing DB -- A database package that creates and maintains
#* 		       a database of RPG characters, monsters, treasures,
#* 		       spells, and playing environments.
#* 
#*     Copyright (C) 1995,1998  Robert Heller D/B/A Deepwoods Software
#* 			51 Locke Hill Road
#* 			Wendell, MA 01379-9728
#* 
#*     This program is free software; you can redistribute it and/or modify
#*     it under the terms of the GNU General Public License as published by
#*     the Free Software Foundation; either version 2 of the License, or
#*     (at your option) any later version.
#* 
#*     This program is distributed in the hope that it will be useful,
#*     but WITHOUT ANY WARRANTY; without even the implied warranty of
#*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#*     GNU General Public License for more details.
#* 
#*     You should have received a copy of the GNU General Public License
#*     along with this program; if not, write to the Free Software
#*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#* 
#*  
#* 

#@Chapter:RPGEdDressing.tcl -- Various items that might be about
#@Label:RPGEdDressing.tcl
#$Id: RPGEdDressing.tcl,v 1.4 2000/02/11 00:30:25 heller Rel $
# This file deals with various fixed items that might be in a room or other
# place in an adventure: things like furniture and other items that ``dress
# up the place''


proc RPGEdDressing {{filename {}}} {
# This procedure creates or edits a (dungeon) ``dressing'' -- things like
# furniture and related items.
# <in> filename -- the file to open.
# [index] RPGEdDressing!procedure

  global tk_version
  set toplevel [GenerateToplevelName rpgEdDres]

  RPGToplevel .$toplevel {Role Playing V2 Dressing Editor} Dressing
  wm withdraw .$toplevel
  global .$toplevel
  upvar #0 .$toplevel data
  set data(filename) "$filename"
  set data(filetype) "dressing"
  if {[string length "$filename"] > 0} {
    set data(object) [Dressing]
    set object $data(object)
    if {[file readable "$filename"]} {
    set buffer [Record]
      if {[catch [list $buffer ReadRecord "$filename"] err]} {
        CloseWindow .$toplevel
        tkerror "Could not load $filename: $err"
        return
      }
      if {[string compare {*Dressing} "[lindex [$buffer ReturnRecord] 0]"] != 0} {
	CloseWindow .$toplevel
	tkerror "Not a dressing file: $filename"
	return
      }
      $object UpdateFromRecord $buffer
      rename $buffer {}
    } else {
      CloseWindow .$toplevel
      tkerror "File does not exist or is not readable: $filename"
      return
    }
  } else {
    set data(object) [Dressing]
    set object $data(object)
    set data(dirty) 0
  }

# Construct a toplevel to hold the dressing's picture
  toplevel .$toplevel.picture
  wm transient .$toplevel.picture .$toplevel
  wm title .$toplevel.picture {Picture of Trick or Trap}
  wm protocol .$toplevel.picture WM_DELETE_WINDOW {NoOperation}
  label .$toplevel.picture.imname -text "[$object Image]" -relief sunken -border 2
  image create photo im$toplevel
#  puts stderr "*** \[image names\] = [image names] - 'im$toplevel'"
  label .$toplevel.picture.picture -image im$toplevel -relief ridge -border 2
  bind .$toplevel.picture <Destroy> [list catch "image delete im$toplevel"]
  pack .$toplevel.picture.imname -expand 1 -fill x
  pack .$toplevel.picture.picture -expand 1 -fill both
  set im "[$object Image]"
  if {[string length "$im"] > 0} { 
    if {[catch [list im$toplevel configure -format gif -file "$im"] err]} {
      tkerror "Could not set image file $im for image im$toplevel: $err"
    }
  }
  set data(image) "$im"

  # build widget .$toplevel.nameValue
  frame .$toplevel.nameValue \
    -borderwidth {2} \
    -relief {ridge}

  # build widget .$toplevel.nameValue.name
  frame .$toplevel.nameValue.name

  # build widget .$toplevel.nameValue.name.label57
  label .$toplevel.nameValue.name.label57 \
    -text {Name:}

  # build widget .$toplevel.nameValue.name.value
  entry .$toplevel.nameValue.name.value \
    -width {0} \
    -textvariable ".[set toplevel](name)"
  bind .$toplevel.nameValue.name.value <KeyPress> "SetDirty .$toplevel"

  # build widget .$toplevel.nameValue.value
  frame .$toplevel.nameValue.value

  # build widget .$toplevel.nameValue.value.label59
  label .$toplevel.nameValue.value.label59 \
    -text {Value:}

  # build widget .$toplevel.nameValue.value.value
  entry .$toplevel.nameValue.value.value \
    -width {0} \
    -textvariable ".[set toplevel](value)"
  bind .$toplevel.nameValue.value.value <KeyPress> "SetDirty .$toplevel"
  bindtags .$toplevel.nameValue.value.value \
	[list .$toplevel.nameValue.value.value Entry .$toplevel all IntEntry]

  # build widget .$toplevel.description
  frame .$toplevel.description \
    -borderwidth {2} \
    -relief {ridge}

  # build widget .$toplevel.description.scrollbar1
  scrollbar .$toplevel.description.scrollbar1 \
    -command ".$toplevel.description.value yview" \
    -relief {raised}

  # build widget .$toplevel.description.value
  text .$toplevel.description.value \
    -height {10} \
    -width {60} \
    -wrap {word} \
    -yscrollcommand ".$toplevel.description.scrollbar1 set"
  bindtags .$toplevel.description.value \
	[list .$toplevel.description.value Text .$toplevel all UpdComments]

  # build widget .$toplevel.buttons
  frame .$toplevel.buttons \
    -borderwidth {2}

  # build widget .$toplevel.buttons.button61
  button .$toplevel.buttons.button61 \
    -text {Load} \
    -command "LoadDressing .$toplevel"

  # build widget .$toplevel.buttons.button62
  button .$toplevel.buttons.button62 \
    -text {Save} \
    -command "SaveDressing .$toplevel"

  # build widget .$toplevel.buttons.button63
  button .$toplevel.buttons.button63 \
    -text {Change Picture} \
    -command "ChangeDressingPicture .$toplevel im$toplevel"

  # pack master .$toplevel.nameValue
  pack configure .$toplevel.nameValue.name \
    -expand 1 \
    -fill x \
    -side left
  pack configure .$toplevel.nameValue.value \
    -expand 1 \
    -fill x \
    -side left

  # pack master .$toplevel.nameValue.name
  pack configure .$toplevel.nameValue.name.label57 \
    -side left
  pack configure .$toplevel.nameValue.name.value \
    -expand 1 \
    -fill x \
    -side right

  # pack master .$toplevel.nameValue.value
  pack configure .$toplevel.nameValue.value.label59 \
    -side left
  pack configure .$toplevel.nameValue.value.value \
    -expand 1 \
    -fill x \
    -side right

  # pack master .$toplevel.description
  pack configure .$toplevel.description.scrollbar1 \
    -fill y \
    -side right
  pack configure .$toplevel.description.value \
    -expand 1 \
    -fill both

  # pack master .$toplevel.buttons
  pack configure .$toplevel.buttons.button61 \
    -expand 1 \
    -side left
  pack configure .$toplevel.buttons.button62 \
    -expand 1 \
    -side left
  pack configure .$toplevel.buttons.button63 \
    -expand 1 \
    -side left

  # pack master .$toplevel
  pack configure .$toplevel.nameValue \
    -fill x
  pack configure .$toplevel.description \
    -fill both
  pack configure .$toplevel.buttons \
    -fill x

  set data(name) "[$object Name]"
  set data(value) [$object Value]
  set data(comments) "[$object Description]"
  .$toplevel.description.value insert end "$data(comments)"
  rename $object {}


# end of widget tree


  wm deiconify .$toplevel
}

proc SaveAsDressing {tl} {
# This procedure saves the current object in a prompted for file.  Bound to
# the ``SaveAs...'' menu item on the ``File'' menu.
# <in> tl -- the toplevel to save.
# [index] SaveAsDressing!procedure

  SaveDressing $tl 1
}

proc SaveDressing {tl {forceNew 0}} {
# This procedure saves the current object in the file named in the structure.
# Bound to the ``Save'' menu item on the ``File'' menu.
# <in> tl -- the toplevel to save.
# <in> forceNew -- force a new filename flag.
# [index] SaveDressing!procedure

  upvar #0 $tl data
  set filename "$data(filename)"
  set filetype "$data(filetype)"
  set object [Dressing -this [NewDressing \
			-name  "$data(name)" \
			-description "$data(comments)" \
			-image "$data(image)" \
			-value  $data(value)]]
  set buffer [Record -this [$object RawData]]
  set initdir "[file dirname $filename]"
  if {[string compare "$initdir" {.}] == 0} {set initdir "[pwd]"}
  if {[string compare "[string index "$initdir" 0]" {/}] != 0} {
    set initdir [file join "[pwd]" "$initdir"]
  }
  if {[string length "$filename"] == 0} {
    set initfile "new.$filetype"
  } else {
    set initfile "$filename"
  }
  if {$forceNew || [string length "$filename"] == 0} {
    set filename [tk_getSaveFile -defaultextension ".$filetype" \
      				   -initialfile "$initfile" \
				   -initialdir "$initdir" \
				   -filetypes [list [list "Dressing files" \
							  "*.$filetype"]]\
				   -parent . \
				   -title {File to save dressing data in}]
    if {[string length "$filename"] == 0} {return}
    if {[string length "[file extension $filename]"] == 0} {
	set filename "$filename.$filetype"
    }
  }
  $buffer WriteRecord "$filename"
  rename $buffer {}
  rename $object {}
  set data(dirty) 0
}

proc LoadDressing {tl} {
# This procedure loads a dressing object file into the current GUI toplevel.
# <in> tl -- the toplevel to load into.
# [index] LoadDressing!procedure

  upvar #0 $tl data
  set filename "$data(filename)"
  set filetype "$data(filetype)"
  if {$data(dirty)} {
    set saveP [tk_dialog .askDirty "Save dressing?" \
		"Save modified Dressing data?" \
		questhead 0 "Yes" "No"]
    if {$saveP == 0} {SaveDressing $tl}
  }
  set initdir "[file dirname $filename]"
  if {[string compare "$initdir" {.}] == 0} {set initdir "[pwd]"}
  if {[string compare "[string index "$initdir" 0]" {/}] != 0} {
    set initdir [file join "[pwd]" "$initdir"]
  }
  set filename [tk_getOpenFile -defaultextension ".$filetype" \
				   -initialfile "$filename" \
                                   -initialdir "$initdir" \
                                   -filetypes [list [list "Dressing files" \
							  "*.$filetype"]]\
                                   -parent $tl \
                                   -title {File to load dressing data from}]
  if {[string length "$filename"] == 0} {return}
  set buffer [Record]
  if {[catch [list $buffer ReadRecord "$filename"] err]} {
    tkerror "Could not load file $filename: $err"
    rename $buffer {}
    return
  }
  set key [lindex [$buffer ReturnRecord] 0]
  if {[string compare "$key" {*Dressing}] != 0} {
    rename $buffer {}
    tkerror "Not a trick / trap file: $filename"
    return
  }
  set object [Dressing]
  $object UpdateFromRecord $buffer
  rename $buffer {}
  set data(name) "[$object Name]"
  set data(value) [$object Value]
  set data(image) "[$object Image]"
  set data(comments) "[$object Description]"
  $tl.description.value insert end "$data(comments)"
  set data(dirty) 0
  rename $object {}
  set img [$tl.picture.picture cget -image]
  if {[catch [list $img configure -format gif -file "$data(image)"] err]} {
    tkerror "Could not set image file $data(image) for image $img: $err"
  }
  $tl.picture.imname configure -text "$data(image)"
}

proc CheckWriteDirtyRecordDressing {tl} {
# This procedure is called when the toplevel is being closed and the data
# structure is ``dirty'' (modified).  The user is asked if the data should
# be saved.
# <in> tl -- the toplevel.
# [index] CheckWriteDirtyRecordDressing!procedure

  upvar #0 $tl data
  set filename "$data(filename)"
  set filetype "$data(filetype)"
  set saveP [tk_dialog .askDirty "Save dressing?" "Save modified Dressing data?" \
	questhead 0 "Yes" "No"]
  if {$saveP == 0} {
    set object [Dressing -this [NewDressing \
			-name  "$data(name)" \
			-description "$data(comments)" \
			-image "$data(image)" \
			-value  $data(value)]]
    set buffer [Record -this [$object RawData]]
    set initdir "[file dirname $filename]"
    if {[string compare "$initdir" {.}] == 0} {set initdir "[pwd]"}
    if {[string compare "[string index "$initdir" 0]" {/}] != 0} {
      set initdir [file join "[pwd]" "$initdir"]
    }
    if {[string length "$filename"] == 0} {
      set initfile "new.$filetype"
    } else {
      set initfile "$filename"
    }
    if {[string length "$filename"] == 0} {
      set filename [tk_getSaveFile -defaultextension ".$filetype" \
      				   -initialfile "$initfile" \
				   -initialdir "$initdir" \
				   -filetypes [list [list "Dressing files" \
							  "*.$filetype"]]\
				   -parent . \
				   -title {File to save dressing data in}]
      if {[string length "$filename"] == 0} {return}
      if {[string length "[file extension $filename]"] == 0} {
	set filename "$filename.$filetype"
      }
    }
    $buffer WriteRecord "$filename"
    rename $buffer {}
    rename $object {}
  }
}



proc OpenDressing {tl} {
# This procedure loads a dressing data object file into a new toplevel GUI
# window.
# <in> tl -- the current toplevel.
# [index] OpenDressing!procedure

  if {"$tl" == {.}} {
    set data(filename) {}
    set data(filetype) dressing
    set data(class) Dressing
  } else {
    upvar #0 $tl data
  }
  set filename "$data(filename)"
  set filetype "$data(filetype)"
  set initdir "[file dirname $filename]"
  if {[string compare "$initdir" {.}] == 0} {set initdir "[pwd]"}
  if {[string compare "[string index "$initdir" 0]" {/}] != 0} {
    set initdir [file join "[pwd]" "$initdir"]
  }
  set filename [tk_getOpenFile -defaultextension ".$data(filetype)" \
			   -filetypes [list [list "$data(class) files" \
					"*.$filetype"]]\
			   -parent $tl \
			   -initialfile "$filename" \
			   -initialdir "$initdir" \
			   -title "File to load $data(class) data from"]
  if {[string length "$filename"] == 0} {return}
  RPGEd$data(class) "$filename"
}

proc ChangeDressingPicture {tl img} {
# This procedure is used to update the dressing's picture (GIF file).
# <in> tl -- the current toplevel.
# <in> img -- the image to update.
# [index] ChangeDressingPicture!procedure

  upvar #0 $tl data
  set initdir "[file dirname $data(image)]"
  if {[string compare "$initdir" {.}] == 0} {set initdir "[pwd]"}
  if {[string compare "[string index "$initdir" 0]" {/}] != 0} {
    set initdir [file join "[pwd]" "$initdir"]
  }
  set newIm [tk_getOpenFile -defaultextension {.gif} \
			    -filetypes { { {GIF Files} {*.gif *.GIF} GIFf } }  \
			    -initialfile "$data(image)" \
			    -initialdir "$initdir" \
			    -parent "$tl" \
			    -title {Select a new imgage file}]
  if {[string length "$newIm"] == 0} {return}
  if {[catch [list $img configure -format gif -file "$newIm"] err]} {
    tkerror "Could not set image file $newIm for image $img: $err"
  }
  $tl.picture.imname configure -text "$newIm"
  set data(image) "$newIm"
  set data(dirty) 1
}


package provide RPGEdDressing 1.0