示例#1
0
        protected override Surface CreateSurface()
        {
            if (ParentScreen.Background == null && ParentScreen.UseTiles) {
                Surface surf = new Surface (Width, Height);
                surf.Fill (new Rectangle (new Point (0,0), new Size (Width, Height)),
                       Color.FromArgb (0,0,0,0));
                surf.TransparentColor = Color.Black; /* XXX */

                Pcx pal = new Pcx ();
                pal.ReadFromStream ((Stream)Mpq.GetResource ("unit\\cmdbtns\\ticon.pcx"),
                            -1, -1);

                /* tile the top border */
                TileRow (surf, tileGrp, pal.Palette, TILE_TL, TILE_T, TILE_TR, 0);

                /* tile everything down to the bottom border */
                for (int y = tileGrp.Height - 2; y < surf.Height - tileGrp.Height; y += tileGrp.Height - 2)
                    TileRow (surf, tileGrp, pal.Palette, TILE_L, TILE_C, TILE_R, y);

                /* tile the bottom row */
                TileRow (surf, tileGrp, pal.Palette, TILE_BL, TILE_B, TILE_BR, surf.Height - tileGrp.Height);
                return surf;
            }
            else
                return null;
        }
示例#2
0
	public static void Main (string[] args)
	{
		MpqContainer mpq = new MpqContainer ();
		mpq.Add (new MpqArchive ("/home/toshok/src/starcraft/sc-cd/install.exe"));
		mpq.Add (new MpqArchive ("/home/toshok/src/starcraft/starcraft/StarDat.mpq"));

		Fnt fnt = (Fnt)mpq.GetResource ("files\\font\\font16.fnt");
		Console.WriteLine ("loading font palette");
		Stream palStream = (Stream)mpq.GetResource ("glue\\Palmm\\tFont.pcx");
		Pcx pcx1 = new Pcx ();
		pcx1.ReadFromStream (palStream, -1, -1);

		Painter.InitializePainter (false, 300);

		Surface textSurf1 = GuiUtil.ComposeText (str1, fnt, pcx1.Palette);
		Surface textSurf2 = GuiUtil.ComposeText (str2, fnt, pcx1.Palette);
		Surface textSurf3 = GuiUtil.ComposeText (str3, fnt, pcx1.Palette);
		Surface textSurf4 = GuiUtil.ComposeText (str4, fnt, pcx1.Palette);

		Surface backgroundSurface = new Surface (Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);
		backgroundSurface.Fill (new Rectangle (new Point (0, 0), backgroundSurface.Size), Color.Red);

		Painter.Add (Layer.UI,
			     delegate (DateTime now) {
				int y = 0;
				Painter.Blit (textSurf1, new Point (0, y)); y += textSurf1.Height;
				Painter.Blit (textSurf2, new Point (0, y)); y += textSurf2.Height;
				Painter.Blit (textSurf3, new Point (0, y)); y += textSurf3.Height;
				Painter.Blit (textSurf4, new Point (0, y)); y += textSurf4.Height;
			     });

		Painter.Add (Layer.Background,
			     delegate (DateTime now) {
				     Painter.Blit (backgroundSurface);
			     });

		Events.KeyboardUp += delegate (object o, KeyboardEventArgs keyargs) {
			if (keyargs.Key == Key.Escape)
				Events.QuitApplication();
		};

		Events.Run ();
	}
示例#3
0
	public static void Main (string[] args) {
		string filename = args[0];
		string palettename = args[1];

		Console.WriteLine ("grp file {0}", filename);
		Console.WriteLine ("palette file {0}", palettename);

		FileStream fs = File.OpenRead (filename);

		Grp grp = new Grp ();

		((MpqResource)grp).ReadFromStream (fs);
		Pcx pal = new Pcx ();
		pal.ReadFromStream (File.OpenRead(palettename), -1, -1);

		for (int i = 0; i < grp.FrameCount; i ++) {
			BMP.WriteBMP (String.Format ("output{0:0000}.bmp", i),
				      grp.GetFrame (i),
				      grp.Width, grp.Height,
				      pal.Palette);
		}
	}
示例#4
0
 public static Surface SurfaceFromStream(Stream stream, int translucentIndex, int transparentIndex)
 {
     Pcx pcx = new Pcx();
     pcx.ReadFromStream (stream, translucentIndex, transparentIndex);
     return SurfaceFromPcx (pcx);
 }
示例#5
0
 public static Surface SurfaceFromPcx(Pcx pcx)
 {
     return CreateSurfaceFromRGBAData (pcx.RgbaData, pcx.Width, pcx.Height, pcx.Depth, pcx.Stride);
 }
示例#6
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);
		}
示例#7
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;
		}
示例#8
0
        public static void InitializePainter(bool fullscreen, int milli)
        {
            if (init_done)
                throw new Exception ("painter can only be initialized once");

            init_done = true;

            #if !RELEASE
            if (show_fps) {
                Pcx pcx = new Pcx ();
                pcx.ReadFromStream ((Stream)Game.Instance.PlayingMpq.GetResource ("game\\tfontgam.pcx"), 0, 0);
                fontpal = pcx.Palette;
            }
            #endif

            millis = milli;

            Fullscreen = fullscreen;

            /* init our list of painter delegates */
            layers = new List<PainterDelegate>[(int)Layer.Count];
            for (Layer i = Layer.Background; i < Layer.Count; i ++)
                layers[(int)i] = new List<PainterDelegate>();

            /* and set ourselves up to invalidate at a regular interval*/
                        Events.Tick += Tick;
        }
示例#9
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 ();
        }