Author Topic: New Menu Code and how to adapt old scripts  (Read 869 times)

0 Members and 1 Guest are viewing this topic.

Offline GaderianTopic starter

  • Jr. Member
  • **
  • Posts: 56
  • Activity:
    2.4%
  • Reputation Power: 4
  • Gaderian has no influence.
  • Respect: +11
  • Referrals: 0
    • View Profile
New Menu Code and how to adapt old scripts
« on: January 14, 2020, 05:58:26 PM »
+2
This will have several parts to it which I will post below.
This is Part 1 with a general overview.
Part 2 will have code comparisons of the old vs. New code for menu's.
Part 3 will have "How To" examples to accomplish things.

I am not covering how to use the menu creation tool that Cerveza covered in the Sticky Menu post.

Menu: Part 1
It has been a while since the menu code was updated. At first it seemed a little confusing to implement because I had always used the Menu Designer and the old version of EUO. I made very few modifications without that tool.

There is no tool to create the new menus and it has 2 affects:
1) The nice new features are not being used by new scripts
2) Old scripts and styles are often broken

There are not a lot of examples on how to write good menu code now. I have been offering to modify old menu code that isn't working in scripts for others and decided that a simple guide might help.

What happens to old menu code? Does it still work or simply break scripts?

The old menu code can still work and most of it's features are still there. That is the good news. The bad part of this is that the rules are more strict now. If the original script didn't follow the current (revised) rules, then it is very easy for the menu to break. It will seem like a script will either not work or work intermittently and require stopping and restarting to get it to function again.

My goal is to make clear the rules that a programmer needs to follow and show some common ways to get around what used to be "the method" to have dynamic menus.

The old menu code would allow a single menu vs. the new menu code allows multiple menus.
This makes the new menu code more efficient and flexible than the old way.

There is 1 basic rule:
Each element on the menus must have a unique name. (Re-using names will cause it to break.)

Functional Changes with new menu system:
menu shape is really emulated via "menu image... "
Old menu creation commands vs. New menu creation commands
 New menu commands create forms that are 10 pixels larger in both the X and Y axis than the original commands. This leaves additional space on the right edge and bottom edge of menu's. If you are really dependent on screen real estate - this may affect your overall screen layout. Offsets for where everything is placed is correct, just that the form is larger.

Restrictions:
menu shape can't have dash lines or rounded corners
menu transparent only applies to old menu code
menu font transparent only applies to old menu code

A few commands no longer exist:
menu image pixline (this could be accomplished with a sub to process the data to draw the line with pixel/line statements)
menu hideeuo

New additions:
Panel
Radiobutton
pushdef
popdef
setdef
getdef
setprop
Every element has a parent (along with other new properties)


Logic changes:
If a script used multiple menu's in the past, it was done with "effects". Maybe it would create a menu for setup, then clear it and recreate the menu for running the script.
It could have a button to go to the setup and what would be done:
 -clear the running script menu
 -rewrite all the setup elements
 -get the information
 -clear the setup menu
 -rewrite the running script menu all fresh
Separate forms (menus) can be created now and simply use "setprop [formname] visible [#true|#false]" to hide one of the other to accomplish the former behavior. The good part is that the menus do not need to be recreated, but can simply be updated and change the visible setting.

The old system could change a Text element with 'menu set [text]', but all too often the script would delete the former element and create a new element in it's place with the same name. (This is the most common violation of the new rule to have unique element names, by the way, and usually makes the menu "break".)

If the old system needed to display some message, an ad hoc 'menu text' element was defined and then subsequently deleted. It would be recreated the next time the message
was displayed.
Similar code was in use often to make buttons, then change the button place function by deleting/creating a new button in it's place.

This method of delete/create violates the unique element name requirement now.

How to revise the delete/create code?

There are several functional examples in a post below, but here is the concept:

Create a subroutine to create all the menu elements  that will be used in the script.
This is nice because all restructure changes in one place, too.

Now set the visibility #false on each of the elements you want to use later, but don't want displayed all the time:
Code: easyuo
  1. menu button Mybutton 10 10 30 20 My Button
  2. menu setprop Mybutton visible #false

Later in the routine where you want to bring forward the element, you can set the element
you want to turn off to invisible, while changing the "hidden" element to be visible:
Code: easyuo
  1. menu setprop ActionButton visible #false
  2. menu setprop Mybutton visible #true
  3.  
  4. ... Do some stuff in your script ...
  5.  
  6. ; restore the buttons:
  7. menu setprop Mybutton visible #false
  8. menu setprop Actionbutton visible #true

