22
33import io .github .techstreet .dfscript .DFScript ;
44import io .github .techstreet .dfscript .screen .CScreen ;
5- import io .github .techstreet .dfscript .screen .widget .CButton ;
6- import io .github .techstreet .dfscript .screen .widget .CItem ;
7- import io .github .techstreet .dfscript .screen .widget .CScrollPanel ;
8- import io .github .techstreet .dfscript .screen .widget .CText ;
9- import io .github .techstreet .dfscript .screen .widget .CTexturedButton ;
10- import io .github .techstreet .dfscript .screen .widget .CWidget ;
5+ import io .github .techstreet .dfscript .screen .widget .*;
116import io .github .techstreet .dfscript .script .Script ;
7+ import io .github .techstreet .dfscript .script .ScriptComment ;
128import io .github .techstreet .dfscript .script .ScriptManager ;
139import io .github .techstreet .dfscript .script .ScriptPart ;
1410import io .github .techstreet .dfscript .script .action .ScriptAction ;
2016import net .minecraft .client .gui .DrawableHelper ;
2117import net .minecraft .client .sound .PositionedSoundInstance ;
2218import net .minecraft .client .util .math .MatrixStack ;
19+ import net .minecraft .item .ItemStack ;
20+ import net .minecraft .item .Items ;
2321import net .minecraft .sound .SoundEvents ;
22+ import net .minecraft .text .Style ;
2423import net .minecraft .text .Text ;
24+ import net .minecraft .text .TextColor ;
25+ import net .minecraft .util .Formatting ;
2526import net .minecraft .util .Identifier ;
2627
2728public class ScriptEditScreen extends CScreen {
2829 private final Identifier identifier_main = new Identifier (DFScript .MOD_ID + ":wrench.png" );
2930
3031 private final Script script ;
3132 private static int scroll = 0 ;
33+
34+ private final static int width = 125 ;
3235 private final CScrollPanel panel ;
3336 private final List <CWidget > contextMenu = new ArrayList <>();
3437
3538 public ScriptEditScreen (Script script ) {
36- super (125 , 100 );
39+ super (width , 100 );
3740 this .script = script ;
3841 panel = new CScrollPanel (0 , 3 , 120 , 94 );
3942
@@ -113,41 +116,24 @@ public boolean mouseClicked(double x, double y, int button) {
113116 panel .add (new CItem (5 + indent , y , sa .getType ().getIcon ()));
114117 panel .add (new CText (15 + indent , y + 2 , Text .literal (sa .getType ().getName ())));
115118
116- for (int i = 0 ; i < indent ; i += 5 ) {
117- int xpos = 8 + i ;
118- int ypos = y ;
119- panel .add (new CWidget () {
120- @ Override
121- public void render (MatrixStack stack , int mouseX , int mouseY , float tickDelta ) {
122- DrawableHelper .fill (stack , xpos , ypos , xpos + 1 , ypos + 8 , 0xFF333333 );
123- }
124-
125- @ Override
126- public Rectangle getBounds () {
127- return new Rectangle (0 ,0 ,0 ,0 );
128- }
129- });
130- }
119+ createIndent (indent , y );
131120
132121 int currentIndex = index ;
133- panel .add (new CButton (5 , y -1 , 115 , 10 , "" ,() -> {}) {
122+ panel .add (new CButton (5 , y - 1 , 115 , 10 , "" , () -> {
123+ }) {
134124 @ Override
135125 public void render (MatrixStack stack , int mouseX , int mouseY , float tickDelta ) {
136126 Rectangle b = getBounds ();
137127 if (b .contains (mouseX , mouseY )) {
138128 int color = 0x33000000 ;
139129
140- if (sa .getType ().isDeprecated ())
141- {
130+ if (sa .getType ().isDeprecated ()) {
142131 color = 0x80FF0000 ;
143132 }
144133
145134 DrawableHelper .fill (stack , b .x , b .y , b .x + b .width , b .y + b .height , color );
146- }
147- else
148- {
149- if (sa .getType ().isDeprecated ())
150- {
135+ } else {
136+ if (sa .getType ().isDeprecated ()) {
151137 DrawableHelper .fill (stack , b .x , b .y , b .x + b .width , b .y + b .height , 0x33FF0000 );
152138 }
153139 }
@@ -156,7 +142,7 @@ public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
156142 @ Override
157143 public boolean mouseClicked (double x , double y , int button ) {
158144 if (getBounds ().contains (x , y )) {
159- DFScript .MC .getSoundManager ().play (PositionedSoundInstance .ambient (SoundEvents .UI_BUTTON_CLICK , 1f ,1f ));
145+ DFScript .MC .getSoundManager ().play (PositionedSoundInstance .ambient (SoundEvents .UI_BUTTON_CLICK , 1f , 1f ));
160146
161147 if (button == 0 ) {
162148 if (sa .getType () != ScriptActionType .CLOSE_BRACKET ) {
@@ -167,10 +153,10 @@ public boolean mouseClicked(double x, double y, int button) {
167153 CButton insertBefore = new CButton ((int ) x , (int ) y , 40 , 8 , "Insert Before" , () -> {
168154 DFScript .MC .setScreen (new ScriptActionCategoryScreen (script , currentIndex ));
169155 });
170- CButton insertAfter = new CButton ((int ) x , (int ) y + 8 , 40 , 8 , "Insert After" , () -> {
156+ CButton insertAfter = new CButton ((int ) x , (int ) y + 8 , 40 , 8 , "Insert After" , () -> {
171157 DFScript .MC .setScreen (new ScriptActionCategoryScreen (script , currentIndex + 1 ));
172158 });
173- CButton delete = new CButton ((int ) x , (int ) y + 16 , 40 , 8 , "Delete" , () -> {
159+ CButton delete = new CButton ((int ) x , (int ) y + 16 , 40 , 8 , "Delete" , () -> {
174160 script .getParts ().remove (currentIndex );
175161 scroll = panel .getScroll ();
176162 DFScript .MC .setScreen (new ScriptEditScreen (script ));
@@ -193,6 +179,63 @@ public boolean mouseClicked(double x, double y, int button) {
193179 if (sa .getType ().hasChildren ()) {
194180 indent += 5 ;
195181 }
182+ } else if (part instanceof ScriptComment sc ) {
183+ panel .add (new CItem (5 + indent , y , new ItemStack (Items .MAP ).setCustomName (Text .literal ("Comment" ).setStyle (Style .EMPTY .withItalic (false )))));
184+
185+ CTextField cTextField = new CTextField (sc .getComment (),15 +indent , y -1 , width -(15 +indent )-5 , 10 , true );
186+
187+ cTextField .setChangedListener (() -> sc .setComment (cTextField .getText ()));
188+
189+ panel .add (cTextField );
190+
191+ int currentIndex = index ;
192+
193+ panel .add (new CButton (5 , y -1 , 115 , 10 , "" ,() -> {}) {
194+ @ Override
195+ public void render (MatrixStack stack , int mouseX , int mouseY , float tickDelta ) {
196+ Rectangle b = getBounds ();
197+
198+ if (b .contains (mouseX , mouseY )) {
199+ int color = 0x33000000 ;
200+
201+ DrawableHelper .fill (stack , b .x , b .y , b .x + b .width , b .y + b .height , color );
202+ }
203+ }
204+
205+ @ Override
206+ public boolean mouseClicked (double x , double y , int button ) {
207+ if (getBounds ().contains (x , y )) {
208+ DFScript .MC .getSoundManager ().play (PositionedSoundInstance .ambient (SoundEvents .UI_BUTTON_CLICK , 1f ,1f ));
209+
210+ if (button != 0 ) {
211+ CButton insertBefore = new CButton ((int ) x , (int ) y , 40 , 8 , "Insert Before" , () -> {
212+ DFScript .MC .setScreen (new ScriptActionCategoryScreen (script , currentIndex ));
213+ });
214+ CButton insertAfter = new CButton ((int ) x , (int ) y +8 , 40 , 8 , "Insert After" , () -> {
215+ DFScript .MC .setScreen (new ScriptActionCategoryScreen (script , currentIndex + 1 ));
216+ });
217+ CButton delete = new CButton ((int ) x , (int ) y +16 , 40 , 8 , "Delete" , () -> {
218+ script .getParts ().remove (currentIndex );
219+ scroll = panel .getScroll ();
220+ DFScript .MC .setScreen (new ScriptEditScreen (script ));
221+ });
222+ DFScript .MC .send (() -> {
223+ panel .add (insertBefore );
224+ panel .add (insertAfter );
225+ panel .add (delete );
226+ contextMenu .add (insertBefore );
227+ contextMenu .add (insertAfter );
228+ contextMenu .add (delete );
229+ });
230+
231+ return true ;
232+ }
233+ }
234+ return false ;
235+ }
236+ });
237+
238+ createIndent (indent , y );
196239 } else {
197240 throw new IllegalArgumentException ("Unknown script part type" );
198241 }
@@ -209,6 +252,25 @@ public boolean mouseClicked(double x, double y, int button) {
209252 panel .setScroll (scroll );
210253 }
211254
255+ public void createIndent (int indent , int y )
256+ {
257+ for (int i = 0 ; i < indent ; i += 5 ) {
258+ int xpos = 8 + i ;
259+ int ypos = y ;
260+ panel .add (new CWidget () {
261+ @ Override
262+ public void render (MatrixStack stack , int mouseX , int mouseY , float tickDelta ) {
263+ DrawableHelper .fill (stack , xpos , ypos , xpos + 1 , ypos + 8 , 0xFF333333 );
264+ }
265+
266+ @ Override
267+ public Rectangle getBounds () {
268+ return new Rectangle (0 , 0 , 0 , 0 );
269+ }
270+ });
271+ }
272+ }
273+
212274 @ Override
213275 public void close () {
214276 scroll = panel .getScroll ();
0 commit comments