From 98ebd2926cba2e608bceda22ae8577508e7b8fe9 Mon Sep 17 00:00:00 2001 From: Nikolay <57866196+j1sk1ss@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:26:11 +0500 Subject: [PATCH] Update README.md --- README.md | 146 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 3dd93bf..c111e65 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,13 @@ # **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 inventory:
- - var window = Bukkit.createInventory(player, 27, Component.text("Test_Inventory")); - -Then create a new **MenuWindow** object. This object is representation of your future menu:
+To get started, you will need to create a new window:
public static MenuWindow TestMenu = new MenuWindow(new ArrayList()); 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()); + var testPage = new Panel(new ArrayList(), "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:
@@ -28,6 +24,7 @@ As you can see, panels should take **Components**. **Components** is a UI object - **CheckBox** - **Bar** - **ClickArea** +- **ItemArea** - **LittleButton** - **Icon**
@@ -36,103 +33,111 @@ As you can see, panels should take **Components**. **Components** is a UI object

Buttons

-**Buttons** can be created by next code:
+GUI **buttons** can be created by next code:
- var button = new Button(int firstPos, int secPos, String name, String lore, Action action); + var button = new Button(Margin position, String name, String lore, Action action); -First and second positions - is positions of button`s corners. Main idea you can see on image below:
+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(6, 26, "Name", "Lore", - (event) -> { + 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(title); - }) - - + player.sendMessage("Button clicked!"); + });

Slider

-**Sliders** can be created by next code:
+**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 Options, String lore, String name, Action action); - var slider = new Slider(ArrayList coordinates, ArrayList 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 + 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(Arrays.asList( - var panel = new Panel(Arrays.asList( - new Slider(Arrays.asList( - 0, 1, 2, 3, 4, 5 - ), Arrays.asList( - "100", "200", "300", "400", "500", "600" - ), "", "Slider", null), - - new Button(9, 21, "TestButton", "Lore", - (event) -> { - var player = (Player)event.getWhoClicked(); - var sliderChose = Menu.getPanel("TestPanel").getSliders("Slider").getChose(event); - if (sliderChose.equals("none")) return; - - player.sendMessage(sliderChose); // Will prints current slider parameter - }), - ), "TestPanel"))); - - + 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) + ));

Checkbox

-**Checkboxes** can be created by next code:
+**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(int firstSlot, int secondSlot, String name, String lore, Action action); + 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).
+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 = checkbox.isChecked(event) // event -> InventoryClickEvent + var check = MainWindow.getPanel("PanelWhereCheckBow").getComponent("checkBox1", CheckBox.class).isChecked(event) // event -> InventoryClickEvent -

Click area

+

Click area and Item area

**ClickArea** can be created by next code:
- var clickArea = ClickArea(firstCoordinate, secondCoordinate, action, name, lore); - var clickArea = ClickArea(coordinates, action, name, lore); + 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(0, 44, - (event) -> { + new ClickArea(new Margin(0, 0, 4, 8), + (event, menu) -> { var player = (Player) event.getWhoClicked(); var option = event.getCurrentItem(); if (option == null) return; - if (option.getLoreLines().size() < 2) return; - var amount = option.getDoubleFromContainer("item-bank-value"); - - func1(Math.abs(amount), player); - openMenu(player, event.getInventory()); + player.sendMessage("You click " + option.getType().toString()); }), *Note*: **Component** class has his own **PDC**. You can use it with next methods: @@ -143,49 +148,66 @@ For example next code shoulde handle clicks on generated options in menu: public int getIntegerFromContainer(key); public void deleteKeyFromContainer(key); +

+

Little buttons

-**LittleButton** can be created by next code:
+If you want create traditional GUI without resoursepacks, you can use **littleButton**. This component can be created by next code:
- var button = new LittleButton(41, "LB", "\n" + Math.round(playerBalance * 100) / 100 + CashManager.currencySigh); + 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. +*Note*: **LittleButton** works like **Button**.

Icons

-**Icon** can be created by next code:
+**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); + var icon = Icon(Margin position, String name, String lore, Material material, int dataModel);

How to use it?

**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 = ... // Create new menu with panels + 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**. +After this, MenuFramework listen all inventory clicks and invoke functions that was linked to **components** 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); + 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

+
+ +

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 -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: +
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);