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

0 Members and 1 Guest are viewing this topic.

Offline GaderianTopic starter

  • Elite
  • *
  • *
  • Posts: 490
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +283
  • Referrals: 3
    • View Profile
New Menu Code and how to adapt old scripts
« on: January 14, 2020, 05:58:26 PM »
+3
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. So in order to use multiple groups of radio buttons, use panels to keep each group of radio buttons.

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: October 26, 2021, 06:10:02 PM by Gaderian »
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline GaderianTopic starter

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

« Last Edit: October 26, 2021, 07:35:00 PM by Gaderian »
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline GaderianTopic starter

  • Elite
  • *
  • *
  • Posts: 490
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +283
  • Referrals: 3
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #2 on: January 14, 2020, 05:59:26 PM »
+2
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.   menu get radingot1
  17.   if #menures = #true
  18.    menu setprop txt1 text radingot1
  19.   menu get radboard1
  20.   if #menures = #true
  21.    menu setprop txt1 text radboard1
  22.   menu get radsaltpeter1
  23.   if #menures = #true
  24.    menu setprop txt1 text radsaltpeter1
  25.   menu get radingot2
  26.   if #menures = #true
  27.    menu setprop txt2 text radingot2
  28.   menu get radboard2
  29.   if #menures = #true
  30.    menu setprop txt2 text radboard2
  31.   menu get radsaltpeter2
  32.   if #menures = #true
  33.    menu setprop txt2 text radsaltpeter2
  34.   }
  35. return
  36.  
  37. sub showEUOMenuNew
  38.  menu form FormEquivalent 0 0 210 163 Equivalent Form
  39.  menu setprop FormEquivalent color %BtnFace
  40.  menu setdef alignment Right
  41.  menu setdef fontname MS Sans Serif
  42.  menu setdef fontsize 8
  43.  menu setdef fontstyle 0
  44.  menu setdef fontcolor %Black
  45.  menu Button Quit 10 10 50 25 Quit
  46.  menu pushdef ; this inherits any defaults
  47.  menu panel PnlRad1 10 70 100 80
  48.  menu setprop PnlRad1 color %red ; we can see where the panel borders are, because items inside it are set relative to the panel location
  49.  menu setdef parent PnlRad1 ; sets all new items to have it's parent set to PnlRad1
  50.  menu radio RADingot1 10 5 80 20 #true Ingots
  51.  menu radio RADboard1 10 30 80 20 #false Boards
  52.  menu radio RADsaltpeter1 10 55 80 20 #false Saltpeter
  53.  menu popdef ; restores previous defaults at the 'pushdef' statement above
  54.  menu pushdef ; this inherits any defaults
  55.  menu panel PnlRad2 115 70 100 80
  56.  menu setprop PnlRad2 color %blue ; we can see where the panel borders are, because items inside it are set relative to the panel location
  57.  menu setdef parent PnlRad2 ; sets all new items to have it's parent set to PnlRad2
  58.  menu radio RADingot2 10 5 80 20 #true Ingots
  59.  menu radio RADboard2 10 30 80 20 #false Boards
  60.  menu radio RADsaltpeter2 10 55 80 20 #false Saltpeter
  61.  menu popdef ; restores previous defaults at the 'pushdef' statement above
  62.  menu text txt1 70 10
  63.  menu text txt2 70 40
  64.  menu setprop FormEquivalent visible #true
  65.  
  66. return
Updated Feb 11, 2020


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: February 11, 2020, 05:47:38 PM by Gaderian »
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13310
  • Activity:
    0%
  • Reputation Power: 154
  • 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: +3089
  • Referrals: 34
    • View Profile
    • ScriptUO
Re: New Menu Code and how to adapt old scripts
« Reply #3 on: January 15, 2020, 06:33:23 AM »
+1
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

  • Elite
  • *
  • *
  • Posts: 490
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +283
  • Referrals: 3
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #4 on: January 15, 2020, 08:10:45 AM »
+1
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 »
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1917
  • Activity:
    0%
  • Reputation Power: 25
  • The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.
  • Respect: +556
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #5 on: January 15, 2020, 08:19:39 AM »
+1
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

  • Global Moderator
  • *
  • *
  • Posts: 3084
  • Activity:
    2.6%
  • Reputation Power: 42
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +566
  • Referrals: 2
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #6 on: January 15, 2020, 01:06:02 PM »
+1
Gaderian gets my vote for B.M.O.C.!!!!!

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • 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: +786
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #7 on: January 15, 2020, 02:08:31 PM »
+1
+ 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: 2556
  • Activity:
    0%
  • 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: +272
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #8 on: January 15, 2020, 05:18:31 PM »
+1
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: 1291
  • Activity:
    0%
  • Reputation Power: 15
  • Tidus is working their way up.Tidus is working their way up.Tidus is working their way up.
  • Gender: Male
  • Mind Blown
  • Respect: +367
  • 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 »
+1
Topic has been Stickied.
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Offline Fabolous1

  • Jr. Member
  • **
  • Posts: 18
  • Activity:
    0%
  • Reputation Power: 1
  • Fabolous1 has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #10 on: January 26, 2020, 06:29:32 PM »
+1
This is legendary, I appreciate you Gaderian

Offline GaderianTopic starter

  • Elite
  • *
  • *
  • Posts: 490
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +283
  • Referrals: 3
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #11 on: March 19, 2020, 05:16:19 PM »
+1
So I updated this to reflect proper values for menu setdef/setprop alignment because the values of "left, right and center" all get translated to a 0 which means it is 'left'.
Old code that used the name version of the alignment need to be modified to numeric values.

I also updated the menu image file to show that *.GIF files can be used.

Gaderian
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • 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: +272
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #12 on: January 15, 2021, 03:00:11 PM »
+1

Thank you for writing out all this
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 manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • 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: +272
  • Referrals: 1
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #13 on: January 15, 2021, 05:59:06 PM »
+1
So, if you want to actually DELETE something, to say move it somewhere else.... You have to create an entirely new unique name for the menu item.
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 GaderianTopic starter

  • Elite
  • *
  • *
  • Posts: 490
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +283
  • Referrals: 3
    • View Profile
Re: New Menu Code and how to adapt old scripts
« Reply #14 on: January 15, 2021, 06:05:56 PM »
+1
There are several options available if you do not actually want to delete it.

You can hide it:
menu setprop widgetid visible #false

You can change it's parent to move it to a different panel or for:
menu setprop widgetid parent otherParentWidgetID

You can just move it around:
menu setprop widgetid top 123
menu setprop widgetid left 246

If you have to remove a line from a ComboBox or ListBox then you have to delete the widget and recreate it without the unwanted data. This is the only time I have needed to delete somethign and recreate something with the same name.

Gaderian
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Tags: