Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MusketWidget.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
5 public class MusketWidget : CanvasWidget {
7
8 public int m_slotIndex;
9
11
13
15 public static string fName = "MusketWidget";
16
17 public MusketWidget(IInventory inventory, int slotIndex) {
18 m_inventory = inventory;
19 m_slotIndex = slotIndex;
20 XElement node = ContentManager.Get<XElement>("Widgets/MusketWidget");
21 LoadContents(this, node);
22 m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
23 m_inventorySlotWidget = Children.Find<InventorySlotWidget>("InventorySlot");
24 m_instructionsLabel = Children.Find<LabelWidget>("InstructionsLabel");
25 for (int i = 0; i < m_inventoryGrid.RowsCount; i++) {
26 for (int j = 0; j < m_inventoryGrid.ColumnsCount; j++) {
27 InventorySlotWidget widget = new();
28 m_inventoryGrid.Children.Add(widget);
29 m_inventoryGrid.SetWidgetCell(widget, new Point2(j, i));
30 }
31 }
32 int num = 10;
33 foreach (Widget child in m_inventoryGrid.Children) {
34 (child as InventorySlotWidget)?.AssignInventorySlot(inventory, num++);
35 }
36 m_inventorySlotWidget.AssignInventorySlot(inventory, slotIndex);
37 m_inventorySlotWidget.CustomViewMatrix = Matrix.CreateLookAt(new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 0f), -Vector3.UnitZ);
38 }
39
40 public override void Update() {
41 int slotValue = m_inventory.GetSlotValue(m_slotIndex);
42 int slotCount = m_inventory.GetSlotCount(m_slotIndex);
43 if (Terrain.ExtractContents(slotValue) == 212
44 && slotCount > 0) {
45 switch (MusketBlock.GetLoadState(Terrain.ExtractData(slotValue))) {
46 case MusketBlock.LoadState.Empty: m_instructionsLabel.Text = LanguageControl.Get(fName, 0); break;
47 case MusketBlock.LoadState.Gunpowder: m_instructionsLabel.Text = LanguageControl.Get(fName, 1); break;
48 case MusketBlock.LoadState.Wad: m_instructionsLabel.Text = LanguageControl.Get(fName, 2); break;
49 case MusketBlock.LoadState.Loaded: m_instructionsLabel.Text = LanguageControl.Get(fName, 3); break;
50 default: m_instructionsLabel.Text = string.Empty; break;
51 }
52 }
53 else {
54 ParentWidget.Children.Remove(this);
55 }
56 }
57 }
58}
Engine.Vector3 Vector3
readonly WidgetsList Children
static object Get(Type type, string name)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static LoadState GetLoadState(int data)
LabelWidget m_instructionsLabel
override void Update()
MusketWidget(IInventory inventory, int slotIndex)
GridPanelWidget m_inventoryGrid
InventorySlotWidget m_inventorySlotWidget
static int ExtractContents(int value)
static int ExtractData(int value)
ContainerWidget ParentWidget
virtual void LoadContents(object eventsTarget, XElement node)
static Matrix CreateLookAt(Vector3 position, Vector3 target, Vector3 up)
static readonly Vector3 UnitZ