protected override void OnMouseUp(MouseButtonEventArgs e) { var btnDown = e.Button == MouseButton.Left; if (!ClientRectangle.Contains(e.Position) && !btnDown) { _holding = null; return; } if (!btnDown || _holding == null) { return; } if (_trashEntity != null && _trashEntity.MouseOver) { _elementEntities.Remove(_holding); } if (GetTopElementAtPoint(new PointF(_holding.X, _holding.Y), _holding) is ElementEntity ee) { var products = ElementRegistry.GetProducts(ee.Element, _holding.Element); var max = ElementEntity.ElementIconSize / 2; foreach (var product in products) { if (product == null) { continue; } var middleX = (_holding.X + ee.X) / 2; var middleY = (_holding.Y + ee.Y) / 2; _elementEntities.Remove(_holding); _elementEntities.Remove(ee); middleX += max - (float)_rand.NextDouble() * max * 2; middleY += max - (float)_rand.NextDouble() * max * 2; LearnElement(product); SpawnElementEntity(middleX, middleY, product); } if (products.Length > 0) { if (_learntElements.Count == ElementRegistry.GetTotalCount()) { _toastQueue.Add(new AchievementToast("That's it!", "You know everything!", TextureManager.GetOrRegister("obsidian"), this)); } } } _holding = null; }
private void AddBaseElements(Point p = new Point()) { var radius = ElementEntity.ElementIconSize; var baseElements = ElementRegistry.GetBaseElements(); for (int i = 0; i < baseElements.Length; i++) { var element = baseElements[i]; var progress = (float)i / baseElements.Length; var x = (float)Math.Cos(progress * MathHelper.TwoPi + MathHelper.PiOver4) * radius; var y = (float)Math.Sin(progress * MathHelper.TwoPi + MathHelper.PiOver4) * radius; SpawnElementEntity(p.X - x, p.Y - y, element); } }
protected override void OnRenderFrame(FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); var partialTicks = (float)(_updateTimer.Elapsed.TotalMilliseconds / (TargetUpdatePeriod * 1000f)); _trashEntity?.SetShown(_holding != null && _trashEntity.MouseOverDestination && !_inventoryGui.IsShown()); _trashEntity?.Render(partialTicks); for (var index = 0; index < _elementEntities.Count; index++) { var entity = _elementEntities[index]; if (entity != _holding) { entity?.Render(partialTicks); } } _holding?.Render(partialTicks); var offsetY = 0f; if (_toastQueue.Count > 0) { var toast = _toastQueue.First(); if (toast != null) { toast.Render(partialTicks); offsetY = toast.CurrentY; } } var baseCount = ElementRegistry.GetBaseElements().Length; FontRenderer.DrawTextCentered(Width / 2f, 16 - offsetY, $"DISCOVERED {_learntElements.Count - baseCount}/{ElementRegistry.GetTotalCount() - baseCount}"); _inventoryGui?.SetShown(_holding == null && (_inventoryGui.MouseOverTrigger || _inventoryGui.IsShown() && _inventoryGui.MouseOverRectangle)); _inventoryGui?.Render(partialTicks); SwapBuffers(); }
private void LoadElementsFromFile() { var file = "Elements.json"; if (!File.Exists(file)) { var obj = new CustomElementJson(new[] { new ElementNode("Water", "water", true), new ElementNode("Fire", "fire", true), new ElementNode("Air", "air", true), new ElementNode("Earth", "earth", true), new ElementNode("Steam", "steam"), new ElementNode("Mud", "mud"), new ElementNode("Dust", "dust"), new ElementNode("Sand", "sand"), new ElementNode("Glass", "glass"), new ElementNode("Obsidian", "obsidian"), new ElementNode("Lava", "lava") }, new[] { new ElementCombinationNode("Fire", "Earth", "Lava"), new ElementCombinationNode("Fire", "Sand", "Glass"), new ElementCombinationNode("Fire", "Water", "Steam", "Steam"), new ElementCombinationNode("Water", "Earth", "Mud"), new ElementCombinationNode("Water", "Lava", "Obsidian"), new ElementCombinationNode("Earth", "Air", "Dust"), new ElementCombinationNode("Dust", "Dust", "Sand") }); var jsonString = JsonConvert.SerializeObject(obj, Formatting.Indented); File.WriteAllText(file, jsonString); } var json = File.ReadAllText(file); var cej = JsonConvert.DeserializeObject <CustomElementJson>(json); foreach (var element in cej.Elements) { var e = new Element(element.Name, element.TextureName, element.IsBaseElement); ElementRegistry.RegisterElement(e); if (element.IsBaseElement) { _learntElements.Add(e); } } foreach (var combination in cej.ElementCombinations) { var e1 = ElementRegistry.GetElement(combination.Element1); var e2 = ElementRegistry.GetElement(combination.Element2); var products = new Element[combination.Products.Length]; for (var index = 0; index < combination.Products.Length; index++) { products[index] = ElementRegistry.GetElement(combination.Products[index]); } ElementRegistry.RegisterCombination(e1, e2, products); } }