Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
完成玩家首次进入存档的公告提示
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed May 26, 2018
1 parent eadf417 commit 5c72d99
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/cfpa/i18nupdatemod/I18nUpdateMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cfpa.i18nupdatemod.notice.CmdNotice;
import org.cfpa.i18nupdatemod.download.DownloadManager;
import org.cfpa.i18nupdatemod.download.DownloadStatus;
import org.cfpa.i18nupdatemod.download.DownloadWindow;
import org.cfpa.i18nupdatemod.notice.CmdNotice;
import org.cfpa.i18nupdatemod.report.CmdReport;
import org.cfpa.i18nupdatemod.report.ReportKey;

Expand Down Expand Up @@ -42,8 +42,8 @@ public void construct(FMLConstructionEvent event) throws InterruptedException {
downloader.start();

// 阻塞主线程,以保证资源包在preInit阶段被安装
// 超时1分钟
int i = 1200;
// 超时30秒,1分钟有人反馈太长了
int i = 600;
while (!downloader.isDone() && i >= 0) {
Thread.sleep(50);
if (i == 0) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/cfpa/i18nupdatemod/notice/NoticeButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cfpa.i18nupdatemod.notice;

import net.minecraft.client.gui.GuiButton;

import java.awt.*;
import java.net.URI;

public class NoticeButton extends GuiButton {
public NoticeButton(int buttonId, int x, int y, String buttonText) {
super(buttonId, x, y, 200, 20, buttonText);
}

public void mouseReleased(int mouseX, int mouseY) {
String url = "https://github.com/CFPAOrg/Minecraft-Mod-Language-Package#%E4%BB%93%E5%BA%93%E8%AF%B4%E6%98%8E";
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception e) {
e.printStackTrace();
}
}
}
11 changes: 10 additions & 1 deletion src/main/java/org/cfpa/i18nupdatemod/notice/NoticeGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ public void initGui() {
super.initGui();
}

@Override
public boolean doesGuiPauseGame() {
return false;
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
this.drawGradientRect((int) (this.width * 0.1), (int) (this.height * 0.1), (int) (this.width * 0.9), (int) (this.height * 0.9), -0x3fefeff0, -0x2fefeff0);
this.drawGradientRect((int) (this.width * 0.1), (int) (this.height * 0.1), (int) (this.width * 0.9), (int) (this.height * 0.8), -0x3fefeff0, -0x2fefeff0);
int h = (int) (this.height * 0.16);
int w = (int) (this.width * 0.14);
StringBuilder sb = new StringBuilder();
strings.forEach(v -> sb.append(v).append('\n'));
fontRenderer.drawSplitString(sb.toString(), w, h, (int) (this.width * 0.72), 0xffffff);

// 绘制按钮
NoticeButton noticeButton = new NoticeButton(0, (this.width - 200) / 2, this.height * 8 / 10 + 3, "§l我想要参与模组翻译");
this.addButton(noticeButton);
}
}
76 changes: 76 additions & 0 deletions src/main/java/org/cfpa/i18nupdatemod/notice/ShowNoticeFirst.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.cfpa.i18nupdatemod.notice;

import net.minecraft.client.Minecraft;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.cfpa.i18nupdatemod.I18nUpdateMod;

import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;

@Mod.EventBusSubscriber(modid = I18nUpdateMod.MODID)
public class ShowNoticeFirst {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onPlayerFirstJoin(RenderGameOverlayEvent.Post event) throws InterruptedException {
if (event.getType() != RenderGameOverlayEvent.ElementType.HOTBAR || fileIsExist()) {
return;
}
showNotice();
}

private static List<String> strings;

public static void showNotice() {
new Thread(() -> {
try {
createFile(); // 创建证明文件
Thread.sleep(1000); // 手榴弹,都给我延时 1 秒丢出去
URL url = new URL("http://p985car2i.bkt.clouddn.com/Notice.txt");
strings = IOUtils.readLines(url.openStream(), StandardCharsets.UTF_8);
onDone();
} catch (Throwable e) {
catching(e);
}
}, "I18n_NOTICE_PENDING_THREAD").start();
}

private static void onDone() {
Minecraft.getMinecraft().displayGuiScreen(new NoticeGui(strings));
}

private static void catching(Throwable e) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("获取公告失败。"));
I18nUpdateMod.logger.error("获取公告失败:", e);
}

private static void createFile() {
Minecraft mc = Minecraft.getMinecraft();
File file = new File(mc.mcDataDir.getPath() + File.separator + "config" + File.separator + I18nUpdateMod.MODID + ".txt");
try {
FileOutputStream fos = new FileOutputStream(file);
IOUtils.write("你看到这个文件时候,说明你已经不是第一次使用该模组了", fos, "UTF-8");
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

private static boolean fileIsExist() {
Minecraft mc = Minecraft.getMinecraft();
File file = new File(mc.mcDataDir.getPath() + File.separator + "config" + File.separator + I18nUpdateMod.MODID + ".txt");
if (file.exists()) {
return true;
} else {
return false;
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/i18nmod/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 英文?英文是不存在的
key.category.i18nmod=汉化更新模组键位设定
key.report_key.desc=报告键

0 comments on commit 5c72d99

Please sign in to comment.