Former "#menures = Closed" value only works for form0.
All other forms when the "X" at the top right is clicked will set #menures = [formname]

Old code anamolies:
menu clear
 Deletes all forms except for form0 (the classic menu)!
 sets #menubutton to nothing (used to be N/A)
 running old scripts require setting #menubutton to N/A after menu clear statements to behave the same as previously.
Menu delete/Menu [create] looks like it worked, but clicking on a button is unresponsive  use the visible #false/#true method to fix it

Color Rules and Changes:
Named colors of Windows 'Theme' only works with old method of creating windows and the Pascal named colors do not work with new menu
Attached to this post is a subroutine that can be called to set colors to variable names.
 -addresses many usable colors (including a direct correlation to the old color values).
 -creates all the windows 'theme' values as variables with settings for a default windows theme. If you want to change your theme colors you can adjust the
settings in the ColorNameSub.txt routine.
Save the attached file in your Easyuo directory and call it during script setup to make the color variables available to your script.
Where the Easyuo commands could reference "red" or "black", now you would reference a variable named "%red" or "%black" respectively. Many colors are included in the subroutine.

Groupings by new property Parent:
All elements have a parent. It could be a form or a panel.
The parent is inherited by the current default parent.
 -The default parent is either the most recently created form or panel or established using "setdef parent [form or panel name]"
 -Changed after element creation using "setprop [element] parent [form or panel name]"
All Radio buttons in the same parent - only 1 can be 'checked', others in the same parent are automatically turned off.

Menu font deprecated and defaults expanded to include other properties:
menu setdef replaces all but "menu font transparent"
menu getdef allows seeing the settings

Pushdef/Popdef allows protected logic elsewhere so you can have your own settings.
menu pushdef
menu popdef
If you will create your own menu to go with a routine, you would structure it enveloped inside the pushdef/popdef commands.
Instead of using Display, you could create a menu form that displays the message. This would work in called libraries and the menu can live after the library call is done.

There are 1 attachment(s) in this post. You must register and post an acceptable introduction to download
ColorNameSub.txt
« Last Edit: January 17, 2020, 11:46:17 AM by Gaderian »

Offline GaderianTopic starter

  • Jr. Member
  • **
  • Posts: 56
  • Activity:
    2.4%
  • Reputation Power: 4
  • Gaderian has no influence.
  • Respect: +11
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #1 on: January 14, 2020, 05:58:52 PM »
+1
Part 2 Menu Code: Compare Old Syntax vs. Modern Syntax
New menu system concepts/requirements
 Each element must have a unique name.
 Each element has a parent.
         The parent is inherited from the last 'form' or 'panel' created, the current "menu setdef parent" command in effect, or set after creation via "menu setprop [element name] parent [parent name]".
 Top reasons old menu code breaks:
  - reusing element names to create additional elements
  - #menubutton <> N/A following command "menu clear"
 Former named colors no longer are honored in new menus.
  -
Obsolete commands
Code: easyuo
  1.  menu image pixline - was rarely used, but can be accomplished with a subroutine
  2.  menu hideeuo - no longer present
  3.  menu font transparent - deprecated
New commands
Code: easyuo
  1.  menu form
  2.  menu panel
  3.  menu getdef
  4.  menu setdef
  5.  menu setprop - change 1 property pair of an item
  6.  menu pushdef
  7.  menu popdef
  8.  menu radio

Limited commands
 Some commands are limited to the original method.
 These would only affect 'form0' which is the name given to any legacy menu code for it's form.
Code: easyuo
  1.  menu clear * Note changed behavior below
  2.  menu window title
  3.  menu window size
  4.  menu show
  5.  menu window transparent

Changed behavior commands:
Code: easyuo
  1.  menu delete - the old method to delete and recreate a same name element breaks menu code. Each created menu item needs a unique name.
  2.  menu shape - no longer allows some effects (dotted/dash fill and rounded corners)
  3.       - line effects could be done with sub routines
  4.       - rounded corners might be possible with clever effects, but are no longer available as internal options
  5.  Using the Window X in the top right corner of a standard window sets #menures = closed for form0, but the form name on other menus that are closed
  6.  menu clear - sets #menubutton to nothing (used to be N/A)
  7.           - deletes all forms. There was only a single form (form0) in legacy scripting.
  8.  New form sizes are 10 pixels larger (vertical and horizontal) than 'menu Window Size' command

