Skip to content

Commit

Permalink
修复帮助包识别旋转后复杂方块错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaofengdiZhu committed Nov 29, 2023
1 parent 7f8d385 commit 1a7a281
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<GVHelperInventorySlotWidget xmlns="runtime-namespace:Game" Size="72, 72" HorizontalAlignment="Far">
<BevelledRectangleWidget BevelSize="-2" DirectionalLight="0.15" CenterColor="181, 172, 154"/>
<RectangleWidget FillColor="192, 192, 192" OutlineColor="0, 0, 0, 0" Size="56, 56" VerticalAlignment="Center" HorizontalAlignment="Center" Subtexture="{Textures/Atlas/HelpTopicIcon}"/>
<GVHelperInventorySlotWidget xmlns="runtime-namespace:Game" Size="44, 72" HorizontalAlignment="Far">
<BevelledRectangleWidget BevelSize="-2" DirectionalLight="0.15" BevelColor="109, 103, 92, 153" CenterColor="60, 57, 51, 76"/>
<RectangleWidget FillColor="216, 216, 216" OutlineColor="0, 0, 0, 0" Size="36, 36" VerticalAlignment="Center" HorizontalAlignment="Center" Subtexture="{Textures/Atlas/HelpTopicIcon}"/>
<ClickableWidget Name="GVHelperInventorySlotWidget.Clickable" SoundName="Audio/UI/ButtonClick"/>
</GVHelperInventorySlotWidget>
15 changes: 12 additions & 3 deletions Gigavolt.Helper/ComponentGVHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class ComponentGVHelper : Component, IUpdateable {
public ComponentPlayer m_componentPlayer;
public ComponentGui m_componentGui;
public ComponentBlockHighlight m_componentBlockHighlight;

public GVHelperInventorySlotWidget m_GVHelperInventorySlotWidget;
public StackPanelWidget m_shortInventoryPanel;

public bool m_slotAdded;
public UpdateOrder UpdateOrder => UpdateOrder.Default;

Expand All @@ -18,22 +21,28 @@ public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToE
m_componentGui = Entity.FindComponent<ComponentGui>(true);
m_componentBlockHighlight = Entity.FindComponent<ComponentBlockHighlight>(true);
m_GVHelperInventorySlotWidget = new GVHelperInventorySlotWidget(m_componentBlockHighlight);
m_shortInventoryPanel = new StackPanelWidget { Direction = LayoutDirection.Horizontal };
m_componentGui.ShortInventoryWidget.AddChildren(m_shortInventoryPanel);
GridPanelWidget temp = m_componentGui.ShortInventoryWidget.Children.Find<GridPanelWidget>("InventoryGrid");
m_componentGui.ShortInventoryWidget.RemoveChildren(temp);
m_shortInventoryPanel.AddChildren(temp);
temp.ChangeParent(m_shortInventoryPanel);
if (GVStaticStorage.GVHelperSlotActive) {
m_componentGui.ShortInventoryWidget.AddChildren(m_GVHelperInventorySlotWidget);
m_shortInventoryPanel.AddChildren(m_GVHelperInventorySlotWidget);
m_slotAdded = true;
}
}

