Skip to content

Commit

Permalink
Add configurable buttons in Trade menu
Browse files Browse the repository at this point in the history
Adds configurable balance, sell and buy buttons in the trading menu
  • Loading branch information
AfkF24 committed Sep 3, 2023
1 parent ff6588a commit 2655487
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/main/java/me/sat7/dynamicshop/guis/InGameUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,43 @@ public static Material GetShopInfoButtonIconMat()
}
return mat;
}

public static Material GetBalanceButtonIconMat()
{
String iconName = ConfigUtil.GetBalanceButtonIcon();
Material mat = Material.getMaterial(iconName);
if (mat == null)
{
mat = Material.EMERALD;
ConfigUtil.SetBalanceButtonIcon("EMERALD");
ConfigUtil.Save();
}
return mat;
}

public static Material GetSellToggleButtonIconMat()
{
String iconName = ConfigUtil.GetSellToggleButtonIcon();
Material mat = Material.getMaterial(iconName);
if (mat == null)
{
mat = Material.GREEN_STAINED_GLASS;
ConfigUtil.SetSellToggleButtonIcon("GREEN_STAINED_GLASS");
ConfigUtil.Save();
}
return mat;
}

public static Material GetBuyToggleButtonIconMat()
{
String iconName = ConfigUtil.GetBuyToggleButtonIcon();
Material mat = Material.getMaterial(iconName);
if (mat == null)
{
mat = Material.RED_STAINED_GLASS;
ConfigUtil.SetBuyToggleButtonIcon("RED_STAINED_GLASS");
ConfigUtil.Save();
}
return mat;
}
}
6 changes: 3 additions & 3 deletions src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP))
if (ChatColor.stripColor(temp).startsWith("\n"))
moneyLore = moneyLore.replaceFirst("\n", "");

CreateButton(CHECK_BALANCE, Material.EMERALD, t(player, "TRADE.BALANCE"), moneyLore);
CreateButton(CHECK_BALANCE, InGameUI.GetBalanceButtonIconMat(), t(player, "TRADE.BALANCE"), moneyLore);
}

private void CreateSellBuyOnlyToggle()
Expand All @@ -252,8 +252,8 @@ private void CreateSellBuyOnlyToggle()
if (player.hasPermission(P_ADMIN_SHOP_EDIT))
buyLore.add(t(player,"TRADE.TOGGLE_BUYABLE"));

CreateButton(SELL_ONLY_TOGGLE, Material.GREEN_STAINED_GLASS, t(player, "TRADE.SELL"), sellLore);
CreateButton(BUY_ONLY_TOGGLE, Material.RED_STAINED_GLASS, t(player, "TRADE.BUY"), buyLore);
CreateButton(SELL_ONLY_TOGGLE, InGameUI.GetSellToggleButtonIconMat(), t(player, "TRADE.SELL"), sellLore);
CreateButton(BUY_ONLY_TOGGLE, InGameUI.GetBuyToggleButtonIconMat(), t(player, "TRADE.BUY"), buyLore);
}

private void CreateTradeButtons()
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,36 @@ public static void SetShopInfoButtonIcon(String value)
config.set("UI.ShopInfoButtonIcon", value);
}

public static String GetBalanceButtonIcon()
{
return config.getString("UI.BalanceButtonIcon");
}

public static void SetBalanceButtonIcon(String value)
{
config.set("UI.BalanceButtonIcon", value);
}

public static String GetSellToggleButtonIcon()
{
return config.getString("UI.SellToggleButtonIcon");
}

public static void SetSellToggleButtonIcon(String value)
{
config.set("UI.SellToggleButtonIcon", value);
}

public static String GetBuyToggleButtonIcon()
{
return config.getString("UI.BuyToggleButtonIcon");
}

public static void SetBuyToggleButtonIcon(String value)
{
config.set("UI.BuyToggleButtonIcon", value);
}

public static String GetIntFormat()
{
return config.getString("UI.IntFormat");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ UI.OpenStartPageWhenClickCloseButton: true
UI.CloseButtonIcon : BARRIER
UI.PageButtonIcon : PAPER
UI.ShopInfoButtonIcon : OAK_SIGN
UI.BalanceButtonIcon : EMERALD
UI.SellToggleButtonIcon : GREEN_STAINED_GLASS
UI.BuyToggleButtonIcon : RED_STAINED_GLASS
UI.IntFormat: '###,###'
UI.DoubleFormat: '###,##0.00'
UI.LocalizedItemName: true
Expand Down

0 comments on commit 2655487

Please sign in to comment.