forked from fuzzball-muck/fuzzball-muf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib-optionsgui.muf
1389 lines (1287 loc) · 52.9 KB
/
lib-optionsgui.muf
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@prog lib-optionsgui
1 99999 d
1 i
( $lib/optionsgui Copyright 7/22/2002 by Revar <revar@belfry.com> )
( Released under the GNU LGPL. )
( )
( A MUF library to automatically create dialogs to edit a set of )
( option values. )
( )
( v1.000 -- 7/22/2002 -- Revar <revar@belfry.com> )
( Initial relase. )
( v1.005 -- 7/30/2002 -- Revar <revar@belfry.com> )
( Changed callback arguments. )
( v1.100 -- 8/02/2002 -- Revar <revar@belfry.com> )
( Majorly reworked interface. Many bugfixes. )
( v1.101 -- 8/13/2002 -- Revar <revar@belfry.com> )
( Bigfix for the help dialogs sent to other descriptors. )
( v1.102 -- 8/20/2002 -- Revar <revar@belfry.com> )
( Made dbref options use combobox. )
( v1.103 -- 8/29/2002 -- Revar <revar@belfry.com> )
( Made dbref options update combobox with matched object name. )
( v1.104 -- 8/18/2003 -- Revar <revar@belfry.com> )
( Made fallback to $lib/optionsmenu in textmode. )
( Added opts_id to callback data. )
( Split optionsinfo calls into $lib/optionsinfo. )
$author Revar Desmera <revar@belfry.com>
$version 1.104
$lib-version 1.102
$note Released under the LGPL.
(
GUI_OPTIONS_GENERATE[ int:dscr any:caller_ctx addr:saveall_cb
str:title arr:optionsinfo -- int:opts_id ]
Generates a dialog or set of dialogs that will edit a set of options
that are described by the optionsinfo array. The dialog[s] will be
created with the given title root, and displayed to the given dscr
descriptor connection. The caller program may provide the address
to a saveall_cb callback function that will be called when the user
saves the changes. If saveall_cb is 0, this call will not be made.
The caller program also provides a caller_ctx context data item that
will be passed to any callback routines that are called. This can
be whatever single stack item the caller program wants to pass,
including an array or dictionary.
This function will return the opts_id of the current options set.
You must call GUI_OPTIONS_FREE with this opts_id after all the
dialogs have been closed.
The format of the data in the optionsinfo array is a list of
optioninfo description dictionaries. Each optioninfo description
can have the following fields:
"group" The name of the option group to group this option with.
This field is required.
"name" The name of this option, used to refer to its data.
This field is required.
"type" The type of this option. May be one of "label",
"string", "password", "multistring", "boolean",
"integer", "float", "dbref", "dbreflist", "timespan",
"option" or "custom". This field is required.
"label" The short text to label this option with. Required.
"help" The human readable long help text for this option.
"value" The actual current value of this option. Required.
"minval" For numeric options, the minimum legal value.
If not given, assumes 0.
"maxval" For numeric options, the maximum legal value.
If not given, assumes 99999999.
"digits" For float options, the number of significant digits.
If not given, assumes 0.
"resolution" For float options, this specifies the smallest change
that can be made to the value.
"options" For option options, gives list of predefined values.
This is required for options of type option.
"editable" For option options, if true, user can give arbitrary
values that aren't in the predefined value set.
If not given, assumes not editable.
"objtype" For dbref options, lists the allowed object types.
This is a list array of strings of valid types, and
can contain "any", "bad", "garbage", "player", "room",
"exit", "program", "thing", "zombie", and "vehicle".
If "thing" is given, "zombie" and "vehicle" are ok.
If not given, assumes any object type is ok.
"create_cb" For custom options, this is the address of the
function to call to get the controls description
used to created the controls needed by this custom
option.
"vfy_cb" Optional address of function to call back to verify
the value of this option before saving it.
"save_cb" Optional address of function to call back when saving
the value of this option via Apply or Done.
When the dialog is created, the options will be re-ordered by group
name. The order of the options within each group will be determined
by the order that they were given in the optionsinfo list.
An optionsinfo list may look like:
{
{
"group" "Self Destruct"
"name" "self_destruct_label"
"type" "label"
"value" "This is the emergency self destruct system, with convenient access for all protagonists."
}dict
{
"group" "Self Destruct"
"name" "destruct_armed"
"type" "boolean"
"label" "Arm self destruct system"
"help" "This arms the self destruct system so that the countdown will be initiated if the big red button is pushed."
"value" 0
}dict
{
"group" "Self Destruct"
"name" "destruct_delay"
"type" "timespan"
"label" "Delay before self destruct"
"help" "This specifies how long will elapse between initiation of the self destruct sequence, and when things go boom."
"minval" 60
"maxval" 86400
"save_cb" 'delay_save_callback
"vfy_cb" 'delay_verify_callback
"value" 300
}dict
{
"group" "Self Destruct"
"name" "destruct_password"
"type" "string"
"label" "Self destruct password"
"help" "This is the password to the self destruct system."
"value" "1A2B3"
}dict
{
"group" "Self Destruct"
"name" "destruct_warning"
"type" "string"
"label" "Self destruct initiation warning"
"help" "This is the warning message to announce when the self destruct sequence is initiated."
"value" "WARNING: SELF DESTRUCT SEQENCE INITIATED!"
}dict
{
"group" "Minions"
"name" "minion_count"
"type" "integer"
"label" "Number of minions"
"help" "This specifies how many minions you control."
"minval" 0
"maxval" 99999
"value" 25
}dict
{
"group" "Minions"
"name" "minion_type"
"type" "option"
"label" "Type of minions"
"help" "This defines the type of minions that you control."
"options" { "Ninjas" "Double Agents" "Triple Agents" "Zombies" "Drones" }list
"editable" 1
"value" "Ninjas"
}dict
{
"group" "Secret Base"
"name" "base_location"
"type" "dbref"
"label" "Secret Base Location"
"help" "This is the room where your secret base is located."
"objtype" { "room" }list
"value" #1234
}dict
{
"group" "Secret Base"
"name" "secret_base_value"
"type" "float"
"label" "Value of Secret Base in Millions"
"help" "This is how much your secret base cost to build, in Millions of dollars."
"minval" 0.0
"maxval" 10000.0
"digits" 2
"value" 27.35
}dict
{
"group" "Secret Base"
"name" "secret_base_desc"
"type" "multistring"
"label" "Description of Secret Base"
"help" "This is the description of your secret base. It can be multiple lines long."
"value" { "This is the" "base description." }list
}dict
{
"group" "Laboratory"
"name" "lab_ctrls"
"type" "custom"
"create_cb" 'lab_ctrls_create
"save_cb" 'lab_ctrls_save
"vfy_cb" 'lab_ctrls_verify
"value" 0
}dict
}list
The create_cb field above should contain the address of a function
that has the following signature:
[ int:dscr any:context -- arr:ctrlsdescr ]
The return value should be a valid $lib/gui control set description
array with all neccesary callbacks, etc.
The save_cb and vfy_cb fields above should contain the address of a
function that has the following signature:
[ dict:extradata str:optname any:value -- str:errs ]
The extradata dictionary contains the following extra data:
"descr" The descriptor the dialog was displayed to.
"dlogid" The dialog's ID.
"opts_id" The optionsinfo identifier.
"context" The caller's context data.
"optionsinfo" Information on all the other options.
The save_cb callback will only be called if the associated value
has changed [or is a custom option] and Apply or Done were clicked.
The vfy_cb callbacks will always be called when Apply or Done are
clicked, regardless of whether the value has changed or not.
The saveall_cb argument to GUI_OPTIONS_PROCESS is a callback function
address that is called after all the option specific save_cb call-
backs have been done. This callback will only be called if all
options passed their verifications. It has the signature:
[ dict:extradata dict:optionsinfo -- str:errs ]
The extradata arg is the same as for the save_cb and vfy_cb callbacks.
The context extradata argument will contain whatever you passed to
the GUI_OPTIONS_PROCESS function in the caller_ctx argument.
The optionsinfo argument given to callbacks will contain the
optionsinfo array you provided to GUI_OPTION_PROCESS, re-indexed
by option name, with updated "value", "oldvalue", and "changed"
fields in each option description. The old value of the each
option will be in the "oldvalue" field. The new value will be
in the "value" field. If the value changed, the "changed" field
will be set to 1.
ie: The value of the optionsinfo argument may look like this:
{
"base_location" {
"group" "Secret Base"
"name" "base_location"
"type" "dbref"
"label" "Secret Base Location"
"help" "This is the room where your secret base is located."
"objtype" { "room" }list
"value" #1234
"oldvalue" #1234
"changed" 0
}dict
"secret_base_desc" {
"group" "Secret Base"
"name" "secret_base_desc"
"type" "multistring"
"label" "Description of Secret Base"
"help" "This is the description of your secret base. It can be multiple lines long."
"value" { "This is the" "new base description." }list
"oldvalue" { "This is the" "old base description." }list
"changed" 1
}dict
... etc ...
}dict
If the save was successful, the save and verify callback functions
should return with a null string. If there was an error, then the
human readable error messages should be returned in a single string.
GUI_OPTIONS_VALUE_SET[ int:opts_id str:optname any:value -- ]
Sets the value of the given option within the gui option editor
specified by opts_id. This change will be shown to the user in
any gui option editor dialogs she may have up at the moment.
GUI_OPTIONS_FREE[ int:opts_id -- ]
Frees up all internal memory associated with the gui options editor.
GUI_OPTIONS_PROCESS[ int:dscr any:caller_ctx addr:saveall_cb
str:title arr:optionsinfo -- ]
GUI_OPTIONS_PROCESS will call GUI_OPTIONS_GENERATE, go into the
background, wait for the user to dismiss the dialogs it creates,
then call GUI_OPTIONS_FREE and return.
)
$include $lib/case
$include $lib/gui
$include $lib/optionsinfo
$include $lib/optionsmisc
$include $lib/optionsmenu
$def DEFAULT_CAPTION "Edit the following data and click on 'Done' or 'Apply' to commit the changes."
( ------------------------------------------------------------- )
: gui_dlog_generic_help[ int:dscr dict:item -- ]
dscr @ descrdbref var! who
{SIMPLE_DLOG item @ "name" [] "Help for %s" fmtstring
{LABEL "optnamel"
"value" "Name:"
"newline" 0
"sticky" "w"
}CTRL
{LABEL "optname"
"value" item @ "name" []
"newline" 1
"sticky" "w"
"toppad" 0
}CTRL
{LABEL "optlbll"
"value" "Label:"
"newline" 0
"sticky" "w"
}CTRL
{LABEL "optlbl"
"value" item @ "label" []
"newline" 1
"maxwidth" 400
"sticky" "w"
"toppad" 0
}CTRL
{LABEL "opttypel"
"value" "Type:"
"newline" 0
"sticky" "w"
}CTRL
{LABEL "opttype"
"value" item @ "type" []
"newline" 1
"sticky" "w"
"toppad" 0
}CTRL
{LABEL "optvall"
"value" "Value:"
"newline" 0
"sticky" "w"
}CTRL
{LABEL "optval"
"value" item @ "value" []
item @ "type" [] "timespan" stringcmp not if
optmisc_timespan2str
then
item @ "type" [] "dbref" stringcmp not if
who @ swap optmisc_dbref_unparse
then
item @ "type" [] "dbreflist" stringcmp not if
{ }list var! reflistset
foreach swap pop
who @ swap optmisc_dbref_unparse
reflistset @ array_appenditem reflistset !
repeat
reflistset @ "\r" array_join
then
item @ "type" [] "boolean" stringcmp not if
if "yes" else "no" then
then
item @ "type" [] "password" stringcmp not if
pop ""
then
item @ "type" [] "timespan" stringcmp not if
"" var! spanstr
dup 86400 / dup if
swap 86400 % swap
"%id " fmtstring
spanstr @ swap strcat spanstr !
else pop
then
dup 3600 /
swap 3600 % swap
dup 60 /
swap 60 %
swap rot
"%02i:%02i:%02i" fmtstring
spanstr @ swap strcat strip
then
"newline" 1
"sticky" "w"
"maxwidth" 400
"hweight" 1
"toppad" 0
}CTRL
{LABEL "opthelp"
"value" item @ "help" [] dup not if pop "" then
"colspan" 2
"newline" 1
"maxwidth" 500
"sticky" "w"
}CTRL
{HRULE "hrule1"
"sticky" "ew"
"colspan" 2
"newline" 1
}CTRL
{FRAME "btnfr"
"sticky" "e"
"colspan" 2
{BUTTON "done"
"text" "&Done"
"width" 6
"sticky" "e"
"dismiss" 1
}CTRL
}CTRL
}DLOG
dscr @ swap GUI_GENERATE
dup GUI_DLOG_SHOW
swap gui_dlog_register
;
: gui_dlog_generic_cancel_cb[ dict:context str:dlogid str:ctrlid str:event -- int:exit ]
dlogid @ gui_dlog_deregister
0
;
: gui_dlog_generic_help_cb[ dict:context str:dlogid str:ctrlid str:event -- int:exit ]
context @ "descr" [] var! dscr
context @ "values" [] var! vals
context @ "statedata" [] var! statedata
statedata @ "title" [] var! title
statedata @ "opts_id" [] var! opts_id
ctrlid @ "name_" "helpbtn_" subst
vals @ swap [] 0 [] var! ctrlname
dscr @
opts_id @ ctrlname @ optioninfo_get
gui_dlog_generic_help
0
;
: gui_dlog_generic_save_cb[ dict:context str:dlogid str:ctrlid str:event -- int:exit ]
context @ "descr" [] var! dscr
context @ "values" [] var! vals
context @ "statedata" [] var! statedata
statedata @ "opts_id" [] var! opts_id
statedata @ "save_cb" [] var! save_fn
statedata @ "caller_ctx" [] var! caller_ctx
opts_id @ optionsinfo_get var! optionsinfo
0 var! stackdepth
0 var! ctrlval
0 var! minmaxchk
"" var! errs
dscr @ descrdbref var! who
vals @ "ctrl_cnt" [] 0 [] atoi
0 swap -- 1 for var! cnt
0 minmaxchk !
vals @ cnt @ "name_%03i" fmtstring []
dup if
0 [] var! ctrlname
optionsinfo @ ctrlname @ [] var! iteminfo
iteminfo @ "type" [] var! ctrltype
iteminfo @ "label" [] var! ctrllbl
ctrltype @ case
"password" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] ctrlval !
end
"string" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] ctrlval !
end
"multistring" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] ctrlval !
end
"timespan" stringcmp not when
vals @ cnt @ "value_days_%03i" fmtstring [] 0 [] atoi 24 *
vals @ cnt @ "value_hrs_%03i" fmtstring [] 0 [] atoi + 60 *
vals @ cnt @ "value_mins_%03i" fmtstring [] 0 [] atoi + 60 *
vals @ cnt @ "value_secs_%03i" fmtstring [] 0 [] atoi +
ctrlval !
1 minmaxchk !
end
"integer" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] atoi ctrlval !
1 minmaxchk !
end
"float" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] strtof ctrlval !
1 minmaxchk !
end
"option" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] ctrlval !
iteminfo @ "editable" [] not if
iteminfo @ "options" []
ctrlval @ array_findval not if
{
errs @ dup not if pop then
ctrllbl @ "Value for '%s' is invalid." fmtstring
}list "\r" array_join
errs !
then
then
end
"dbref" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 []
who @ optmisc_dbref_parse ctrlval !
who @ ctrlval @ iteminfo @
optmisc_objtype_check
dup if errs ! else pop then
1 minmaxchk !
end
"dbreflist" stringcmp not when
{ }list ctrlval !
vals @ cnt @ "value_%03i" fmtstring [] 0 []
";" explode_array
foreach swap pop
strip who @ optmisc_dbref_parse
who @ over iteminfo @
optmisc_objtype_check
dup if errs ! pop break else pop then
ctrlval @ array_appenditem ctrlval !
repeat
end
"boolean" stringcmp not when
vals @ cnt @ "value_%03i" fmtstring [] 0 [] atoi
if 1 else 0 then ctrlval !
end
default
ctrlname @ ctrltype @ "Invalid control type '%s' for '%s'!" fmtstring abort
end
endcase
( check min/max constraints. )
minmaxchk @ if
ctrlval @ iteminfo @ "minval" [] < if
{
errs @ dup not if pop then
ctrllbl @ "Value for '%s' is too low." fmtstring
}list "\r" array_join
errs !
else
ctrlval @
iteminfo @ "maxval" []
dup not if pop 99999999 then
> if
{
errs @ dup not if pop then
ctrllbl @ "Value for '%s' is too high." fmtstring
}list "\r" array_join
errs !
then
then
then
iteminfo @ "value" [] var! oldctrlval
oldctrlval @ iteminfo @ "oldvalue" ->[] iteminfo !
ctrlval @ iteminfo @ "value" ->[] iteminfo !
oldctrlval @ ctrlval @ optmisc_equalvals? if 0 else 1 then
iteminfo @ "changed" ->[] iteminfo !
iteminfo @ optionsinfo @ ctrlname @ ->[] optionsinfo !
( check verification callback function. )
iteminfo @ "vfy_cb" [] var! vfy_fn
vfy_fn @ address? if
depth stackdepth !
{
"descr" dscr @
"opts_id" opts_id @
"dlogid" dlogid @
"context" caller_ctx @
"optionsinfo" optionsinfo @
}dict
ctrlname @
iteminfo @ "value" []
vfy_fn @ execute
depth stackdepth dup ++ @ = not if
depth stackdepth @ > if
ctrlname @
"Verify callback for '%s' returned extra garbage on the stack."
else
ctrlname @
"Verify callback for '%s' was supposed to return a string."
then
fmtstring abort
then
dup string? not if
ctrlname @
"Verify callback for '%s' was supposed to return a string."
fmtstring abort
then
dup if
(If we have an error, don't bother continuing. )
errs ! break
else pop
then
then
errs @ if break then
ctrltype @ "dbref" stringcmp not if
dlogid @ cnt @ "value_%03i" fmtstring
who @ iteminfo @ "value" [] optmisc_dbref_unparse
GUI_VALUE_SET
(
dlogid @ cnt @ "value_%03i" fmtstring
"cursor" { "position" "end" }dict
GUI_CTRL_COMMAND
)
then
else pop
then
repeat
errs @ if
( if any verification failed, tell the user and keep dlog up. )
dlogid @ "errtext" errs @ gui_value_set
else
( call individual save callbacks )
optionsinfo @
foreach iteminfo ! ctrlname !
iteminfo @ "changed" []
iteminfo @ "type" [] "custom" stringcmp not or
if
iteminfo @ "save_cb" [] var! itemsave_fn
itemsave_fn @ address? if
depth stackdepth !
{
"descr" dscr @
"opts_id" opts_id @
"dlogid" dlogid @
"context" caller_ctx @
"optionsinfo" optionsinfo @
}dict
ctrlname @
iteminfo @ "value" []
itemsave_fn @ execute
depth stackdepth dup ++ @ = not if
depth stackdepth @ > if
ctrlname @
"Save callback for '%s' returned extra garbage on the stack."
else
ctrlname @
"Save callback for '%s' was supposed to return a string."
then
fmtstring abort
then
dup string? not if
ctrlname @
"Save callback for '%s' was supposed to return a string."
fmtstring abort
then
dup if
(If we have an error, don't bother continuing. )
errs ! break
else
( If no errors, remember changes )
opts_id @ ctrlname @ "oldvalue" iteminfo @ "oldvalue" []
optionsinfo_set_indexed
opts_id @ ctrlname @ "value" iteminfo @ "value" []
optionsinfo_set_indexed
then
then
then
repeat
( call save callback function. )
save_fn @ address? if
depth stackdepth !
{
"descr" dscr @
"opts_id" opts_id @
"dlogid" dlogid @
"context" caller_ctx @
"optionsinfo" optionsinfo @
}dict
optionsinfo @
save_fn @ execute
depth stackdepth dup ++ @ = not if
depth stackdepth @ > if
"Save callback returned extra garbage on the stack."
else
"Save callback was supposed to return a string."
then
abort
then
dup string? not if
"Save callback was supposed to return a string."
abort
then
errs !
then
errs @ if
( if save failed, tell the user and keep dlog up. )
dlogid @ "errtext" errs @ gui_value_set
else
( remember changes )
optionsinfo @
foreach iteminfo ! ctrlname !
opts_id @ ctrlname @ "oldvalue" iteminfo @ "oldvalue" []
optionsinfo_set_indexed
opts_id @ ctrlname @ "value" iteminfo @ "value" []
optionsinfo_set_indexed
repeat
ctrlid @ "apply" stringcmp if
dlogid @ gui_dlog_deregister
dlogid @ gui_dlog_close
else
dlogid @ "errtext" DEFAULT_CAPTION gui_value_set
then
then
then
dlogid @
{
"opts_id" opts_id @
"caller_ctx" caller_ctx @
"save_cb" save_fn @
}dict GUI_DLOG_STATEDATA_SET
0
;
( ------------------------------------------------------------- )
: singlegroup_ctrls_generate[ int:dscr int:startnum any:context int:opts_id str:group -- arr:ctrlsdesc int:optcount ]
var maxval
var minval
5 var! toppad
dscr @ descrdbref var! who
{
opts_id @ group @ optionsinfo_get_group_opts var! groupopts
groupopts @
startnum @ var! cnt
foreach var! optname pop
opts_id @ optname @ optioninfo_get var! item
item @ "type" [] "label" stringcmp not if
{LABEL ""
"value" item @ "value" []
"maxwidth" 500
"newline" 1
"sticky" "w"
"colspan" 3
}CTRL
else
{DATUM cnt @ "name_%03i" fmtstring
"value" item @ "name" []
}CTRL
{IMAGE cnt @ "helpbtn_%03i" fmtstring
"value" "http://www.belfry.com/pics/info.gif"
"width" 9
"height" 9
"sticky" "w"
"toppad" toppad @
"hweight" 0
"newline" 0
"report" 1
"|buttonpress" 'gui_dlog_generic_help_cb
}CTRL
item @ "type" []
case
"password" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{PASSWORD cnt @ "value_%03i" fmtstring
"value" item @ "value" []
"sticky" "ew"
"width" item @ "width" [] dup not if pop 40 then
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"string" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{EDIT cnt @ "value_%03i" fmtstring
"value" item @ "value" []
"sticky" "ew"
"width" item @ "width" [] dup not if pop 40 then
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"multistring" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 1
"colspan" 2
"hweight" 1
"sticky" "w"
"toppad" toppad @
}CTRL
{FRAME cnt @ "filler%003i" fmtstring
"newline" 0
}CTRL
{MULTIEDIT cnt @ "value_%03i" fmtstring
"value" item @ "value" []
"sticky" "nsew"
"width" item @ "width" [] dup not if pop 60 then
"height" item @ "height" [] dup not if pop 5 then
"colspan" 2
"hweight" 1
"vweight" 1
"newline" 1
"toppad" toppad @
}CTRL
end
"custom" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 1
"colspan" 2
"hweight" 1
"sticky" "w"
"toppad" toppad @
}CTRL
{FRAME cnt @ "filler%003i" fmtstring
"newline" 0
}CTRL
{FRAME cnt @ "framer%003i" fmtstring
"newline" 0
"colspan" 2
"hweight" 1
"vweight" 1
"newline" 1
"sticky" "nsew"
item @ "create_cb" [] address? if
dscr @ context @
item @ "create_cb" [] execute
else
item @ "name" []
"Bad create_cb callback for option '%s'."
fmtstring abort
then
}CTRL
end
"integer" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{SPINNER cnt @ "value_%03i" fmtstring
item @ "maxval" [] dup not if pop 999999999 then
var! smaxval
item @ "width" [] dup not if
pop smaxval @ float log10 fabs 2 + int
then
var! swidth
"value" item @ "value" []
"maxval" smaxval @
"minval" item @ "minval" [] dup not if pop 0 then
"sticky" "w"
"width" swidth @
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"float" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{SCALE cnt @ "value_%03i" fmtstring
"value" item @ "value" []
"digits" item @ "digits" []
"maxval" item @ "maxval" [] dup not if pop 100.0 then
"minval" item @ "minval" [] dup not if pop 0.0 then
"resolution" item @ "resolution" [] dup not if pop 0.1 then
"interval" 6 pick 5 pick - 4.0 /
"sticky" "ew"
"length" 200
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"dbref" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{COMBOBOX cnt @ "value_%03i" fmtstring
"value" who @ item @ "value" [] optmisc_dbref_unparse
"options" who @ item @ optmisc_dbref_option_list
"editable" 1
"sticky" "w"
"width" 30
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"dbreflist" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{COMBOBOX cnt @ "value_%03i" fmtstring
"value" item @ "value" []
{ }list var! reflistset
foreach swap pop
who @ swap optmisc_dbref_unparse
reflistset @ array_appenditem reflistset !
repeat
reflistset @ ";" array_join
"options" who @ item @ optmisc_dbref_option_list
"editable" 1
"sticky" "w"
"width" 30
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"option" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{COMBOBOX cnt @ "value_%03i" fmtstring
"value" item @ "value" []
"editable" item @ "editable" []
"sorted" item @ "sorted" []
"options" item @ "options" []
"sticky" "w"
item @ "editable" [] if
"width" 30
then
"hweight" 100
"newline" 1
"toppad" toppad @
}CTRL
end
"boolean" stringcmp not when
{CHECKBOX cnt @ "value_%03i" fmtstring
"text" item @ "label" []
"value" item @ "value" []
"sticky" "w"
"colspan" 2
"newline" 1
"hweight" 1
"toppad" toppad @
}CTRL
end
"timespan" stringcmp not when
{LABEL ""
"value" item @ "label" []
"newline" 0
"sticky" "w"
}CTRL
{FRAME cnt @ "timefr_%03i" fmtstring
"sticky" "w"
"newline" 1
"hweight" 100
"toppad" toppad @
item @ "maxval" [] dup not if pop 999999999 then maxval !
item @ "minval" [] dup not if pop 0 then minval !
maxval @ 86400 >= if
{SPINNER cnt @ "value_days_%03i" fmtstring
"value" item @ "value" [] 86400 /
"maxval" maxval @ 86400 /
"minval" minval @ 86400 /
"sticky" "w"
"width" 4
"hweight" 0
"newline" 0
}CTRL
{LABEL ""
"value" "Days"
"newline" 0
"leftpad" 2
"sticky" "w"
}CTRL
then