예제 #1
0
        protected override Surface CreateSurface()
        {
            if (calc_width)
            {
                Surface textSurf = GuiUtil.ComposeText(Text, Font, Palette, -1, -1,
                                                       Sensitive ? 4 : 24);
                Width  = (ushort)textSurf.Width;
                Height = (ushort)textSurf.Height;

                return(textSurf);
            }
            else
            {
                /* this is wrong */
                Surface surf = new Surface(Width, Height);

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

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

                surf.Blit(textSurf, new Point(x, 0));

                surf.TransparentColor = Color.Black /* XXX */;
                return(surf);
            }
        }
예제 #2
0
        protected override Surface CreateSurface()
        {
            Surface surf = new Surface(Width, Height);

            int y = 0;

            for (int i = first_visible; i < first_visible + num_visible; i++)
            {
                if (i >= items.Count)
                {
                    break;
                }
                Surface item_surface = GuiUtil.ComposeText(items[i], Font, Palette,
                                                           (!selectable ||
                                                            (!selecting && cursor == i) ||
                                                            (selecting && selectionIndex == i)) ? 4 : 24);

                surf.Blit(item_surface, new Point(0, y));
                y += item_surface.Height;
            }

            surf.TransparentColor = Color.Black;             /* XXX */

            return(surf);
        }
예제 #3
0
        void Events_Tick(object sender, TickEventArgs e)
        {
            //There should be an easier way to get the video data to SDL

            timeElapsed += (e.SecondsElapsed);
            while (timeElapsed > 1.0 / file.Header.Fps && frameQueue.Count > 0)
            {
                timeElapsed -= (float)(1.0f / file.Header.Fps);
                byte[] rgbData = frameQueue.Dequeue();

                if (surf == null)
                {
                    surf = GuiUtil.CreateSurface(rgbData, (ushort)file.Header.Width, (ushort)file.Header.Height,
                                                 32, (int)file.Header.Width * 4,
                                                 (int)0x00ff0000,
                                                 (int)0x0000ff00,
                                                 (int)0x000000ff,
                                                 unchecked ((int)0xff000000));
                }
                else
                {
                    surf.Lock();
                    Marshal.Copy(rgbData, 0, surf.Pixels, rgbData.Length);
                    surf.Unlock();
                    surf.Update();
                }

                EmitFrameReady();

                if (frameQueue.Count < (buffered_frames / 2) + 1)
                {
                    waitEvent.Set();
                }
            }
        }
예제 #4
0
        void TileRow(Surface surf, Grp grp, byte[] pal, int l, int c, int r, int y)
        {
            Surface lsurf = GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(l),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);

            Surface csurf = GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(c),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);


            Surface rsurf = GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(r),
                                                            grp.Width, grp.Height,
                                                            pal,
                                                            41, 0);


            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));
        }
예제 #5
0
 protected override Surface CreateSurface()
 {
     return(GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(frame),
                                            grp.Width, grp.Height,
                                            Palette,
                                            true));
 }
예제 #6
0
        void CalculateTextPosition()
        {
            if (text_surf == null)
            {
                text_surf = GuiUtil.ComposeText(Text, Font, Palette, -1, -1,
                                                Sensitive ? 4 : 24);
            }

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

            if ((Flags & ElementFlags.CenterTextVert) == ElementFlags.CenterTextVert)
            {
                text_y = (Height - text_surf.Height) / 2;
            }
            else if ((Flags & ElementFlags.BottomAlignText) == ElementFlags.BottomAlignText)
            {
                text_y = (Height - text_surf.Height);
            }
            else
            {
                text_y = 0;
            }
        }
예제 #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
파일: GuiUtil.cs 프로젝트: xerohour/scsharp
        public static void PlaySound(Mpq mpq, string resourcePath)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

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

            s.Play();
        }
예제 #9
0
파일: GuiUtil.cs 프로젝트: xerohour/scsharp
        public static void PlayMusic(Mpq mpq, string resourcePath, int numLoops)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

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

            s.Play(true);
        }
예제 #10
0
        protected virtual Surface CreateSurface()
        {
            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);
            }
        }
