- ItemManager.PC
- CordellDB.EXMPL
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
- ItemArea
- LittleButton
- Icon
GUI 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:
var buttonPosition = new Margin(int row, int col, int h, int w);
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).
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 can be used as a default sliders from popular frameworks. It 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 currentChosenParameter = PanelWindow.getPanel("PanelWhereSlider").getComponent("SliderName", Slider.class).getChose(event);
This slider`s ability give us a opportunity to connect Buttons and Sliders like in example below:
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)
));
Checkboxes have same functions with buttons instead one addition. Checkboxes, as Sliders, have action on click. Checkbox regenerate himself on every click like checkboxes from popular frameworks. This component can be created by next code:
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
Again. remember, 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 = MainWindow.getPanel("PanelWhereCheckBow").getComponent("checkBox1", CheckBox.class).isChecked(event) // event -> InventoryClickEvent
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);
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);
Note: LittleButton works like Button.
Icon looks like LittleButtons, but difference in action. Icons dont have action on click, that
s why you can use them as decoration. This component can be created by next code:
var icon = Icon(Margin position, String name, String lore, Material material, int dataModel);
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 invoke functions that was linked to components in panels.
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);
Example of panel with click area, stider, checkbox \ button and little button \ icon
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
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 should 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