public void AfterEdit(MapperType mapper) { // We cannot use undo system for PIOs, because they are dymanic // trying to save them will result in exception on 'undo' while // getting mapper type inside OnEditField if (mapper is MCustom <string> ) { BlockMapper.OnEditField(BlockBehaviour, mapper); } else { Player localPlayer = Player.GetLocalPlayer(); if (localPlayer == null || localPlayer.IsHost) { return; } var tempdata = new XDataHolder(); BlockBehaviour.OnSave(tempdata); tempdata.Encode(out byte[] dataBytes); var message = ModContext.CpuInfoMessage.CreateMessage( this.BlockBehaviour, dataBytes ); ModNetworking.SendToHost(message); } }
public override void BuildingUpdate() { if (Input.GetMouseButton(0) && !InputManager.ToggleSimulationKey()) { return; } if (BlockMapper.CurrentInstance) { return; } bool close = false; if (missingSizeSave) { missingSizeSave = false; BlockMapper.OnEditField(Behaviour, size); close = true; } if (missingCorrSave) { missingCorrSave = false; BlockMapper.OnEditField(Behaviour, correction); close = true; } if (close) { BlockMapper.Close(); } }
void Start() { BlockMapper newBlock = new BlockMapper(); newBlock.blockObject = this.gameObject; newBlock.position = new Vector2(transform.position.x, transform.position.y); DrawMap.instance.blocksMapper.Add(newBlock); }
public override void SafeAwake() { Key1 = AddKey("Spawn block", //按键信息 "Spawn", //名字 KeyCode.V); //默认按键 List <string> list = new List <string>(); foreach (var pair in PrefabMaster.BlockPrefabs) { list.Add(pair.Value.name); } 模块ID = AddMenu("Block", 0, list); 模块ID.ValueChanged += (v) => { blockModified = true; }; modifyBlock = AddToggle("Modify Spawned Block", "modifySpawnedBlock", false); modifyBlock.Toggled += (b) => { if (b) { if (blockModified) { SpawnChild(); } modifyBlock.IsActive = false; BlockMapper.Open(blockToSpawn); } }; 生成间隔 = AddSlider("Spawn Frequency", //滑条信息 "Freq", //名字 0.25f, //默认值 0f, //最小值 10f); //最大值 生成大小 = AddSlider("Block Scale", //滑条信息 "Scale", //名字 1f, //默认值 0.01f, //最小值 100f); //最大值 继承速度 = AddToggle("Inherit My Velocity", //toggle信息 "IMV", //名字 true); //默认状态 FunnyMode = AddToggle("Funny Mode", //toggle信息 "FMD", //名字 false); //默认状态 FunnyMode.Toggled += (t) => { blockModified = true; modifyBlock.DisplayInMapper = !t; }; }
public virtual void SetCentering(float value) { correction.SetValue(value); if (Input.GetMouseButton(0) && !IsSimulating && !InputManager.ToggleSimulationKey()) { missingCorrSave = true; return; } missingCorrSave = false; BlockMapper.OnEditField(Behaviour, correction); fakeOpen = true; }
public virtual void SetSize(float value) { size.SetValue(value); if (Input.GetMouseButton(0) && !IsSimulating && !InputManager.ToggleSimulationKey()) { missingSizeSave = true; return; } missingSizeSave = false; BlockMapper.OnEditField(Behaviour, size); fakeOpen = true; }
void OnDestroy() { BlockMapper thisBlockMap = DrawMap.instance.blocksMapper.Find(x => x.blockObject == this.gameObject); DrawMap.instance.blocksMapper.Remove(thisBlockMap); AutoSetBlock AutoSetBlock = GetComponent <AutoSetBlock>(); AutoStickWall AutoStickWall = GetComponent <AutoStickWall>(); if (AutoSetBlock != null) { AutoSetBlock.UpdateOthers(); } }
protected override void BuildingUpdate() { foreach (var action in actions) { action.Update(); } if (configuring) { if (BlockMapper.CurrentInstance != null) { BlockMapper.Close(); AddPiece.keyMapMode = true; } } }
void RotateWallStickers() { Vector3 touchpoint = CommonMethods.GetTouchPoint(); Vector3 snappedTouchPoint = CommonMethods.GetSnappedPoint(touchpoint); BlockMapper block = CheckListForPosition(snappedTouchPoint); if (block != null && mapAssets[selectedBlock].prefab != null) { if (block.blockObject.GetComponent <BlockTypeManager>().blockType == mapAssets[selectedBlock].prefab.GetComponent <BlockTypeManager>().blockType) { AutoStickWall autoStickWall = block.blockObject.GetComponent <AutoStickWall>(); if (autoStickWall != null) { autoStickWall.SetSprites(); } } } }
private void DoneMapperUpdate() { if (InputManager.LeftMouseButton() || InputManager.LeftMouseButtonHeld()) { return; } if (!rangeChanging && !radiusChanging) { return; } if (BlockMapper.CurrentInstance != null) { BlockMapper.Open(BlockMapper.CurrentInstance.Block); } rangeChanging = false; radiusChanging = false; }
protected virtual void Toggled(bool active) { configuring = active; var keyMapModeButton = FindObjectOfType <KeyMapModeButton>(); if (active) { keyMapModeButton?.KeyMapOff(); Game.AddPiece.hudOccluding = true; AddPiece.keyMapMode = true; } else { keyMapModeButton?.KeyMapOn(); Game.AddPiece.hudOccluding = false; BlockMapper.Open(this); } }
public void CheckUpdate() { allAngles = new List <float>(); BlockMapper block = new BlockMapper(); BlockTypeManager blockTypeManager; for (int i = 0; i < DrawMap.instance.directionList.Length; i++) { block = DrawMap.instance.CheckListForPosition(transform.position + DrawMap.instance.directionList[i]); if (block != null) { blockTypeManager = block.blockObject.GetComponent <BlockTypeManager>(); if (stickWith.Contains(blockTypeManager.blockType)) { allAngles.Add(angleList[i]); } } } SetSprites(); }
public void SetSprites() { if (allAngles.Count != 0) { if (rotationIdx >= allAngles.Count) { rotationIdx = 0; } transform.GetChild(0).rotation = Quaternion.Euler(new Vector3(transform.GetChild(0).rotation.eulerAngles.x, transform.GetChild(0).rotation.eulerAngles.y, allAngles[rotationIdx])); rotationIdx++; if (rotationIdx >= allAngles.Count) { rotationIdx = 0; } } else { BlockMapper block = DrawMap.instance.CheckListForPosition(transform.position); Destroy(block.blockObject); DrawMap.instance.blocksMapper.Remove(block); } }
void DrawBlocks() { Vector3 touchpoint = CommonMethods.GetTouchPoint(); Vector3 snappedTouchPoint = CommonMethods.GetSnappedPoint(touchpoint); BlockMapper block = CheckListForPosition(snappedTouchPoint); if (mapAssets[selectedBlock].prefab == null && block != null) { Destroy(block.blockObject); } else if (block == null && mapAssets[selectedBlock].prefab != null) { Instantiate(mapAssets[selectedBlock].prefab, snappedTouchPoint, Quaternion.identity); } else if (block != null) { if (block.blockObject.GetComponent <ButtonReference>() != null) { ModeManager.insatance.buttonReference = block.blockObject.GetComponent <ButtonReference>(); ModeManager.insatance.SetButtonReferenceMode(true); } } }
public virtual void UpdateAllPortalDevicesCentering(float value) { if (updatingDevices) { return; } updatingDevices = true; Correction = value; foreach (var device in PortalDevices) { if (device == this) { continue; } device.SetCentering(value); } if (fakeOpen) { BlockMapper.Open(Behaviour); fakeOpen = false; } updatingDevices = false; }
public bool Asynchronous => true; //ActiveResourcePacks.All(x => x.Asynchronous); public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback) { LoadHWID(); PreloadCallback = preloadCallback; Log.Info($"Loading registries..."); progressReceiver?.UpdateProgress(0, "Loading registries..."); Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json")); progressReceiver?.UpdateProgress(100, "Loading registries..."); string defaultResources; string defaultBedrock; if (!CheckJavaAssets(progressReceiver, out defaultResources)) { return(false); } if (!CheckBedrockAssets(progressReceiver, out defaultBedrock)) { return(false); } progressReceiver?.UpdateProgress(0, "Loading vanilla resources..."); var vanilla = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultResources), preloadCallback); if (vanilla.Info != null) { vanilla.Info.Name = "Vanilla"; } ActiveResourcePacks.AddFirst((McResourcePack)vanilla); Alex.AudioEngine.Initialize((McResourcePack)vanilla); // Log.Info($"Loading bedrock resources..."); progressReceiver?.UpdateProgress(0, "Loading bedrock resources..."); var vanillaBedrock = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultBedrock)); ActiveBedrockResourcePacks.AddFirst((BedrockResourcePack)vanillaBedrock); //Log.Info($"Loading known entity data..."); Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root); ResourcePackDirectory = root; LoadRegistries(progressReceiver); LoadResourcePacks( device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value); EntityFactory.Load(this, progressReceiver); ItemFactory.Init(RegistryManager, this, progressReceiver); BlockEntityFactory.LoadResources(device, this); if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info)) { SkinPackDirectory = info; LoadBedrockPacks(progressReceiver, info); } else { if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks"))) { if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo)) { SkinPackDirectory = dirInfo; } } } BlockMapper.Init(progressReceiver); Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged); _hasInit = true; var data = ReadResource("Alex.Resources.nethergames.png"); NethergamesLogo = TextureUtils.BitmapToTexture2D(Alex.GraphicsDevice, Image.Load(data)); return(true); }
public void Update() { if (BlockMapper.IsOpen) { this.refresh |= BlockMapper.CurrentInstance != this.blockMapper; if (this.refresh) { this.blockMapper = BlockMapper.CurrentInstance; this.refresh &= this.blockMapper.IsBlock; if (this.refresh) { this.block = this.blockMapper.Block; this.blockCount = PlayerMachine.GetLocal().GetBlocksOfType((int)this.block.Prefab.Type).Count; this.refresh &= this.machineInspector.regulation.ChildBlockRestriction.TryGetValue((int)this.block.Prefab.Type, out BlockRestriction blockRestriction); if (this.refresh) { this.selectors = this.blockMapper.GetComponentsInChildren <SliderSelector>(); this.holders = this.blockMapper.GetComponentsInChildren <SliderHolder>(); switch (this.block.Prefab.Type) { case BlockType.Cannon: this.min = blockRestriction.minPower; this.max = blockRestriction.maxPowers[this.blockCount - 1]; this.sliderSelector = this.selectors[0]; this.sliderHolder = this.holders[0]; break; case BlockType.ShrapnelCannon: case BlockType.WaterCannon: this.min = blockRestriction.minPower; this.max = blockRestriction.maxPowers[0]; this.sliderSelector = this.selectors[0]; this.sliderHolder = this.holders[0]; break; case BlockType.CogMediumPowered: case BlockType.Wheel: case BlockType.LargeWheel: this.min = blockRestriction.minPower; this.max = blockRestriction.maxPowers[0]; this.sliderSelector = this.selectors[0]; this.sliderHolder = this.holders[0]; break; case BlockType.Rocket: this.min = blockRestriction.minPower; this.max = blockRestriction.maxPowers[0]; this.sliderSelector = this.selectors[1]; this.sliderHolder = this.holders[1]; break; default: return; } this.mSlider = this.sliderSelector.Slider; this.sliderName = this.mSlider.DisplayName; this.key = this.mSlider.Key; this.value = this.mSlider.Value; if (this.blockCount <= blockRestriction.maxNum && this.blockCount > 0) { this.sliderSelector.Slider = new MSlider(this.sliderName, this.key, this.value, this.min, this.max, null, null, true, false); this.sliderSelector.Value = value; this.sliderHolder.SetValue(value); } } } } this.refresh = false; } }
public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback) { LoadHWID(); PreloadCallback = preloadCallback; Log.Info($"Loading registries..."); progressReceiver?.UpdateProgress(0, "Loading registries..."); Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json")); progressReceiver?.UpdateProgress(100, "Loading registries..."); string defaultResources; string defaultBedrock; if (!CheckJavaAssets(progressReceiver, out defaultResources)) { return(false); } if (!CheckBedrockAssets(progressReceiver, out defaultBedrock)) { return(false); } progressReceiver?.UpdateProgress(0, "Loading vanilla resources..."); var vanilla = LoadResourcePack(progressReceiver, new RealFileSystem(defaultResources), preloadCallback); vanilla.Manifest.Name = "Vanilla"; ActiveResourcePacks.AddFirst(vanilla); Alex.AudioEngine.Initialize(vanilla); // Log.Info($"Loading bedrock resources..."); progressReceiver?.UpdateProgress(0, "Loading bedrock resources..."); using (RealFileSystem fileSystem = new RealFileSystem(defaultBedrock)) { BedrockResourcePack = new BedrockResourcePack( fileSystem, (percentage, file) => { progressReceiver?.UpdateProgress(percentage, null, file); }); int modelCount = EntityFactory.LoadModels(BedrockResourcePack, device, true, progressReceiver); Log.Info($"Imported {modelCount} entity models..."); } //Log.Info($"Loading known entity data..."); EntityFactory.Load(this, progressReceiver); Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root); ResourcePackDirectory = root; LoadRegistries(progressReceiver); LoadResourcePacks( device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value); ItemFactory.Init(RegistryManager, this, ResourcePack, progressReceiver); BlockEntityFactory.LoadResources(device, ResourcePack); if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info)) { SkinPackDirectory = info; LoadBedrockPacks(progressReceiver, info); } else { if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks"))) { if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo)) { SkinPackDirectory = dirInfo; } } } BlockMapper.Init(progressReceiver); Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged); _hasInit = true; return(true); }
private void Update() { if (!Game.AddPiece) { return; } if (increaseTime.Pressed()) { TimeSliderObject sliderObj = FindObjectOfType <TimeSliderObject>(); TimeSlider slider = FindObjectOfType <TimeSlider>(); sliderObj.SetPercentage( Mathf.Clamp01((slider.delegateTimeScale + 0.1f) / 2f)); } if (decreaseTime.Pressed()) { TimeSliderObject sliderObj = FindObjectOfType <TimeSliderObject>(); TimeSlider slider = FindObjectOfType <TimeSlider>(); sliderObj.SetPercentage( Mathf.Clamp01((slider.delegateTimeScale - 0.1f) / 2f)); } if (timeTo100.Pressed()) { FindObjectOfType <TimeSliderObject>().SetPercentage(0.5f); } if (timeTo0.Pressed()) { FindObjectOfType <TimeSliderObject>().SetPercentage(0.0f); } if (Game.IsSimulating) { return; } //Debug code helpful for filling out blockIndices table #if DEBUG if (Input.GetKeyDown(KeyCode.N)) { var buttons = tabController.tabs[tabController.activeTab] .GetComponent <BlockMenuControl>().buttons; for (int i = 0; i < buttons.Length; i++) { Debug.Log("buttons[" + i + "] = " + buttons[i]); } } #endif if (pipette.Pressed()) { RaycastHit hit; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { var myName = hit.transform.GetComponent <MyBlockInfo>().blockName; for (int i = 0; i < PrefabMaster.BlockPrefabs.Count; i++) { var type = PrefabMaster.BlockPrefabs[i].gameObject; if ((type.GetComponent <MyBlockInfo>() && type.GetComponent <MyBlockInfo>().blockName == myName) || (type.GetComponentInChildren <MyBlockInfo>() && type.GetComponentInChildren <MyBlockInfo>().blockName == myName)) { StartCoroutine(ExecuteWithDisabledGhost(() => { Game.AddPiece.SetBlockType(i); })); break; } } } } if (openSettings.Pressed()) { RaycastHit hit; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { var block = hit.transform.gameObject.GetComponent <BlockBehaviour>(); FindObjectOfType <KeyMapModeButton>().KeyMapOn(); BlockSelect(block); BlockMapper.Open(block); } } if (nextTab.Pressed()) { currentTab = InternalToOrderedTabIndex(tabController.activeTab); tabController.OpenTab(tabIndices[mod(++currentTab, tabIndices.Length)]); } if (previousTab.Pressed()) { currentTab = InternalToOrderedTabIndex(tabController.activeTab); tabController.OpenTab(tabIndices[mod(--currentTab, tabIndices.Length)]); } // Don't react to block shortcuts when block settings are open to prevent // typing a slider value changing what block is selected if (BlockMapper.CurrentInstance == null) { for (int i = 0; i < 9; i++) { if (blockKeys[i].Pressed()) { var index = blockIndices[ InternalToOrderedTabIndex(tabController.activeTab)][i]; if (index != -1) { StartCoroutine(ExecuteWithDisabledGhost(() => { tabController.tabs[tabController.activeTab] .GetComponent <BlockMenuControl>() .buttons[index].Set(); })); } } } } for (int i = 0; i < 7; i++) { if (tabKeys[i].Pressed()) { tabController.OpenTab(tabIndices[i]); } } }