예제 #11
0
 public void Layout()
 {
     lineSurfaces = new List <Surface> ();
     foreach (string l in lines)
     {
         if (l.Trim() == "")
         {
             lineSurfaces.Add(null);
         }
         else
         {
             lineSurfaces.Add(GuiUtil.ComposeText(l, fnt, pal, Painter.SCREEN_RES_X - X_OFFSET * 2, -1, 4));
         }
     }
 }
예제 #12
0
        protected override Surface CreateSurface()
        {
            Surface surf = new Surface(Width, Height);

            /* XXX draw the arrow (and border) */

            if (cursor != -1)
            {
                Surface item_surface = GuiUtil.ComposeText(items[cursor], Font, Palette, 4);

                item_surface.TransparentColor = Color.Black;
                surf.Blit(item_surface, new Point(0, 0));
            }

            return(surf);
        }
예제 #13
0
        void CreateDropdownSurface()
        {
            dropdownSurface = new Surface(Width, items.Count * Font.LineSize);

            int y = 0;

            for (int i = 0; i < items.Count; i++)
            {
                Surface item_surface = GuiUtil.ComposeText(items[i], Font, Palette,
                                                           i == selected_item ? 4 : 24);

                item_surface.TransparentColor = Color.Black;

                dropdownSurface.Blit(item_surface, new Point(0, y));
                y += item_surface.Height;
            }
        }
예제 #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
파일: Sprite.cs 프로젝트: xerohour/scsharp
        void DoPlayFrame(int frame_num)
        {
            if (current_frame != frame_num)
            {
                current_frame = frame_num;

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

                sprite_surface = GuiUtil.CreateSurfaceFromBitmap(grp.GetFrame(frame_num),
                                                                 grp.Width, grp.Height,
                                                                 palette,
                                                                 true);
                Invalidate();
            }
        }
예제 #16
0
        void Paint(DateTime now)
        {
            int draw_x = (int)(x - hot_x);
            int draw_y = (int)(y - hot_y);

            if (current_frame == grp.FrameCount)
            {
                current_frame = 0;
            }

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

            Painter.Blit(surfaces[current_frame], new Point(draw_x, draw_y));
        }
예제 #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 Surface CreateSurface()
 {
     return(GuiUtil.ComposeText(Text, Font, Palette, Width, Height,
                                Sensitive ? 4 : 24));
 }
예제 #19
0
 public MarkupPage(Stream background)
 {
     newBackground = GuiUtil.SurfaceFromStream(background, 254, 0);
 }
예제 #20
0
        public void Tick(object sender, TickEventArgs e)
        {
            TriggerAction[] actions = triggerData.Triggers[0].Actions;

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

            totalElapsed += e.TicksElapsed;

            /* if we're presently waiting, make sure
             * enough time has gone by.  otherwise
             * return */
            if (totalElapsed < sleepUntil)
            {
                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;
                }
            }
        }
