|
3 | 3 | using Content.Client.Guidebook.Richtext; |
4 | 4 | using Content.Client.Message; |
5 | 5 | using Content.Client.UserInterface.ControlExtensions; |
| 6 | +using Content.Shared.Chemistry.Reaction; |
6 | 7 | using Content.Shared.Chemistry.Reagent; |
| 8 | +using Content.Shared.EntityEffects.Effects.EntitySpawning; |
7 | 9 | using Content.Shared.Kitchen; |
8 | 10 | using JetBrains.Annotations; |
9 | 11 | using Robust.Client.AutoGenerated; |
@@ -197,4 +199,107 @@ private void GenerateControl(FoodRecipePrototype recipe) |
197 | 199 | GenerateCookTime(recipe); |
198 | 200 | GenerateDeviceType(recipe); |
199 | 201 | } |
| 202 | + |
| 203 | + #region Starlight |
| 204 | + |
| 205 | + public GuideMicrowaveEmbed(ReactionPrototype reaction) : this() => GenerateControl(reaction); |
| 206 | + |
| 207 | + private void GenerateHeader(ReactionPrototype reaction) |
| 208 | + { |
| 209 | + if (TryGetPrimaryReactionResultEntity(reaction, out var resultEntity, out var amount)) |
| 210 | + { |
| 211 | + RepresentedPrototype = resultEntity; |
| 212 | + IconContainer.AddChild(new GuideEntityEmbed(resultEntity.ID, false, false)); |
| 213 | + |
| 214 | + var escapedResultName = FormattedMessage.EscapeText(resultEntity.Name); |
| 215 | + ResultName.SetMarkup($"[bold]{escapedResultName}[/bold] x {amount}"); |
| 216 | + ResultDescription.SetMarkup(FormattedMessage.EscapeText(resultEntity.Description)); |
| 217 | + return; |
| 218 | + } |
| 219 | + |
| 220 | + ResultName.SetMarkup(FormattedMessage.EscapeText(reaction.ID)); |
| 221 | + ResultDescription.SetMarkup(string.Empty); |
| 222 | + } |
| 223 | + |
| 224 | + private bool TryGetPrimaryReactionResultEntity(ReactionPrototype reaction, out EntityPrototype resultEntity, out int amount) |
| 225 | + { |
| 226 | + foreach (var effect in reaction.Effects) |
| 227 | + { |
| 228 | + if (effect is not SpawnEntity spawn) |
| 229 | + continue; |
| 230 | + |
| 231 | + resultEntity = _prototype.Index<EntityPrototype>(spawn.Entity); |
| 232 | + amount = Math.Max(1, spawn.Number); |
| 233 | + return true; |
| 234 | + } |
| 235 | + |
| 236 | + resultEntity = default!; |
| 237 | + amount = 0; |
| 238 | + return false; |
| 239 | + } |
| 240 | + |
| 241 | + private void GenerateReactionIngredients(ReactionPrototype reaction) |
| 242 | + { |
| 243 | + foreach (var (reagentId, reactant) in reaction.Reactants.OrderByDescending(p => p.Value.Amount)) |
| 244 | + { |
| 245 | + var reagent = _prototype.Index<ReagentPrototype>(reagentId); |
| 246 | + |
| 247 | + var liquidColorMsg = new FormattedMessage(); |
| 248 | + liquidColorMsg.AddMarkupOrThrow(Loc.GetString("guidebook-microwave-reagent-color-display", ("color", reagent.SubstanceColor))); |
| 249 | + liquidColorMsg.Pop(); |
| 250 | + |
| 251 | + var liquidColorLabel = new GuidebookRichPrototypeLink(); |
| 252 | + liquidColorLabel.SetMessage(liquidColorMsg); |
| 253 | + liquidColorLabel.HorizontalAlignment = Control.HAlignment.Center; |
| 254 | + liquidColorLabel.LinkedPrototype = reagent; |
| 255 | + IngredientsGrid.AddChild(liquidColorLabel); |
| 256 | + |
| 257 | + var liquidNameMsg = new FormattedMessage(); |
| 258 | + liquidNameMsg.AddMarkupOrThrow("[bold]"); |
| 259 | + liquidNameMsg.AddText(reagent.LocalizedName); |
| 260 | + liquidNameMsg.AddMarkupOrThrow("[/bold]"); |
| 261 | + if (reactant.Catalyst) |
| 262 | + { |
| 263 | + liquidNameMsg.AddText(" "); |
| 264 | + liquidNameMsg.AddText(Loc.GetString("guidebook-microwave-reagent-catalyst-label")); |
| 265 | + } |
| 266 | + |
| 267 | + var liquidNameLabel = new RichTextLabel(); |
| 268 | + liquidNameLabel.SetMessage(liquidNameMsg); |
| 269 | + IngredientsGrid.AddChild(liquidNameLabel); |
| 270 | + |
| 271 | + var liquidQuantityMsg = new FormattedMessage(); |
| 272 | + liquidQuantityMsg.AddMarkupOrThrow(Loc.GetString("guidebook-microwave-reagent-quantity-display", ("amount", reactant.Amount))); |
| 273 | + liquidQuantityMsg.Pop(); |
| 274 | + |
| 275 | + var liquidQuantityLabel = new RichTextLabel(); |
| 276 | + liquidQuantityLabel.SetMessage(liquidQuantityMsg); |
| 277 | + IngredientsGrid.AddChild(liquidQuantityLabel); |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + private void GenerateReactionCookTime() |
| 282 | + { |
| 283 | + var msg = new FormattedMessage(); |
| 284 | + msg.AddMarkupOrThrow(Loc.GetString("guidebook-microwave-cook-time", ("time", 0))); |
| 285 | + msg.Pop(); |
| 286 | + CookTimeLabel.SetMessage(msg); |
| 287 | + } |
| 288 | + |
| 289 | + private void GenerateReactionDeviceType() |
| 290 | + { |
| 291 | + var msg = new FormattedMessage(); |
| 292 | + msg.AddMarkupOrThrow(Loc.GetString("guidebook-microwave-device-type", ("type", "Chemistry"))); |
| 293 | + msg.Pop(); |
| 294 | + DeviceTypeLabel.SetMessage(msg); |
| 295 | + } |
| 296 | + |
| 297 | + private void GenerateControl(ReactionPrototype reaction) |
| 298 | + { |
| 299 | + GenerateHeader(reaction); |
| 300 | + GenerateReactionIngredients(reaction); |
| 301 | + GenerateReactionCookTime(); |
| 302 | + GenerateReactionDeviceType(); |
| 303 | + } |
| 304 | + #endregion |
200 | 305 | } |
0 commit comments