Add skins into the UI
This commit is contained in:
parent
bf940177f9
commit
c78eb933b3
@ -22,14 +22,12 @@ public class GameCosmeticCategoryPage extends GadgetPage
|
||||
{
|
||||
|
||||
private final List<GameCosmeticCategory> _categories;
|
||||
private boolean _buildPage;
|
||||
|
||||
public GameCosmeticCategoryPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, GameCosmeticType type, List<GameCosmeticCategory> categories)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, type.getName(), player);
|
||||
super(plugin, shop, clientManager, donationManager, type.getName(), player, false);
|
||||
|
||||
_categories = categories;
|
||||
_buildPage = true;
|
||||
|
||||
buildPage();
|
||||
}
|
||||
@ -37,11 +35,6 @@ public class GameCosmeticCategoryPage extends GadgetPage
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
if (!_buildPage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] slots = UtilUI.getIndicesFor(_categories.size(), 2);
|
||||
int index = 0;
|
||||
|
||||
|
@ -17,15 +17,13 @@ public class GameCosmeticGadgetPage extends GadgetPage
|
||||
|
||||
private final GameCosmeticCategoryPage _previousMenu;
|
||||
private final GameCosmeticCategory _category;
|
||||
private boolean _buildPage;
|
||||
|
||||
public GameCosmeticGadgetPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, GameCosmeticCategoryPage previousMenu, GameCosmeticCategory category)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, name, player);
|
||||
super(plugin, shop, clientManager, donationManager, name, player, false);
|
||||
|
||||
_previousMenu = previousMenu;
|
||||
_category = category;
|
||||
_buildPage = true;
|
||||
|
||||
buildPage();
|
||||
}
|
||||
@ -33,11 +31,6 @@ public class GameCosmeticGadgetPage extends GadgetPage
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
if (!_buildPage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int slot = 10;
|
||||
|
||||
for (GameModifierGadget gadget : _category.getGadgets())
|
||||
|
@ -0,0 +1,104 @@
|
||||
package mineplex.core.cosmetic.ui.page.gamemodifiers.moba;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.skin.SkinData;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilUI;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.cosmetic.ui.CosmeticShop;
|
||||
import mineplex.core.cosmetic.ui.page.GadgetPage;
|
||||
import mineplex.core.cosmetic.ui.page.gamemodifiers.GameCosmeticCategoryPage;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.gadgets.gamemodifiers.moba.HeroSkinGadget;
|
||||
import mineplex.core.gadget.gadgets.gamemodifiers.moba.HeroSkinGadgetData;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
|
||||
public class HeroSkinCategoryPage extends GadgetPage
|
||||
{
|
||||
|
||||
private static final Map<String, SkinData> SKIN_DATA = new HashMap<>();
|
||||
|
||||
private static SkinData getSkinItem(String name)
|
||||
{
|
||||
if (SKIN_DATA.containsKey(name))
|
||||
{
|
||||
return SKIN_DATA.get(name);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Field field = SkinData.class.getDeclaredField(name.toUpperCase());
|
||||
SkinData data = (SkinData) field.get(null);
|
||||
SKIN_DATA.put(name, data);
|
||||
return data;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final GameCosmeticCategoryPage _previousMenu;
|
||||
|
||||
public HeroSkinCategoryPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, GameCosmeticCategoryPage previousMenu)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, name, player, false);
|
||||
|
||||
_previousMenu = previousMenu;
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
Map<String, List<HeroSkinGadgetData>> skinData = HeroSkinGadget.getSkins();
|
||||
int[] slots = UtilUI.getIndicesFor(skinData.size(), 2);
|
||||
int index = 0;
|
||||
|
||||
for (Entry<String, List<HeroSkinGadgetData>> entry : skinData.entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
List<HeroSkinGadgetData> gadgetDataList = entry.getValue();
|
||||
SkinData data = getSkinItem(name);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int own = 0;
|
||||
int total = 0;
|
||||
for (HeroSkinGadgetData gadgetData : gadgetDataList)
|
||||
{
|
||||
if (gadgetData.getGadget().ownsGadget(getPlayer()))
|
||||
{
|
||||
own++;
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
ItemStack itemStack = data.getSkull(C.cGreenB + name, Arrays.asList(
|
||||
"",
|
||||
C.cWhite + "You own " + own + "/" + total,
|
||||
"",
|
||||
C.cGreen + "Left-Click to view " + name + "'s skins"
|
||||
));
|
||||
|
||||
addButton(slots[index++], itemStack, (player, clickType) -> getShop().openPageForPlayer(player, new HeroSkinGadgetPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), name, getPlayer(), this, gadgetDataList)));
|
||||
}
|
||||
|
||||
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), (player, clickType) -> getShop().openPageForPlayer(getPlayer(), _previousMenu));
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package mineplex.core.cosmetic.ui.page.gamemodifiers.moba;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.cosmetic.ui.CosmeticShop;
|
||||
import mineplex.core.cosmetic.ui.page.GadgetPage;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.gadgets.gamemodifiers.moba.HeroSkinGadgetData;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
|
||||
public class HeroSkinGadgetPage extends GadgetPage
|
||||
{
|
||||
|
||||
private final GadgetPage _previousMenu;
|
||||
private final List<HeroSkinGadgetData> _gadgetData;
|
||||
|
||||
HeroSkinGadgetPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, GadgetPage previousMenu, List<HeroSkinGadgetData> gadgetData)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, name, player, false);
|
||||
|
||||
_previousMenu = previousMenu;
|
||||
_gadgetData = gadgetData;
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int slot = 10;
|
||||
|
||||
for (HeroSkinGadgetData gadgetData : _gadgetData)
|
||||
{
|
||||
addGadget(gadgetData.getGadget(), slot);
|
||||
|
||||
if (++slot % 9 == 8)
|
||||
{
|
||||
slot += 2;
|
||||
}
|
||||
}
|
||||
|
||||
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[0], 1, false), (player, clickType) -> getShop().openPageForPlayer(getPlayer(), _previousMenu));
|
||||
}
|
||||
}
|
@ -37,6 +37,9 @@ import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.cosmetic.ui.page.GadgetPage;
|
||||
import mineplex.core.cosmetic.ui.page.gamemodifiers.GameCosmeticCategoryPage;
|
||||
import mineplex.core.cosmetic.ui.page.gamemodifiers.moba.HeroSkinCategoryPage;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.commands.AmmoCommand;
|
||||
@ -739,6 +742,12 @@ public class GadgetManager extends MiniPlugin
|
||||
{
|
||||
HeroSkinGadget.getSkins().values().forEach(heroSkins -> heroSkins.forEach(skinData -> addGameGadget(new HeroSkinGadget(getManager(), this, skinData))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GadgetPage getGadgetPage(GameCosmeticCategoryPage parent)
|
||||
{
|
||||
return new HeroSkinCategoryPage(parent.getPlugin(), parent.getShop(), parent.getClientManager(), parent.getDonationManager(), getCategoryName(), parent.getClient().GetPlayer(), parent);
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this, "Taunts", new ItemStack(Material.LAVA_BUCKET), false)
|
||||
{
|
||||
|
@ -6,25 +6,34 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.skin.SkinData;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.gadgets.gamemodifiers.GameCosmeticCategory;
|
||||
import mineplex.core.gadget.types.GadgetType;
|
||||
import mineplex.core.gadget.types.GameModifierGadget;
|
||||
import mineplex.core.game.GameDisplay;
|
||||
import mineplex.core.google.GoogleSheetsManager;
|
||||
import mineplex.core.reward.RewardRarity;
|
||||
|
||||
public class HeroSkinGadget extends GameModifierGadget
|
||||
{
|
||||
|
||||
private static final GoogleSheetsManager SHEET_MANAGER = Managers.require(GoogleSheetsManager.class);
|
||||
|
||||
private static Map<String, List<HeroSkinGadgetData>> SKIN_DATA;
|
||||
public static Map<String, List<HeroSkinGadgetData>> getSkins()
|
||||
{
|
||||
if (SKIN_DATA != null)
|
||||
{
|
||||
return SKIN_DATA;
|
||||
}
|
||||
|
||||
Map<String, List<HeroSkinGadgetData>> skinData = new HashMap<>();
|
||||
Map<String, List<List<String>>> sheet = SHEET_MANAGER.getSheetData("MOBA_SKINS");
|
||||
Map<String, List<List<String>>> sheet = Managers.require(GoogleSheetsManager.class).getSheetData("MOBA_SKINS");
|
||||
|
||||
sheet.forEach((sheetName, rows) ->
|
||||
{
|
||||
@ -39,16 +48,19 @@ public class HeroSkinGadget extends GameModifierGadget
|
||||
return;
|
||||
}
|
||||
|
||||
HeroSkinGadgetData heroSkin = new HeroSkinGadgetData(columns.get(0), columns.get(1), RewardRarity.valueOf(columns.get(2).toUpperCase()), new SkinData(columns.get(3), columns.get(4)));
|
||||
HeroSkinGadgetData heroSkin = new HeroSkinGadgetData(sheetName, columns.get(0), columns.get(2), RewardRarity.valueOf(columns.get(1).toUpperCase()), new SkinData(columns.get(3), columns.get(4)));
|
||||
heroSkins.add(heroSkin);
|
||||
});
|
||||
|
||||
skinData.put(sheetName, heroSkins);
|
||||
});
|
||||
|
||||
SKIN_DATA = skinData;
|
||||
return skinData;
|
||||
}
|
||||
|
||||
private final HeroSkinGadgetData _gadgetData;
|
||||
|
||||
public HeroSkinGadget(GadgetManager manager, GameCosmeticCategory category, HeroSkinGadgetData skinData)
|
||||
{
|
||||
this(manager, category, skinData, -2);
|
||||
@ -56,8 +68,28 @@ public class HeroSkinGadget extends GameModifierGadget
|
||||
|
||||
public HeroSkinGadget(GadgetManager manager, GameCosmeticCategory category, HeroSkinGadgetData skinData, int cost)
|
||||
{
|
||||
super(manager, category, skinData.getName(), new String[]{skinData.getDescription()}, cost, Material.GLASS, (byte) 0);
|
||||
super(manager, category, skinData.getName(), new String[]{C.cGray + "Rarity: " + skinData.getRarity().getColor() + skinData.getRarity().getName(), "", C.cGray + ChatColor.translateAlternateColorCodes('&', skinData.getDescription())}, cost, Material.GLASS, (byte) 0);
|
||||
|
||||
setDisplayItem(skinData.getSkinData().getSkull());
|
||||
skinData.setGadget(this);
|
||||
_gadgetData = skinData;
|
||||
}
|
||||
|
||||
public HeroSkinGadgetData getGadgetData()
|
||||
{
|
||||
return _gadgetData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableCustom(Player player, boolean message)
|
||||
{
|
||||
Manager.getGameCosmeticManager().getGadgetsFrom(GameDisplay.MOBA)
|
||||
.stream()
|
||||
.filter(
|
||||
gadget -> gadget instanceof HeroSkinGadget &&
|
||||
((HeroSkinGadget) gadget).getGadgetData().getHero().equals(_gadgetData.getHero()))
|
||||
.forEach(gadget -> gadget.disable(player));
|
||||
|
||||
super.enableCustom(player, message);
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,27 @@ import mineplex.core.reward.RewardRarity;
|
||||
public class HeroSkinGadgetData
|
||||
{
|
||||
|
||||
private final String _hero;
|
||||
private final String _name;
|
||||
private final String _description;
|
||||
private final RewardRarity _rarity;
|
||||
private final SkinData _skinData;
|
||||
private HeroSkinGadget _gadget;
|
||||
|
||||
public HeroSkinGadgetData(String name, String description, RewardRarity rarity, SkinData skinData)
|
||||
public HeroSkinGadgetData(String hero, String name, String description, RewardRarity rarity, SkinData skinData)
|
||||
{
|
||||
_hero = hero;
|
||||
_name = name;
|
||||
_description = description;
|
||||
_rarity = rarity;
|
||||
_skinData = skinData;
|
||||
}
|
||||
|
||||
public String getHero()
|
||||
{
|
||||
return _hero;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
@ -38,4 +46,14 @@ public class HeroSkinGadgetData
|
||||
{
|
||||
return _skinData;
|
||||
}
|
||||
|
||||
public void setGadget(HeroSkinGadget gadget)
|
||||
{
|
||||
_gadget = gadget;
|
||||
}
|
||||
|
||||
public HeroSkinGadget getGadget()
|
||||
{
|
||||
return _gadget;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,9 @@ public enum SpreadsheetType
|
||||
|
||||
GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"),
|
||||
GEM_HUNTERS_SHOP("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"),
|
||||
MOBA_SKINS("1bgTz46jdnaywOXlmkWKZ5LNWfTDFGTzrTI7QrVEtkDA"),
|
||||
QUESTS_SHEET("1Gy1a7GCVopmOLwYE3Sk1DNVCAIwT8ReaLu4wRe0sfDE"),
|
||||
SMASH_KITS("1Z_SLBzjiIVqu25PMGw9TwNKR3wd9Y9sX7rSDBl_rpxk")
|
||||
SMASH_KITS("1Z_SLBzjiIVqu25PMGw9TwNKR3wd9Y9sX7rSDBl_rpxk"),
|
||||
;
|
||||
|
||||
private String _id;
|
||||
|
Loading…
Reference in New Issue
Block a user