private void UpdateSideCommandbar(Player player) { var sideCommandBar = _root.ScriptObject.GetMember("SideCommandBar").ToObject(); if (player.SelectedUnits.Count > 0) { if (!_commandbarVisible) { var fadeIn = sideCommandBar.Item.ScriptObject.GetMember("FadeIn"); if (fadeIn.Type != ValueType.Undefined) { var emptyArgs = new List <Value>(); FunctionCommon.ExecuteFunction(fadeIn, emptyArgs.ToArray(), sideCommandBar.Item.ScriptObject, _window.Context.Avm); _commandbarVisible = true; } } } else if (player.SelectedUnits.Count == 0 && _commandbarVisible) { var fadeOut = sideCommandBar.Item.ScriptObject.GetMember("FadeOut"); if (fadeOut.Type != ValueType.Undefined) { var emptyArgs = new List <Value>(); FunctionCommon.ExecuteFunction(fadeOut, emptyArgs.ToArray(), sideCommandBar.Item.ScriptObject, _window.Context.Avm); _commandbarVisible = true; } _commandbarVisible = false; } }
private void InitializePalantir(Player player) { if (!_palantirInitialized) { logger.Info("Initialize Palantir!"); var showCommandInterface = _root.ScriptObject.GetMember("SetPalantirFrameState"); if (showCommandInterface.Type != ValueType.Undefined) { bool good = Array.Exists(player.Template.IntrinsicSciences, s => s == "SCIENCE_GOOD"); List <Value> emptyArgs = new List <Value>(); emptyArgs.Add(Value.FromString(good ? "_good" : "_evil")); FunctionCommon.ExecuteFunction(showCommandInterface, emptyArgs.ToArray(), _root.ScriptObject, _window.Context.Avm); _palantirInitialized = true; } } }
private void UpdateCommandbuttons() { if (_game.Scene3D.LocalPlayer.SelectedUnits.Count == 0) { return; } var selectedUnit = _game.Scene3D.LocalPlayer.SelectedUnits.First(); if (selectedUnit == null) { return; } if (selectedUnit.Definition.CommandSet == null || selectedUnit.Definition.CommandSet.Value == null) { return; } var isProducing = selectedUnit.ProductionUpdate?.IsProducing ?? false; var commandSet = selectedUnit.Definition.CommandSet.Value; var aptCommandButtons = _root.ScriptObject.GetMember("CommandButtons").ToObject(); for (var i = 1; i <= 6; i++) { var commandButton = aptCommandButtons.GetMember((i - 1).ToString()).ToObject(); var placeHolder = commandButton.GetMember("placeholder").ToObject(); placeHolder.Item.Visible = false; if (!commandSet.Buttons.ContainsKey(i)) { continue; } var button = commandSet.Buttons[i].Value; if (!button.InPalantir || button.Command == CommandType.Revive) { continue; } var createContent = commandButton.GetMember("CreateContent"); var args = new List <Value>(); args.Add(Value.FromString("bttn")); args.Add(Value.FromString("CommandButton")); //TODO: fix so this works FunctionCommon.ExecuteFunction(createContent, args.ToArray(), commandButton.Item.ScriptObject, _window.Context.Avm); placeHolder.Item.Visible = true; var shape = (placeHolder.Item as SpriteItem).Content.Items[1] as RenderItem; var(count, progress) = isProducing ? selectedUnit.ProductionUpdate.GetCountAndProgress(button) : (0, 0.0f); var texture = button.ButtonImage.Value; shape.RenderCallback = (AptRenderingContext renderContext, Geometry geom, Texture orig) => { var enabled = selectedUnit.CanPurchase(button); var rect = new Rectangle(renderContext.GetBoundingBox(geom)).ToRectangleF(); renderContext.GetActiveDrawingContext().DrawMappedImage(texture, rect, grayscaled: !enabled); if (count > 0) { renderContext.GetActiveDrawingContext().FillRectangleRadial360( new Rectangle(rect), new ColorRgbaF(1.0f, 1.0f, 1.0f, 0.6f), progress); if (count > 1) { var textRect = new Rectangle(RectangleF.Transform(rect, Matrix3x2.CreateTranslation(new Vector2(0, rect.Width / 4)))); renderContext.GetActiveDrawingContext().DrawText(count.ToString(), _font, TextAlignment.Center, _fontColor, textRect); } } }; } }