Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIWorkshopPublishResourcePackListItem.cs
Go to the documentation of this file.
7using Terraria.IO;
9using Terraria.UI;
10
12
14{
16
18
20
22
24
26
28
29 private int _orderInList;
30
32
33 private const int ICON_SIZE = 64;
34
35 private const int ICON_BORDER_PADDING = 4;
36
37 private const int HEIGHT_FLUFF = 10;
38
39 private bool _canPublish;
40
41 public UIWorkshopPublishResourcePackListItem(UIState ownerState, ResourcePack data, int orderInList, bool canBePublished)
42 {
43 _ownerState = ownerState;
44 _orderInList = orderInList;
45 _data = data;
46 _canPublish = canBePublished;
49 UIElement uIElement = new UIElement
50 {
51 Width = new StyleDimension(72f, 0f),
52 Height = new StyleDimension(72f, 0f),
53 Left = new StyleDimension(4f, 0f),
54 VAlign = 0.5f
55 };
56 uIElement.OnLeftDoubleClick += PublishButtonClick_ImportResourcePackToLocalFiles;
57 UIImage element = new UIImage(data.Icon)
58 {
59 Width = new StyleDimension(-6f, 1f),
60 Height = new StyleDimension(-6f, 1f),
61 HAlign = 0.5f,
62 VAlign = 0.5f,
63 ScaleToFit = true,
64 AllowResizingDimensions = false,
66 };
67 UIImage element2 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Achievement_Borders", (AssetRequestMode)1))
68 {
69 HAlign = 0.5f,
70 VAlign = 0.5f,
72 };
73 uIElement.Append(element);
74 uIElement.Append(element2);
75 Append(uIElement);
76 _iconArea = uIElement;
77 _ = 4f;
78 _publishButton = new UIIconTextButton(Language.GetText("Workshop.Publish"), Color.White, "Images/UI/Workshop/Publish");
79 _publishButton.HAlign = 1f;
80 _publishButton.VAlign = 1f;
81 _publishButton.OnLeftClick += PublishButtonClick_ImportResourcePackToLocalFiles;
84 _publishButton.SetSnapPoint("Publish", orderInList);
85 }
86
87 private void LoadTextures()
88 {
89 _dividerTexture = Main.Assets.Request<Texture2D>("Images/UI/Divider", (AssetRequestMode)1);
90 _innerPanelTexture = Main.Assets.Request<Texture2D>("Images/UI/InnerPanelBackground", (AssetRequestMode)1);
91 _iconBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_Borders", (AssetRequestMode)1);
93 }
94
95 private void InitializeAppearance()
96 {
97 Height.Set(82f, 0f);
98 Width.Set(0f, 1f);
99 SetPadding(6f);
101 }
102
103 private void SetColorsToHovered()
104 {
105 BackgroundColor = new Color(73, 94, 171);
106 BorderColor = new Color(89, 116, 213);
107 if (!_canPublish)
108 {
109 BorderColor = new Color(150, 150, 150) * 1f;
110 BackgroundColor = Color.Lerp(BackgroundColor, new Color(120, 120, 120), 0.5f) * 1f;
111 }
112 }
113
115 {
116 BackgroundColor = new Color(63, 82, 151) * 0.7f;
117 BorderColor = new Color(89, 116, 213) * 0.7f;
118 if (!_canPublish)
119 {
120 BorderColor = new Color(127, 127, 127) * 0.7f;
121 BackgroundColor = Color.Lerp(new Color(63, 82, 151), new Color(80, 80, 80), 0.5f) * 0.7f;
122 }
123 }
124
126 {
127 if (listeningElement == evt.Target && !TryMovingToRejectionMenuIfNeeded())
128 {
130 }
131 }
132
134 {
135 if (!_canPublish)
136 {
138 Main.instance.RejectionMenuInfo = new RejectionMenuInfo
139 {
140 TextToShow = Language.GetTextValue("Workshop.ReportIssue_CannotPublishZips"),
141 ExitAction = RejectionMenuExitAction
142 };
143 Main.menuMode = 1000001;
144 return true;
145 }
146 return false;
147 }
148
150 {
152 if (_ownerState == null)
153 {
154 Main.menuMode = 0;
155 return;
156 }
157 Main.menuMode = 888;
158 Main.MenuUI.SetState(_ownerState);
159 }
160
161 public override int CompareTo(object obj)
162 {
163 if (obj is UIWorkshopPublishResourcePackListItem uIWorkshopPublishResourcePackListItem)
164 {
165 return _orderInList.CompareTo(uIWorkshopPublishResourcePackListItem._orderInList);
166 }
167 return base.CompareTo(obj);
168 }
169
170 public override void MouseOver(UIMouseEvent evt)
171 {
172 base.MouseOver(evt);
174 }
175
176 public override void MouseOut(UIMouseEvent evt)
177 {
178 base.MouseOut(evt);
180 }
181
182 private void DrawPanel(SpriteBatch spriteBatch, Vector2 position, float width, float height)
183 {
184 Utils.DrawSplicedPanel(spriteBatch, _innerPanelTexture.Value, (int)position.X, (int)position.Y, (int)width, (int)height, 10, 10, 10, 10, Color.White);
185 }
186
187 protected override void DrawSelf(SpriteBatch spriteBatch)
188 {
189 base.DrawSelf(spriteBatch);
190 CalculatedStyle innerDimensions = GetInnerDimensions();
192 float num = dimensions.X + dimensions.Width;
193 Color white = Color.White;
194 Utils.DrawBorderString(spriteBatch, _data.Name, new Vector2(num + 8f, innerDimensions.Y + 3f), white);
195 float num2 = (innerDimensions.Width - 22f - dimensions.Width - _publishButton.GetDimensions().Width) / 2f;
196 float height = _publishButton.GetDimensions().Height;
197 Vector2 vector = new Vector2(num + 8f, innerDimensions.Y + innerDimensions.Height - height);
198 float num3 = num2;
199 DrawPanel(spriteBatch, vector, num3, height);
200 string textValue = Language.GetTextValue("UI.Author", _data.Author);
201 Color white2 = Color.White;
202 Vector2 vector2 = FontAssets.MouseText.Value.MeasureString(textValue);
203 float x = vector2.X;
204 float y = vector2.Y;
205 float x2 = num3 * 0.5f - x * 0.5f;
206 float num4 = height * 0.5f - y * 0.5f;
207 Utils.DrawBorderString(spriteBatch, textValue, vector + new Vector2(x2, num4 + 3f), white2);
208 vector.X += num3 + 5f;
209 float num5 = num2;
210 DrawPanel(spriteBatch, vector, num5, height);
211 string textValue2 = Language.GetTextValue("UI.Version", _data.Version.GetFormattedVersion());
212 Color white3 = Color.White;
213 Vector2 vector3 = FontAssets.MouseText.Value.MeasureString(textValue2);
214 float x3 = vector3.X;
215 float y2 = vector3.Y;
216 float x4 = num5 * 0.5f - x3 * 0.5f;
217 float num6 = height * 0.5f - y2 * 0.5f;
218 Utils.DrawBorderString(spriteBatch, textValue2, vector + new Vector2(x4, num6 + 3f), white3);
219 vector.X += num5 + 5f;
220 }
221}
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Asset< Texture2D >[] Extra
void DrawPanel(SpriteBatch spriteBatch, Vector2 position, float width, float height)
void PublishButtonClick_ImportResourcePackToLocalFiles(UIMouseEvent evt, UIElement listeningElement)
UIWorkshopPublishResourcePackListItem(UIState ownerState, ResourcePack data, int orderInList, bool canBePublished)
ResourcePackVersion Version
static LocalizedText GetText(string key)
Definition Language.cs:10
static string GetTextValue(string key)
Definition Language.cs:15
static UserInterface MenuUI
Definition Main.cs:381
static IAssetRepository Assets
Definition Main.cs:209
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
CalculatedStyle GetInnerDimensions()
Definition UIElement.cs:377
StyleDimension Left
Definition UIElement.cs:25
void SetSnapPoint(string name, int id, Vector2? anchor=null, Vector2? offset=null)
Definition UIElement.cs:122
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void SetPadding(float pixels)
Definition UIElement.cs:361
readonly UIElement Target
Definition UIEvent.cs:5
static void DrawSplicedPanel(SpriteBatch sb, Texture2D texture, int x, int y, int w, int h, int leftEnd, int rightEnd, int topEnd, int bottomEnd, Color c)
Definition Utils.cs:1964
static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1891
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
void Set(float pixels, float precent)