Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
- NeoColor: 可以提供十六进制颜色值以灵活自定义文本颜色
- ItemEntity: 方便在场景中显示物品实体(由于技术原因,物品实体不会转)
- Key: 提供某个功能的id以显示这个功能绑定的按键
- Colour: 渐变色,提供2种颜色让文本渐变(非动态),也可以设置文本的样式
- 粗细(bold)
- 斜体(italic)
- 下划线(underlined)
- 删除线(strikethrough)
- 阴影(dropShadow)
- WIP: 咕咕咕

部分文本抄自[AnvilCraft-Patchouli](https://github.com/Anvil-Dev/AnvilCraft-Patchouli)和[Xekr's TODO](https://github.com/Anvil-Dev/AnvilCraft/issues?q=is%3Aissue%20state%3Aopen%20author%3AXeKr%20label%3A%22%F0%9F%93%8B%EF%B8%8F%20TODO%22)
部分文本抄自[AnvilCraft-Patchouli](https://github.com/Anvil-Dev/AnvilCraft-Patchouli)
和[Xekr's TODO](https://github.com/Anvil-Dev/AnvilCraft/issues?q=is%3Aissue%20state%3Aopen%20author%3AXeKr%20label%3A%22%F0%9F%93%8B%EF%B8%8F%20TODO%22)

## 使用许可

[LICENSE 文件(LGPL-3.0)](./LICENSE)

## 使用方法

下载对应版本[GuideME](https://github.com/AppliedEnergistics/GuideME)、[AnvilCraft](https://github.com/Anvil-Dev/AnvilCraft)和此 `mod` 放入 `mods` 文件夹,启动游戏即可
下载对应版本[GuideME](https://github.com/AppliedEnergistics/GuideME)、[AnvilCraft](https://github.com/Anvil-Dev/AnvilCraft)和此 `mod` 放入
`mods` 文件夹,启动游戏即可

## 主要维护者

[@theabab2333](https://github.com/theabab23333)
[@theabab2333](https://github.com/theabab23333)
[@Gugle](https://github.com/Gu-ZT)
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ minecraft = "1.21.1"
neoForge = "21.1.152"
registrate = "MC1.21-1.3.0+62"
anvillib = "1.4.0+build.172"
anvilcraft = "1.5.0+hotfix.1562"
anvilcraft = "1.5.0+hotfix.1563"
curios = "9.0.15+1.21.1"
jei = "19.21.0.247"
jade = "15.3.4+neoforge"
Expand Down
29 changes: 15 additions & 14 deletions guidebook/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ navigation:

## 本模组目前状态:

<NeoColor id="d8df00"> - [y] 绝大部分配方的兼容 </NeoColor>
<NeoColor id="e5dc00"> - [n] guide内容重写和新写 </NeoColor>
<NeoColor id="ffd600"> - [?] 有用没用的功能添加 </NeoColor>
- <NeoColor id="d8df00"> [y] 绝大部分配方的兼容 </NeoColor>
- <NeoColor id="e5dc00"> [n] guide内容重写和新写 </NeoColor>
- <NeoColor id="ffd600"> [?] 有用没用的功能添加 </NeoColor>

### 其他:

<NeoColor id="c1ffc7"> - [y] 在开发环境中[实时预览](https://guideme.appliedenergistics.org/live-preview) </NeoColor>
<NeoColor id="acecd4"> - [n] 从帕秋莉转换 ~~(已放弃 出各种莫名其妙的bug)~~ </NeoColor>
<NeoColor id="97d9e1"> - [?] 英文翻译 ~~(等中文补全再说吧 咕咕咕)~~ </NeoColor>
- <NeoColor id="c1ffc7"> [y] 在开发环境中[实时预览](https://guideme.appliedenergistics.org/live-preview) </NeoColor>
- <NeoColor id="acecd4"> [n] 从帕秋莉转换 ~~(已放弃 出各种莫名其妙的bug)~~ </NeoColor>
- <NeoColor id="97d9e1"> [?] 英文翻译 ~~(等中文补全再说吧 咕咕咕)~~ </NeoColor>

## 模组加载情况:

<ModInfo id="anvilcraft_guideme" url="https://github.com/Anvil-Dev/AnvilCraft-GuideME"></ModInfo>
<ModInfo id="guideme" url="https://github.com/AppliedEnergistics/GuideME"></ModInfo>
<ModInfo id="anvilcraft" url="https://github.com/Anvil-Dev/AnvilCraft"></ModInfo>
<ModInfo id="大脑" url="https://github.com/theabab23333"></ModInfo>
<ModInfo id="anvilcraft_guideme" url="https://github.com/Anvil-Dev/AnvilCraft-GuideME"> </ModInfo>
<ModInfo id="guideme" url="https://github.com/AppliedEnergistics/GuideME"> </ModInfo>
<ModInfo id="anvilcraft" url="https://github.com/Anvil-Dev/AnvilCraft"> </ModInfo>
<ModInfo id="大脑" url="https://github.com/theabab23333"> </ModInfo>

## 添加的功能:

<NeoColor id="ff75ff"> - ModInfo: **提供modid以查看当前当前模组加载情况** (可以添加url跳转至外部链接) </NeoColor>
<NeoColor id="ca80ff"> - NeoColor: **提供十六进制颜色值以灵活自定义文本颜色** ~~("我吐了怎么guideme本体只能填那几个注册好的颜色啊")~~</NeoColor>
<NeoColor id="968bff"> - ItemEntity: **方便在场景中显示物品实体**~~(由于技术原因,物品实体不会转)~~ </NeoColor>
<NeoColor id="dc4796"> - Key: **提供某个功能的id以显示这个功能绑定的按键** </NeoColor>
- <NeoColor id="ff75ff"> ModInfo: **提供modid以查看当前当前模组加载情况**(可以添加url跳转至外部链接) </NeoColor>
- <NeoColor id="ca80ff"> NeoColor: **提供十六进制颜色值以灵活自定义文本颜色** ~~("我吐了怎么guideme本体只能填那几个注册好的颜色啊")~~ </NeoColor>
- <NeoColor id="968bff"> ItemEntity: **方便在场景中显示物品实体**~~(由于技术原因,物品实体不会转)~~ </NeoColor>
- <NeoColor id="dc4796"> Key: **提供某个功能的id以显示这个功能绑定的按键** </NeoColor>
- <Colour firstColor="d9afd9" lastColor="97d9e1" bold={true}> Colour: 渐变色,提供2种颜色让文本渐变(非动态) </Colour>
2 changes: 1 addition & 1 deletion guidebook/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
navigation:
title: "介绍"
icon: "anvilcraft_guideme:guideme_book"
icon: "anvilcraft:guide_book"
position: 0
---

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/anvilcraft/guideme/AnvilCraftGuideME.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.logging.LogUtils;
import com.tterrag.registrate.Registrate;
import dev.anvilcraft.guideme.data.ModDatagen;
import dev.anvilcraft.guideme.guide.compiler.tag.GradientColourTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.KeyMapTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.ModInfoTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.NeoColorTagCompiler;
Expand Down Expand Up @@ -37,6 +38,7 @@ private void guide() {
.folder("ac_guidebook")
.extension(SceneElementTagCompiler.EXTENSION_POINT, new ItemEntityShapeCompiler())
.extension(TagCompiler.EXTENSION_POINT, new NeoColorTagCompiler())
.extension(TagCompiler.EXTENSION_POINT, new GradientColourTagCompiler())
.extension(TagCompiler.EXTENSION_POINT, new ModInfoTagCompiler())
.extension(TagCompiler.EXTENSION_POINT, new KeyMapTagCompiler())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package dev.anvilcraft.guideme.guide.compiler.tag;

import dev.anvilcraft.guideme.guide.compiler.util.ColorUtil;
import guideme.color.ColorValue;
import guideme.compiler.PageCompiler;
import guideme.compiler.tags.FlowTagCompiler;
import guideme.compiler.tags.MdxAttrs;
import guideme.document.flow.LytFlowParent;
import guideme.document.flow.LytFlowSpan;
import guideme.libs.mdast.mdx.model.MdxJsxElementFields;
import guideme.libs.mdast.model.MdAstNode;
import guideme.style.TextStyle;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class GradientColourTagCompiler extends FlowTagCompiler {
@Override
public Set<String> getTagNames() {
return Set.of("Colour", "GradientColour", "BetterColor");
}

@Override
protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElementFields el) {
String string1 = MdxAttrs.getString(compiler, parent, el, "firstColor", null);
String string2 = MdxAttrs.getString(compiler, parent, el, "lastColor", null);
if (string1 == null) {
parent.appendError(compiler, "Missing 'firstColor' attribute", el);
return;
} else if (string2 == null) {
parent.appendError(compiler, "Missing 'lastColor' attribute", el);
return;
}

ColorValue firstColor;
ColorValue lastColor;

try {
firstColor = new ColorUtil(string1);
lastColor = new ColorUtil(string2);
} catch (IllegalArgumentException e) {
parent.appendError(compiler, "Unknown color: '" + string1 + "||" + string2 + "'", el);
return;
}

List<String> strings = new ArrayList<>();
List<LytFlowSpan> spans = new ArrayList<>();
List<ColorValue> colorValues = new ArrayList<>();

boolean bold = MdxAttrs.getBoolean(compiler, parent, el, "bold", false);
boolean italic = MdxAttrs.getBoolean(compiler, parent, el, "italic", false);
boolean underlined = MdxAttrs.getBoolean(compiler, parent, el, "underlined", false);
boolean strikethrough = MdxAttrs.getBoolean(compiler, parent, el, "strikethrough", false);
boolean obfuscated = MdxAttrs.getBoolean(compiler, parent, el, "obfuscated", false);
boolean dropShadow = MdxAttrs.getBoolean(compiler, parent, el, "dropShadow", false);

if (el.children() != null) {
for (var child : el.children()) {
if (child instanceof MdAstNode node) {
String text = node.toText();
for (int i = 0; i < text.length(); i++) {
strings.add(String.valueOf(text.charAt(i)));
}
}
}
}

int stringSize = strings.size();
if (stringSize > 0) {
for (int i = 0; i < stringSize; i++) {
float ratio = stringSize > 1 ? (float) i / (stringSize - 1) : 0.0f;
String gradientColor = ColorUtil.calculateGradientColor(firstColor, lastColor, ratio);
colorValues.add(new ColorUtil(gradientColor));
}

for (String string : strings) {
LytFlowSpan span = new LytFlowSpan();
span.appendText(string);
spans.add(span);
}

int spanSize = spans.size();
for (int i = 0; i < spanSize; i++) {
var span = spans.get(i);
span.setStyle(
TextStyle.builder()
.color(colorValues.get(i))
.bold(bold)
.italic(italic)
.underlined(underlined)
.strikethrough(strikethrough)
.obfuscated(obfuscated)
.dropShadow(dropShadow)
.build()
);
parent.append(span);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElemen
parent.appendError(compiler, "Missing 'id' attribute", el);
return;
}

LytFlowLink link = new LytFlowLink();
String modName = IntegrationUtil.getName(id);
String modVersion = IntegrationUtil.getVersion(id);
String url = el.getAttributeString("url", null);
String nameAndVersion;

if (modName != null && modVersion != null) {
nameAndVersion = modName + " " + modVersion;
link.appendText(Component.translatable("gui.ac_guideme.loaded", nameAndVersion).getString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElemen
return;
}

ColorValue firstColor;
ColorValue colorValue;

try {
firstColor = new ColorUtil(string);
colorValue = new ColorUtil(string);
} catch (IllegalArgumentException e) {
parent.appendError(compiler, "Unknown color: '" + string + "'", el);
return;
}

LytFlowSpan span = new LytFlowSpan();
span.setStyle(TextStyle.builder().color(firstColor).build());
span.setStyle(TextStyle.builder().color(colorValue).build());
parent.append(span);
compiler.compileFlowContext(el.children(), span);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ public static int argb(int a, int r, int g, int b) {
return FastColor.ARGB32.color(a, r, g, b);
}

public static String calculateGradientColor(ColorValue firstColor, ColorValue lastColor, float ratio) {
int firstColorInt = firstColor.resolve(LightDarkMode.LIGHT_MODE);
int lastColorInt = lastColor.resolve(LightDarkMode.LIGHT_MODE);

int firstR = (firstColorInt >> 16) & 0xFF;
int firstG = (firstColorInt >> 8) & 0xFF;
int firstB = firstColorInt & 0xFF;
int firstA = (firstColorInt >> 24) & 0xFF;

int lastR = (lastColorInt >> 16) & 0xFF;
int lastG = (lastColorInt >> 8) & 0xFF;
int lastB = lastColorInt & 0xFF;
int lastA = (lastColorInt >> 24) & 0xFF;

int r = Math.max(0, Math.min(255, (int) (firstR + ratio * (lastR - firstR))));
int g = Math.max(0, Math.min(255, (int) (firstG + ratio * (lastG - firstG))));
int b = Math.max(0, Math.min(255, (int) (firstB + ratio * (lastB - firstB))));
int a = Math.max(0, Math.min(255, (int) (firstA + ratio * (lastA - firstA))));

return String.format("#%02X%02X%02X%02X", r, g, b, a);
}

@Override
public int resolve(LightDarkMode lightDarkMode) {
return color;
Expand Down