forked from JannisX11/blockbench-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathground_plane_editor.js
More file actions
221 lines (189 loc) · 8.38 KB
/
Copy pathground_plane_editor.js
File metadata and controls
221 lines (189 loc) · 8.38 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
(async function() {
let aboutAction, groundPlaneAction, groundPlaneDialog;
const id = "ground_plane_editor"
const name = "Ground Plane Editor"
const icon = "icon-format_free"
const author = "SirJain"
// Store the ground plane material in a dialog
let groundPlane = Canvas.ground_plane.material
// localStorage variables
let localStorageColor = localStorage.getItem("groundPlaneColor")
let localStorageOpacity = localStorage.getItem("groundPlaneOpacity")
const links = {
twitter: "https://www.twitter.com/SirJain2",
discordlink: "https://discord.gg/wM4CKTbFVN"
}
// Register plugin
Plugin.register(id, {
title: name,
icon,
author,
description: "Edits the opacity and color of the ground plane feature in Blockbench.",
about: "This simple plugin allows you to customize the ground plane feature in Blockbench; more specifically, the opacity and color.\n## How to use\nTo use this plugin, simply go to `Tools > Ground Plane Editor`, fill out the appropriate categories, and hit `Done`. You can choose to edit either the color, the opacity, or both!\n\nPlease report any bugs or suggestions you may have.",
tags: ["Ground Plane", "Animation", "Customization"],
version: "1.1.1",
min_version: "4.2.0",
variant: "both",
oninstall() {
showAbout(true)
Blockbench.showQuickMessage("Successfully Installed Ground Plane Editor!");
},
onuninstall() {
Blockbench.showQuickMessage("Uninstalled Ground Plane Editor");
},
onload() {
addAbout()
// Handles the ground plane on loading the plugin
groundPlane.transparent = true;
if (localStorageColor) groundPlane.color.setHex(JSON.parse(localStorageColor))
else groundPlane.color.setHex(parseInt("#21252B".substring(1), 16))
if (localStorageOpacity) groundPlane.opacity = localStorageOpacity / 255
else groundPlane.opacity = 1
groundPlaneAction = new Action({
name: "Edit Ground Plane",
id: "edit_ground_plane_action",
icon: icon,
condition: () => Format?.id !== "image",
click: () => openDialog()
})
MenuBar.addAction(groundPlaneAction, "tools")
},
onunload() {
aboutAction.delete()
groundPlaneAction.delete()
// Reset values if plugin is uninstalled
localStorage.removeItem("groundPlaneColor")
localStorage.removeItem("groundPlaneOpacity")
groundPlane.color.setHex(parseInt("#21252B".substring(1), 16))
groundPlane.opacity = 1
MenuBar.removeAction(`help.about_plugins.about_${id}`)
}
})
function openDialog() {
groundPlaneDialog = new Dialog("ground_plane_dialog", {
name: "Edit Ground Plane",
part_order: ["form", "lines", "component"],
form: {
color: {
label: "Color",
value: getPlaneColor(),
type: "color"
},
opacity: {
label: "Opacity",
value: getPlaneOpacity(),
type: "range",
min: 60,
max: 255,
step: 1
},
actions: {
type: 'buttons',
buttons: ['Reset Values'],
click() {
groundPlane.color.setHex(parseInt("#21252B".substring(1), 16))
groundPlane.opacity = 1
groundPlaneDialog.hide()
localStorage.setItem("groundPlaneColor", groundPlane.color)
localStorage.setItem("groundPlaneOpacity", groundPlane.opacity)
Blockbench.showQuickMessage("Reset ground plane values!", 1500)
}
}
},
onConfirm(formData) {
const planeColor = parseInt(formData.color.toHexString().substring(1), 16)
groundPlane.color.setHex(planeColor)
groundPlane.opacity = formData.opacity / 255
localStorage.setItem("groundPlaneColor", planeColor)
localStorage.setItem("groundPlaneOpacity", formData.opacity)
console.log(groundPlane.color)
Blockbench.showQuickMessage("Updated ground plane values!", 1500)
}
}).show()
}
function getPlaneColor() {
return '#' + groundPlane.color.getHexString()
}
function getPlaneOpacity() {
return groundPlane.opacity * 255;
}
// Adds about dialog
function addAbout() {
let about = MenuBar.menus.help.structure.find(e => e.id === "about_plugins")
if (!about) {
about = new Action("about_plugins", {
name: "About Plugins...",
icon: "info",
children: []
})
MenuBar.addAction(about, "help")
}
aboutAction = new Action(`about_${id}`, {
name: `About ${name}...`,
icon,
click: () => showAbout()
})
about.children.push(aboutAction)
}
function showAbout(banner) {
const infoBox = new Dialog({
id: "about",
title: name,
width: 780,
buttons: [],
lines: [`
<li></li>
<style>
dialog#about .dialog_title {
padding-left: 0;
display: flex;
align-items: center;
gap: 10px;
}
dialog#about .dialog_content {
text-align: left!important;
margin: 0!important;
}
dialog#about .socials {
padding: 0!important;
}
dialog#about #banner {
background-color: var(--color-accent);
color: var(--color-accent_text);
width: 100%;
padding: 0 8px
}
dialog#about #content {
margin: 24px;
}
</style>
${banner ? `<div id="banner">This window can be reopened at any time from <strong>Help > About Plugins > ${name}</strong></div>` : ""}
<div id="content">
<h1 style="margin-top:-10px">${name}</h1>
<p>This plugin is used for changing the opacity and color of the ground plane feature in Blockbench.</p>
<h4>Worth noting:</h4>
<p>- There is currently no way to revert back to the default ground plane. However, adding this feature is planned. For now you'll have to uninstall the plugin and restart Blockbench to revert back to the default.</p>
<p>- Just like the default ground plane, changing it's properties in one tab will update in other tabs as well.</p>
<h4>How to use:</h4>
<p>To use this plugin, simply go to <b>Tools > Ground Plane Editor</b>, fill out the appropriate categories, and hit <b>Done</b>. You can choose to edit either the color, the opacity, or both!</p>
<p>Please report any bugs or suggestions you may have to make this plugin more enjoyable for everyone.</p>
<br>
<div class="socials">
<a href="${links["twitter"]}" class="open-in-browser">
<i class="fa-brands fa-twitter" style="color:#00acee"></i>
<label>By ${author}</label>
</a>
<a href="${links["discordlink"]}" class="open-in-browser">
<i class="fa-brands fa-discord" style="color:#5865F2"></i>
<label>Discord Server</label>
</a>
</div>
</div>
`]
}).show()
$("dialog#about .dialog_title").html(`
<i class="icon material-icons">${icon}</i>
${name}
`)
}
})()