Просмотр исходного кода

Revert not-working group tooltips + code improvements

Lortseam 4 лет назад
Родитель
Сommit
113e039d56

+ 1 - 1
src/main/java/me/lortseam/completeconfig/api/ConfigEntry.java

@@ -211,7 +211,7 @@ public @interface ConfigEntry {
          *
          * @return whether the color has an alpha value
          */
-        boolean alphaMode() default false;
+        boolean alphaMode();
 
     }
 

+ 22 - 22
src/main/java/me/lortseam/completeconfig/api/ConfigEntryContainer.java

@@ -14,16 +14,6 @@ import java.util.List;
  */
 public interface ConfigEntryContainer {
 
-    /**
-     * Used to register other containers. They will then be located at the same level as this container.
-     *
-     * @return an array of other containers
-     * @see Transitive
-     */
-    default ConfigEntryContainer[] getTransitiveConfigEntryContainers() {
-        return new ConfigEntryContainer[0];
-    }
-
     /**
      * Specifies whether this class is a POJO. If true, every field inside this class will be considered to be a config
      * entry.
@@ -34,18 +24,6 @@ public interface ConfigEntryContainer {
         return false;
     }
 
-    /**
-     * Applied to declare that a field of type {@link ConfigEntryContainer} is transitive. The container will then be
-     * registered at the same level as this container.
-     *
-     * @see #getTransitiveConfigEntryContainers()
-     */
-    @Target(ElementType.FIELD)
-    @Retention(RetentionPolicy.RUNTIME)
-    @interface Transitive {
-
-    }
-
     default List<Class<? extends ConfigEntryContainer>> getConfigClasses() {
         List<Class<? extends ConfigEntryContainer>> classes = new ArrayList<>();
         Class<? extends ConfigEntryContainer> clazz = getClass();
@@ -58,5 +36,27 @@ public interface ConfigEntryContainer {
         }
         return ImmutableList.copyOf(classes);
     }
+
+    /**
+     * Used to register other containers. They will then be located at the same level as this container.
+     *
+     * @return an array of other containers
+     * @see Transitive
+     */
+    default ConfigEntryContainer[] getTransitiveContainers() {
+        return new ConfigEntryContainer[0];
+    }
+
+    /**
+     * Applied to declare that a field of type {@link ConfigEntryContainer} is transitive. The container will then be
+     * registered at the same level as this container.
+     *
+     * @see #getTransitiveContainers()
+     */
+    @Target(ElementType.FIELD)
+    @Retention(RetentionPolicy.RUNTIME)
+    @interface Transitive {
+
+    }
     
 }

+ 1 - 5
src/main/java/me/lortseam/completeconfig/api/ConfigGroup.java

@@ -14,12 +14,8 @@ public interface ConfigGroup extends ConfigEntryContainer {
      *
      * @return the ID of this group
      */
-    default String getConfigGroupID() {
+    default String getGroupID() {
         return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, getClass().getSimpleName());
     }
 
-    default String[] getCustomTooltipKeys() {
-        return null;
-    }
-
 }

+ 2 - 14
src/main/java/me/lortseam/completeconfig/data/Collection.java

@@ -12,28 +12,20 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Collectors;
 
 public class Collection implements FlatDataPart<ConfigMap> {
 
     private final TranslationIdentifier translation;
-    private final TranslationIdentifier[] tooltipTranslation;
     @Getter
     private final EntryMap entries;
     @Getter
     private final CollectionMap collections;
 
     Collection(TranslationIdentifier parentTranslation, ConfigGroup group) {
-        translation = parentTranslation.append(group.getConfigGroupID());
+        translation = parentTranslation.append(group.getGroupID());
         entries = new EntryMap(translation);
         collections = new CollectionMap(translation);
-        String[] customTooltipKeys = group.getCustomTooltipKeys();
-        if (customTooltipKeys != null && customTooltipKeys.length > 0) {
-            tooltipTranslation = Arrays.stream(customTooltipKeys).map(key -> translation.root().append(key)).toArray(TranslationIdentifier[]::new);
-        } else {
-            tooltipTranslation = translation.appendTooltip().orElse(null);
-        }
         resolve(group);
     }
 
@@ -41,10 +33,6 @@ public class Collection implements FlatDataPart<ConfigMap> {
         return translation.translate();
     }
 
-    public Optional<TranslationIdentifier[]> getTooltip() {
-        return Optional.ofNullable(tooltipTranslation);
-    }
-
     private void resolve(ConfigEntryContainer container) {
         entries.resolve(container);
         List<ConfigEntryContainer> containers = new ArrayList<>();
@@ -74,7 +62,7 @@ public class Collection implements FlatDataPart<ConfigMap> {
                 }
             }).collect(Collectors.toList()));
         }
