Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
CreativeInventoryPanel.cs
浏览该文件的文档.
1
using
System.Xml.Linq;
2
using
Engine
;
3
4
namespace
Game
{
5
public
class
CreativeInventoryPanel
:
CanvasWidget
{
6
public
CreativeInventoryWidget
m_creativeInventoryWidget
;
7
8
public
ComponentCreativeInventory
m_componentCreativeInventory
;
9
10
public
List<int>
m_slotIndices
= [];
11
12
public
GridPanelWidget
m_inventoryGrid
;
13
14
public
int
m_pagesCount
;
15
16
public
int
m_assignedCategoryIndex
= -1;
17
18
public
int
m_assignedPageIndex
= -1;
19
20
public
CreativeInventoryPanel
(
CreativeInventoryWidget
creativeInventoryWidget) {
21
m_creativeInventoryWidget
= creativeInventoryWidget;
22
m_componentCreativeInventory
= creativeInventoryWidget.
Entity
.FindComponent<
ComponentCreativeInventory
>(
true
);
23
XElement node =
ContentManager
.
Get
<XElement>(
"Widgets/CreativeInventoryPanel"
);
24
LoadContents
(
this
, node);
25
m_inventoryGrid
=
Children
.Find<
GridPanelWidget
>(
"InventoryGrid"
);
26
for
(
int
i = 0; i <
m_inventoryGrid
.RowsCount; i++) {
27
for
(
int
j = 0; j <
m_inventoryGrid
.ColumnsCount; j++) {
28
InventorySlotWidget
widget =
new
() { HideEditOverlay =
true
, HideInteractiveOverlay =
true
, HideFoodOverlay =
true
};
29
m_inventoryGrid
.Children.Add(widget);
30
m_inventoryGrid
.SetWidgetCell(widget,
new
Point2
(j, i));
31
}
32
}
33
}
34
35
public
override
void
Update
() {
36
if
(
m_assignedCategoryIndex
>= 0) {
37
if
(
Input
.Scroll.HasValue) {
38
Widget
widget =
HitTestGlobal
(
Input
.Scroll.Value.XY);
39
if
(widget !=
null
40
&& widget.
IsChildWidgetOf
(
m_inventoryGrid
)) {
41
m_componentCreativeInventory.PageIndex -= (int)
Input
.Scroll.Value.Z;
42
}
43
}
44
if
(
m_creativeInventoryWidget
.PageDownButton.IsClicked) {
45
++
m_componentCreativeInventory
.PageIndex;
46
}
47
if
(
m_creativeInventoryWidget
.PageUpButton.IsClicked) {
48
--
m_componentCreativeInventory
.PageIndex;
49
}
50
m_componentCreativeInventory.PageIndex =
m_pagesCount
> 0
51
? Math.Clamp(
m_componentCreativeInventory
.PageIndex, 0,
m_pagesCount
- 1)
52
: 0;
53
}
54
if
(
m_componentCreativeInventory
.CategoryIndex !=
m_assignedCategoryIndex
) {
55
if
(
m_creativeInventoryWidget
.GetCategoryName(
m_componentCreativeInventory
.CategoryIndex)
56
==
LanguageControl
.
Get
(
"CreativeInventoryWidget"
, 2)) {
57
m_slotIndices
=
new
List<int>(Enumerable.Range(10,
m_componentCreativeInventory
.OpenSlotsCount - 10));
58
}
59
else
{
60
m_slotIndices
.Clear();
61
for
(
int
i =
m_componentCreativeInventory
.OpenSlotsCount; i <
m_componentCreativeInventory
.SlotsCount; i++) {
62
int
slotValue =
m_componentCreativeInventory
.GetSlotValue(i);
63
int
num2 =
Terrain
.
ExtractContents
(slotValue);
64
if
(
BlocksManager
.
Blocks
[num2].
GetCategory
(slotValue)
65
==
m_creativeInventoryWidget
.GetCategoryName(
m_componentCreativeInventory
.CategoryIndex)) {
66
m_slotIndices
.Add(i);
67
}
68
}
69
}
70
int
num3 = m_inventoryGrid.ColumnsCount *
m_inventoryGrid
.RowsCount;
71
m_pagesCount
= (m_slotIndices.Count + num3 - 1) / num3;
72
m_assignedCategoryIndex
=
m_componentCreativeInventory
.CategoryIndex;
73
m_assignedPageIndex
= -1;
74
m_componentCreativeInventory.PageIndex = 0;
75
}
76
if
(
m_componentCreativeInventory
.PageIndex !=
m_assignedPageIndex
) {
77
int
num4 = m_inventoryGrid.ColumnsCount *
m_inventoryGrid
.RowsCount;
78
int
num5 = m_componentCreativeInventory.PageIndex * num4;
79
foreach
(
Widget
child
in
m_inventoryGrid
.Children) {
80
if
(child is
InventorySlotWidget
inventorySlotWidget) {
81
if
(num5 <
m_slotIndices
.Count) {
82
inventorySlotWidget.AssignInventorySlot(
m_componentCreativeInventory
,
m_slotIndices
[num5++]);
83
}
84
else
{
85
inventorySlotWidget.AssignInventorySlot(
null
, 0);
86
}
87
}
88
}
89
m_assignedPageIndex
=
m_componentCreativeInventory
.PageIndex;
90
}
91
m_creativeInventoryWidget.PageLabel.Text =
m_pagesCount
> 0
92
? $
"{m_componentCreativeInventory.PageIndex + 1}/{m_pagesCount}"
93
:
string
.Empty;
94
m_creativeInventoryWidget.PageDownButton.IsEnabled = m_componentCreativeInventory.PageIndex <
m_pagesCount
- 1;
95
m_creativeInventoryWidget.PageUpButton.IsEnabled = m_componentCreativeInventory.PageIndex > 0;
96
}
97
}
98
}
Game.Block.GetCategory
virtual string GetCategory(int value)
定义
Block.cs:293
Game.BlocksManager
定义
BlocksManager.cs:10
Game.BlocksManager.Blocks
static Block[] Blocks
定义
BlocksManager.cs:41
Game.CanvasWidget
定义
CanvasWidget.cs:4
Game.ComponentCreativeInventory
定义
ComponentCreativeInventory.cs:7
Game.ContainerWidget.Children
readonly WidgetsList Children
定义
ContainerWidget.cs:5
Game.ContentManager
定义
ContentManager.cs:50
Game.ContentManager.Get
static object Get(Type type, string name)
定义
ContentManager.cs:70
Game.CreativeInventoryPanel.m_inventoryGrid
GridPanelWidget m_inventoryGrid
定义
CreativeInventoryPanel.cs:12
Game.CreativeInventoryPanel.m_assignedPageIndex
int m_assignedPageIndex
定义
CreativeInventoryPanel.cs:18
Game.CreativeInventoryPanel.Update
override void Update()
定义
CreativeInventoryPanel.cs:35
Game.CreativeInventoryPanel.m_slotIndices
List< int > m_slotIndices
定义
CreativeInventoryPanel.cs:10
Game.CreativeInventoryPanel.m_pagesCount
int m_pagesCount
定义
CreativeInventoryPanel.cs:14
Game.CreativeInventoryPanel.CreativeInventoryPanel
CreativeInventoryPanel(CreativeInventoryWidget creativeInventoryWidget)
定义
CreativeInventoryPanel.cs:20
Game.CreativeInventoryPanel.m_assignedCategoryIndex
int m_assignedCategoryIndex
定义
CreativeInventoryPanel.cs:16
Game.CreativeInventoryPanel.m_componentCreativeInventory
ComponentCreativeInventory m_componentCreativeInventory
定义
CreativeInventoryPanel.cs:8
Game.CreativeInventoryPanel.m_creativeInventoryWidget
CreativeInventoryWidget m_creativeInventoryWidget
定义
CreativeInventoryPanel.cs:6
Game.CreativeInventoryWidget
定义
CreativeInventoryWidget.cs:6
Game.CreativeInventoryWidget.Entity
Entity Entity
定义
CreativeInventoryWidget.cs:36
Game.GridPanelWidget
定义
GridPanelWidget.cs:4
Game.InventorySlotWidget
定义
InventorySlotWidget.cs:7
Game.LanguageControl
定义
LanguageControl.cs:8
Game.LanguageControl.Get
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
定义
LanguageControl.cs:247
Game.Terrain
定义
Terrain.cs:5
Game.Terrain.ExtractContents
static int ExtractContents(int value)
定义
Terrain.cs:303
Game.Widget
定义
Widget.cs:10
Game.Widget.HitTestGlobal
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
定义
Widget.cs:696
Game.Widget.Input
WidgetInput Input
定义
Widget.cs:296
Game.Widget.LoadContents
virtual void LoadContents(object eventsTarget, XElement node)
定义
Widget.cs:507
Game.Widget.IsChildWidgetOf
virtual bool IsChildWidgetOf(ContainerWidget containerWidget)
定义
Widget.cs:609
Engine
定义
BaseSound.cs:10
Game
定义
ContentFileBridge.cs:4
Engine.Point2
定义
Point2.cs:2
SurvivalcraftApi 1.8.2.3
Survivalcraft.Windows
Game
CreativeInventoryPanel.cs
制作者
1.16.1