Git Product home page Git Product logo

radial-menu-godot's Introduction

radial-menu-godot

This is a Radial Menu class for the Godot game engine, written for my project Paramnesia. Feel free to use this code for your own projects.

example menu

The menu is rendered using Godot's _draw() function. It is customizable by default through global variables, but you may need to tweak some code to get it looking the way you want. The code is heavily commented, so it should be easy to understand.

How to use

First, transfer the files RadialMenu.tscn and RadialMenu.gd to your project. The menu is setup as a class, so it is instantiated through code.

The following code creates a menu with three options:

var r: RadialMenu = RadialMenu.new(["item1", "item2", "item3"])
r.connect("selected", self, "selected_from_menu")
r.connect("closed", self, "menu_closed")
add_child(r)

Add the menu as a child of a control node.

The RadialMenu.new() function takes an array of strings, each representing a menu option, as its only parameter.

A RadialMenu has 2 signals: selected and closed.

selected is emitted when the user clicks on an option. It also passes one parameter, the string corresponding to the option selected.

The following code handles the selection of options:

func selected_from_menu(option: String):
  match option:
    "item1":
      print("Item1 selected")
    "item2":
      print("Item2 selected")
    "item3":
      print("Item3 selected")

closed is emitted when the user clicks outside of the menu circle, and the menu is closed.

See the file RadialMenu.gd for all the variables that can be changed. If all of the menus you are creating have the same visual style, you can edit the variables in this file. Otherwise, you can change the member variables of a specific menu object after instantiating it. You may need to write setter function for some of these changes (specifically, the font, if it is not declared in the .gd file).

An example implementation is seen in the files Example.tscn and Example.gd

License

MIT License. Free to use, modify, and distribute. No attribution necessary.

radial-menu-godot's People

Contributors

ericanderson2 avatar

Stargazers

OakheartSoftware avatar Robert avatar Jung Ho avatar  avatar Mauro Risonho de Paula Assumpção avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.