-        containers.addAll(Arrays.asList(container.getTransitiveConfigEntryContainers()));
+        containers.addAll(Arrays.asList(container.getTransitiveContainers()));
         for (ConfigEntryContainer c : containers) {
             if (c instanceof ConfigGroup) {
                 collections.resolve((ConfigGroup) c);

+ 1 - 1
src/main/java/me/lortseam/completeconfig/data/CollectionMap.java

@@ -14,7 +14,7 @@ public class CollectionMap extends ConfigMap<Collection> {
     }
 
     void resolve(ConfigGroup group) {
-        String groupID = group.getConfigGroupID();
+        String groupID = group.getGroupID();
         Collection collection = new Collection(translation, group);
         if (collection.getEntries().isEmpty() && collection.getCollections().isEmpty()) {
             LOGGER.warn("[CompleteConfig] Group " + groupID + " is empty!");

+ 6 - 6
src/main/java/me/lortseam/completeconfig/data/Entry.java

@@ -163,7 +163,7 @@ public class Entry<T> extends EntryBase<T> implements DataPart {
         if (customTooltipTranslation != null) {
             translation = customTooltipTranslation;
         } else {
-            Optional<TranslationIdentifier[]> defaultTooltip = TranslationIdentifier.defaultTooltip(getTranslation());
+            Optional<TranslationIdentifier[]> defaultTooltip = getTranslation().appendTooltip();
             if (defaultTooltip.isPresent()) {
                 translation = defaultTooltip.get();
             } else {
@@ -188,12 +188,12 @@ public class Entry<T> extends EntryBase<T> implements DataPart {
             if (!StringUtils.isBlank(customTranslationKey)) {
                 customTranslation = parentTranslation.root().appendKey(customTranslationKey);
             }
-            String[] customTooltipKeys = annotation.tooltipTranslationKeys();
-            if (customTooltipKeys.length > 0) {
-                if (Arrays.stream(customTooltipKeys).anyMatch(StringUtils::isBlank)) {
-                    throw new IllegalAnnotationParameterException("Entry tooltip key(s) must not be blank");
+            String[] customTooltipTranslationKeys = annotation.tooltipTranslationKeys();
+            if (customTooltipTranslationKeys.length > 0) {
+                if (Arrays.stream(customTooltipTranslationKeys).anyMatch(StringUtils::isBlank)) {
+                    throw new IllegalAnnotationParameterException("Entry tooltip translation key(s) must not be blank");
                 }
-                customTooltipTranslation = Arrays.stream(customTooltipKeys).map(key -> parentTranslation.root().appendKey(key)).toArray(TranslationIdentifier[]::new);
+                customTooltipTranslation = Arrays.stream(customTooltipTranslationKeys).map(key -> parentTranslation.root().appendKey(key)).toArray(TranslationIdentifier[]::new);
             }
             forceUpdate = annotation.forceUpdate();
             requiresRestart = annotation.requiresRestart();

+ 0 - 1
src/main/java/me/lortseam/completeconfig/gui/cloth/ClothGuiBuilder.java

@@ -42,7 +42,6 @@ public class ClothGuiBuilder implements GuiBuilder {
         builder.setTitle(customTitle.exists() ? customTitle.translate() : new TranslatableText("completeconfig.gui.defaultTitle", FabricLoader.getInstance().getModContainer(config.getModID()).get().getMetadata().getName()));
         for(Collection collection : config.values()) {
             ConfigCategory category = builder.getOrCreateCategory(collection.getText());
-            //TODO: Add tooltip (description)
             for (AbstractConfigListEntry<?> entry : buildCollection(collection)) {
                 category.addEntry(entry);
             }