AbstractTabbedConfigScreen.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This file is part of Cloth Config.
  3. * Copyright (C) 2020 - 2021 shedaniel
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 3 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. package me.shedaniel.clothconfig2.gui;
  20. import com.google.common.collect.Maps;
  21. import me.shedaniel.clothconfig2.api.TabbedConfigScreen;
  22. import net.minecraft.client.gui.screens.Screen;
  23. import net.minecraft.network.chat.Component;
  24. import net.minecraft.resources.ResourceLocation;
  25. import java.util.Map;
  26. public abstract class AbstractTabbedConfigScreen extends AbstractConfigScreen implements TabbedConfigScreen {
  27. private final Map<Component, ResourceLocation> categoryBackgroundLocation = Maps.newHashMap();
  28. protected AbstractTabbedConfigScreen(Screen parent, Component title, ResourceLocation backgroundLocation) {
  29. super(parent, title, backgroundLocation);
  30. }
  31. @Override
  32. public final void registerCategoryBackground(Component text, ResourceLocation identifier) {
  33. this.categoryBackgroundLocation.put(text, identifier);
  34. }
  35. @Override
  36. public ResourceLocation getBackgroundLocation() {
  37. Component selectedCategory = getSelectedCategory();
  38. if (categoryBackgroundLocation.containsKey(selectedCategory))
  39. return categoryBackgroundLocation.get(selectedCategory);
  40. return super.getBackgroundLocation();
  41. }
  42. }