Пример #1
0
            public void CreateLineLayers()
            {
                lineContainer             = CALayer.Create();
                lineContainer.AnchorPoint = new PointF(0, 0);
                lineContainer.Bounds      = new RectangleF(0, 0, 640, 480);

                lineLayers = new List <CALayer> ();
                foreach (string l in lines)
                {
                    CALayer layer;
                    if (l.Trim() == "")
                    {
                        layer = null;
                    }
                    else
                    {
                        layer = GuiUtil.ComposeText(l, fnt, pal, 640 /*Painter.SCREEN_RES_X*/ - X_OFFSET * 2, -1, 4);
                    }
                    lineLayers.Add(layer);
                    if (layer != null)
                    {
                        lineContainer.AddSublayer(layer);
                    }
                }
            }
Пример #2
0
        void TileRow(CALayer surf, Grp grp, byte[] pal, int l, int c, int r, int y)
        {
            CALayer l_layer = GuiUtil.CreateLayerFromBitmap(grp.GetFrame(l),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);

            CALayer c_layer = GuiUtil.CreateLayerFromBitmap(grp.GetFrame(c),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);


            CALayer r_layer = GuiUtil.CreateLayerFromBitmap(grp.GetFrame(r),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);

#if notyet
            surf.Blit(lsurf, new Point(0, y));
            for (int x = grp.Width; x < surf.Width - grp.Width; x += grp.Width)
            {
                surf.Blit(csurf, new Point(x, y));
            }
            surf.Blit(rsurf, new Point(surf.Width - grp.Width, y));
#endif
        }
Пример #3
0
 protected override CALayer CreateLayer()
 {
     return(GuiUtil.CreateLayerFromBitmap(grp.GetFrame(frame),
                                          grp.Width, grp.Height,
                                          Palette,
                                          true));
 }
Пример #4
0
        void Events_Tick(object sender, TickEventArgs e)
        {
            timeElapsed += e.SecondsElapsed;

            while (timeElapsed > 1.0 / file.Header.Fps)
            {
                lock (((ICollection)frameQueue).SyncRoot) {
                    if (frameQueue.Count <= 0)
                    {
                        return;
                    }
                }

                timeElapsed -= (float)(1.0f / file.Header.Fps);
                byte[] argbData = frameQueue.Dequeue();

                currentFrame = GuiUtil.CreateImage(argbData, (ushort)Width, (ushort)Height, 32, Width * 4);

                EmitFrameReady();

                if (frameQueue.Count < (buffered_frames / 2) + 1)
                {
                    waitEvent.Set();
                }
            }
        }
Пример #5
0
        void CalculateTextBounds()
        {
            int text_x, text_y;

            SizeF text_size = GuiUtil.MeasureText(Text, Font);

            if ((Flags & ElementFlags.CenterTextHoriz) == ElementFlags.CenterTextHoriz)
            {
                text_x = (int)((Width - text_size.Width) / 2);
            }
            else if ((Flags & ElementFlags.RightAlignText) == ElementFlags.RightAlignText)
            {
                text_x = (int)(Width - text_size.Width);
            }
            else
            {
                text_x = 0;
            }

            if ((Flags & ElementFlags.CenterTextVert) == ElementFlags.CenterTextVert)
            {
                text_y = (int)((Height - text_size.Height) / 2 - text_size.Height);
            }
            else if ((Flags & ElementFlags.TopAlignText) == ElementFlags.TopAlignText)
            {
                text_y = (int)(Height - text_size.Height);
            }
            else
            {
                text_y = 0;
            }

            text_bounds = new RectangleF(new PointF(text_x, text_y), text_size);
        }
Пример #6
0
        protected override CALayer CreateLayer()
        {
            CALayer layer = GuiUtil.LayerFromPcx(Pcx);

            layer.AnchorPoint = new PointF(0, 0);

            return(layer);
        }
Пример #7
0
 public override void MouseEnter()
 {
     if (Sensitive && (Flags & ElementFlags.RespondToMouse) == ElementFlags.RespondToMouse)
     {
         /* highlight the text */
         GuiUtil.PlaySound(Mpq, Builtins.MouseoverWav);
     }
     base.MouseEnter();
 }
Пример #8
0
        public override void DrawLayer(CALayer layer, CGContext context)
        {
            /* XXX draw the arrow (and border) */

            if (el.SelectedIndex != -1)
            {
                GuiUtil.RenderTextToContext(context, new PointF(0, 0), el.SelectedItem, el.Font, el.Palette, 4);
            }
        }
