Skip to content

Commit

Permalink
完善XP功能
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Aug 18, 2024
1 parent 9281104 commit 4cd444b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.cneko.toneko.common.mod.quirks;

import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;

import java.util.List;

public class CaressQuirk extends ToNekoQuirk{
public CaressQuirk(String id) {
super(id);
Expand All @@ -15,5 +20,9 @@ public int getInteractionValue() {
return 1;
}


@Override
public Component getTooltip() {
// 添加描述
return Component.translatable("quirk.toneko.caress.des");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import net.minecraft.network.chat.Component;

import java.util.List;
import javax.annotation.Nullable;

public interface ModQuirk {
/**
* 添加悬浮文本,可参考物品的appendTooltip方法
* @param context 上下文
* @param tooltip tooltip列表
* 添加悬浮文本,可返回null
*/
default void appendTooltip(QuirkContext context,List<Component> tooltip){
}
@Nullable
Component getTooltip();

int getInteractionValue(QuirkContext context);

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/toneko/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"attribute.name.neko.degree": "neko degree",
"enchantment.toneko.reversion": "Reversion",
"quirk.toneko.caress": "caress",
"quirk.toneko.caress.des": "You like to be touched",
"quirk.toneko.caress.use": "§dYou gently stroked %d.",
"quirk.toneko.caress.be_used": "§dYou were gently petted by %d",
"key.toneko.lie" : "lie",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/toneko/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"attribute.name.neko.degree": "猫猫等级",
"enchantment.toneko.reversion": "反转",
"quirk.toneko.caress": "抚摸",
"quirk.toneko.caress.des": "你喜欢被摸摸",
"quirk.toneko.caress.use": "§d你轻轻抚摸了 %d §d喵~",
"quirk.toneko.caress.be_used": "§d你被 %d §d轻轻地抚摸了一下喵~",
"key.toneko.lie" : "躺下",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/toneko/lang/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"attribute.name.neko.degree": "猫猫等级",
"enchantment.toneko.reversion": "反轉",
"quirk.toneko.caress": "撫摸",
"quirk.toneko.caress.des": "你喜欢被摸摸",
"quirk.toneko.caress.use": "§d你輕輕撫摸了 %d §d喵~",
"quirk.toneko.caress.be_used": "§d你被 %d §d輕輕地撫摸了一下喵~",
"key.toneko.lie" : "躺下",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import org.cneko.toneko.common.mod.packets.QuirkQueryPayload;
import org.cneko.toneko.common.mod.quirks.ToNekoQuirk;
import org.cneko.toneko.common.quirks.QuirkRegister;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand Down Expand Up @@ -49,17 +52,25 @@ protected void init() {
Button button = Button.builder(text, new OnQuirkPress(quirk, quirks))
.bounds(x, y, buttonWidth, buttonHeight)
.build();

// 添加悬浮文本
try{
ToNekoQuirk q = (ToNekoQuirk) QuirkRegister.getById(quirk);
Component tooltip = q.getTooltip();
if (tooltip != null) {
button.setTooltip(Tooltip.create(tooltip));
}
}catch (Exception ignored){}
addRenderableWidget(button);
y += buttonHeight + buttonSpacing; // 下一个按钮的位置
}

// 添加返回按钮
int doneButtonX = (this.width - buttonWidth) / 2;
int doneButtonY = y + buttonSpacing*2; // 放置在所有quirk按钮下方
int doneButtonX = this.width / 2 - buttonWidth;
int doneButtonY = y + buttonSpacing*4; // 放置在所有quirk按钮下方
addRenderableWidget(Button.builder(translatable("gui.done"), (btn) -> {
onClose();
}).bounds(doneButtonX, doneButtonY, buttonWidth, buttonHeight).build());
}).bounds(doneButtonX, doneButtonY, buttonWidth, buttonHeight)
.size(buttonWidth*2, buttonHeight).build());
}

@Override
Expand Down

0 comments on commit 4cd444b

Please sign in to comment.