Commands that need no update (unless element names are inappropriately replicated):
Code: easyuo
  1.  menu Activate [name]
  2.  menu Button [name] [width] [height] [text]
  3.  menu Check {name} {x} {y} {width} {height} {checked} {text}
  4.  menu Combo Create {name} {x} {y} {width}
  5.  menu Combo Add {name} {text}
  6.  menu Combo SELECT {name} {index}
  7.  menu Edit {name} {x} {y} {width} {text}
  8.  menu Get [name]
  9.  menu GetNum {name} {default}
  10.  menu List Create {name} {x} {y} {width} {height}
  11.  menu List Add {name} {string}
  12.  menu List Select {list name} {item number}
  13.  menu Image Create {name} {x} {y} {width} {height}
  14.  menu Image Ellipse {name} {x1} {y1} {x2} {y2} {color} {fill} [width]
  15.  menu Image File {name} {x} {y} {filename}
  16.  menu Image FloodFill {name} {x} {y} {color}
  17.  menu Image Line {name} {x1} {y1} {x2} {y2} {color} [width]
  18.  menu Image Pix {name} {x} {y} {color}
  19.  menu Image Pos {name} x y width height
  20.  menu Image Rectangle [element unique name] relative-x1 relative-y1 relative-x2 relative-y2 color [fill: #false leaves internal clear/transparent, anything else fills with color] [width: if fill = #false, then a line width may be set]
  21.  menu Set [element] [value] *Note: See menu setprop in New Commands section for a more flexible command
  22.  menu Text [element unique name] left top [text]

Equivalent coding for all commands:
Code: easyuo
  1.   ; Primarily alphabetized by the original statement or inserted alphabetically as the new statement.
  2. menu Activate [name]                                                    menu activate [element's unique name] ; brings forward along with it's parent (form and/or panel) (gives focus?)
  3. menu Button [name] [width] [height] [text]                              menu button [button unique name] left top height width  [button label]
  4. menu Check {name} {x} {y} {width} {height} {checked} {text}             menu check [element unique name] left top width height [checked:#true/#false] [text...]
  5. menu Clear                                                              menu delete form0 (Note: all forms are actually deleted with the "menu clear")
  6. menu Combo Add {name} {text}                                            menu combo add [element unique name] [text entry...]
  7. menu Combo Create {name} {x} {y} {width}                                menu combo create [element unique name] left top width
  8. menu Combo SELECT {name} {index}                                        menu combo select [element unique name] index
  9. menu Delete {name}                                                      menu delete [element's unique name]
  10. menu Edit {name} {x} {y} {width} {text}                                 menu edit [element unique name] left top width height [text...]
  11. [new command]                                                           menu getdef [option name: will be returned in #menures]
  12. menu Font Align { left|center|right }                                   menu setdef alignment [ left|center|right ]
  13. menu Font BGColor [color-descriptor]                                    menu setdef color $BBGGRR
  14. menu Font Color [color-descriptor]                                      menu setdef fontcolor $BBGGRR
  15. menu Font Name  [font-name]                                             menu setdef fontname [fontname]
  16. menu Font Size  {point-size}                                            menu setdef fontsize [pointsize]
  17. menu Font Style {b|i|u|s}                                               menu setdef fontstyle {sum of style attributes} ; 1=bold, 2=italic, 4=underline, 8=strikeout
  18. menu Font Transparent [ #true|#false ]                                 -no equivalent: only works with form0
  19. [new command]                                                           menu form [form unique name] left top width height [text]
  20.                                                                              Creates a new window which is 10 pixels wider and taller than old measurements
  21.                                                                              It is set to "visible #false" by default, so needs to be made visible with "menu setprop"
  22. menu Get [name]                                                         menu get [element unique name] : sets #menures
  23. menu GetNum {name} {default}                                            menu GetNum {name} {default}
  24. menu Hide                                                               menu setprop [form unique name] visible #false
  25. menu HideEUO                                                           -No longer functions
  26. menu List Add {name} {string}                                           menu list add [element unique name] [text...]
  27. menu List Create {name} {x} {y} {width} {height}                        menu list create [element unique name] left top width height
  28. menu List Select {list name} {item number}                              menu list select [element unique name] index
  29. menu Image Create {name} {x} {y} {width} {height}                       menu image create [element unique name] left top width height
  30.                                                                              All the elements created within the image reference the image_unique_name and have relative x/y positions
  31.                                                                              within it's canvas
  32. menu Image Ellipse {name} {x1} {y1} {x2} {y2} {color} {fill} [width]    menu image ellipse [element unique name] left top width height color fill outline_width
  33. menu Image File {name} {x} {y} {filename}                               menu image file [element unique name] relative-x relative-y [external filename *.jpg, *.bmp]
  34. menu Image FloodFill {name} {x} {y} {color}                             menu image floodfill [element unique name] relative-x relative-y color
  35. menu Image Line {name} {x1} {y1} {x2} {y2} {color} [width]              menu image line [element unique name] relative-x1 relative-y1 relative-x2 relative-y2 color width
  36. menu Image Pix {name} {x} {y} {color}                                   menu image pix [element unique name] relative-x relative-y color
  37. menu Image Pixline {name} {x} {y} {data}                               -no equivalent
  38. menu Image Pos {name} x y width height                                  menu image pos [element unique name] left top width height
  39.                                                                              moves or resizes the image
  40. menu Image Rectangle {name} {x1} {y1} {x2} {y2} {color} {fill} [width]  menu image rectangle [element unique name] x1 y1 width height color fill border_width
  41.                                                                              ; [fill: #false leaves internal clear/transparent, anything else fills with color]
  42.                                                                              ; [width: if fill = #false, then a line width may be set]
  43. [new command]                                                           menu panel [panel unique name] left top height width
  44. [new command]                                                           menu popdef
  45. [new command]                                                           menu pushdef
  46. [new command]                                                           menu radio [radio_unique_name] left top width height [checked: #true/#false] [labeled text...]
  47. menu Set [element] [value]                                              menu set [unique-element-name] [value]
  48.                                                                         menu setprop [unique-element-name] [checked #true|#false] ; Applies to checkbox and radiobutton
  49.                                                                         menu setprop {unique-element-name] [text 'value']
  50. [new command - but replaces some old]                                   menu setdef
  51.                                                                              alignment [left|center|right]
  52.                                                                              color     $BBGGRR
  53.                                                                              fontcolor $BBGGRR
  54.                                                                              fontname {font name}
  55.                                                                              fontsize {point size of font}
  56.                                                                              fontstyle 1=bold, 2=italic, 4=underline, 8=strikeout
  57.                                                                              parent [parent-name]
  58.                                                                         menu setprop [element's unique name] [option #spc value pair]
  59.                                                                              alignment:             TEXT,               RADIO, CHECK,                     DEFAULT
  60.                                                                              color:    FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST,        DEFAULT
  61.                                                                              checked:                                   RADIO, CHECK
  62.                                                                              enabled:  FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  63.                                                                              fontcolor:             TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST,        DEFAULT
  64.                                                                              fontname:              TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST,        DEFAULT
  65.                                                                              fontsize:              TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST,        DEFAULT
  66.                                                                              fontstyle:             TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST,        DEFAULT
  67.                                                                              height:   FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  68.                                                                              left:     FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  69.                                                                              parent:         PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE, DEFAULT
  70.                                                                              text:     FORM,        TEXT, BUTTON, EDIT, RADIO, CHECK
  71.                                                                              tooltip:  FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  72.                                                                              top:      FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  73.                                                                              visible:  FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  74.                                                                              width:    FORM, PANEL, TEXT, BUTTON, EDIT, RADIO, CHECK, COMBO, LIST, IMAGE
  75.        
  76. menu Shape {name} {x1} {y1} {x2} {y2} {shapetype} {linetype} {linewidth} {linecolor} {filltype} {fillcolor}
  77.                                                                         menu Shape {element unique name} {left} {top} {width} {height} {shapetype} {linetype} {linewidth} {linecolor} {filltype} {fillcolor}
  78.                                                                                               shapetype 1 (circle), 2 (ellipse), 3|4 (rectangle), 5|6 (square)
  79.                                                                                               linetype 1 (clear), 2-7 (solid)
  80.                                                                                               filltype 1-6,8 (clear), 7 (solid)
  81. menu Show                                                               menu setprop [form unique name] visible #true
  82. menu Text [element unique name] left top [text]                         menu text [element unique name] left top [text...]
  83.  
  84. ; menu Window commands can be set in a single command and subsequently adjusted by menu setprop commands. See "menu form" above.
  85. menu Window Color  {color-descriptor}                                   menu setprop [form unique name] color $BBGGRR ; Window color is *NOT* inherited from "menu setdef color",
  86.                                                                                                                       ; so must be set after creation
  87. menu Window Size {width} {height}                                       menu setprop [form unique name] width [width] (old {width} = [width] - 10)
  88.                                                                         menu setprop [form unique name] height [height] (old {height} = [height] - 10)
  89. menu Window Title {title}                                               menu setprop [form unique name] text [title]
  90. menu Window Transparent [ opacity percentile ]                         -No equivalent, but now only works on form0

Note: menu setprop works for 1 keyword/value pair. Use separate statements for each setting.[/size]

« Last Edit: January 17, 2020, 12:23:07 PM by Gaderian »

Offline GaderianTopic starter

  • Jr. Member
  • **
  • Posts: 56
  • Activity:
    2.4%
  • Reputation Power: 4
  • Gaderian has no influence.
  • Respect: +11
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #2 on: January 14, 2020, 05:59:26 PM »
+1
Part 3: How To examples
Basic Menu
Code: easyuo
  1. ; Demonstrate the comparison of the original menu method vs. the new menu method to  make a simple menu
  2. ; comment out the "goto" statement method you don't want to try
  3. ;goto OriginalMenu
  4. goto NewMenu
  5. halt
  6.  
  7. NewMenu:
  8. call ColorNameSub.txt
  9. gosub showEUOMenuNew
  10. while #menubutton <> EUOButton1 && #menubutton <> FormEquivalent ; When using X to close the menu... #menubutton set to [form name]
  11.  {
  12.  wait 1
  13.  }
  14. halt
  15. sub showEUOMenuNew
  16.   menu form FormEquivalent 0 0 210 163 Equivalent Form
  17.   menu setprop FormEquivalent color %BtnFace
  18.   menu setdef alignment Right
  19.   menu setdef fontname MS Sans Serif
  20.   menu setdef fontsize 8
  21.   menu setdef fontstyle 0
  22.   menu setdef fontcolor %Black
  23.   menu Button EUOButton1 10 10 50 25 Quit
  24.   menu setprop FormEquivalent visible #true         1
  25. return
  26.  
  27. OriginalMenu:
  28. gosub showEUOMenuOriginal
  29. while #menubutton <> EUOButton1 && #menubutton <> CLOSED ; When using X to close the menu... #menubutton set to CLOSED
  30.  {
  31.  wait 1
  32.  }
  33. halt
  34. sub showEUOMenuOriginal
  35.   menu Clear
  36.   menu Window Title Original Menu
  37.   menu Window Color BtnFace
  38.   menu Window Size 210 163           1
  39.   menu Font Transparent #true
  40.   menu Font Align Right
  41.   menu Font Name MS Sans Serif
  42.   menu Font Size 8
  43.   menu Font Style
  44.   menu Font Color Black
  45.   menu Button EUOButton1 10 10 50 25 Quit
  46.   menu Show 0 0
  47. return


Fix Delete/Re-Create Buttons (or other elements)
If either multiple elements are created with the same name or deleted and recreated, there is unexpected behavior. A button will work once, but after the delete/recreate it will become unresponsive because of the unique name violation.
Code: easyuo
  1. ; How to reuse a button (or another element during a subroutine)
  2. ; This will create 2 buttons in the same place in the main menu section, but
  3. ; the BtnResume is not initially visible. During the sub BtnPause, the BtnPause
  4. ; will be set to "visible #false" and BtnResume is set to "visible #true".
  5. ; This gives the effect of deleting BtnPause and creating BtnResume, but doesn't violate creating 2 elements with the same name.
  6. ; If a menu does the Delete/Re-Create BtnPause logic, then it will successfully pause the first time, but on subsequent
  7. ; Pause attempts the button seems to be ignored. This style of logic will correct that behavior.
  8. call ColorNameSub.txt
  9. gosub showEUOMenuNew
  10. set #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any value
  11. gosub CheckButtons
  12.  
  13. halt
  14.  
  15. sub CheckButtons
  16.  while #menubutton <> formEquivalent && #menubutton <> Quit
  17.   {
  18.   gosub #menubutton
  19.   }
  20. return
  21.  
  22. sub showEUOMenuNew
  23.   menu form FormEquivalent 0 0 210 163 Equivalent Form
  24.   menu setprop FormEquivalent color %BtnFace
  25.   menu setdef alignment Right
  26.   menu setdef fontname MS Sans Serif
  27.   menu setdef fontsize 8
  28.   menu setdef fontstyle 0
  29.   menu setdef fontcolor %Black
  30.   menu Button Quit 10 10 50 25 Quit
  31.   menu Button BtnPause 10 50 50 25 Pause
  32.   menu Button BtnResume 10 50 50 25 Resume ; create Resume button for later
  33.   menu setprop BtnResume visible #false    ; set element invisible for later use
  34.   menu setprop FormEquivalent visible #true         1
  35. return
  36.  
  37. sub BtnPause
  38.  set #menubutton N/A
  39.  menu setprop BtnPause visible #false ; hide Pause button
  40.  menu setprop BtnResume visible #true ; show Resume button (in same place as pause button)
  41.  while #menubutton = N/A
  42.   wait 1
  43.  menu setprop BtnResume visible #false ; hide Resume button
  44.  menu setprop BtnPause visible #true   ; show Pause button
  45. return

Fix Delete/Re-Create Text elements
Labels ('menu text ...') may not display or if simply recreated over the top of the previous label, leaves residual text in the background.
Rather than delete the text element, create it during menu initialization and use the new "menu setprop ..." command to update it.
Note: Technically this could have also been done using the original "menu set" statement.

Code: easyuo
  1. ; Demonstrate updating a text label using "menu setprop" to avoid unique element name violation with delete/recreate
  2. ; The logic of the sub 'status' was modeled after MWinc Lumberjacker
  3. call ColorNameSub.txt
  4. gosub showEUOMenuNew
  5. set #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any value
  6. set %status Run
  7. gosub Status
  8. gosub CheckButtons
  9. set %status Quit
  10. gosub Status
  11. halt
  12.  
  13. sub CheckButtons
  14.  while #menubutton <> formEquivalent && #menubutton <> Quit
  15.   {
  16.   gosub #menubutton
  17.   }
  18. return
  19.  
  20. sub showEUOMenuNew
  21.   menu form FormEquivalent 0 0 210 163 Equivalent Form
  22.   menu setprop FormEquivalent color %BtnFace
  23.   menu setdef alignment Right
  24.   menu setdef fontname MS Sans Serif
  25.   menu setdef fontsize 8
  26.   menu setdef fontstyle 0
  27.   menu setdef fontcolor %Black
  28.   menu Button Quit 10 10 50 25 Quit
  29.   menu Button BtnPause 10 50 50 25 Pause
  30.   menu Button BtnResume 10 50 50 25 Resume ; create Resume button for later
  31.   menu setprop BtnResume visible #false    ; set element invisible for later use
  32.   menu text status 10 75 Status
  33.   menu setprop FormEquivalent visible #true
  34.   set %status Initializing
  35.   wait 20 ; pause for effect... to see label = "Status"
  36.   gosub Status
  37.   wait 20 ; pause for effect... to see label = "initializing" before changed to "run"
  38. return
  39.  
  40. ;=============================================================================
  41. ; Displays Status Of Script on Menu
  42. sub status
  43.  menu setdef fontcolor %blue
  44.  if %status = Initializing
  45.   menu setprop status text Initializing...
  46.  if %status = Quit
  47.   menu setprop status text Quitting...
  48.  if %status = Run
  49.   menu setprop status text Running.
  50.  if %status = Finding
  51.   menu setprop status text Finding Your Books..
  52.  if %status = Bookdone
  53.   menu setprop status text Books Found.
  54.  if %status = Recall
  55.   menu setprop status text Recalling..
  56.  menu setdef fontcolor %yellow
  57. return

Dotted Lines (Approximation for menu shape to create dotted lines)
This is limited to horizontal or vertical lines. It would need trigonometry modifications to allow consistent lines at other slopes.
Code: easyuo
  1. menu form FormLines 0 0 255 255 Line Example
  2. menu setprop FormLines visible #true
  3. set %name ImageLines
  4. set %color 0 ; black against default grey background for example routine
  5. gosub Dotted_line %name , 1 , _  0  79 167   1 %color 3 h
  6. gosub Dotted_line %name , 2 , _   0 127 167   1 %color 3 h
  7. gosub Dotted_line %name , 3 , _  97   0   1  79 %color 3 v
  8. gosub Dotted_line %name , 4 , _ 167   0   1 255 %color 3 v
  9. gosub Dotted_line %name , 5 , _ 240   0   1 255 %color 3 v
  10. halt
  11.  
  12. ; shapename %1
  13. ; x %2
  14. ; y %3
  15. ; x2 %4
  16. ; height %5
  17. ; color %6
  18. ; interval %7
  19. ; orientation = (h)orizontal|(v)ertical
  20. sub Dotted_line
  21.  set %gl_shapename %1
  22.  set %gl_x %2
  23.  set %gl_y %3
  24.  set %gl_x2 %4
  25.  set %gl_y2 %5
  26.  set %gl_color %6
  27.  set %gl_interval %7
  28.  set %gl_orientation %8
  29.  if %gl_orientation = h
  30.   {
  31.   while %gl_x <= %gl_x2
  32.    {
  33.    menu shape %gl_shapename , %gl_x %gl_x %gl_y %gl_interval %gl_y2 3 7 1 %gl_color 2 0
  34.    set %gl_x %gl_x + ( %gl_interval * 2 )
  35.    }
  36.   }
  37.  else
  38.   {
  39.   while %gl_y <= %gl_y2
  40.    {
  41.    menu shape %gl_shapename , %gl_y %gl_x %gl_y %gl_x2 %gl_interval 3 7 1 %gl_color 2 0
  42.    set %gl_y %gl_y + ( %gl_interval * 2 )
  43.    }
  44.   }
  45. return

New Radio Buttons (Panel and pushdef/popdef examples)
The new Radio Buttons work similar to a ComboBox (1 element active at a time), but have a different graphic/feel.
Each element has a property called "parent". All Radio Buttons in the same parent allow a single radio button to be active at anytime. When one is selected, the other radio buttons in the parent will be disabled ("checked #false" setting).

Pushdef and Popdef, a Panel and then Setdef can be used to create a radio button group that is isolated from others on the menu. Here is an example to setup 2 sets of Radio buttons:

Code: easyuo
  1. ; Demonstrate creating 2 isolated groups of radio buttons in separate panels.
  2. ; This also shows an example using pushdef/popdef/setdef
  3. call ColorNameSub.txt
  4. gosub showEUOMenuNew
  5. set #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any value
  6. set %status Run
  7. gosub Status
  8. gosub CheckButtons
  9.  
  10. halt
  11.  
  12. sub CheckButtons
  13.  while #menubutton <> formEquivalent && #menubutton <> Quit
  14.   {
  15.   gosub #menubutton
  16.   }
  17. return
  18.  
  19. sub showEUOMenuNew
  20.   menu form FormEquivalent 0 0 210 163 Equivalent Form
  21.   menu setprop FormEquivalent color %BtnFace
  22.   menu setdef alignment Right
  23.   menu setdef fontname MS Sans Serif
  24.   menu setdef fontsize 8
  25.   menu setdef fontstyle 0
  26.   menu setdef fontcolor %Black
  27.   menu Button Quit 10 10 50 25 Quit
  28.   menu pushdef ; this inherits any defaults
  29.   menu panel PnlRad1 10 70 100 80
  30.   menu setprop PnlRad1 color %red ; we can see where the panel borders are, because items inside it are set relative to the panel location
  31.   menu setdef parent PnlRad1 ; sets all new items to have it's parent set to PnlRad1
  32.   menu radio RADingot1 10 5 80 20 #true Ingots
  33.   menu radio RADboard1 10 30 80 20 #false Boards
  34.   menu radio RADboard1 10 55 80 20 #false Saltpeter
  35.   menu popdef ; restores previous defaults at the 'pushdef' statement above
  36.   menu pushdef ; this inherits any defaults
  37.   menu panel PnlRad2 115 70 100 80
  38.   menu setprop PnlRad2 color %blue ; we can see where the panel borders are, because items inside it are set relative to the panel location
  39.   menu setdef parent PnlRad2 ; sets all new items to have it's parent set to PnlRad2
  40.   menu radio RADingot2 10 5 80 20 #true Ingots
  41.   menu radio RADboard2 10 30 80 20 #false Boards
  42.   menu radio RADboard2 10 55 80 20 #false Saltpeter
  43.   menu popdef ; restores previous defaults at the 'pushdef' statement above
  44.   menu setprop FormEquivalent visible #true
  45.  
  46. return


Display Debug/Error Messages in a Called Library
Here is an example to create a menu inside a called library to display an error message.
This example gives a configurable option for where to place the message, which could be handled with a variable setting instead of passed into the library. I just chose to demonstrate with the passed values.

Code: easyuo
  1. ; User script which calls a library example.
  2. ; The passed parameters are the x and y location where to place the "error message menu" on the screen.
  3. call library_menu.txt Library_routine1 700 20
  4. wait 40
  5. call library_menu.txt Library_routine2 500 20
  6. halt
Code: easyuo
  1. ; Library file that is called by the user script.
  2. ; This is not an example of how to setup a library with multiple subs - look at Endless Night's examples for that.
  3. ; This will set an error message on the screen which doesn't halt the processing. The user can close the form by using the "X" method.
  4. ; If a button were defined, then the calling script would have to handle the button function,
  5. ; which would make an undue requirement on the caller.
  6. ; This is better than "saying" something by the character running the script because it keeps the information out of the UO client.
  7. ; It is also better than only a simple #result returned, because you can show more information unobtrusively to the client.
  8. set %errorx %2
  9. set %errory %3
  10. gosub %1
  11. exit
  12.  
  13. sub Library_routine1
  14.  ; When an actual error is encountered, you would issue the gosub to the form routine
  15.  ; This just demonstrates the functional logic
  16.  gosub errorMessage An error has occurred in Library_routine1
  17. return
  18.  
  19. sub Library_routine2
  20.  ; When an actual error is encountered, you would issue the gosub to the form routine
  21.  ; This just demonstrates the functional logic
  22.  gosub errorMessage An error has occurred in Library_routine2
  23. return
  24.  
  25. sub errorMessage
  26.  set %EM_message
  27.  if %0 > 0
  28.   {
  29.   for %EM_index 1 %0
  30.    {
  31.    set %EM_message %EM_message , % . %EM_index
  32.    if %EM_index < %0
  33.     set %EM_message %EM_message , #spc
  34.    }
  35.   }
  36.  else
  37.   set %EM_message A , #spc , generic , #spc , error , #spc , occurred.
  38.  menu form formerror %errorx %errory 300 50 formerrror
  39.  menu setprop formerror visible #true
  40.  menu text 10 10 20 %EM_message
  41. return
« Last Edit: January 17, 2020, 07:40:36 PM by Gaderian »

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12979
  • Activity:
    3.6%
  • Reputation Power: 151
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1333
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: New Menu Code and how to adapt old scripts
« Reply #3 on: January 15, 2020, 06:33:23 AM »
0
Awesome contribution, Gaderian!  Thanks for the input.  I've been away long enough not to realize there was this much change.  Do you think there are some legacy scripts out there that were negatively impacted by this?  I notice you talk about unsupported commands, but they seem to be obscure in nature and probably not used much.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline GaderianTopic starter

  • Jr. Member
  • **
  • Posts: 56
  • Activity:
    2.4%
  • Reputation Power: 4
  • Gaderian has no influence.
  • Respect: +11
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #4 on: January 15, 2020, 08:10:45 AM »
0
The major change is reusing element names which force menus to break. I have examples to edit above showing how to fix these. I just ran out of time last night.

If a script deleted and recreated the same name button-it no longer honors the click on the new button.
That is very common for pause/resume for scripts.

Another is delete/recreate a text widget for message display.

I have examples on how to fix each of these common issues.

I also have examples using new features to do other things that were not available with the original menu functions. I will update it as I have time soon.
« Last Edit: January 15, 2020, 08:12:38 AM by Gaderian »

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1695
  • Activity:
    0.6%
  • Reputation Power: 22
  • The Ghost might someday be someone...The Ghost might someday be someone...The Ghost might someday be someone...The Ghost might someday be someone...
  • Respect: +242
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #5 on: January 15, 2020, 08:19:39 AM »
0
This is awesome,  I know that the new future where available, but never take a look at them.     Thx for taking the time to explain and giving the exemple. 

Most of the menu  script that we have (95% of them work)
 The one that we had issue was
     sosmaster_4.3.h (Gaderian 23 Jun 18).txt.   He fix it
     Cyberpopes Mining Radar 4.1c_F001.euo  He fix it


Offline Crisis

  • Elite
  • *
  • *
  • Posts: 2109
  • Activity:
    3.8%
  • Reputation Power: 32
  • Crisis is a rising star!Crisis is a rising star!Crisis is a rising star!Crisis is a rising star!Crisis is a rising star!Crisis is a rising star!
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +186
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #6 on: January 15, 2020, 01:06:02 PM »
0
Gaderian gets my vote for B.M.O.C.!!!!!

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5382
  • Activity:
    4.2%
  • Reputation Power: 61
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +389
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #7 on: January 15, 2020, 02:08:31 PM »
0
+ reputation    :)

Thanks for this...  I wonder if any of my scripts are broken ...
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2539
  • Activity:
    0.2%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #8 on: January 15, 2020, 05:18:31 PM »
0
That would explain why a lot of my menus have been being pissy.
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline Tidus

  • Lazy
  • Administrator
  • *
  • *
  • Posts: 1235
  • Activity:
    0.2%
  • Reputation Power: 14
  • Tidus barely matters.Tidus barely matters.
  • Gender: Male
  • Mind Blown
  • Respect: +147
  • Referrals: 2
    • View Profile
    • Ultimate Apparel
Re: New Menu Code and how to adapt old scripts
« Reply #9 on: January 16, 2020, 05:54:44 AM »
0
Topic has been Stickied.
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Tags: