Kaynağa Gözat

Add a Patreon button

Jared 5 yıl önce
ebeveyn
işleme
c0d3035409

+ 1 - 1
build.gradle

@@ -21,7 +21,7 @@ archivesBaseName = 'Controlling'
 sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
 
 minecraft {
-    mappings channel: 'snapshot', version: '20190719-1.14.3'
+    mappings channel: 'snapshot', version: '20200409-1.15.1'
     accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
 
     runs {

+ 21 - 0
src/main/java/com/blamejared/controlling/Controlling.java

@@ -6,13 +6,34 @@ import net.minecraftforge.fml.common.Mod;
 import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
 import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
 
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.stream.Collectors;
+
 import static com.blamejared.controlling.reference.Reference.MODID;
 
 @Mod(MODID)
 public class Controlling {
     
+    public static Set<String> PATRON_LIST = new HashSet<>();
+    
     public Controlling() {
         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::init);
+        new Thread(() -> {
+            try {
+                URL url = new URL("https://blamejared.com/patrons.txt");
+                URLConnection urlConnection = url.openConnection();
+                urlConnection.setConnectTimeout(15000);
+                urlConnection.setReadTimeout(15000);
+                urlConnection.setRequestProperty("User-Agent", "Controlling|1.15.2");
+                try(BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
+                    PATRON_LIST = reader.lines().filter(s -> !s.isEmpty()).collect(Collectors.toSet());
+                }
+            } catch(IOException e) {
+                e.printStackTrace();
+            }
+        }).start();
     }
     
     private void init(final FMLClientSetupEvent event) {

+ 47 - 2
src/main/java/com/blamejared/controlling/client/gui/GuiNewControls.java

@@ -1,5 +1,7 @@
 package com.blamejared.controlling.client.gui;
 
+import com.blamejared.controlling.Controlling;
+import com.mojang.blaze3d.platform.GlStateManager;
 import net.minecraft.client.*;
 import net.minecraft.client.gui.IGuiEventListener;
 import net.minecraft.client.gui.screen.*;
@@ -12,6 +14,7 @@ import net.minecraft.util.Util;
 import net.minecraftforge.api.distmarker.*;
 import org.lwjgl.glfw.GLFW;
 
+import java.util.Random;
 import java.util.function.Predicate;
 
 @OnlyIn(Dist.CLIENT)
@@ -32,9 +35,11 @@ public class GuiNewControls extends ControlsScreen {
     private Button buttonConflicting;
     private GuiCheckBox buttonKey;
     private GuiCheckBox buttonCat;
-    
+    private Button patreonButton;
     private boolean confirmingReset = false;
     
+    private String name;
+    
     public GuiNewControls(Screen screen, GameSettings settings) {
         super(screen, settings);
         this.parentScreen = screen;
@@ -120,6 +125,37 @@ public class GuiNewControls extends ControlsScreen {
             p_213126_1_.setMessage(I18n.format("options.sort") + ": " + sortOrder.getName());
             filterKeys();
         }));
+        name = Controlling.PATRON_LIST.stream().skip(Controlling.PATRON_LIST.isEmpty() ? 0 : new Random().nextInt(Controlling.PATRON_LIST.size())).findFirst().orElse("");
+        patreonButton = this.addButton(new Button(this.width / 2 - 155 + 160, this.height - 29 - 24 - 24, 150 / 2, 20, "Patreon", p_onPress_1_ -> {
+            Util.getOSType().openURI("https://patreon.com/jaredlll08?s=controllingmod");
+        }) {
+            private boolean wasHovered;
+            
+            @Override
+            public void render(int p_render_1_, int p_render_2_, float p_render_3_) {
+                if(this.visible) {
+                    this.isHovered = p_render_1_ >= this.x && p_render_2_ >= this.y && p_render_1_ < this.x + this.width && p_render_2_ < this.y + this.height;
+                    if(this.wasHovered != this.isHovered()) {
+                        if(this.isHovered()) {
+                            if(this.isFocused()) {
+                                this.nextNarration = Util.milliTime() + 200L;
+                            } else {
+                                this.nextNarration = Util.milliTime() + 750L;
+                            }
+                        } else {
+                            this.nextNarration = Long.MAX_VALUE;
+                        }
+                    }
+                    
+                    if(this.visible) {
+                        this.renderButton(p_render_1_, p_render_2_, p_render_3_);
+                    }
+                    
+                    this.narrate();
+                    this.wasHovered = this.isHovered();
+                }
+            }
+        });
         lastSearch = "";
         displayMode = DisplayMode.ALL;
         searchType = SearchType.NAME;
@@ -201,7 +237,16 @@ public class GuiNewControls extends ControlsScreen {
         }
         
         String text = I18n.format("options.search");
+        GlStateManager.disableLighting();
         font.drawString(text, this.width / 2 - (155 / 2) - (font.getStringWidth(text) / 2), this.height - 29 - 39, 16777215);
+        GlStateManager.enableLighting();
+        
+        if(patreonButton.isHovered()) {
+            GlStateManager.disableLighting();
+            String str = "Join " + name + " and other patrons!";
+            renderTooltip(str, mouseX, mouseY);
+            GlStateManager.enableLighting();
+        }
     }
     
     public boolean mouseClicked(double mx, double my, int mb) {
@@ -260,7 +305,7 @@ public class GuiNewControls extends ControlsScreen {
     public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
         if(!search.isFocused() && this.buttonId == null) {
             if(hasControlDown()) {
-                if(InputMappings.isKeyDown(Minecraft.getInstance().func_228018_at_().getHandle(), GLFW.GLFW_KEY_F)) {
+                if(InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), GLFW.GLFW_KEY_F)) {
                     search.setFocused2(true);
                     return true;
                 }

+ 1 - 1
src/main/java/com/blamejared/controlling/events/ClientEventHandler.java

@@ -13,7 +13,7 @@ public class ClientEventHandler {
         try {
             if(event.getGui() instanceof ControlsScreen && !(event.getGui() instanceof GuiNewControls)) {
                 ControlsScreen gui = (ControlsScreen) event.getGui();
-                event.setGui(new GuiNewControls(gui.field_228182_a_, Minecraft.getInstance().gameSettings));
+                event.setGui(new GuiNewControls(gui.parentScreen, Minecraft.getInstance().gameSettings));
             }
         } catch(Exception e) {
             e.printStackTrace();