-
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.
Feature: API for mods to disable minimap. Waypoints now contains rota…
…tion angle.
- Loading branch information
1 parent
ebb31bb
commit e0001a7
Showing
11 changed files
with
184 additions
and
29 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.teacon.signmeup.api; | ||
|
||
import net.neoforged.fml.loading.FMLLoader; | ||
import org.teacon.signmeup.hud.MiniMapAPI; | ||
|
||
public interface MiniMap { | ||
static MiniMap getInstance() { | ||
if (!FMLLoader.getDist().isClient()) { | ||
throw new IllegalStateException("This API is only available on Client."); | ||
} | ||
return MiniMapAPI.INSTANCE; | ||
} | ||
|
||
/** | ||
* <p>Set the visibility of MiniMap.</p> | ||
* | ||
* <p>Mods should make sure the minimap is hided in a minimize time | ||
* After the expected time range, mods must invoke setMiniMapVisibility(modID, true) | ||
* to show the minimap normally.</p> | ||
* | ||
* <p>For the first time a mod hide the minimap, a message will be shown | ||
* to make players clear that the minimap is hided. And it will also be shown | ||
* on the map screen.</p> | ||
* | ||
* <p>There's no need for different mods to check whether the minimap is visibility. | ||
* Minimap won't be shown if any mod set it invisible.</p> | ||
* | ||
* <p>This method can be invoked from any threads.</p> | ||
* | ||
* @param modID the caller's mod id. | ||
* @param visibility whether the MiniMap should be visible. | ||
* @throws IllegalArgumentException if target mod (specific by modID) is not loaded | ||
* @throws IllegalStateException if the same mod wants to hide / show the minimap, but | ||
* it's already hided / shown | ||
* @throws NullPointerException if modID is null | ||
*/ | ||
void setMiniMapVisibility(String modID, boolean visibility); | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.teacon.signmeup.hud; | ||
|
||
import net.neoforged.fml.loading.FMLLoader; | ||
import net.neoforged.fml.loading.moddiscovery.ModInfo; | ||
import org.teacon.signmeup.api.MiniMap; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.stream.Collectors; | ||
|
||
public final class MiniMapAPI implements MiniMap { | ||
public static final MiniMapAPI INSTANCE = new MiniMapAPI(); | ||
|
||
private final Map<String, String> ID_NAME_MAP = FMLLoader.getLoadingModList().getMods().stream().collect(Collectors.toMap( | ||
ModInfo::getModId, ModInfo::getDisplayName | ||
)); | ||
|
||
private final CopyOnWriteArrayList<String> hider = new CopyOnWriteArrayList<>(); | ||
|
||
@Override | ||
public void setMiniMapVisibility(String modID, boolean visibility) { | ||
Objects.requireNonNull(modID, "Argument modID cannot be null"); | ||
if (!ID_NAME_MAP.containsKey(modID)) { | ||
throw new IllegalArgumentException("No such mod: " + modID); | ||
} | ||
|
||
if (!(visibility ? hider.remove(modID) : hider.addIfAbsent(modID))) { | ||
throw new IllegalStateException("The minimap has already been " + (!visibility ? "hided" : "visible") + " by " + modID); | ||
} | ||
} | ||
|
||
public boolean visible() { | ||
return hider.isEmpty(); | ||
} | ||
|
||
public String getHiderString() { | ||
if (hider.isEmpty()) { | ||
return null; | ||
} | ||
|
||
Iterator<String> iterator = hider.iterator(); | ||
if (!iterator.hasNext()) { | ||
return null; | ||
} | ||
String m1 = iterator.next(); | ||
if (!iterator.hasNext()) { | ||
return m1; | ||
} | ||
String m2 = iterator.next(); | ||
if (!iterator.hasNext()) { | ||
return m1 + ", " + m2; | ||
} | ||
int size = hider.size() - 2; | ||
if (size > 1) { | ||
return m1 + ", " + m2 + ", ... (" + size + " more mods)"; | ||
} else if (size == 1) { | ||
return m1 + ", " + m2 + ", ... (1 more mod)"; | ||
}else { | ||
return m1 + ", " + m2; | ||
} | ||
} | ||
} |
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
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
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
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
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,3 +1,15 @@ | ||
{ | ||
"key.categories.sign_up": "Sign Me Up", | ||
"key.sign_up.open_map": "打开地图", | ||
"key.sign_up.open_new_map": "打开新地图", | ||
|
||
"gui.sign_up.minimap": "小地图", | ||
"gui.sign_up.minimap.minimap": "小地图", | ||
"gui.sign_up.minimap.minimap.on": "开启", | ||
"gui.sign_up.minimap.minimap.off": "关闭", | ||
"gui.sign_up.minimap.range": "小地图渲染范围", | ||
"gui.sign_up.minimap.rotate": "跟随玩家旋转", | ||
"gui.sign_up.minimap.ssaa": "SSAA 角度", | ||
|
||
"hud.sign_up.minimap.hide": "小地图被以下模组隐藏:%s" | ||
} |