public override void Enter(object[] parameters) { BestiaryCreatureInfo item = (BestiaryCreatureInfo)parameters[0]; m_infoList = (IList <BestiaryCreatureInfo>)parameters[1]; m_index = m_infoList.IndexOf(item); UpdateCreatureProperties(); }
public static void SetupBestiaryModelWidget(BestiaryCreatureInfo info, ModelWidget modelWidget, Vector3 offset, bool autoRotate, bool autoAspect) { modelWidget.Model = ContentManager.Get <Model>(info.ModelName); modelWidget.TextureOverride = ContentManager.Get <Texture2D>(info.TextureOverride); Matrix[] absoluteTransforms = new Matrix[modelWidget.Model.Bones.Count]; modelWidget.Model.CopyAbsoluteBoneTransformsTo(absoluteTransforms); BoundingBox boundingBox = modelWidget.Model.CalculateAbsoluteBoundingBox(absoluteTransforms); float x = MathUtils.Max(boundingBox.Size().X, 1.4f * boundingBox.Size().Y, boundingBox.Size().Z); modelWidget.ViewPosition = new Vector3(boundingBox.Center().X, 1.5f, boundingBox.Center().Z) + 2.6f * MathUtils.Pow(x, 0.75f) * offset; modelWidget.ViewTarget = boundingBox.Center(); modelWidget.ViewFov = 0.3f; modelWidget.AutoRotationVector = (autoRotate ? new Vector3(0f, MathUtils.Clamp(1.7f / boundingBox.Size().Length(), 0.25f, 1.4f), 0f) : Vector3.Zero); if (autoAspect) { float num = MathUtils.Clamp(boundingBox.Size().XZ.Length() / boundingBox.Size().Y, 1f, 1.5f); modelWidget.Size = new Vector2(modelWidget.Size.Y * num, modelWidget.Size.Y); } }
public BestiaryScreen() { XElement node = ContentManager.Get <XElement>("Screens/BestiaryScreen"); LoadContents(this, node); m_creaturesList = Children.Find <ListPanelWidget>("CreaturesList"); m_creaturesList.ItemWidgetFactory = delegate(object item) { BestiaryCreatureInfo bestiaryCreatureInfo2 = (BestiaryCreatureInfo)item; XElement node2 = ContentManager.Get <XElement>("Widgets/BestiaryItem"); ContainerWidget obj = (ContainerWidget)Widget.LoadWidget(this, node2, null); ModelWidget modelWidget = obj.Children.Find <ModelWidget>("BestiaryItem.Model"); SetupBestiaryModelWidget(bestiaryCreatureInfo2, modelWidget, (m_creaturesList.Items.IndexOf(item) % 2 == 0) ? new Vector3(-1f, 0f, -1f) : new Vector3(1f, 0f, -1f), autoRotate: false, autoAspect: false); obj.Children.Find <LabelWidget>("BestiaryItem.Text").Text = bestiaryCreatureInfo2.DisplayName; obj.Children.Find <LabelWidget>("BestiaryItem.Details").Text = bestiaryCreatureInfo2.Description; return(obj); }; m_creaturesList.ItemClicked += delegate(object item) { ScreensManager.SwitchScreen("BestiaryDescription", item, m_creaturesList.Items.Cast <BestiaryCreatureInfo>().ToList()); }; List <BestiaryCreatureInfo> list = new List <BestiaryCreatureInfo>(); foreach (ValuesDictionary entitiesValuesDictionary in DatabaseManager.EntitiesValuesDictionaries) { ValuesDictionary valuesDictionary = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentCreature)); if (valuesDictionary != null) { string value = valuesDictionary.GetValue <string>("DisplayName"); if (value.StartsWith("[") && value.EndsWith("]")) { string[] lp = value.Substring(1, value.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); value = LanguageControl.GetDatabase("DisplayName", lp[1]); } if (!string.IsNullOrEmpty(value)) { int order = -1; ValuesDictionary value2 = entitiesValuesDictionary.GetValue <ValuesDictionary>("CreatureEggData", null); ValuesDictionary value3 = entitiesValuesDictionary.GetValue <ValuesDictionary>("Player", null); if (value2 != null || value3 != null) { if (value2 != null) { int value4 = value2.GetValue <int>("EggTypeIndex"); if (value4 < 0) { continue; } order = value4; } ValuesDictionary valuesDictionary2 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentCreatureModel)); ValuesDictionary valuesDictionary3 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentBody)); ValuesDictionary valuesDictionary4 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentHealth)); ValuesDictionary valuesDictionary5 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentMiner)); ValuesDictionary valuesDictionary6 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentLocomotion)); ValuesDictionary valuesDictionary7 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentHerdBehavior)); ValuesDictionary valuesDictionary8 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentMount)); ValuesDictionary valuesDictionary9 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentLoot)); string dy = valuesDictionary.GetValue <string>("Description"); if (dy.StartsWith("[") && dy.EndsWith("]")) { string[] lp = dy.Substring(1, dy.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); dy = LanguageControl.GetDatabase("Description", lp[1]); } BestiaryCreatureInfo bestiaryCreatureInfo = new BestiaryCreatureInfo { Order = order, DisplayName = value, Description = dy, ModelName = valuesDictionary2.GetValue <string>("ModelName"), TextureOverride = valuesDictionary2.GetValue <string>("TextureOverride"), Mass = valuesDictionary3.GetValue <float>("Mass"), AttackResilience = valuesDictionary4.GetValue <float>("AttackResilience"), AttackPower = (valuesDictionary5?.GetValue <float>("AttackPower") ?? 0f), MovementSpeed = MathUtils.Max(valuesDictionary6.GetValue <float>("WalkSpeed"), valuesDictionary6.GetValue <float>("FlySpeed"), valuesDictionary6.GetValue <float>("SwimSpeed")), JumpHeight = MathUtils.Sqr(valuesDictionary6.GetValue <float>("JumpSpeed")) / 20f, IsHerding = (valuesDictionary7 != null), CanBeRidden = (valuesDictionary8 != null), HasSpawnerEgg = (value2?.GetValue <bool>("ShowEgg") ?? false), Loot = ((valuesDictionary9 != null) ? ComponentLoot.ParseLootList(valuesDictionary9.GetValue <ValuesDictionary>("Loot")) : new List <ComponentLoot.Loot>()) }; if (value3 != null && entitiesValuesDictionary.DatabaseObject.Name.ToLower().Contains("female")) { bestiaryCreatureInfo.AttackPower *= 0.8f; bestiaryCreatureInfo.AttackResilience *= 0.8f; bestiaryCreatureInfo.MovementSpeed *= 1.03f; bestiaryCreatureInfo.JumpHeight *= MathUtils.Sqr(1.03f); } list.Add(bestiaryCreatureInfo); } } } } foreach (BestiaryCreatureInfo item in list.OrderBy((BestiaryCreatureInfo ci) => ci.Order)) { m_creaturesList.AddItem(item); } }
public void UpdateCreatureProperties() { if (m_index >= 0 && m_index < m_infoList.Count) { BestiaryCreatureInfo bestiaryCreatureInfo = m_infoList[m_index]; m_modelWidget.AutoRotationVector = new Vector3(0f, 1f, 0f); BestiaryScreen.SetupBestiaryModelWidget(bestiaryCreatureInfo, m_modelWidget, new Vector3(-1f, 0f, -1f), autoRotate: true, autoAspect: true); m_nameWidget.Text = bestiaryCreatureInfo.DisplayName; m_descriptionWidget.Text = bestiaryCreatureInfo.Description; m_propertyNames1Widget.Text = string.Empty; m_propertyValues1Widget.Text = string.Empty; m_propertyNames1Widget.Text += LanguageControl.Get(fName, "resilience"); LabelWidget propertyValues1Widget = m_propertyValues1Widget; propertyValues1Widget.Text = propertyValues1Widget.Text + bestiaryCreatureInfo.AttackResilience.ToString() + "\n"; m_propertyNames1Widget.Text += LanguageControl.Get(fName, "attack"); LabelWidget propertyValues1Widget2 = m_propertyValues1Widget; propertyValues1Widget2.Text = propertyValues1Widget2.Text + ((bestiaryCreatureInfo.AttackPower > 0f) ? bestiaryCreatureInfo.AttackPower.ToString("0.0") : LanguageControl.Get("Usual", "none")) + "\n"; m_propertyNames1Widget.Text += LanguageControl.Get(fName, "herding"); LabelWidget propertyValues1Widget3 = m_propertyValues1Widget; propertyValues1Widget3.Text = propertyValues1Widget3.Text + (bestiaryCreatureInfo.IsHerding ? LanguageControl.Get("Usual", "yes") : LanguageControl.Get("Usual", "no")) + "\n"; m_propertyNames1Widget.Text += LanguageControl.Get(fName, 1); LabelWidget propertyValues1Widget4 = m_propertyValues1Widget; propertyValues1Widget4.Text = propertyValues1Widget4.Text + (bestiaryCreatureInfo.CanBeRidden ? LanguageControl.Get("Usual", "yes") : LanguageControl.Get("Usual", "no")) + "\n"; m_propertyNames1Widget.Text = m_propertyNames1Widget.Text.TrimEnd(); m_propertyValues1Widget.Text = m_propertyValues1Widget.Text.TrimEnd(); m_propertyNames2Widget.Text = string.Empty; m_propertyValues2Widget.Text = string.Empty; m_propertyNames2Widget.Text += LanguageControl.Get(fName, "speed"); LabelWidget propertyValues2Widget = m_propertyValues2Widget; propertyValues2Widget.Text = propertyValues2Widget.Text + ((double)bestiaryCreatureInfo.MovementSpeed * 3.6).ToString("0") + LanguageControl.Get(fName, "speed unit"); m_propertyNames2Widget.Text += LanguageControl.Get(fName, "jump height"); LabelWidget propertyValues2Widget2 = m_propertyValues2Widget; propertyValues2Widget2.Text = propertyValues2Widget2.Text + bestiaryCreatureInfo.JumpHeight.ToString("0.0") + LanguageControl.Get(fName, "length unit"); m_propertyNames2Widget.Text += LanguageControl.Get(fName, "weight"); LabelWidget propertyValues2Widget3 = m_propertyValues2Widget; propertyValues2Widget3.Text = propertyValues2Widget3.Text + bestiaryCreatureInfo.Mass.ToString() + LanguageControl.Get(fName, "weight unit"); m_propertyNames2Widget.Text += LanguageControl.Get("BlocksManager", "Spawner Eggs"); LabelWidget propertyValues2Widget4 = m_propertyValues2Widget; propertyValues2Widget4.Text = propertyValues2Widget4.Text + (bestiaryCreatureInfo.HasSpawnerEgg ? LanguageControl.Get("Usual", "yes") : LanguageControl.Get("Usual", "no")) + "\n"; m_propertyNames2Widget.Text = m_propertyNames2Widget.Text.TrimEnd(); m_propertyValues2Widget.Text = m_propertyValues2Widget.Text.TrimEnd(); m_dropsPanel.Children.Clear(); if (bestiaryCreatureInfo.Loot.Count > 0) { foreach (ComponentLoot.Loot item in bestiaryCreatureInfo.Loot) { string text = (item.MinCount >= item.MaxCount) ? $"{item.MinCount}" :string.Format(LanguageControl.Get(fName, "range"), item.MinCount, item.MaxCount); if (item.Probability < 1f) { text += string.Format(LanguageControl.Get(fName, 2), $"{item.Probability * 100f:0}"); } m_dropsPanel.Children.Add(new StackPanelWidget { Margin = new Vector2(20f, 0f), Children = { (Widget) new BlockIconWidget { Size = new Vector2(32f), Scale = 1.2f, VerticalAlignment = WidgetAlignment.Center, Value = item.Value }, (Widget) new CanvasWidget { Size = new Vector2(10f, 0f) }, (Widget) new LabelWidget { VerticalAlignment = WidgetAlignment.Center, Text = text } } }); } } else { m_dropsPanel.Children.Add(new LabelWidget { Margin = new Vector2(20f, 0f), Font = ContentManager.Get <BitmapFont>("Fonts/Pericles"), Text = LanguageControl.Get("Usual", "nothing") }); } } }