Dependencies:
- ItemManager.PC (
https://www.spigotmc.org/resources/itemmanager.118016/)
- CordellDB.EXMPL (
https://github.com/j1sk1ss/CordellDB.EXMPL/releases/tag/ver0.2)
<dependency>
<groupId>com.github.j1sk1ss</groupId>
<artifactId>MenuFramework.PC</artifactId>
<version>ver1.0.7.5</version>
</dependency>
Main info:
This is a very simple basis for creating your own menu in Minecraft.
To get started, you will need to create a new window:
public static MenuWindow TestMenu = new MenuWindow(new ArrayList<Panel>());
In array list should be placed
Panels. Panels, in few words, is representation of separated pages in your future menu. Let`s create a simple page:
var testPage = new Panel(new ArrayList<Component>(), "PanelName", MenuSizes panelSize, String UI, String color); // UI and color give ability to create custom GUI
As you can see, panels should take Components. Components is a UI objects in your menu. Let`s talk about them a little more:
Components presented by next types of UI objects:
- Button
- Slider
- CheckBox
- Bar
- ClickArea
- LittleButton
- Icon
- ItemArea
BUTTONS
Buttons can be created by next code:
var button = new Button(Margin position, String name, String lore, Action action);
Position - is positions of button`s corners. Main idea you can see on image below, and usualy you will use next code:</br>
var buttonPosition = new Margin(int row, int col, int h, int w);
First and second positions - is positions of button`s corners. Main idea you can see on image below:
Actions for buttons presented as functions that can be added to button and invoked by
button.click(event), where
event is *InventoryClickEvent* (Component click envokes ComponentClickEvent). </br>
Also, example of adding delegate to
button:
var button = new Button(new Margin(0, 0, 3, 3), "Name", "Lore",
(event, menu) -> {
var player = (Player)event.getWhoClicked();
var title = event.getView().getTitle();
player.sendMessage("Button clicked!");
});
SLIDERS
Sliders can be created by next code:
var slider = new Slider(Margin position, ArrayList<String> Options, String lore, String name, Action action);
In this case we can use another
margin constructor. Like next:
var sliderPosition = new Margin(int row, int col, int w, Direction dir); // Direction can be horizontal and vertical.
Red slot - chosen option in slider
Note, that slider has default delegate. This "default" delegate regenerate slider body on click when chosen parameter changes.
If you need to take chosen param from Slider, you can use next code:
var slider = new Slider(panelWhereStoredSlider.getSliders("SliderName"), event.getInventory());
var parameter = slider.getChose(event); // parameter is a String lore line from Options
This **slider`s** ability give us a opportunity to connect **Buttons** and **Sliders** like in example below:</br>
public static MenuWindow Menu = new MenuWindow(List.of(
new Panel(
List.of(
new Slider(new Margin(0, 0, 4, Direction.Horizontal), Arrays.asList(
"100", "200", "300", "400", "500", "600"
), "SliderLore", "Slider1", null),
new Button(new Margin(1, 0, 2, 2), "TestButton", "Lore",
(event, menu) -> {
var player = (Player)event.getWhoClicked();
var sliderValue = menu.getPanel("TestPanel").getComponent("Slider", Slider.class).getChose(event);
if (sliderChose.equals(Slider.None)) return;
player.sendMessage("Current slider value: " + sliderValue); // Will prints current slider parameter
}),
),
"TestPanel", MenuSizes.FiveLines)
));
CHECBOX
Checkboxes can be created by next code:</br>
var checkbox = new Checkbox(Margin position, String name, String lore, Action action, int cdm, int ddm, Material cm, Material dm);
// cdm - Checked data model
// ddm - Default data model
// cm - Checked material
// dm - Default material
Note, that checkbox has default delegate too. This "default" delegate regenerate checkbox body on click (Checked and unchecked).
Here first slot and second slot works like in Button part. One difference in method
isChecked.
var check = checkbox.isChecked(event) // event -> InventoryClickEvent
CLICKAREA
ClickArea can be created by next code:
var clickArea = ClickArea(Margin position, action, name, lore);
ClickArea solves problem with generated (non-static) buttons. You can just put ClickArea where will be generated non-static Components then just handle any clicks in action delegate.
For example next code shoulde handle clicks on generated options in menu:
new ClickArea(new Margin(0, 0, 4, 8),
(event, menu) -> {
var player = (Player) event.getWhoClicked();
var option = event.getCurrentItem();
if (option == null) return;
player.sendMessage("You click " + option.getType().toString());
}),
Note: Component class has his own PDC. You can use it with next methods:
public void setDouble2Container(value, key);
public void setInteger2Container(value, key);
public double getDoubleFromContainer(key);
public int getIntegerFromContainer(key);
public void deleteKeyFromContainer(key);
LITTLE BUTTONS
If you want create traditional GUI without resoursepacks, you can use
littleButton. This component can be created by next code:
var button = new LittleButton(Margin position, String name, String lore, Action action, Material material, int dataModel);
LittleButton works like Button, but this component has onlu one position.
ICONS
Icon looks like
LittleButtons, but difference in action.
Icons don`t have action on click, that`s why you can use them as decoration. This component can be created by next code:
var icon = Icon(position, name, lore, material, dataModel);
HOW TO USE THIS?
Components placed in panels. Panels placed in Menu. After all preparations we can start using all stuff what we make earlier.
public static MenuWindow Menu = new MenuWindow(new Panel(List.of(new Button(...), new Slider(...))), "MenuName", new LocalizationManager("path")); // Create new menu with panels
After this, MenuFramework listen all inventory clicks and anvoke functions that was linked to buttons in panels.
PANEL
Panel is a representation of every inventory that used as menu in your plugin. Creation of panel is simple:
var panel = new Panel(Arrays.asList( ... ), "InventoryTitlePart", MenuSizes.SixLines, String UI, Strign color);
LOCALIZATION
MenuFramework support multi-language GUI. For this, you should download CordellDB plugin (It used for working with localization files), create localization file and insert into MenuWindow LocalizationManager.
Localization file has next structure:
LNG_componentName:translatedName/translatedLore
// For example:
RU_button1:кнопка1/кнопка
EN_кнп:button
IT_button:- // - means, that name not translated
PS
Remember that MenuFramework will execute linked function in situation, when used inventory have same name with panel. (Or panel name is a part of inventory title).
To place all components to inventory you shoukd use next code:
public void getView(player);
public void getView(player, inventory);
// Or
public void getView(player, lore);
public void getView(player, customLore, names);
public void getViewWith(player, newComponents); // newComponents - non-static components
public void getView(player, lore, inventory);
public void getView(player, customLore, names, inventory); // customLore - lore for components with names from names
public void getViewWith(player, newComponents, inventory); // newComponents - non-static components