Пример #9
0
        public override void DrawLayer(CALayer layer, CGContext context)
        {
            int y = 0;

            for (int i = el.Items.Count - 1; i >= 0; i--)
            {
                GuiUtil.RenderTextToContext(context, new PointF(0, y), el.Items[i], el.Font, el.Palette,
                                            i == el.DropdownHoverIndex ? 4 : 24);

                y += (int)el.Font.LineSize;
            }
        }
Пример #10
0
        public static void PlaySound(Mpq mpq, string resourcePath)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            NSSound s = GuiUtil.SoundFromStream(stream);

            s.Play();
        }
Пример #11
0
        public static void PlayMusic(Mpq mpq, string resourcePath, int numLoops)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            NSSound s = GuiUtil.SoundFromStream(stream);

            s.Loops = true;;
            s.Play();
        }
Пример #12
0
        public override void DrawInContext(CGContext ctx)
        {
            current_frame = current_frame % frames.Length;

            if (frames[current_frame] == null)
            {
                frames[current_frame] = GuiUtil.CGImageFromBitmap(grp.GetFrame(current_frame),
                                                                  grp.Width, grp.Height,
                                                                  palette,
                                                                  true);
            }

            ctx.DrawImage(new RectangleF(x, y, grp.Width, grp.Height), frames[current_frame]);
        }
Пример #13
0
        protected virtual CALayer CreateLayer()
        {
            switch (Type)
            {
            case ElementType.DefaultButton:
            case ElementType.Button:
            case ElementType.ButtonWithoutBorder:
                return(GuiUtil.ComposeText(Text, Font, palette, Width, Height,
                                           sensitive ? 4 : 24));

            default:
                return(null);
            }
        }
Пример #14
0
        void ShowGameModeDialog(UIScreenType nextScreen)
        {
            GameModeDialog d = new GameModeDialog(this, mpq);

            d.Cancel   += delegate() { DismissDialog(); };
            d.Activate += delegate(bool expansion) {
                DismissDialog();
                try {
                    Game.Instance.PlayingBroodWar = expansion;
                    GuiUtil.PlaySound(mpq, Builtins.Mousedown2Wav);
                    Game.Instance.SwitchToScreen(nextScreen);
                }
                catch (Exception e) {
                    ShowDialog(new OkDialog(this, mpq, e.Message));
                }
            };
            ShowDialog(d);
        }
Пример #15
0
		public override void DrawLayer (CALayer layer, CGContext context)
		{
			if (el.Items != null) {
				int y = el.Bounds.Height - el.Font.LineSize;
				for (int i = el.FirstVisible; i < el.FirstVisible + el.NumVisible; i ++) {
					if (i >= el.Items.Count)
						return;
					GuiUtil.RenderTextToContext (context, new PointF (0, y),
												el.Items[i], el.Font, el.Palette, 4);
#if notyet
												(!el.Selectable ||
									     		(!el.Selecting && el.SelectedIndex == i) ||
									     		(el.Selecting && el.SelectionIndex == i)) ? 4 : 24);
#endif
					y -= el.Font.LineSize;
				}
			}
		}
Пример #16
0
        void DoPlayFrame(int frame_num)
        {
            if (current_frame != frame_num)
            {
                current_frame = frame_num;

#if notyet
                if (sprite_surface != null)
                {
                    sprite_surface.Dispose();
                }

                sprite_surface = GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(frame_num),
                                                                 grp.Width, grp.Height,
                                                                 palette,
                                                                 true);
                Invalidate();
#endif
            }
        }
Пример #17
0
        protected override void ResourceLoader()
        {
            Console.WriteLine("loading font palette");
            Stream palStream = (Stream)mpq.GetResource("glue\\Palmm\\tFont.pcx");
            Pcx    pcx       = new Pcx();

            pcx.ReadFromStream(palStream, -1, -1);

            pal = pcx.RGBData;

            Console.WriteLine("loading font");
            fnt = GuiUtil.GetFonts(mpq)[3];

            Console.WriteLine("loading markup");
            LoadMarkup();

            /* set things up so we're ready to go */
            millisDelay    = 4000;
            pageEnumerator = pages.GetEnumerator();
            AdvanceToNextPage();
        }
