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 .CScrollPanel ;
7- import io .github .techstreet .dfscript .screen .widget .CTextField ;
8- import io .github .techstreet .dfscript .screen .widget .CWidget ;
5+ import io .github .techstreet .dfscript .screen .widget .*;
96import io .github .techstreet .dfscript .script .Script ;
107import io .github .techstreet .dfscript .script .ScriptManager ;
8+ import io .github .techstreet .dfscript .script .action .ScriptActionType ;
119import io .github .techstreet .dfscript .script .options .ScriptOption ;
12-
10+ import io .github .techstreet .dfscript .util .chat .ChatUtil ;
11+ import net .minecraft .client .gui .DrawableHelper ;
12+ import net .minecraft .client .sound .PositionedSoundInstance ;
13+ import net .minecraft .client .util .math .MatrixStack ;
14+ import net .minecraft .sound .SoundEvents ;
15+ import net .minecraft .text .Text ;
16+
17+ import java .awt .*;
1318import java .util .ArrayList ;
1419import java .util .List ;
1520
@@ -29,15 +34,76 @@ public ScriptSettingsScreen(Script script) {
2934
3035 widgets .add (panel );
3136
32- CTextField description = new CTextField (script .getDescription (), 3 , 3 , 115 , 20 , true );
37+ int y = 3 ;
38+ int index = 0 ;
39+
40+ CText descriptionText = new CText (5 , y , Text .of ("Description:" ));
41+ panel .add (descriptionText );
42+
43+ y += 5 ;
44+
45+ CTextField description = new CTextField (script .getDescription (), 5 , y , 110 , 20 , true );
3346 description .setChangedListener (() -> script .setDescription (description .getText ()));
3447 panel .add (description );
3548
36- int y = 25 ;
37- int index = 0 ;
49+ y += 22 ;
3850
3951 for (ScriptOption option : script .getOptions ())
4052 {
53+ String name = option .getName () + ":" ;
54+
55+ Text text = Text .of (name );
56+
57+ CWrappedText ctext = new CWrappedText (5 , y , 110 *2 , text );
58+
59+ panel .add (ctext );
60+
61+ int height = DFScript .MC .textRenderer .getWrappedLinesHeight (name , 110 *2 ) / 2 ;
62+ int finalIndex = index ;
63+ panel .add (new CButton (5 , y , 115 , height , "" ,() -> {}) {
64+ @ Override
65+ public void render (MatrixStack stack , int mouseX , int mouseY , float tickDelta ) {
66+ Rectangle b = getBounds ();
67+ if (b .contains (mouseX , mouseY )) {
68+ DrawableHelper .fill (stack , b .x , b .y , b .x + b .width , b .y + b .height , 0x33000000 );
69+ }
70+ }
71+
72+ @ Override
73+ public boolean mouseClicked (double x , double y , int button ) {
74+ if (getBounds ().contains (x , y )) {
75+ DFScript .MC .getSoundManager ().play (PositionedSoundInstance .ambient (SoundEvents .UI_BUTTON_CLICK , 1f ,1f ));
76+
77+ if (button != 0 ) {
78+ CButton insertBefore = new CButton ((int ) x , (int ) y , 40 , 8 , "Insert Before" , () -> {
79+ DFScript .MC .setScreen (new ScriptAddSettingScreen (script , finalIndex ));
80+ });
81+ CButton insertAfter = new CButton ((int ) x , (int ) y +8 , 40 , 8 , "Insert After" , () -> {
82+ DFScript .MC .setScreen (new ScriptAddSettingScreen (script , finalIndex + 1 ));
83+ });
84+ CButton delete = new CButton ((int ) x , (int ) y +16 , 40 , 8 , "Delete" , () -> {
85+ script .getOptions ().remove (finalIndex );
86+ scroll = panel .getScroll ();
87+ DFScript .MC .setScreen (new ScriptSettingsScreen (script ));
88+ });
89+ DFScript .MC .send (() -> {
90+ panel .add (insertBefore );
91+ panel .add (insertAfter );
92+ panel .add (delete );
93+ contextMenu .add (insertBefore );
94+ contextMenu .add (insertAfter );
95+ contextMenu .add (delete );
96+ });
97+ }
98+ return true ;
99+ }
100+ return false ;
101+ }
102+ });
103+
104+ y += height ;
105+ y ++;
106+
41107 y = option .create (panel , 5 , y , 105 );
42108
43109 index ++;
@@ -56,4 +122,16 @@ public ScriptSettingsScreen(Script script) {
56122 public void close () {
57123 DFScript .MC .setScreen (new ScriptEditScreen (script ));
58124 }
59- }
125+
126+ public boolean mouseClicked (double mouseX , double mouseY , int button ) {
127+ boolean b = super .mouseClicked (mouseX , mouseY , button );
128+ clearContextMenu ();
129+ return b ;
130+ }
131+ private void clearContextMenu () {
132+ for (CWidget w : contextMenu ) {
133+ panel .remove (w );
134+ }
135+ contextMenu .clear ();
136+ }
137+ }
0 commit comments