de.pewpewproject.lasertag.client.screen.LasertagLoadingScreen   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A render(MatrixStack,int,int,float) 0 30 1
A renderVignette() 0 14 1
A renderBackground() 0 12 1
A LasertagLoadingScreen() 0 2 1
A keyPressed(int,int,int) 0 3 1
1
package de.pewpewproject.lasertag.client.screen;
2
3
import com.mojang.blaze3d.platform.GlStateManager;
4
import com.mojang.blaze3d.systems.RenderSystem;
5
import de.pewpewproject.lasertag.lasertaggame.state.synced.implementation.UIState;
6
import net.minecraft.client.MinecraftClient;
7
import net.minecraft.client.gui.DrawableHelper;
8
import net.minecraft.client.gui.screen.Screen;
9
import net.minecraft.client.render.*;
10
import net.minecraft.client.util.NarratorManager;
11
import net.minecraft.client.util.math.MatrixStack;
12
import net.minecraft.text.Text;
13
import net.minecraft.util.Identifier;
14
15
/**
16
 * Class to implement the custom lasertag loading screen
17
 *
18
 * @author Étienne Muser
19
 */
20
public class LasertagLoadingScreen extends Screen {
21
22
    private static final Identifier VIGNETTE_TEXTURE = new Identifier("textures/misc/vignette.png");
23
24
    public LasertagLoadingScreen() {
25
        super(NarratorManager.EMPTY);
26
    }
27
28
    @Override
29
    public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
30
31
        // Get the game managers
32
        var gameManager = MinecraftClient.getInstance().world.getClientLasertagManager();
33
        var uiState = gameManager.getSyncedState().getUIState();
34
35
        var hMid = this.height / 2.0F;
36
        var wMid = this.width / 2.0F;
37
38
        this.renderBackground();
39
        this.renderVignette();
40
41
        var textColor = 0xFFFFFFFF;
42
        var stepString = uiState.mapLoadingStepString + "...";
43
        var textWidth = this.textRenderer.getWidth(stepString);
44
        this.textRenderer.drawWithShadow(matrices, Text.literal(stepString), wMid - (textWidth / 2.0F), hMid - 15, textColor);
45
46
        int barStart = (int)(wMid - (UIState.progressBarWidth / 2.0));
47
        int progressWidth = (int) (UIState.progressBarWidth * uiState.mapLoadingProgress);
48
        int barUpperHeight = (int)hMid + 10;
49
        int barLowerHeight = (int)hMid + 15;
50
51
        // Draw background
52
        DrawableHelper.fill(matrices, barStart, barUpperHeight, barStart + UIState.progressBarWidth, barLowerHeight, UIState.boxColor);
53
54
        // Draw progress
55
        DrawableHelper.fill(matrices, barStart, barUpperHeight, barStart + progressWidth, barLowerHeight, 0xFFFFFFFF);
56
57
        super.render(matrices, mouseX, mouseY, delta);
58
    }
59
60
    // Override the keyPressed so that the player can't close the loading screen with escape
61
    @Override
62
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
63
        return false;
64
    }
65
66
    private void renderBackground() {
67
        RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
68
        RenderSystem.setShaderTexture(0, DrawableHelper.OPTIONS_BACKGROUND_TEXTURE);
69
        Tessellator tessellator = Tessellator.getInstance();
70
        BufferBuilder bufferBuilder = tessellator.getBuffer();
71
        bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
72
        var a = 0.5f;
73
        bufferBuilder.vertex(0.0,     this.height, this.getZOffset()).texture(0.0f,                          0.0f                          ).color(a, a, a, 1.0f).next();
74
        bufferBuilder.vertex(this.width, this.height, this.getZOffset()).texture(this.width * 0.015625f * 2.0f, 0.0f                          ).color(a, a, a, 1.0f).next();
75
        bufferBuilder.vertex(this.width, 0.0,      this.getZOffset()).texture(this.width * 0.015625f * 2.0f, this.height * 0.015625f * 2.0f).color(a, a, a, 1.0f).next();
76
        bufferBuilder.vertex(0.0,     0.0,      this.getZOffset()).texture(0.0f,                          this.height * 0.015625f * 2.0f).color(a, a, a, 1.0f).next();
77
        tessellator.draw();
78
    }
79
80
    private void renderVignette() {
81
        RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
82
        RenderSystem.setShaderTexture(0, VIGNETTE_TEXTURE);
83
        RenderSystem.enableBlend();
84
        RenderSystem.blendFunc(GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE_MINUS_SRC_COLOR);
85
        Tessellator tessellator = Tessellator.getInstance();
86
        BufferBuilder bufferBuilder = tessellator.getBuffer();
87
        bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
88
        bufferBuilder.vertex(0.0,     this.height, this.getZOffset()).texture(0.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).next();
89
        bufferBuilder.vertex(this.width, this.height, this.getZOffset()).texture(1.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).next();
90
        bufferBuilder.vertex(this.width, 0.0,      this.getZOffset()).texture(1.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).next();
91
        bufferBuilder.vertex(0.0,     0.0,      this.getZOffset()).texture(0.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).next();
92
        tessellator.draw();
93
        RenderSystem.disableBlend();
94
    }
95
}
96