Пример #18
0
        protected override CALayer CreateLayer()
        {
            if (calc_width)
            {
                CALayer textLayer = GuiUtil.ComposeText(Text, Font, Palette, -1, -1, Sensitive ? 4 : 24);

                textLayer.AnchorPoint = new PointF(0, 0);

                Width  = (ushort)textLayer.Bounds.Width;
                Height = (ushort)textLayer.Bounds.Height;

                return(textLayer);
            }
            else
            {
                /* this is wrong */
                CALayer layer = CALayer.Create();
                layer.Bounds = new RectangleF(0, 0, Width, Height);

                CALayer textLayer = GuiUtil.ComposeText(Text, Font, Palette, Width, Height,
                                                        Sensitive ? 4 : 24);

                float x = 0;
                if (Type == ElementType.LabelRightAlign)
                {
                    x += Width - textLayer.Bounds.Width;
                }
                else if (Type == ElementType.LabelCenterAlign)
                {
                    x += (Width - textLayer.Bounds.Width) / 2;
                }

                textLayer.AnchorPoint = new PointF(0, 0);
                textLayer.Position    = new PointF(x, 0);

                layer.AddSublayer(textLayer);

                return(layer);
            }
        }
Пример #19
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];
                            }
                        }
                    }
                }
            }
        }
Пример #20
0
 public static NSSound SoundFromStream(Stream stream)
 {
     byte[] buf = GuiUtil.ReadStream(stream);
     return(new NSSound(NSData.FromArray(buf)));
 }
Пример #21
0
        // TODO: give this layer a delegate and render the tiles we need to at runtime
        public CALayer RenderToLayer()
        {
            byte[] bitmap = RenderToBitmap(mpq, chk);

            return(GuiUtil.CreateLayerFromRGBAData(bitmap, (ushort)pixel_width, (ushort)pixel_height, 32, (ushort)(pixel_width * 4)));
        }
Пример #22
0
        CGImage GetTile(int mapTile)
        {
            if (tileCache == null)
            {
                tileCache = new Dictionary <int, CGImage>();
            }

            //					bool odd = (mapTile & 0x10) == 0x10;

            int tile_group  = mapTile >> 4;            /* the tile's group in the cv5 file */
            int tile_number = mapTile & 0x0F;          /* the megatile within the tile group */

            int megatile_id = Util.ReadWord(cv5, (tile_group * 26 + 10 + tile_number) * 2);

            if (tileCache.ContainsKey(megatile_id))
            {
                return(tileCache[megatile_id]);
            }

            if (image == null)
            {
                image = new byte[32 * 32 * 4];
            }

            int minitile_x, minitile_y;

            for (minitile_y = 0; minitile_y < 4; minitile_y++)
            {
                for (minitile_x = 0; minitile_x < 4; minitile_x++)
                {
                    ushort minitile_id    = Util.ReadWord(vx4, megatile_id * 32 + minitile_y * 8 + minitile_x * 2);
                    ushort minitile_flags = Util.ReadWord(vf4, megatile_id * 32 + minitile_y * 8 + minitile_x * 2);
                    bool   flipped        = (minitile_id & 0x01) == 0x01;
                    minitile_id >>= 1;

                    int pixel_x, pixel_y;
                    if (flipped)
                    {
                        for (pixel_y = 0; pixel_y < 8; pixel_y++)
                        {
                            for (pixel_x = 0; pixel_x < 8; pixel_x++)
                            {
                                int x = (minitile_x + 1) * 8 - pixel_x - 1;
                                int y = (minitile_y * 8) * 32 + pixel_y * 32;

                                byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x];

                                image[0 + 4 * (x + y)] = (byte)(255 - wpe[palette_entry * 4 + 3]);
                                image[1 + 4 * (x + y)] = wpe[palette_entry * 4 + 2];
                                image[2 + 4 * (x + y)] = wpe[palette_entry * 4 + 1];
                                image[3 + 4 * (x + y)] = wpe[palette_entry * 4 + 0];
                            }
                        }
                    }
                    else
                    {
                        for (pixel_y = 0; pixel_y < 8; pixel_y++)
                        {
                            for (pixel_x = 0; pixel_x < 8; pixel_x++)
                            {
                                int x = minitile_x * 8 + pixel_x;
                                int y = (minitile_y * 8) * 32 + pixel_y * 32;

                                byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x];

                                image[0 + 4 * (x + y)] = (byte)(255 - wpe[palette_entry * 4 + 3]);
                                image[1 + 4 * (x + y)] = wpe[palette_entry * 4 + 2];
                                image[2 + 4 * (x + y)] = wpe[palette_entry * 4 + 1];
                                image[3 + 4 * (x + y)] = wpe[palette_entry * 4 + 0];
                            }
                        }
                    }
                }
            }

            CGImage tile = GuiUtil.CreateImage(image, 32, 32, 32, 32 * 4);

            tileCache [megatile_id] = tile;

            return(tile);
        }