public void Update(float dt) {
if (GVStaticStorage.GVHelperSlotActive) {
if (!m_slotAdded) {
m_componentGui.ShortInventoryWidget.AddChildren(m_GVHelperInventorySlotWidget);
m_shortInventoryPanel.AddChildren(m_GVHelperInventorySlotWidget);
m_slotAdded = true;
}
}
else {
if (m_slotAdded) {
m_componentGui.ShortInventoryWidget.RemoveChildren(m_GVHelperInventorySlotWidget);
m_shortInventoryPanel.RemoveChildren(m_GVHelperInventorySlotWidget);
m_slotAdded = false;
}
}
Expand Down
37 changes: 33 additions & 4 deletions Gigavolt.Helper/StaticGVHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Game {
Expand All @@ -21,18 +22,46 @@ public static class StaticGVHelper {
{ GVJavascriptMicrocontrollerBlock.Index, new[] { "js单片机-javascript-microcontroller", "GVJavascriptMicrocontrollerBlock" } }
};

public static readonly Dictionary<int, Func<int, int>> BlockIndex2DataHandler = new() {
{ GVWireBlock.Index, blockData => GVWireBlock.SetColor(0, GVWireBlock.GetColor(blockData)) },
{ GVLedBlock.Index, blockData => GVLedBlock.SetColor(0, GVLedBlock.GetColor(blockData)) },
{ GVFourLedBlock.Index, blockData => GVFourLedBlock.SetColor(0, GVFourLedBlock.GetColor(blockData)) },
{ GVSevenSegmentDisplayBlock.Index, blockData => GVSevenSegmentDisplayBlock.SetColor(0, GVSevenSegmentDisplayBlock.GetColor(blockData)) },
{ GVAnalogToDigitalConverterBlock.Index, blockData => GVAnalogToDigitalConverterBlock.SetType(0, GVAnalogToDigitalConverterBlock.GetType(blockData)) },
{ GVDigitalToAnalogConverterBlock.Index, blockData => GVDigitalToAnalogConverterBlock.SetType(0, GVDigitalToAnalogConverterBlock.GetType(blockData)) },
{ GVPistonBlock.Index, blockData => GVPistonBlock.SetMode(0, GVPistonBlock.GetMode(blockData)) },
{ GV8x4LedBlock.Index, blockData => GV8x4LedBlock.SetType(0, GV8x4LedBlock.GetType(blockData)) },
{ GVDoorBlock.Index, blockData => GVDoorBlock.SetModel(0, GVDoorBlock.GetModel(blockData)) },
{ GVTrapdoorBlock.Index, blockData => GVTrapdoorBlock.SetModel(0, GVTrapdoorBlock.GetModel(blockData)) },
{ GVFenceGateBlock.Index, blockData => GVFenceGateBlock.SetModel(GVFenceGateBlock.SetColor(0, GVFenceGateBlock.GetColor(blockData)), GVFenceGateBlock.GetModel(blockData)) },
{ GVDisplayLedBlock.Index, blockData => GVDisplayLedBlock.SetComplex(GVDisplayLedBlock.SetType(0, GVDisplayLedBlock.GetType(blockData)), GVDisplayLedBlock.GetComplex(blockData)) },
{ GVMoreTwoInTwoOutBlock.Index, blockData => GVMoreTwoInTwoOutBlock.SetType(0, GVMoreTwoInTwoOutBlock.GetType(blockData)) },
{ GVMoreOneInOneOutBlock.Index, blockData => GVMoreOneInOneOutBlock.SetType(0, GVMoreOneInOneOutBlock.GetType(blockData)) },
{ GVInventoryFetcherBlock.Index, blockData => GVInventoryFetcherBlock.SetType(0, GVInventoryFetcherBlock.GetType(blockData)) },
{ GVEWireThroughBlock.Index, blockData => GVEWireThroughBlock.SetType(0, GVEWireThroughBlock.GetType(blockData)) },
{ GVPressurePlateBlock.Index, blockData => GVPressurePlateBlock.SetMaterial(0, GVPressurePlateBlock.GetMaterial(blockData)) },
{ GVPressurePlateCBlock.Index, blockData => GVPressurePlateCBlock.SetMaterial(0, GVPressurePlateCBlock.GetMaterial(blockData)) },
{ GVLightbulbBlock.Index, blockData => GVLightbulbBlock.SetColor(0, GVLightbulbBlock.GetColor(blockData)) },
{ GVWoodenPostedSignCBlock.Index, blockData => GVPostedSignCBlock.SetColor(0, GVPostedSignCBlock.GetColor(blockData)) },
{ GVIronPostedSignCBlock.Index, blockData => GVPostedSignCBlock.SetColor(0, GVPostedSignCBlock.GetColor(blockData)) }
};

public static void GotoBlockDescriptionScreen(int blockValue) {
int blockContent = Terrain.ExtractContents(blockValue);
if (BlockIndex2HelperInfo.TryGetValue(blockContent, out string[] value)) {
GotoGVHelpScreen(value[0], value[1]);
}
else {
int id = blockContent;
int newBlockValue = blockContent;
int blockData = Terrain.ExtractData(blockValue);
Block block = BlocksManager.Blocks[blockContent];
if (block.GetCreativeValues().Contains(blockValue)) {
id = blockValue;
newBlockValue = blockValue;
}
else if (BlockIndex2DataHandler.TryGetValue(blockContent, out Func<int, int> blockIndex2DataHandler)) {
newBlockValue = Terrain.MakeBlockValue(blockContent, 0, blockIndex2DataHandler(blockData));
}
ScreensManager.SwitchScreen("RecipaediaDescription", id, new List<int> { id });
ScreensManager.SwitchScreen("RecipaediaDescription", newBlockValue, new List<int> { newBlockValue });
}
}

Expand Down
2 changes: 1 addition & 1 deletion Gigavolt/Assets/Lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
"DisplayName": "GV活板门",
"Description": "活板门可用来搭建建筑物的垂直入口。单击可以打开和关闭它们。连接到铜线时,活板门将根据电压强度打开或部分打开,0V关门,0x2D V打开45度,0x5A V及以上完全打开。连上电路后时,铁质活板门无法手动操作。它们可以正常放置,也可以上下放置,具体取决于它们是安装在方块的顶部还是底部。颠倒的活板门将阻止掉落的障碍物。"
},
"IronFenceGateBlock:0": {
"GVFenceGateBlock:0": {
"DisplayName": "GV栅栏门",
"Description": "栅栏门用于通往围栏区域。单击它们可以打开和关闭它们。当连接到铜线上时,栅栏门将根据电压强度打开或部分打开,0V关门,0x2D V打开45度,0x5A V及以上完全打开。动物不能跳过栅栏门。可以染色。"
},
Expand Down

0 comments on commit 1a7a281

Please sign in to comment.