Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BestiaryScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
5
6namespace Game {
7 public class BestiaryScreen : Screen {
9
10 [Obsolete]
12
13 public virtual void OnCreaturesListItemClicked(object item) {
14 ScreensManager.SwitchScreen("BestiaryDescription", item, m_creaturesList.Items.Cast<BestiaryCreatureInfo>().ToList());
15 }
16
17 public BestiaryScreen() {
18 XElement node = ContentManager.Get<XElement>("Screens/BestiaryScreen");
19 LoadContents(this, node);
20 m_creaturesList = Children.Find<ListPanelWidget>("CreaturesList");
21 m_creaturesList.ItemWidgetFactory = delegate(object item) {
22 BestiaryCreatureInfo bestiaryCreatureInfo2 = (BestiaryCreatureInfo)item;
23 XElement node2 = ContentManager.Get<XElement>("Widgets/BestiaryItem");
24 ContainerWidget obj = (ContainerWidget)LoadWidget(this, node2, null);
25 ModelWidget modelWidget = obj.Children.Find<ModelWidget>("BestiaryItem.Model");
27 bestiaryCreatureInfo2,
28 modelWidget,
29 m_creaturesList.Items.IndexOf(item) % 2 == 0 ? new Vector3(-1f, 0f, -1f) : new Vector3(1f, 0f, -1f),
30 false,
31 false
32 );
33 obj.Children.Find<LabelWidget>("BestiaryItem.Text").Text = bestiaryCreatureInfo2.DisplayName;
34 obj.Children.Find<LabelWidget>("BestiaryItem.Details").Text = bestiaryCreatureInfo2.Description;
36 "LoadCreatureInfoInBestiaryScreen",
37 loader => {
38 loader.LoadCreatureInfoInBestiaryScreen(this, obj, bestiaryCreatureInfo2, bestiaryCreatureInfo2.EntityValuesDictionary);
39 return false;
40 }
41 );
42 return obj;
43 };
44 m_creaturesList.ItemClicked += OnCreaturesListItemClicked;
45 List<BestiaryCreatureInfo> list = new();
46 foreach (ValuesDictionary entitiesValuesDictionary in DatabaseManager.EntitiesValuesDictionaries) {
48 entitiesValuesDictionary,
49 typeof(ComponentCreature)
50 );
51 if (valuesDictionary != null) {
52 string value = valuesDictionary.GetValue<string>("DisplayName");
53 if (value.StartsWith('[')
54 && value.EndsWith(']')) {
55 string[] lp = value.Substring(1, value.Length - 2).Split(':', StringSplitOptions.RemoveEmptyEntries);
56 value = LanguageControl.GetDatabase("DisplayName", lp[1]);
57 }
58 if (!string.IsNullOrEmpty(value)) {
59 int order = -1;
60 ValuesDictionary value2 = entitiesValuesDictionary.GetValue<ValuesDictionary>("CreatureEggData", null);
61 ValuesDictionary value3 = entitiesValuesDictionary.GetValue<ValuesDictionary>("Player", null);
62 if (value2 != null
63 || value3 != null) {
64 if (value2 != null) {
65 int value4 = value2.GetValue<int>("EggTypeIndex");
66 if (value4 < 0) {
67 continue;
68 }
69 order = value4;
70 }
72 entitiesValuesDictionary,
74 );
76 entitiesValuesDictionary,
77 typeof(ComponentBody)
78 );
80 entitiesValuesDictionary,
81 typeof(ComponentHealth)
82 );
84 entitiesValuesDictionary,
85 typeof(ComponentMiner)
86 );
88 entitiesValuesDictionary,
90 );
92 entitiesValuesDictionary,
94 );
96 entitiesValuesDictionary,
97 typeof(ComponentMount)
98 );
100 entitiesValuesDictionary,
101 typeof(ComponentLoot)
102 );
103 string dy = valuesDictionary.GetValue<string>("Description");
104 if (dy.StartsWith('[')
105 && dy.EndsWith(']')) {
106 string[] lp = dy.Substring(1, dy.Length - 2).Split(':', StringSplitOptions.RemoveEmptyEntries);
107 dy = LanguageControl.GetDatabase("Description", lp[1]);
108 }
109 BestiaryCreatureInfo bestiaryCreatureInfo = new() {
110 EntityValuesDictionary = entitiesValuesDictionary,
111 Order = order,
112 DisplayName = value,
113 Description = dy,
114 ModelName = valuesDictionary2.GetValue<string>("ModelName"),
115 TextureOverride = valuesDictionary2.GetValue<string>("TextureOverride"),
116 Mass = valuesDictionary3.GetValue<float>("Mass"),
117 AttackResilience = valuesDictionary4.GetValue<float>("AttackResilience"),
118 AttackPower = valuesDictionary5?.GetValue<float>("AttackPower") ?? 0f,
119 MovementSpeed =
121 valuesDictionary6.GetValue<float>("WalkSpeed"),
122 valuesDictionary6.GetValue<float>("FlySpeed"),
123 valuesDictionary6.GetValue<float>("SwimSpeed")
124 ),
125 JumpHeight = MathUtils.Sqr(valuesDictionary6.GetValue<float>("JumpSpeed")) / 20f,
126 IsHerding = valuesDictionary7 != null,
127 CanBeRidden = valuesDictionary8 != null,
128 HasSpawnerEgg = value2?.GetValue<bool>("ShowEgg") ?? false,
129 Loot = valuesDictionary9 != null
130 ? ComponentLoot.ParseLootList(valuesDictionary9.GetValue<ValuesDictionary>("Loot"))
131 : []
132 };
133 if (value3 != null
134 && entitiesValuesDictionary.DatabaseObject.Name.ToLower().Contains("female")) {
135 bestiaryCreatureInfo.AttackPower *= 0.8f;
136 bestiaryCreatureInfo.AttackResilience *= 0.8f;
137 bestiaryCreatureInfo.MovementSpeed *= 1.03f;
138 bestiaryCreatureInfo.JumpHeight *= MathUtils.Sqr(1.03f);
139 }
140 list.Add(bestiaryCreatureInfo);
141 }
142 }
143 }
144 }
145 foreach (BestiaryCreatureInfo item in list.OrderBy(ci => ci.Order)) {
146 m_creaturesList.AddItem(item);
147 }
148 }
149
150 public override void Enter(object[] parameters) {
151 /*if (ScreensManager.PreviousScreen != ScreensManager.FindScreen<Screen>("BestiaryDescription")) {
152 m_previousScreen = ScreensManager.PreviousScreen;
153 }*/
154 m_creaturesList.SelectedItem = null;
155 }
156
157 public override void Update() {
158 if (Input.Back
159 || Input.Cancel
160 || Children.Find<ButtonWidget>("TopBar.Back").IsClicked) {
162 }
163 }
164
166 ModelWidget modelWidget,
167 Vector3 offset,
168 bool autoRotate,
169 bool autoAspect) {
170 SetupBestiaryModelWidget(info.ModelName, info.TextureOverride, modelWidget, offset, autoRotate, autoAspect);
171 }
172
173 public static void SetupBestiaryModelWidget(string modelName,
174 string textureOverrideName,
175 ModelWidget modelWidget,
176 Vector3 offset,
177 bool autoRotate,
178 bool autoAspect) {
179 Model model = ContentManager.Get<Model>(modelName);
180 SetModel(model, modelWidget);
181 modelWidget.Textures[model] = ContentManager.Get<Texture2D>(textureOverrideName);
182 Matrix[] absoluteTransforms = new Matrix[model.Bones.Count];
183 model.CopyAbsoluteBoneTransformsTo(absoluteTransforms);
184 BoundingBox boundingBox = model.CalculateAbsoluteBoundingBox(absoluteTransforms);
185 float x = MathUtils.Max(boundingBox.Size().X, 1.4f * boundingBox.Size().Y, boundingBox.Size().Z);
186 modelWidget.ViewPosition = new Vector3(boundingBox.Center().X, 1.5f, boundingBox.Center().Z) + 2.6f * MathF.Pow(x, 0.75f) * offset;
187 modelWidget.ViewTarget = boundingBox.Center();
188 modelWidget.ViewFov = 0.3f;
189 modelWidget.AutoRotationVector = autoRotate
190 ? new Vector3(0f, Math.Clamp(1.7f / boundingBox.Size().Length(), 0.25f, 1.4f), 0f)
191 : Vector3.Zero;
192 if (autoAspect) {
193 float num = Math.Clamp(boundingBox.Size().XZ.Length() / boundingBox.Size().Y, 1f, 1.5f);
194 modelWidget.Size = new Vector2(modelWidget.Size.Y * num, modelWidget.Size.Y);
195 }
196 }
197
198 static void SetModel(Model model, ModelWidget widget, int index = 0) {
199 if (model != null) {
200 if (widget.Models.Count == 0
201 || index >= widget.Models.Count) {
202 widget.Models.Add(model);
203 }
204 else {
205 widget.Models[index] = model;
206 }
207 widget.m_boneTransforms[model] = new Matrix?[model.Bones.Count];
208 widget.m_absoluteBoneTransforms[model] = new Matrix[model.Bones.Count];
209 }
210 else {
211 widget.Models.RemoveAt(index);
212 }
213 }
214 }
215}
Engine.Vector3 Vector3
BoundingBox CalculateAbsoluteBoundingBox(Matrix[] absoluteTransforms)
ReadOnlyList< ModelBone > Bones
void CopyAbsoluteBoneTransformsTo(Matrix[] absoluteTransforms)
static int Max(int x1, int x2)
static int Sqr(int x)
virtual void OnCreaturesListItemClicked(object item)
ListPanelWidget m_creaturesList
static void SetModel(Model model, ModelWidget widget, int index=0)
static void SetupBestiaryModelWidget(BestiaryCreatureInfo info, ModelWidget modelWidget, Vector3 offset, bool autoRotate, bool autoAspect)
override void Enter(object[] parameters)
static void SetupBestiaryModelWidget(string modelName, string textureOverrideName, ModelWidget modelWidget, Vector3 offset, bool autoRotate, bool autoAspect)
static List< Loot > ParseLootList(ValuesDictionary lootVd)
readonly WidgetsList Children
static object Get(Type type, string name)
static ICollection< ValuesDictionary > EntitiesValuesDictionaries
static ValuesDictionary FindValuesDictionaryForComponent(ValuesDictionary entityVd, Type componentType)
static string GetDatabase(string name, string prop)
List< Model > Models
Dictionary< Model, Texture2D > Textures
Dictionary< Model, Matrix[]> m_absoluteBoneTransforms
Dictionary< Model, Matrix?[]> m_boneTransforms
static void GoBack(params object[] parameters)
static void SwitchScreen(string name, params object[] parameters)
static Widget LoadWidget(object eventsTarget, XElement node, ContainerWidget parentWidget)
virtual void LoadContents(object eventsTarget, XElement node)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static readonly Vector3 Zero