Jump to content
×
×
  • Create New...

Simple V2 gui setup tutorial


Pty
 Share

Recommended Posts

Hi all, with the new upcoming release of V2 we have changed the process from using Java GUI's to native android GUI's. In an effort to make this easier for scripters we have changed the way of doing this by using annotations.

 

@ScriptConfiguration

Using the @ScriptConfiguration tag you can now configure your script as required to make it simple to setup.

There are currently 6 OptionType's you can use to setup your data which can correspond to different types of controls used to get that data.

  • String
  • Integer
  • Double
  • Boolean
  • GameObjects
  • Npcs

Examples

Singular

@ScriptConfiguration(
    name = "Tree",
    description = "Pick which tree type you want to cut",
    defaultValue = "Tree",
    allowedValues = ["Tree", "Oak"],
    optionType = OptionType.STRING, // Default
    enabled = true, // Default
    visible = true, // Default
)
class TreeKiller : AbstractScript() {

    override fun onStart() {
        var tree = getOption<String>("Tree")
    }
  
}

Multiple configurations


@ScriptConfiguration.List(
    [
        ScriptConfiguration(
            name = "Tree",
            description = "Pick which tree type you want to cut",
            allowedValues = ["Tree", "Oak"]
        ),
        ScriptConfiguration(
            name = "Powercut",
            description = "Tick this to drop logs when your inventory is full",
            optionType = OptionType.BOOLEAN,
            defaultValue = "true",
        )
    ]
)

Controls

When entering data you naturally will need different controls for different things, here is a list of the current ones we support. If you have any more feel free to suggest them and give an example use case

Drop down list

  • Must be string type
  • Must have multiple allowed values

This will most likely be the most common one you would be using, it starts at the default value and the complete list contains all the allowed values

image.png.9f68f56999a09f36f9120f9c11434b54.png

Text Fields

This is a field where users can enter data they want, depending on the type you specify it will restrict the characters allowed to be entered.

  • String(no/empty allowed values)
    • Any character allowed
  • Double type
    • 0-9 and .
  • Integer
    • 0-9 only

image.png.19dd46cb8ecbb1dff4a3fc9a5ab7edb3.png

Checkbox

This is a simple field which will return true/false depending whether the checkbox is ticked. Only for Boolean OptionType. 

image.png.72b3da2c31facb59f22bc6e6935f6e1e.png

 

Npc

This is a special field which allows you to select a list of NPC's and return relevant information relating to them in a  List<NpcOption> format.

image.thumb.png.a6467c31c7389d5754e5e869a74dd8cb.png


GameObject

This is another field just like the one above although this one returns in a List<GameObjectOption> format

image.thumb.png.79da4ad592dbb0c6c8c9efcadcdde511.png

 

 

@ValueChanged

This annotation much like the name suggests lets you get notified when the value is changed. You can use one of these for each of the script configurations that you have setup above, combined with the functionality to update the values this allows you to create much more dynamic user interfaces.

Example

In the example below I have two script configurations for when I want to chop wood Location and Tree.

The predicament is that Draynor does not have access to all the trees that Seers or Edgeville does so if I was to add all the trees below and invalid configuration would be possible. Using @ValueChanged we can solve that by listening for when the user changes the Location and update the list of values the user is allowed to select.

@ScriptConfiguration.List(
    [
        ScriptConfiguration(
            name = "Location",
            description = "Pick a location to cut the tree at",
            defaultValue = "Draynor",
            allowedValues = ["Draynor", "Edgeville", "Lumbridge", "Nearby", "Seers"]
        ),
        ScriptConfiguration(
            name = "Tree",
            description = "Pick which tree type you want to cut",
            allowedValues = ["Tree", "Oak"]
        ),
      ]
  )
class x : AbstractScript() {
  
    @ValueChanged("Location")
    fun locationUpdated(updatedValue: String) {
      // Select list of tree's based on the location
        val updatedList = when (updatedValue) {
            "Lumbridge" -> arrayOf("Tree", "Oak")
            "Draynor" -> arrayOf("Tree", "Oak", "Willow")
            "Edgeville" -> arrayOf("Yew")
            "Nearby" -> arrayOf("Tree", "Oak", "Willow", "Maple", "Yew", "Magic")
            "Seers" -> arrayOf("Tree", "Oak", "Willow", "Maple", "Yew", "Magic")
            else -> arrayOf()
        }
      
      // Update the list of allowed trees for the field named "Tree"
        updateAllowedOptions("Tree", updatedList)
    }
  
}
  
  

 

Other methods which do similar things are as follows

// Gets the value of the data from the name. T is the type returned depending on the field(EG String/Boolean)
getOption<T>(name: String)

// Updates the list of allowed options for a field.
updateAllowedOptions(name: String, options: Array<String>)
  
// Updates the value depends on the type of field EG Boolean/String
updateOption(name: String, value: T?, type: OptionType)
  
// Updates whether the field is hidden or shown
updateVisibility(name: String, visibility:Boolean)
  
// Updates whether the field is enabled/disabled
updateEnabled(name: String, enabled: Boolean)
  

 

Hopefully this helps you understand what we are trying to accomplish and how to use these changes. Any suggestions are welcome or any requests for other fields etc.

  • Like 2
  • Thanks 2
Link to post
Share on other sites

  • Pty changed the title to Simple V2 gui setup tutorial

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share