-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from TFSMads/enhancement/remove-old-widget-system
Fjern gammelt gui widget system. Fordi addonet allerede bruger labymod 4 widget system.
- Loading branch information
Showing
10 changed files
with
40 additions
and
1,193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 31 additions & 87 deletions
118
core/src/main/java/ml/volder/unikapi/widgets/DefaultModuleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,38 @@ | ||
package ml.volder.unikapi.widgets; | ||
|
||
|
||
import ml.volder.unikapi.UnikAPI; | ||
import ml.volder.unikapi.api.player.PlayerAPI; | ||
import ml.volder.unikapi.datasystem.Data; | ||
import ml.volder.unikapi.datasystem.DataManager; | ||
import ml.volder.unikapi.event.EventManager; | ||
import ml.volder.unikapi.guisystem.elements.ControlElement; | ||
import ml.volder.unikapi.types.Material; | ||
import ml.volder.unikapi.widgets.editor.GuiEditor; | ||
import ml.volder.unikapi.widgets.elements.ModuleCategoryElement; | ||
import net.labymod.api.Laby; | ||
import net.labymod.api.client.gui.hud.binding.category.HudWidgetCategory; | ||
import net.labymod.api.client.gui.navigation.elements.ScreenNavigationElement; | ||
import net.labymod.api.client.gui.screen.activity.types.TabbedActivity; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public class DefaultModuleManager implements ModuleManager{ | ||
|
||
public DefaultModuleManager() { | ||
instance = this; | ||
GuiModuleRenderer guiModuleRenderer = new GuiModuleRenderer(this, DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json"))); | ||
EventManager.registerEvents(guiModuleRenderer); | ||
} | ||
|
||
private List<GuiModule> guiModuleList = new ArrayList<>(); | ||
private List<ModuleCategoryElement> guiModuleCategories = new ArrayList<>(); | ||
|
||
public List<GuiModule> getGuiModuleList() { | ||
return guiModuleList; | ||
} | ||
|
||
private static DefaultModuleManager instance; | ||
|
||
public static GuiModule getModuleByKey(String key) { | ||
for(GuiModule guiModule : instance.guiModuleList) | ||
if(guiModule.getKey().equals(key)) | ||
return guiModule; | ||
return null; | ||
} | ||
|
||
public List<ModuleCategoryElement> getGuiModuleCategories() { | ||
return guiModuleCategories; | ||
} | ||
|
||
public void addModule(GuiModule module, ModuleCategoryElement category) { | ||
module.setCategory(category); | ||
guiModuleList.add(module); | ||
} | ||
|
||
public void addModule(GuiModule module) { | ||
guiModuleList.add(module); | ||
} | ||
|
||
private final DataManager<Data> dataManager = DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json")); | ||
|
||
@Override | ||
public Object registerCategory(String displayName, Material icon, String description) { | ||
ModuleCategoryElement category = new ModuleCategoryElement(displayName, new ControlElement.IconData(icon)); | ||
getGuiModuleCategories().add(category); | ||
return category; | ||
} | ||
|
||
@Override | ||
public void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function<String, String> getDisplayValue) { | ||
|
||
|
||
if(!(category instanceof ModuleCategoryElement)) | ||
return; | ||
GuiModule module = new GuiModule(2,2, key, defaultPrefix, defaultIsEnabled, dataManager, (ModuleCategoryElement) category) { | ||
@Override | ||
public String getDisplayValue() { | ||
return getDisplayValue.apply(""); | ||
} | ||
}; | ||
ControlElement.IconData iconData = new ControlElement.IconData(icon); | ||
iconData.setItemDamage(icon.getItemDamage(0)); | ||
module.setIconData(iconData); | ||
getGuiModuleList().add(module); | ||
} | ||
|
||
@Override | ||
public void openEditor() { | ||
PlayerAPI.getAPI().openGuiScreen(new GuiEditor(this, PlayerAPI.getAPI().getCurrentScreen())); | ||
} | ||
|
||
public static DataManager<Data> getDataManager() { | ||
if(instance != null && instance.dataManager != null) | ||
return instance.dataManager; | ||
return DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json")); | ||
} | ||
|
||
public class DefaultModuleManager implements ModuleManager { | ||
|
||
int categoryId = 0; | ||
@Override | ||
public Object registerCategory(String title, Material material, String description) { | ||
HudWidgetCategory category = new UnikHudWidgetCategory("unikapi-category-" + categoryId, title, description); | ||
Laby.labyAPI().hudWidgetRegistry().categoryRegistry().register(category); | ||
categoryId += 1; | ||
return category; | ||
} | ||
|
||
@Override | ||
public void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function<String, String> getDisplayValue) { | ||
if(!(category instanceof HudWidgetCategory)) | ||
return; | ||
Laby.labyAPI().hudWidgetRegistry().register(new UnikHudWidget(key, (HudWidgetCategory) category, defaultPrefix, icon,getDisplayValue)); | ||
} | ||
|
||
@Override | ||
public void openEditor() { | ||
ScreenNavigationElement navigationElement = Laby.references().navigationRegistry().getById("labymod") instanceof ScreenNavigationElement ? (ScreenNavigationElement) Laby.references().navigationRegistry().getById("labymod") : null; | ||
if(navigationElement == null || navigationElement.getScreen() == null || !(navigationElement.getScreen() instanceof TabbedActivity)) | ||
return; | ||
TabbedActivity tabbedActivity = (TabbedActivity) navigationElement.getScreen(); | ||
tabbedActivity.switchTab("widgets"); | ||
Laby.labyAPI().minecraft().minecraftWindow().displayScreen(tabbedActivity); | ||
} | ||
} |
Oops, something went wrong.