File size: 2,623 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.mojang.realmsclient.gui;

import java.util.List;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractSelectionList;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public abstract class RowButton {
    public final int width;
    public final int height;
    public final int xOffset;
    public final int yOffset;

    public RowButton(int p_88012_, int p_88013_, int p_88014_, int p_88015_) {
        this.width = p_88012_;
        this.height = p_88013_;
        this.xOffset = p_88014_;
        this.yOffset = p_88015_;
    }

    public void drawForRowAt(GuiGraphics p_281584_, int p_88020_, int p_88021_, int p_88022_, int p_88023_) {
        int i = p_88020_ + this.xOffset;
        int j = p_88021_ + this.yOffset;
        boolean flag = p_88022_ >= i && p_88022_ <= i + this.width && p_88023_ >= j && p_88023_ <= j + this.height;
        this.draw(p_281584_, i, j, flag);
    }

    protected abstract void draw(GuiGraphics p_281291_, int p_88025_, int p_88026_, boolean p_88027_);

    public int getRight() {
        return this.xOffset + this.width;
    }

    public int getBottom() {
        return this.yOffset + this.height;
    }

    public abstract void onClick(int p_88017_);

    public static void drawButtonsInRow(
        GuiGraphics p_281401_, List<RowButton> p_283164_, AbstractSelectionList<?> p_362215_, int p_282527_, int p_281326_, int p_281575_, int p_282538_
    ) {
        for (RowButton rowbutton : p_283164_) {
            if (p_362215_.getRowWidth() > rowbutton.getRight()) {
                rowbutton.drawForRowAt(p_281401_, p_282527_, p_281326_, p_281575_, p_282538_);
            }
        }
    }

    public static void rowButtonMouseClicked(
        AbstractSelectionList<?> p_364213_, ObjectSelectionList.Entry<?> p_88038_, List<RowButton> p_88039_, int p_88040_, double p_88041_, double p_88042_
    ) {
        int i = p_364213_.children().indexOf(p_88038_);
        if (i > -1) {
            p_364213_.setSelectedIndex(i);
            int j = p_364213_.getRowLeft();
            int k = p_364213_.getRowTop(i);
            int l = (int)(p_88041_ - (double)j);
            int i1 = (int)(p_88042_ - (double)k);

            for (RowButton rowbutton : p_88039_) {
                if (l >= rowbutton.xOffset && l <= rowbutton.getRight() && i1 >= rowbutton.yOffset && i1 <= rowbutton.getBottom()) {
                    rowbutton.onClick(i);
                }
            }
        }
    }
}