示例#1
0
        public override void AddToPainter()
        {
            base.AddToPainter();

            player = new SmackerPlayer((Stream)mpq.GetResource(resourcePath));

            player.Finished += PlayerFinished;

            movieElement.Player = player;

            movieElement.Play();

            if (player.Width != 640 ||         /*Painter.Width*/
                player.Height != 480 /*Painter.Height*/)
            {
                float horiz_zoom = (float)640 /*Painter.Width*/ / player.Width;
                float vert_zoom  = (float)480 /*Painter.Height*/ / player.Height;
                float zoom;

                if (horiz_zoom < vert_zoom)
                {
                    zoom = horiz_zoom;
                }
                else
                {
                    zoom = vert_zoom;
                }

                AffineTransform = CGAffineTransform.MakeScale(zoom, zoom);
            }

            movieElement.Layer.AnchorPoint = new PointF(0, 0);
            AddSublayer(movieElement.Layer);
        }
示例#2
0
        public override void MouseButtonDown(MouseButtonEventArgs args)
        {
            if (mouseOverElement != null)
            {
                base.MouseButtonDown(args);
            }
            else if (args.X > MINIMAP_X && args.X < MINIMAP_X + MINIMAP_WIDTH &&
                     args.Y > MINIMAP_Y && args.Y < MINIMAP_Y + MINIMAP_HEIGHT)
            {
                RecenterFromMinimap(args.X, args.Y);
                buttonDownInMinimap = true;
            }
            else
            {
                if (selectedUnit != unitUnderCursor)
                {
                    Console.WriteLine("hey there, keyboard.modifierkeystate = {0}", Keyboard.ModifierKeyState);

                    // if we have a selected unit and we
                    // right click (or ctrl-click?), try
                    // to move there
                    if (selectedUnit != null && (Keyboard.ModifierKeyState & ModifierKeys.ShiftKeys) != 0)
                    {
                        Console.WriteLine("And... we're walking");

                        int pixel_x = args.X + topleft_x;
                        int pixel_y = args.Y + topleft_y;

                        // calculate the megatile
                        int megatile_x = pixel_x >> 5;
                        int megatile_y = pixel_y >> 5;

                        Console.WriteLine("megatile {0},{1}", megatile_x, megatile_y);

                        // the mini tile
                        int minitile_x = pixel_x >> 2;
                        int minitile_y = pixel_y >> 2;

                        Console.WriteLine("minitile {0},{1} ({2},{3} in the megatile)",
                                          minitile_x, minitile_y,
                                          minitile_x - megatile_x * 8,
                                          minitile_y - megatile_y * 8);

                        if (selectedUnit.YesSound != null)
                        {
                            string sound_resource = String.Format("sound\\{0}", selectedUnit.YesSound);
                            Console.WriteLine("sound_resource = {0}", sound_resource);
                            GuiUtil.PlaySound(mpq, sound_resource);
                        }

                        selectedUnit.Move(mapRenderer, minitile_x, minitile_y);

                        return;
                    }

                    portraitElement.Stop();

                    selectedUnit = unitUnderCursor;

                    if (selectedUnit == null)
                    {
                        portraitElement.Visible  = false;
                        wireframeElement.Visible = false;
                        for (int i = 0; i < (int)HudLabels.Count; i++)
                        {
                            labelElements[i].Visible = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine("selected unit: {0}", selectedUnit);
                        Console.WriteLine("selectioncircle = {0}", selectedUnit.SelectionCircleOffset);

                        if (selectedUnit.Portrait == null)
                        {
                            portraitElement.Visible = false;
                        }
                        else
                        {
                            string portrait_resource = String.Format("portrait\\{0}0.smk",
                                                                     selectedUnit.Portrait);

                            portraitElement.Player = new SmackerPlayer((Stream)mpq.GetResource(portrait_resource), 1);
                            portraitElement.Play();
                            portraitElement.Visible = true;
                        }

                        if (selectedUnit.WhatSound != null)
                        {
                            string sound_resource = String.Format("sound\\{0}", selectedUnit.WhatSound);
                            Console.WriteLine("sound_resource = {0}", sound_resource);
                            GuiUtil.PlaySound(mpq, sound_resource);
                        }

                        /* set up the wireframe */
                        wireframeElement.Frame   = selectedUnit.UnitId;
                        wireframeElement.Visible = true;

                        /* then display info about the selected unit */
                        labelElements[(int)HudLabels.UnitName].Text = statTxt[selectedUnit.UnitId];
                        if (true /* XXX unit is a building */)
                        {
                            labelElements[(int)HudLabels.ResourceUsed].Text     = statTxt[820 + (int)Game.Instance.Race];
                            labelElements[(int)HudLabels.ResourceProvided].Text = statTxt[814 + (int)Game.Instance.Race];
                            labelElements[(int)HudLabels.ResourceTotal].Text    = statTxt[817 + (int)Game.Instance.Race];
                            labelElements[(int)HudLabels.ResourceMax].Text      = statTxt[823 + (int)Game.Instance.Race];

                            for (int i = 0; i < (int)HudLabels.Count; i++)
                            {
                                labelElements[i].Visible = true;
                            }
                        }

                        /* then fill in the command buttons */
                        int[] cmd_indices;

                        switch (selectedUnit.UnitId)
                        {
                        case 106:
                            cmd_indices = new int[] { 7, -1, -1, -1, -1, 286, -1, -1, 282 };
                            break;

                        default:
                            Console.WriteLine("cmd_indices == -1");
                            cmd_indices = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
                            break;
                        }

                        for (int i = 0; i < cmd_indices.Length; i++)
                        {
                            if (cmd_indices[i] == -1)
                            {
                                cmdButtonElements[i].Visible = false;
                            }
                            else
                            {
                                cmdButtonElements[i].Visible = true;
                                cmdButtonElements[i].Frame   = cmd_indices[i];
                            }
                        }
                    }
                }
            }
        }