Пример #23
0
        protected override void ResourceLoader()
        {
            base.ResourceLoader();
            for (int i = 0; i < Elements.Count; i++)
            {
                Console.WriteLine("{0}: {1} '{2}' : {3}", i, Elements[i].Type, Elements[i].Text, Elements[i].Flags);
            }

            //Elements[VERSION_ELEMENT_INDEX].Text = "v" + Consts.Version;

            Elements[SINGLEPLAYER_ELEMENT_INDEX].Flags |= ElementFlags.RightAlignText | ElementFlags.CenterTextVert;

            Elements[SINGLEPLAYER_ELEMENT_INDEX].Activate +=
                delegate() {
                if (Game.Instance.IsBroodWar)
                {
                    ShowGameModeDialog(UIScreenType.Login);
                }
                else
                {
                    GuiUtil.PlaySound(mpq, Builtins.Mousedown2Wav);
                    Game.Instance.SwitchToScreen(UIScreenType.Login);
                }
            };

            Elements[MULTIPLAYER_ELEMENT_INDEX].Activate +=
                delegate() {
                if (Game.Instance.IsBroodWar)
                {
                    ShowGameModeDialog(UIScreenType.Connection);
                }
                else
                {
                    GuiUtil.PlaySound(mpq, Builtins.Mousedown2Wav);
                    Game.Instance.SwitchToScreen(UIScreenType.Connection);
                }
            };

            Elements[CAMPAIGNEDITOR_ELEMENT_INDEX].Activate +=
                delegate() {
                OkDialog d = new OkDialog(this, mpq,
                                          "The campaign editor functionality is not available in SCSharp");
                ShowDialog(d);
            };

            Elements[INTRO_ELEMENT_INDEX].Activate +=
                delegate() {
                Cinematic introScreen = new Cinematic(mpq,
                                                      Game.Instance.IsBroodWar
                                                                               ? "smk\\starXIntr.smk"
                                                                               : "smk\\starintr.smk");
                introScreen.Finished += delegate() {
                    Game.Instance.SwitchToScreen(this);
                };
                Game.Instance.SwitchToScreen(introScreen);
            };

            Elements[CREDITS_ELEMENT_INDEX].Activate +=
                delegate() {
                Game.Instance.SwitchToScreen(new CreditsScreen(mpq));
            };

            Elements[EXIT_ELEMENT_INDEX].Activate +=
                delegate() {
                Game.Instance.Quit();
            };

            smkElements = new List <UIElement>();

            AddMovieElements(SINGLEPLAYER_ELEMENT_INDEX, "glue\\mainmenu\\Single.smk", "glue\\mainmenu\\SingleOn.smk", 45, 66, false);
            AddMovieElements(MULTIPLAYER_ELEMENT_INDEX, "glue\\mainmenu\\Multi.smk", "glue\\mainmenu\\MultiOn.smk", 20, 10, true);
            AddMovieElements(CAMPAIGNEDITOR_ELEMENT_INDEX, "glue\\mainmenu\\Editor.smk", "glue\\mainmenu\\EditorOn.smk", 20, 16, true);
            AddMovieElements(EXIT_ELEMENT_INDEX, "glue\\mainmenu\\Exit.smk", "glue\\mainmenu\\ExitOn.smk", 15, 0, true);

            foreach (var ui_el in smkElements)
            {
                ui_el.Layer.Position    = new PointF(ui_el.X1, Bounds.Height - ui_el.Y1 - ui_el.Layer.Bounds.Height);
                ui_el.Layer.AnchorPoint = new PointF(0, 0);
                AddSublayer(ui_el.Layer);
            }
        }
Пример #24
0
 public override void DrawLayer(CALayer layer, CGContext context)
 {
     GuiUtil.RenderTextToContext(context, el.TextPosition, el.Text, el.Font, el.Palette, el.Sensitive ? 4 : 24);
 }
