(99feac023) Unstable 0.9.704.0

This commit is contained in:
Joonas Rikkonen
2020-02-07 20:47:03 +02:00
parent 590619459b
commit 6754b9d5a2
104 changed files with 2224 additions and 1091 deletions
@@ -234,7 +234,7 @@ namespace Barotrauma
!ItemPrefab.Prefabs.Any(ep => ep.Category.HasFlag(c) && ep.CanBeBought));
foreach (MapEntityCategory category in itemCategories)
{
var categoryButton = new GUIButton(new RectTransform(new Point(categoryButtonContainer.Rect.Width), categoryButtonContainer.RectTransform),
var categoryButton = new GUIButton(new RectTransform(new Point(categoryButtonContainer.Rect.Width, categoryButtonContainer.Rect.Width), categoryButtonContainer.RectTransform),
"", style: "ItemCategory" + category.ToString())
{
UserData = category,
@@ -253,7 +253,14 @@ namespace Barotrauma
};
itemCategoryButtons.Add(categoryButton);
new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) },
categoryButton.RectTransform.SizeChanged += () =>
{
var sprite = categoryButton.Frame.sprites[GUIComponent.ComponentState.None].First();
categoryButton.RectTransform.NonScaledSize =
new Point(categoryButton.Rect.Width, (int)(categoryButton.Rect.Width * ((float)sprite.Sprite.SourceRect.Height / sprite.Sprite.SourceRect.Width)));
};
new GUITextBlock(new RectTransform(new Vector2(0.95f, 0.256f), categoryButton.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) },
TextManager.Get("MapEntityCategory." + category), textAlignment: Alignment.Center, textColor: categoryButton.TextColor)
{
Padding = Vector4.Zero,
@@ -262,7 +269,7 @@ namespace Barotrauma
HoverColor = Color.Transparent,
PressedColor = Color.Transparent,
SelectedColor = Color.Transparent,
CanBeFocused = false
CanBeFocused = true
};
}
FillStoreItemList();
@@ -715,11 +722,12 @@ namespace Barotrauma
for (int i = 0; i < availableMissions.Count; i++)
{
var mission = availableMissions[i];
var tickBox = new GUITickBox(new RectTransform(new Vector2(0.1f, 0.1f), missionContent.RectTransform),
var tickBox = new GUITickBox(new RectTransform(new Vector2(0.65f, 0.1f), missionContent.RectTransform),
mission?.Name ?? TextManager.Get("NoMission"), style: "GUIRadioButton")
{
Enabled = GameMain.Client == null || GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign)
};
tickBox.TextBlock.Wrap = true;
missionTickBoxes.Add(tickBox);
missionRadioButtonGroup.AddRadioButton(i, tickBox);
}
@@ -833,7 +841,7 @@ namespace Barotrauma
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 1.0f), frame.RectTransform, Anchor.Center),
isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
RelativeSpacing = 0.02f,
AbsoluteSpacing = (int)(5 * GUI.Scale),
Stretch = true
};
@@ -874,8 +882,11 @@ namespace Barotrauma
UserData = pi,
IntValue = pi.Quantity
};
amountInput.TextBox.OnSelected += (sender, key) => { suppressBuySell = true; };
amountInput.TextBox.OnDeselected += (sender, key) => { suppressBuySell = false; amountInput.OnValueChanged?.Invoke(amountInput); };
amountInput.OnValueChanged += (numberInput) =>
{
if (suppressBuySell) { return; }
PurchasedItem purchasedItem = numberInput.UserData as PurchasedItem;
//Attempting to buy
@@ -889,7 +900,6 @@ namespace Barotrauma
{
BuyItem(numberInput, purchasedItem);
}
numberInput.IntValue = purchasedItem.Quantity;
}
//Attempting to sell
else
@@ -901,14 +911,15 @@ namespace Barotrauma
}
}
};
frame.HoverColor = frame.SelectedColor = Color.Transparent;
}
listBox.RecalculateChildren();
content.Recalculate();
content.RectTransform.RecalculateChildren(true, true);
amountInput?.LayoutGroup.Recalculate();
textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
/*content.RectTransform.IsFixedSize = true;
content.RectTransform.Children.ForEach(c => c.IsFixedSize = true);*/
//content.RectTransform.IsFixedSize = true;
content.RectTransform.Children.ForEach(c => c.IsFixedSize = true);
return frame;
}
@@ -946,21 +957,33 @@ namespace Barotrauma
return false;
}
private bool suppressBuySell;
private void RefreshMyItems()
{
HashSet<GUIComponent> existingItemFrames = new HashSet<GUIComponent>();
foreach (PurchasedItem pi in Campaign.CargoManager.PurchasedItems)
{
var itemFrame = myItemList.Content.GetChildByUserData(pi);
var itemFrame = myItemList.Content.Children.FirstOrDefault(c =>
c.UserData is PurchasedItem pi2 && pi.ItemPrefab == pi2.ItemPrefab);
if (itemFrame == null)
{
var priceInfo = pi.ItemPrefab.GetPrice(Campaign.Map.CurrentLocation);
if (priceInfo == null) { continue; }
itemFrame = CreateItemFrame(pi, priceInfo, myItemList);
itemFrame.Flash(GUI.Style.Green);
itemFrame.Flash(GUI.Style.Green);
}
else
{
itemFrame.UserData = itemFrame.GetChild(0).GetChild<GUINumberInput>().UserData = pi;
}
itemFrame.GetChild(0).GetChild<GUINumberInput>().IntValue = pi.Quantity;
existingItemFrames.Add(itemFrame);
suppressBuySell = true;
var numInput = itemFrame.GetChild(0).GetChild<GUINumberInput>();
if (numInput.IntValue != pi.Quantity) { itemFrame.Flash(GUI.Style.Green); }
numInput.IntValue = (itemFrame.UserData as PurchasedItem).Quantity = pi.Quantity;
suppressBuySell = false;
}
var removedItemFrames = myItemList.Content.Children.Except(existingItemFrames).ToList();
@@ -204,7 +204,7 @@ namespace Barotrauma
Submarine.DrawBack(spriteBatch, false, e => !(e is Structure) || e.SpriteDepth < 0.9f);
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.Limbs.Any(l => l.DeformSprite != null) || !c.IsVisible) { continue; }
if (!c.IsVisible || c.AnimController.Limbs.Any(l => l.DeformSprite != null)) { continue; }
c.Draw(spriteBatch, Cam);
}
spriteBatch.End();
@@ -1111,7 +1111,7 @@ namespace Barotrauma
Alignment textAlignment = Alignment.CenterLeft;
Vector2 textFieldSize = new Vector2(0.5f, 1.0f);
Vector2 tickBoxSize = new Vector2(0.4f, 0.07f);
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.6f, 0.9f), menuTabs[(int)Tab.HostServer].RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.7f, 0.9f), menuTabs[(int)Tab.HostServer].RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
{
RelativeSpacing = 0.02f,
Stretch = true
@@ -1122,7 +1122,7 @@ namespace Barotrauma
//play style -----------------------------------------------------
var playstyleContainer = new GUIFrame(new RectTransform(new Vector2(1.5f, 0.1f), parent.RectTransform), style: null, color: Color.Black);
var playstyleContainer = new GUIFrame(new RectTransform(new Vector2(1.35f, 0.1f), parent.RectTransform), style: null, color: Color.Black);
playstyleBanner = new GUIImage(new RectTransform(new Vector2(1.0f, 0.1f), playstyleContainer.RectTransform),
ServerListScreen.PlayStyleBanners[0], scaleToFit: true)
@@ -1263,7 +1263,7 @@ namespace Barotrauma
var tickboxAreaLower = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, tickBoxSize.Y), parent.RectTransform), isHorizontal: true);
karmaEnabledBox = new GUITickBox(new RectTransform(new Vector2(0.4f, 1.0f), tickboxAreaLower.RectTransform), TextManager.Get("ServerSettingsUseKarma"))
karmaEnabledBox = new GUITickBox(new RectTransform(new Vector2(0.5f, 1.0f), tickboxAreaLower.RectTransform), TextManager.Get("ServerSettingsUseKarma"))
{
ToolTip = TextManager.Get("karmaexplanation"),
OnSelected = (tb) =>
@@ -1272,7 +1272,7 @@ namespace Barotrauma
return true;
}
};
karmaPresetDD = new GUIDropDown(new RectTransform(new Vector2(0.6f, 1.0f), tickboxAreaLower.RectTransform))
karmaPresetDD = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1.0f), tickboxAreaLower.RectTransform))
{
ButtonEnabled = false,
Enabled = false
@@ -24,6 +24,8 @@ namespace Barotrauma
private GUIListBox chatBox, playerList;
private GUIListBox serverLogBox, serverLogFilterTicks;
private GUIComponent jobVariantTooltip;
private GUITextBox chatInput;
private GUITextBox serverLogFilter;
public GUITextBox ChatInput
@@ -419,14 +421,14 @@ namespace Barotrauma
RelativeSpacing = 0.05f
};
FileTransferTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), fileTransferContent.RectTransform), "", font: GUI.SmallFont);
var fileTransferBottom = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), fileTransferContent.RectTransform), isHorizontal: true)
var fileTransferBottom = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), fileTransferContent.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
Stretch = true
};
FileTransferProgressBar = new GUIProgressBar(new RectTransform(new Vector2(0.6f, 1.0f), fileTransferBottom.RectTransform), 0.0f, Color.DarkGreen);
FileTransferProgressText = new GUITextBlock(new RectTransform(Vector2.One, FileTransferProgressBar.RectTransform), "",
font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), fileTransferBottom.RectTransform), TextManager.Get("cancel"))
new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), fileTransferBottom.RectTransform), TextManager.Get("cancel"), style: "GUIButtonSmall")
{
OnClicked = (btn, userdata) =>
{
@@ -458,7 +460,7 @@ namespace Barotrauma
myCharacterFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), sideBar.RectTransform));
playerInfoContainer = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), myCharacterFrame.RectTransform, Anchor.Center), style: null);
spectateBox = new GUITickBox(new RectTransform(new Vector2(0.06f, 0.06f), myCharacterFrame.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.05f) },
spectateBox = new GUITickBox(new RectTransform(new Vector2(0.4f, 0.06f), myCharacterFrame.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.05f) },
TextManager.Get("spectatebutton"))
{
Selected = false,
@@ -1477,6 +1479,39 @@ namespace Barotrauma
}
}
private void CreateJobVariantTooltip(JobPrefab jobPrefab, int variant, GUIComponent parentSlot)
{
jobVariantTooltip = new GUIFrame(new RectTransform(new Point((int)(500 * GUI.Scale), (int)(200 * GUI.Scale)), GUI.Canvas, pivot: Pivot.TopRight),
style: "GUIToolTip")
{
UserData = new Pair<JobPrefab, int>(jobPrefab, variant)
};
jobVariantTooltip.RectTransform.AbsoluteOffset = new Point(parentSlot.Rect.Right, parentSlot.Rect.Bottom);
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), jobVariantTooltip.RectTransform, Anchor.Center))
{
Stretch = true,
RelativeSpacing = 0.02f
};
string name =
TextManager.Get("jobname." + jobPrefab.Identifier + (variant + 1), returnNull: true) ??
jobPrefab.Name;
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform), name, font: GUI.SubHeadingFont);
string description =
TextManager.Get("jobdescription." + jobPrefab.Identifier + (variant + 1), returnNull: true) ??
TextManager.Get("jobdescription." + jobPrefab.Identifier, returnNull: true) ??
"";
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform), description, wrap: true, font: GUI.SmallFont);
new GUICustomComponent(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform, Anchor.BottomLeft),
onDraw: (sb, component) => { DrawJobVariantItems(sb, component, new Pair<JobPrefab, int>(jobPrefab, variant)); });
jobVariantTooltip.RectTransform.MinSize = new Point(0, content.RectTransform.Children.Sum(c => c.Rect.Height));
}
public bool ToggleSpectate(GUITickBox tickBox)
{
SetSpectate(tickBox.Selected);
@@ -2210,6 +2245,22 @@ namespace Barotrauma
JobList.Deselect();
JobSelectionFrame.Visible = false;
}
if (GUI.MouseOn?.UserData is Pair<JobPrefab, int> jobPrefab && GUI.MouseOn.Style?.Name == "JobVariantButton")
{
var prevVisibleVariant = jobVariantTooltip?.UserData as Pair<JobPrefab, int>;
if (jobVariantTooltip == null || prevVisibleVariant.First != jobPrefab.First || prevVisibleVariant.Second != jobPrefab.Second)
{
CreateJobVariantTooltip(jobPrefab.First, jobPrefab.Second, GUI.MouseOn.Parent);
}
}
if (jobVariantTooltip != null)
{
jobVariantTooltip?.AddToGUIUpdateList();
Rectangle mouseRect = jobVariantTooltip.MouseRect;
mouseRect.Inflate(60 * GUI.Scale, 60 * GUI.Scale);
if (!mouseRect.Contains(PlayerInput.MousePosition)) { jobVariantTooltip = null; }
}
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
@@ -2251,6 +2302,52 @@ namespace Barotrauma
}
}
private void DrawJobVariantItems(SpriteBatch spriteBatch, GUICustomComponent component, Pair<JobPrefab, int> jobPrefab)
{
var itemIdentifiers = jobPrefab.First.ItemIdentifiers[jobPrefab.Second]
.Distinct()
.Where(id => jobPrefab.First.ShowItemPreview[jobPrefab.Second][id]);
Point slotSize = new Point(component.Rect.Height);
int spacing = (int)(5 * GUI.Scale);
int slotCount = itemIdentifiers.Count();
float totalWidth = slotSize.X * slotCount + spacing * (slotCount - 1);
if (totalWidth > component.Rect.Width)
{
slotSize = slotSize.Multiply(component.Rect.Width / totalWidth);
}
int i = 0;
foreach (string itemIdentifier in itemIdentifiers)
{
if (!(MapEntityPrefab.Find(null, identifier: itemIdentifier, showErrorMessages: false) is ItemPrefab itemPrefab)) { continue; }
Vector2 slotPos = new Vector2(component.Rect.X + (slotSize.X + spacing) * i, component.Rect.Center.Y - slotSize.Y / 2);
Rectangle slotRect = new Rectangle(slotPos.ToPoint(), slotSize);
Inventory.SlotSpriteSmall.Draw(spriteBatch, slotPos,
scale: slotSize.X / (float)Inventory.SlotSpriteSmall.SourceRect.Width,
color: slotRect.Contains(PlayerInput.MousePosition) ? Color.White : Color.White * 0.6f);
Sprite icon = itemPrefab.InventoryIcon ?? itemPrefab.sprite;
float iconScale = Math.Min(Math.Min(slotSize.X / icon.size.X, slotSize.Y / icon.size.Y), 2.0f) * 0.9f;
icon.Draw(spriteBatch, slotPos + slotSize.ToVector2() * 0.5f, scale: iconScale);
int count = jobPrefab.First.ItemIdentifiers[jobPrefab.Second].Count(id => id == itemIdentifier);
if (count > 1)
{
string itemCountText = "x" + count;
GUI.Font.DrawString(spriteBatch, itemCountText, slotPos + slotSize.ToVector2() - GUI.Font.MeasureString(itemCountText) - Vector2.UnitX * 5, Color.White);
}
if (slotRect.Contains(PlayerInput.MousePosition))
{
GUIComponent.DrawToolTip(spriteBatch, itemPrefab.Name+'\n'+itemPrefab.Description, slotRect);
}
i++;
}
}
public void NewChatMessage(ChatMessage message)
{
float prevSize = chatBox.BarSize;
@@ -3012,8 +3109,10 @@ namespace Barotrauma
(variantIndex + 1).ToString(), style: "JobVariantButton")
{
Selected = jobPrefab.Second == variantIndex,
//ToolTip = TextManager.Get("jobdescription." + jobPrefab.First.Identifier + (variantIndex + 1), returnNull: true) ?? "",
UserData = new Pair<JobPrefab, int>(jobPrefab.First, variantIndex),
};
return btn;
}
@@ -1102,6 +1102,8 @@ namespace Barotrauma
return true;
};
nameBox.Text = subNameLabel?.Text ?? "";
submarineNameCharacterCount.Text = nameBox.Text.Length + " / " + submarineNameLimit;
var descriptionHeaderGroup = new GUILayoutGroup(new RectTransform(new Vector2(.975f, 0.03f), leftColumn.RectTransform), true);