Skip to content
/ CGUI Public

(WIP) Convenient (i hope so) framework for client GUI for Rust (game)

Notifications You must be signed in to change notification settings

romgerman/CGUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CGUI

This plugin is heavily WIP.

Files

CGUI — Base plugin. Contains base classes.

GUILibrary — Requires CGUI. Contains basic UI elements.

GUITest — Is for testing.

Usage

Firstly you need to require one of the files inside your plugin.

// Requires: CGUI

GUIObject represents a basic UI element and acts as ICollection for components derived from GUIComponentBase.

Example:

// Basic text UI element
var element = new GUIObject()
{
	new TextComponent("Example"),
	new RectTransformComponent()
};

To show your UI to a player you can use GUIObject.ShowUI(BasePlayer).

To make more advanced elements you should make your own classes derived from GUIElementBase or use classes from GUILibrary.

GUIElementBase allows you to easily combine basic GUIObject elements. To show a GUIElementBase element to a player you should to use Representation class which acts as ICollection for GUIElementBase.

For example this is a constructor for GUIButton class (GUILibrary):

public GUIObject TextElement;
public GUIObject ButtonElement;

public GUIButton(string text = "", string elementName = null, string parent = null)
{
	elementName = elementName ?? GUIObject.GenerateId();

	ButtonElement = new GUIObject(elementName + "_button", parent)
	{
		new ButtonComponent().OnClick(player =>
		{
			Click?.Invoke(this, player);
		}, Owner),
		new RectTransformComponent()
	};

	TextElement = new GUIObject(elementName + "_text", ButtonElement.Name)
	{
		new TextComponent(text) { Align = TextAlign.MiddleCenter, Color = Color.black }
	};
}

Every class derived from GUIElementBase should implement its own Render method.

For example:

public override ICollection<GUIObject> Render()
{
	return new GUIObject[] { ButtonElement, TextElement };
}

The method is pretty straightforward. But one thing is — you should follow the inheritance order. So the previous element should be a parent of the next element.

If no name is present for GUIObject it generates the name automatically using GUIObject.GenerateId().

Components

Currently not all supported components are presented.

RectTransformComponent should be added at the end. Instead it will not work.

Data binding

Data binding is WIP. Examples can be found inside GUILibrary.

Markup language

WIP

About

(WIP) Convenient (i hope so) framework for client GUI for Rust (game)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages