33using Terraria . GameContent . UI . Elements ;
44using Terraria . ModLoader ;
55using Terraria . UI ;
6+ using UICustomizer . Edit . UI ;
67using UICustomizer . EditMode . System ;
78
8- namespace UICustomizer . EditMode . UI
9+ namespace UICustomizer . EditMode . UI ;
10+ public sealed class EditPanel : UIPanel
911{
10- public class EditPanel : UIPanel
12+ private enum Subpanel { None , Positions , Layouts , Settings }
13+
14+ private readonly IconOptionButton _btnPositions ;
15+ private readonly IconOptionButton _btnLayouts ;
16+ private readonly IconOptionButton _btnSettings ;
17+
18+ private readonly PositionsPanel _positions ;
19+ private readonly LayoutsPanel _layouts ;
20+ private readonly SettingsPanel _settings ;
21+
22+ private Subpanel _active ;
23+
24+ private const int IconSize = 40 ;
25+ private static readonly Point SubPanelPos = new ( 70 , 0 ) ;
26+ private static readonly Point SubPanelSize = new ( 300 , 300 ) ;
27+
28+ public EditPanel ( )
1129 {
12- private UIPanel positionsPanel ;
13- private UIPanel layoutsPanel ;
14- private UIPanel settingsPanel ;
30+ Width . Set ( 50 , 0 ) ;
31+ Top . Set ( 785 , 0 ) ;
32+ Left . Set ( 20 , 0 ) ;
33+ Height . Set ( 6 + IconSize + 6 + IconSize + 6 + IconSize + 6 , 0 ) ;
34+ SetPadding ( 0 ) ;
1535
16- public EditPanel ( )
17- {
18- Width . Set ( 60 , 0 ) ;
19- Height . Set ( 200 , 0 ) ;
20- Top . Set ( 120 , 0 ) ;
21- Left . Set ( 40 , 0 ) ;
22-
23- // Base colors (dark blue like Journey Mode UI)
24- BorderColor = new Color ( 89 , 116 , 213 , 255 ) * 0.9f ;
25- BackgroundColor = new Color ( 73 , 94 , 171 ) * 0.9f ;
26-
27- SetPadding ( 6 ) ;
28-
29- // Create 3 icon buttons
30- var positionsButton = CreateIconButton ( Ass . P . Value , 0 , TogglePositions ) ;
31- var layoutsButton = CreateIconButton ( Ass . O . Value , 40 , ToggleLayouts ) ;
32- var settingsButton = CreateIconButton ( Ass . S . Value , 80 , ToggleSettings ) ;
33-
34- Append ( positionsButton ) ;
35- Append ( layoutsButton ) ;
36- Append ( settingsButton ) ;
37-
38- // Create sub-panels (hidden initially)
39- positionsPanel = CreateSubPanel ( "I am a positions panel" ) ;
40- layoutsPanel = CreateSubPanel ( "I am a layouts panel" ) ;
41- settingsPanel = CreateSubPanel ( "I am a settings panel" ) ;
42- }
36+ BorderColor = new Color ( 89 , 116 , 213 ) * 0.9f ;
37+ BackgroundColor = new Color ( 73 , 94 , 171 ) * 0.9f ;
4338
44- private UIImage CreateIconButton ( Texture2D tex , float topOffset , UIElement . MouseEvent onClick )
45- {
46- var button = new UIImage ( tex )
47- {
48- Width = new StyleDimension ( 32 , 0 ) ,
49- Height = new StyleDimension ( 32 , 0 ) ,
50- Top = new StyleDimension ( topOffset , 0 ) ,
51- HAlign = 0.5f
52- } ;
53- button . OnLeftClick += onClick ;
54- return button ;
55- }
39+ _btnPositions = new IconOptionButton ( Ass . P , "Positions" , 0 ) ;
40+ _btnLayouts = new IconOptionButton ( Ass . O , "Layouts" , 1 ) ;
41+ _btnSettings = new IconOptionButton ( Ass . S , "Settings" , 2 ) ;
5642
57- private UIPanel CreateSubPanel ( string labelText )
58- {
59- var panel = new UIPanel
60- {
61- Width = new StyleDimension ( 200 , 0 ) ,
62- Height = new StyleDimension ( 120 , 0 ) ,
63- Top = new StyleDimension ( 20 , 0 ) ,
64- Left = new StyleDimension ( 70 , 0 ) ,
65- BorderColor = new Color ( 89 , 116 , 213 , 255 ) * 0.9f ,
66- BackgroundColor = new Color ( 73 , 94 , 171 ) * 0.9f
67- } ;
68-
69- var text = new UIText ( labelText )
70- {
71- HAlign = 0.5f ,
72- VAlign = 0.5f
73- } ;
74-
75- panel . Append ( text ) ;
76- panel . Remove ( ) ; // start hidden
77- Append ( panel ) ;
78- return panel ;
79- }
43+ _btnPositions . OnLeftClick += ( _ , _ ) => Toggle ( Subpanel . Positions ) ;
44+ _btnLayouts . OnLeftClick += ( _ , _ ) => Toggle ( Subpanel . Layouts ) ;
45+ _btnSettings . OnLeftClick += ( _ , _ ) => Toggle ( Subpanel . Settings ) ;
8046
81- private void TogglePositions ( UIMouseEvent evt , UIElement listeningElement ) => TogglePanel ( positionsPanel ) ;
82- private void ToggleLayouts ( UIMouseEvent evt , UIElement listeningElement ) => TogglePanel ( layoutsPanel ) ;
83- private void ToggleSettings ( UIMouseEvent evt , UIElement listeningElement ) => TogglePanel ( settingsPanel ) ;
47+ Append ( _btnPositions ) ;
48+ Append ( _btnLayouts ) ;
49+ Append ( _btnSettings ) ;
8450
85- private void TogglePanel ( UIPanel panel )
86- {
87- // Hide all first
88- positionsPanel . Remove ( ) ;
89- layoutsPanel . Remove ( ) ;
90- settingsPanel . Remove ( ) ;
51+ _positions = new PositionsPanel ( ) ;
52+ _layouts = new LayoutsPanel ( ) ;
53+ _settings = new SettingsPanel ( ) ;
54+
55+ _active = Subpanel . None ;
56+ CloseActive ( ) ;
57+ }
58+
59+ private void CloseActive ( )
60+ {
61+ _positions . Remove ( ) ;
62+ _layouts . Remove ( ) ;
63+ _settings . Remove ( ) ;
64+
65+ _btnPositions . SetSelected ( false ) ;
66+ _btnLayouts . SetSelected ( false ) ;
67+ _btnSettings . SetSelected ( false ) ;
9168
92- // Show selected
93- Append ( panel ) ;
69+ _active = Subpanel . None ;
70+ }
71+
72+ private void Toggle ( Subpanel target )
73+ {
74+ if ( _active == target ) { CloseActive ( ) ; return ; }
75+
76+ _positions . Remove ( ) ;
77+ _layouts . Remove ( ) ;
78+ _settings . Remove ( ) ;
79+ _btnPositions . SetSelected ( false ) ;
80+ _btnLayouts . SetSelected ( false ) ;
81+ _btnSettings . SetSelected ( false ) ;
82+
83+ UIPanel panelToShow = null ;
84+ switch ( target )
85+ {
86+ case Subpanel . Positions : panelToShow = _positions ; _btnPositions . SetSelected ( true ) ; break ;
87+ case Subpanel . Layouts : panelToShow = _layouts ; _btnLayouts . SetSelected ( true ) ; break ;
88+ case Subpanel . Settings : panelToShow = _settings ; _btnSettings . SetSelected ( true ) ; break ;
9489 }
9590
96- public override void Draw ( SpriteBatch spriteBatch )
91+ if ( panelToShow != null )
9792 {
9893 var sys = ModContent . GetInstance < EditSystem > ( ) ;
99- if ( ! sys . Enabled ) return ;
94+ sys . editState . Append ( panelToShow ) ;
10095
101- base . Draw ( spriteBatch ) ;
96+ Vector2 SubPanelPos = new ( 70 , 600 ) ;
97+ Vector2 SubPanelSize = new ( 285 , 390 ) ;
98+
99+ panelToShow . Left . Set ( SubPanelPos . X , 0f ) ;
100+ panelToShow . Top . Set ( SubPanelPos . Y , 0f ) ;
101+ panelToShow . Width . Set ( SubPanelSize . X , 0f ) ;
102+ panelToShow . Height . Set ( SubPanelSize . Y , 0f ) ;
103+ _active = target ;
102104 }
103105 }
104- }
106+
107+ public override void LeftClick ( UIMouseEvent evt )
108+ {
109+ var sys = ModContent . GetInstance < EditSystem > ( ) ;
110+ if ( ! sys . Enabled )
111+ return ;
112+
113+
114+ base . LeftClick ( evt ) ;
115+ }
116+
117+ public override void Draw ( SpriteBatch spriteBatch )
118+ {
119+ var sys = ModContent . GetInstance < EditSystem > ( ) ;
120+ if ( ! sys . Enabled )
121+ return ;
122+
123+ base . Draw ( spriteBatch ) ;
124+ }
125+ }
0 commit comments