aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/roomedit/EditingContext.java
blob: ac4521c8c43a8f77875aafb4c7784e45a4eadabe (plain)
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
package kr.syeyoung.dungeonsguide.roomedit;

import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;

import java.util.LinkedList;
import java.util.Stack;

public class EditingContext {

    private static EditingContext editingContext;

    public static void createEditingContext(DungeonRoom dungeonRoom) {
        editingContext = new EditingContext(dungeonRoom);
    }

    public static EditingContext getEditingContext() {
        return editingContext;
    }

    public static void endEditingSession() {
        editingContext = null;
        Minecraft.getMinecraft().displayGuiScreen(null);
    }


    private EditingContext(DungeonRoom dungeonRoom) {
        this.room = dungeonRoom;
    }

    @Getter
    private DungeonRoom room;

    @Getter
    private Stack<GuiScreen> guiStack = new Stack<GuiScreen>();

    public boolean isEditingSecrets() {
        return guiDungeonRoomEdit.isEditingSelected();
    }
    public void endEditing() {
        guiDungeonRoomEdit.endEditing();
    }

    private GuiDungeonRoomEdit guiDungeonRoomEdit;
    @Getter
    private GuiScreen current;

    public void openGui(GuiScreen gui) {
        if (gui instanceof GuiDungeonRoomEdit) guiDungeonRoomEdit = (GuiDungeonRoomEdit) gui;
        guiStack.push(current);
        this.current = gui;
        Minecraft.getMinecraft().displayGuiScreen(gui);
    }

    public void goBack() {
        current = guiStack.pop();
        Minecraft.getMinecraft().displayGuiScreen(current);
    }

    public void reopen() {
        Minecraft.getMinecraft().displayGuiScreen(current);
    }
}