Пример #25
0
        protected override void ResourceLoader()
        {
            base.ResourceLoader();

            /* create the element corresponding to the hud */
            hudElement         = new ImageElement(this, 0, 0, 640, 480, TranslucentIndex);
            hudElement.Palette = fontpal.RGBData;
            hudElement.Text    = String.Format(Builtins.Game_ConsolePcx, Util.RaceCharLower[(int)Game.Instance.Race]);
            hudElement.Visible = true;
            Elements.Add(hudElement);

            /* create the portrait playing area */
            portraitElement         = new MovieElement(this, 415, 415, 48, 48, false);
            portraitElement.Visible = true;
            Elements.Add(portraitElement);

            Pcx pcx = new Pcx();

            pcx.ReadFromStream((Stream)mpq.GetResource("game\\tunit.pcx"), -1, -1);
            //unit_palette = pcx.Palette;

            pcx = new Pcx();
            pcx.ReadFromStream((Stream)mpq.GetResource("tileset\\badlands\\dark.pcx"), 0, 0);
            tileset_palette = pcx.Palette;

#if notyet
            if (scenario.Tileset == Tileset.Platform)
            {
                Spk starfield = (Spk)mpq.GetResource("parallax\\star.spk");

                starfield_layers = new Surface [starfield.Layers.Length];
                for (int i = 0; i < starfield_layers.Length; i++)
                {
                    starfield_layers[i] = new Surface(Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

                    starfield_layers[i].TransparentColor = Color.Black;

                    for (int o = 0; o < starfield.Layers[i].Objects.Length; o++)
                    {
                        ParallaxObject obj = starfield.Layers[i].Objects[o];

                        starfield_layers[i].Fill(new Rectangle(new Point(obj.X, obj.Y), new Size(2, 2)),
                                                 Color.White);
                    }
                }
            }
#endif

            mapRenderer = new MapRenderer(mpq, scenario, 640 /*Painter.SCREEN_RES_X*/, 480 /*Painter.SCREEN_RES_Y*/);
            mapRenderer.MapLayer.AnchorPoint = new PointF(0, 0);

#if notyet
            // load the cursors we'll show when scrolling with the mouse
            string[] cursornames = new string[] {
                "cursor\\ScrollUL.grp",
                "cursor\\ScrollU.grp",
                "cursor\\ScrollUR.grp",
                "cursor\\ScrollR.grp",
                "cursor\\ScrollDR.grp",
                "cursor\\ScrollD.grp",
                "cursor\\ScrollDL.grp",
                "cursor\\ScrollL.grp",
            };
            ScrollCursors = new CursorAnimator [cursornames.Length];
            for (int i = 0; i < cursornames.Length; i++)
            {
                ScrollCursors[i] = new CursorAnimator((Grp)mpq.GetResource(cursornames[i]),
                                                      effectpal.Palette);
                ScrollCursors[i].SetHotSpot(60, 60);
            }

            // load the mag cursors
            string[] magcursornames = new string[] {
                "cursor\\MagG.grp",
                "cursor\\MagY.grp",
                "cursor\\MagR.grp"
            };
            MagCursors = new CursorAnimator [magcursornames.Length];
            for (int i = 0; i < magcursornames.Length; i++)
            {
                MagCursors[i] = new CursorAnimator((Grp)mpq.GetResource(magcursornames[i]),
                                                   effectpal.Palette);
                MagCursors[i].SetHotSpot(60, 60);
            }

            // load the targeting cursors
            string[] targetcursornames = new string[] {
                "cursor\\TargG.grp",
                "cursor\\TargY.grp",
                "cursor\\TargR.grp"
            };
            TargetCursors = new CursorAnimator [targetcursornames.Length];
            for (int i = 0; i < targetcursornames.Length; i++)
            {
                TargetCursors[i] = new CursorAnimator((Grp)mpq.GetResource(targetcursornames[i]),
                                                      effectpal.Palette);
                TargetCursors[i].SetHotSpot(60, 60);
            }
#endif
            /* the following could be made global to speed up the entry to the game screen.. */
            statTxt = (Tbl)mpq.GetResource("rez\\stat_txt.tbl");

            // load the wireframe image info
            wireframe = (Grp)mpq.GetResource("unit\\wirefram\\wirefram.grp");

            // load the command icons
            cmdicons = (Grp)mpq.GetResource("unit\\cmdbtns\\cmdicons.grp");
            pcx      = new Pcx();
            pcx.ReadFromStream((Stream)mpq.GetResource("unit\\cmdbtns\\ticon.pcx"), 0, 0);
            cmdicon_palette = pcx.Palette;

            // create the wireframe display element
            wireframeElement         = new GrpElement(this, wireframe, cmdicon_palette, 170, 390);
            wireframeElement.Visible = false;
            Elements.Add(wireframeElement);

            labelElements = new LabelElement [(int)HudLabels.Count];

            labelElements[(int)HudLabels.UnitName] = new LabelElement(this, fontpal.Palette,
                                                                      GuiUtil.GetFonts(Mpq)[1],
                                                                      254, 390);
            labelElements[(int)HudLabels.ResourceUsed] = new LabelElement(this, fontpal.Palette,
                                                                          GuiUtil.GetFonts(Mpq)[0],
                                                                          292, 420);
            labelElements[(int)HudLabels.ResourceProvided] = new LabelElement(this, fontpal.Palette,
                                                                              GuiUtil.GetFonts(Mpq)[0],
                                                                              292, 434);
            labelElements[(int)HudLabels.ResourceTotal] = new LabelElement(this, fontpal.Palette,
                                                                           GuiUtil.GetFonts(Mpq)[0],
                                                                           292, 448);
            labelElements[(int)HudLabels.ResourceMax] = new LabelElement(this, fontpal.Palette,
                                                                         GuiUtil.GetFonts(Mpq)[0],
                                                                         292, 462);

            for (int i = 0; i < labelElements.Length; i++)
            {
                Elements.Add(labelElements[i]);
            }

            cmdButtonElements = new GrpButtonElement[9];
            int x = 0;
            int y = 0;
            for (int i = 0; i < cmdButtonElements.Length; i++)
            {
                cmdButtonElements[i] = new GrpButtonElement(this, cmdicons, cmdicon_palette, button_xs[x], button_ys[y]);
                x++;
                if (x == 3)
                {
                    x = 0;
                    y++;
                }
                cmdButtonElements[i].Visible = false;
                Elements.Add(cmdButtonElements[i]);
            }

            PlaceInitialUnits();
        }
Пример #26
0
 public MarkupPage(Stream background)
 {
     newBackground             = GuiUtil.LayerFromStream(background, 254, 0);
     newBackground.AnchorPoint = new PointF(0, 0);
     newBackground.Position    = new PointF(0, 0);
 }
Пример #27
0
        protected virtual void ResourceLoader()
        {
            Stream s;

            fontpal   = null;
            effectpal = null;

            if (fontpal_path != null)
            {
                Console.WriteLine("loading font palette");
                s = (Stream)mpq.GetResource(fontpal_path);
                if (s != null)
                {
                    fontpal = new Pcx();
                    fontpal.ReadFromStream(s, -1, -1);
                }
            }
            if (effectpal_path != null)
            {
                Console.WriteLine("loading cursor palette");
                s = (Stream)mpq.GetResource(effectpal_path);
                if (s != null)
                {
                    effectpal = new Pcx();
                    effectpal.ReadFromStream(s, -1, -1);
                }
                if (effectpal != null && arrowgrp_path != null)
                {
                    Console.WriteLine("loading arrow cursor");
                    Grp arrowgrp = (Grp)mpq.GetResource(arrowgrp_path);
                    if (arrowgrp != null)
                    {
                        Cursor = new CursorAnimator(arrowgrp, effectpal.Palette);
                        Cursor.SetHotSpot(64, 64);
                    }
                }
            }

            if (background_path != null)
            {
                Console.WriteLine("loading background");
                background = GuiUtil.LayerFromStream((Stream)mpq.GetResource(background_path),
                                                     background_translucent, background_transparent);

                background.AnchorPoint = new PointF(0, 0);
                AddSublayer(background);
                // FIXME: we should center the background (and scale it?)
            }

            Elements = new List <UIElement> ();
            if (binFile != null)
            {
                Console.WriteLine("loading ui elements");
                Bin = (Bin)mpq.GetResource(binFile);

                if (Bin == null)
                {
                    throw new Exception(String.Format("specified file '{0}' does not exist",
                                                      binFile));
                }

                /* convert all the BinElements to UIElements for our subclasses to use */
                foreach (BinElement el in Bin.Elements)
                {
                    //					Console.WriteLine ("{0}: {1}", el.text, el.flags);

                    UIElement ui_el = null;
                    switch (el.type)
                    {
                    case ElementType.DialogBox:
                        ui_el = new DialogBoxElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.Image:
                        ui_el = new ImageElement(this, el, fontpal.RGBData, translucentIndex);
                        break;

                    case ElementType.TextBox:
                        ui_el = new TextBoxElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.ListBox:
                        ui_el = new ListBoxElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.ComboBox:
                        ui_el = new ComboBoxElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.LabelLeftAlign:
                    case ElementType.LabelCenterAlign:
                    case ElementType.LabelRightAlign:
                        ui_el = new LabelElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.Button:
                    case ElementType.DefaultButton:
                    case ElementType.ButtonWithoutBorder:
                        ui_el = new ButtonElement(this, el, fontpal.RGBData);
                        break;

                    case ElementType.Slider:
                    case ElementType.OptionButton:
                    case ElementType.CheckBox:
                        ui_el = new UIElement(this, el, fontpal.RGBData);
                        break;

                    default:
                        Console.WriteLine("unhandled case {0}", el.type);
                        ui_el = new UIElement(this, el, fontpal.RGBData);
                        break;
                    }

                    Elements.Add(ui_el);
                }
            }
        }
Пример #28
0
        public void Tick(object sender, TickEventArgs e)
        {
            TriggerAction[] actions = triggerData.Triggers[0].Actions;

            if (current_action == actions.Length)
            {
                return;
            }

            // FIXME we need to figure out how many ticks per second SC1 used for normal mode... 6?

            totalElapsed += (int)e.MillisecondsElapsed;

            /* if we're presently waiting, make sure
             * enough time has gone by.  otherwise
             * return */
            if (totalElapsed < sleepUntil * 166 /* 166 = 1/6th of a second */)
            {
                return;
            }

            totalElapsed = 0;

            while (current_action < actions.Length)
            {
                TriggerAction action = actions[current_action];

                current_action++;

                switch (action.Action)
                {
                case 0:                 /* no action */
                    break;

                case 1:
                    sleepUntil = (int)action.Delay;
                    return;

                case 2:
                    GuiUtil.PlaySound(screen.Mpq, prefix + "\\" + scenario.GetMapString((int)action.WavIndex));
                    sleepUntil = (int)action.Delay;
                    return;

                case 3:
                    screen.SetTransmissionText(scenario.GetMapString((int)action.TextIndex));
                    break;

                case 4:
                    screen.SetObjectives(scenario.GetMapString((int)action.TextIndex));
                    break;

                case 5:
                    Console.WriteLine("show portrait:");
                    Console.WriteLine("location = {0}, textindex = {1}, wavindex = {2}, delay = {3}, group1 = {4}, group2 = {5}, unittype = {6}, action = {7}, switch = {8}, flags = {9}",
                                      action.Location,
                                      action.TextIndex,
                                      action.WavIndex,
                                      action.Delay,
                                      action.Group1,
                                      action.Group2,
                                      action.UnitType,
                                      action.Action,
                                      action.Switch,
                                      action.Flags);
                    screen.ShowPortrait((int)action.UnitType, (int)action.Group1);
                    Console.WriteLine(scenario.GetMapString((int)action.TextIndex));
                    break;

                case 6:
                    screen.HidePortrait((int)action.Group1);
                    break;

                case 7:
                    Console.WriteLine("Display Speaking Portrait(Slot, Time)");
                    Console.WriteLine(scenario.GetMapString((int)action.TextIndex));
                    break;

                case 8:
                    Console.WriteLine("Transmission(Text, Slot, Time, Modifier, Wave, WavTime)");
                    screen.SetTransmissionText(scenario.GetMapString((int)action.TextIndex));
                    screen.HighlightPortrait((int)action.Group1);
                    GuiUtil.PlaySound(screen.Mpq, prefix + "\\" + scenario.GetMapString((int)action.WavIndex));
                    sleepUntil = (int)action.Delay;
                    return;

                default:
                    break;
                }
            }
        }
Пример #29
0
 public override void DrawLayer(CALayer layer, CGContext context)
 {
     GuiUtil.RenderTextToContext(context, new PointF(0, el.Height / 2), el.Text, el.Font, el.Palette, el.Sensitive ? 4 : 24);
 }