예제 #21
0
        protected override void ResourceLoader()
        {
            base.ResourceLoader();

            /* create the element corresponding to the hud */
            hudElement         = new ImageElement(this, 0, 0, 640, 480, TranslucentIndex);
            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 (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);
                    }
                }
            }

            mapRenderer = new MapRenderer(mpq, scenario, Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

            // 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);
            }

            /* 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();

            Events.Tick += ScrollTick;
        }
예제 #22
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.SurfaceFromStream ((Stream)mpq.GetResource (background_path),
									background_translucent, background_transparent);
			}

			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);
				}
			}

			UIPainter = new UIPainter (Elements);
		}
예제 #23
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];
                            }
                        }
                    }
                }
            }
        }
예제 #24
0
파일: GuiUtil.cs 프로젝트: xerohour/scsharp
 public static Sound SoundFromStream(Stream stream)
 {
     byte[] buf = GuiUtil.ReadStream(stream);
     return(Mixer.Sound(buf));
 }
예제 #25
0
파일: GuiUtil.cs 프로젝트: xerohour/scsharp
 public static Surface SurfaceFromStream(Stream stream)
 {
     return(GuiUtil.SurfaceFromStream(stream, -1, -1));
 }
예제 #26
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", 50, 70, false);
            AddMovieElements(MULTIPLAYER_ELEMENT_INDEX, "glue\\mainmenu\\Multi.smk", "glue\\mainmenu\\MultiOn.smk", 20, 12, true);
            AddMovieElements(CAMPAIGNEDITOR_ELEMENT_INDEX, "glue\\mainmenu\\Editor.smk", "glue\\mainmenu\\EditorOn.smk", 20, 18, true);
            AddMovieElements(EXIT_ELEMENT_INDEX, "glue\\mainmenu\\Exit.smk", "glue\\mainmenu\\ExitOn.smk", 15, 0, true);

            smkPainter = new UIPainter(smkElements);
        }
예제 #27
0
        Surface GetTile(int mapTile)
        {
            if (tileCache == null)
            {
                tileCache = new Dictionary <int, Surface>();
            }

            //					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;

            bool   show_flag = true;
            ushort flag      = 0x0001;        /* walkable flag */

            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;

                                if (show_flag && (minitile_flags & flag) == flag && (pixel_x == pixel_y))
                                {
                                    image[0 + 4 * (x + y)] = 255;
                                    image[1 + 4 * (x + y)] = 255;
                                    image[2 + 4 * (x + y)] = 0;
                                    image[3 + 4 * (x + y)] = 0;
                                }
                                else
                                {
                                    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;

                                if (show_flag && (minitile_flags & flag) == flag && (pixel_x == pixel_y))
                                {
                                    image[0 + 4 * (x + y)] = 255;
                                    image[1 + 4 * (x + y)] = 255;
                                    image[2 + 4 * (x + y)] = 0;
                                    image[3 + 4 * (x + y)] = 0;
                                }
                                else
                                {
                                    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];
                                }
                            }
                        }
                    }
                }
            }

            Surface surf = GuiUtil.CreateSurfaceFromRGBAData(image, 32, 32, 32, 32 * 4);

            tileCache [megatile_id] = surf;

            return(surf);
        }
예제 #28
0
 protected override Surface CreateSurface()
 {
     return(GuiUtil.SurfaceFromPcx(Pcx));
 }
예제 #29
0
        public Surface RenderToSurface()
        {
            byte[] bitmap = RenderToBitmap(mpq, chk);

            return(GuiUtil.CreateSurfaceFromRGBAData(bitmap, (ushort)pixel_width, (ushort)pixel_height, 32, (ushort)(pixel_width * 4)));
        }
예제 #30
0
        public static void Redraw()
        {
#if !RELEASE
            Rectangle fps_rect = Rectangle.Empty;
            if (show_fps)
            {
                fps_rect = new Rectangle(new Point(10, 10), new Size(80, 30));
                frame_count++;
                if (frame_count == 50)
                {
                    DateTime after = DateTime.Now;

                    fps         = 1.0 / (after - last_time).TotalSeconds * 50;
                    last_time   = after;
                    frame_count = 0;

                    /* make sure we invalidate the region where we're going to draw the fps/related info */
                    Invalidate(fps_rect);
                }
            }
#endif
            //Console.WriteLine ("Redraw");

            if (Painting != null)
            {
                Painting(null, EventArgs.Empty);
            }

            if (dirty.IsEmpty)
            {
                return;
            }

            //Console.WriteLine (" + dirty = {0}", dirty);

            total_elapsed = 0;

            now = DateTime.Now;

            paintingSurface.ClipRectangle = dirty;

#if !RELEASE
            if (debug_dirty)
            {
                paintingSurface.Fill(dirty, Color.Red);
                paintingSurface.Update();
            }
#endif
            paintingSurface.Fill(dirty, Color.Black);

            for (Layer i = Layer.Background; i < Layer.Count; i++)
            {
                DrawLayer(layers[(int)i]);
            }

#if !RELEASE
            if (show_fps)
            {
                if (fps_surface != null)
                {
                    fps_surface.Dispose();
                }

                fps_surface = GuiUtil.ComposeText(String.Format("fps: {0,0:F}", fps),
                                                  GuiUtil.GetFonts(Game.Instance.PlayingMpq)[1],
                                                  fontpal);

                paintingSurface.Blit(fps_surface, new Point(10, 10));
            }
#endif

            paintingSurface.Update();

            paintingSurface.ClipRectangle = paintingSurface.Rectangle;
            dirty = Rectangle.Empty;

            total_elapsed = (DateTime.Now - now).Milliseconds;
        }