예제 #1
0
        void LoadSavedInfo( IDrawer2D drawer )
        {
            try {
                Options.Load();
            } catch( IOException ) {
                return;
            }

            string user = Options.Get( "launcher-username" ) ?? "";
            string ip = Options.Get( "launcher-ip" ) ?? "127.0.0.1";
            string port = Options.Get( "launcher-port" ) ?? "25565";
            ccSkins = Options.GetBool( "launcher-ccskins", false );

            IPAddress address;
            if( !IPAddress.TryParse( ip, out address ) ) ip = "127.0.0.1";
            ushort portNum;
            if( !UInt16.TryParse( port, out portNum ) ) port = "25565";

            string mppass = Options.Get( "launcher-mppass" ) ?? null;
            mppass = Secure.Decode( mppass, user );

            Set( 3, user );
            Set( 4, ip + ":" + port );
            Set( 5, mppass );
        }
 void DrawBorder( IDrawer2D drawer )
 {
     FastColour backCol = Window.ClassicBackground ? FastColour.Black : LauncherSkin.ButtonBorderCol;
     drawer.Clear( backCol, X + 1, Y, Width - 2, border );
     drawer.Clear( backCol, X + 1, Y + Height - border, Width - 2, border );
     drawer.Clear( backCol, X, Y + 1, border, Height - 2 );
     drawer.Clear( backCol, X + Width - border, Y + 1, border, Height - 2 );
 }
예제 #3
0
 public void DrawAt( IDrawer2D drawer, string text, Font font,
     Anchor horAnchor, Anchor verAnchor, int width, int height, int x, int y)
 {
     ButtonWidth = width; ButtonHeight = height;
     Width = width; Height = height;
     CalculateOffset( x, y, horAnchor, verAnchor );
     Redraw( drawer, text, font );
 }
예제 #4
0
        public void Redraw( IDrawer2D drawer, string text, Font font )
        {
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Size size = drawer.MeasureSize( ref args );
            Width = size.Width; Height = size.Height;

            args.SkipPartsCheck = true;
            drawer.DrawText( ref args, X, Y );
            Text = text;
        }
예제 #5
0
        public void SetDrawData( IDrawer2D drawer, Font font, Font titleFont )
        {
            this.font = font;
            this.titleFont = titleFont;

            DrawTextArgs args = new DrawTextArgs( "IMP", titleFont, true );
            headerHeight = drawer.MeasureSize( ref args ).Height;
            args = new DrawTextArgs( "IMP", font, true );
            entryHeight = drawer.MeasureSize( ref args ).Height;
        }
예제 #6
0
        public void DrawAt( IDrawer2D drawer, string text, Font font,
            Anchor horAnchor, Anchor verAnchor, int x, int y)
        {
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Size size = drawer.MeasureSize( ref args );
            Width = size.Width; Height = size.Height;

            CalculateOffset( x, y, horAnchor, verAnchor );
            Redraw( drawer, text, font );
        }
예제 #7
0
        public void SetDrawData( IDrawer2D drawer, string text, Font font,
            Anchor horAnchor, Anchor verAnchor, int x, int y)
        {
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Size size = drawer.MeasureSize( ref args );
            Width = size.Width; Height = size.Height;

            CalculateOffset( x, y, horAnchor, verAnchor );
            Text = text;
            this.font = font;
        }
        public void SetDrawData( IDrawer2D drawer, Font font, Font titleFont,
            Anchor horAnchor, Anchor verAnchor, int x, int y)
        {
            CalculateOffset( x, y, horAnchor, verAnchor );
            this.font = font;
            this.titleFont = titleFont;

            DrawTextArgs args = new DrawTextArgs( "IMP", titleFont, true );
            defaultHeaderHeight = drawer.MeasureSize( ref args ).Height;
            args = new DrawTextArgs( "IMP", font, true );
            defaultInputHeight = drawer.MeasureSize( ref args ).Height;
        }
 public void Redraw( IDrawer2D drawer )
 {
     drawer.DrawRect( FastColour.Black, X, Y, Width, Height );
     if( Value ) {
         DrawTextArgs args = new DrawTextArgs( "X", font, false );
         Size size = drawer.MeasureSize( ref args );
         args.SkipPartsCheck = true;
         drawer.DrawText( ref args, X + (Width - size.Width) / 2,
                         Y + (Height - size.Height) / 2 );
     }
     drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height );
 }
예제 #10
0
 public override void Redraw( IDrawer2D drawer )
 {
     if( Window.Minimised ) return;
     drawer.DrawRect( FastColour.Black, X, Y, Width, Height );
     if( Value ) {
         DrawTextArgs args = new DrawTextArgs( "X", font, false );
         Size size = drawer.MeasureSize( ref args );
         args.SkipPartsCheck = true;
         drawer.DrawText( ref args, X + (Width + 2 - size.Width) / 2, // account for border
                         Y + (Height - size.Height) / 2 );
     }
     drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height );
 }
예제 #11
0
        public static Bitmap ReadBmp32Bpp(IDrawer2D drawer, Stream src)
        {
            Bitmap bmp = ReadBmp(src);

            if (!ValidBitmap(bmp))
            {
                return(null);
            }
            if (!Is32Bpp(bmp))
            {
                drawer.ConvertTo32Bpp(ref bmp);
            }
            return(bmp);
        }
        public void Disconnect(string title, string reason)
        {
            Events.RaiseDisconnected(title, reason);

            Gui.Reset(this);
            World.Reset();
            WorldEvents.RaiseOnNewMap();

            IDrawer2D.InitCols();
            BlockInfo.Reset();
            TexturePack.ExtractDefault(this);
            Gui.SetNewScreen(new DisconnectScreen(this, title, reason));
            GC.Collect();
        }
        public void WordWrap(IDrawer2D drawer, ref string[] lines, ref int[] lineLens,
                             int lineSize, int totalChars)
        {
            int len = Length;

            for (int i = 0; i < lines.Length; i++)
            {
                lines[i]    = null;
                lineLens[i] = 0;
            }

            // Need to make a copy because we mutate the characters.
            char[] realText = value;
            MakeWrapCopy();

            int linesCount = 0;

            for (int index = 0; index < totalChars; index += lineSize)
            {
                if (value[index] == '\0')
                {
                    break;
                }

                int lineEnd = index + (lineSize - 1), nextLine = lineEnd + 1;
                linesCount++;

                // Do we need word wrapping?
                bool needWrap = !IsWrapper(value[lineEnd]) &&
                                nextLine < totalChars && !IsWrapper(value[nextLine]);
                int wrappedLen = needWrap ? WrapLine(index, lineSize) : lineSize;

                // Calculate the maximum size of this line
                int lineLen = lineSize;
                for (int i = lineEnd; i >= index; i--)
                {
                    if (value[i] != '\0')
                    {
                        break;
                    }
                    lineLen--;
                }
                lineLens[index / lineSize] = Math.Min(lineLen, wrappedLen);
            }

            // Output the used lines
            OutputLines(drawer, ref lines, lineLens,
                        linesCount, lineSize, totalChars);
            value = realText;
        }
예제 #14
0
        public override void Redraw( IDrawer2D drawer )
        {
            if( Window.Minimised ) return;
            string text = Text;
            if( !Active ) text = "&7" + text;
            int xOffset = Width - textSize.Width, yOffset = Height - textSize.Height;
            DrawTextArgs args = new DrawTextArgs( text, font, true );

            DrawBorder( drawer );
            if( Window.ClassicBackground ) DrawClassic( drawer );
            else DrawNormal( drawer );

            drawer.DrawText( ref args, X + xOffset / 2, Y + yOffset / 2 );
        }
예제 #15
0
 public void RedrawData( IDrawer2D drawer )
 {
     int x = table.X + 5;
     DrawGrid( drawer );
     x += DrawColumn( drawer, false, font, titleFont,
                     "Name", table.ColumnWidths[0], x, e => e.Name ) + 5;
     x += DrawColumn( drawer, true, font, titleFont,
                     "Players", table.ColumnWidths[1], x, e => e.Players ) + 5;
     x += DrawColumn( drawer, true, font, titleFont,
                     "Uptime", table.ColumnWidths[2], x, e => e.Uptime ) + 5;
     x += DrawColumn( drawer, true, font, titleFont,
                     "Software", table.ColumnWidths[3], x, e => e.Software ) + 5;
     DrawScrollbar( drawer );
 }
        public void WordWrap(IDrawer2D drawer, string[] lines, int maxLines, int maxPerLine)
        {
            int  len      = Length;
            int *lineLens = stackalloc int[lines.Length];

            for (int i = 0; i < lines.Length; i++)
            {
                lines[i]    = null;
                lineLens[i] = 0;
            }

            // Need to make a copy because we mutate the characters.
            char[] realText = value;
            MakeWrapCopy();

            int usedLines = 0, totalChars = maxPerLine * maxLines;

            for (int index = 0; index < totalChars; index += maxPerLine)
            {
                if (value[index] == '\0')
                {
                    break;
                }

                int lineEnd = index + (maxPerLine - 1), nextStart = lineEnd + 1;
                usedLines++;

                // Do we need word wrapping?
                bool needWrap = !IsWrapper(value[lineEnd]) &&
                                nextStart < totalChars && !IsWrapper(value[nextStart]);
                int wrappedLen = needWrap ? WrapLine(index, maxPerLine) : maxPerLine;

                // Calculate the maximum size of this line
                int lineLen = maxPerLine;
                for (int i = lineEnd; i >= index; i--)
                {
                    if (value[i] != '\0')
                    {
                        break;
                    }
                    lineLen--;
                }
                lineLens[index / maxPerLine] = Math.Min(lineLen, wrappedLen);
            }

            // Output the used lines
            OutputLines(drawer, lines, lineLens, usedLines, maxLines, maxPerLine);
            value = realText;
        }
        void DrawTitles( IDrawer2D drawer, Font font )
        {
            int x = 0;
            DrawTextArgs args = new DrawTextArgs( null, font, false );
            for( int i = 0; i < elements.Length; i++ ) {
                args.Text = elements[i].Title;
                FastColour col = i == selectedIndex ? new FastColour( 30, 30, 30, 200 ) :
                    new FastColour( 60, 60, 60, 200 );
                Size size = elements[i].TitleSize;

                drawer.Clear( col, x, 0, size.Width, size.Height );
                drawer.DrawChatText( ref args, x + titleSpacing / 2, 0 );
                x += size.Width;
            }
        }
예제 #18
0
        public void Disconnect(string title, string reason)
        {
            World.Reset();
            WorldEvents.RaiseOnNewMap();
            Gui.SetNewScreen(new DisconnectScreen(this, title, reason));

            IDrawer2D.InitCols();
            BlockInfo.Reset();
            TexturePack.ExtractDefault(this);

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Reset(this);
            }
            GC.Collect();
        }
예제 #19
0
        void DrawTitles(IDrawer2D drawer, Font font)
        {
            int          x    = 0;
            DrawTextArgs args = new DrawTextArgs(null, font, false);

            for (int i = 0; i < elements.Length; i++)
            {
                args.Text = elements[i].Title;
                FastColour col = i == selectedIndex ? new FastColour(30, 30, 30, 200) :
                                 new FastColour(60, 60, 60, 200);
                Size size = elements[i].TitleSize;

                drawer.Clear(col, x, 0, size.Width, size.Height);
                drawer.DrawChatText(ref args, x + titleSpacing / 2, 0);
                x += size.Width;
            }
        }
예제 #20
0
        public void SetText(string value)
        {
            chatInputText.Clear();
            chatInputText.Append(0, value);
            DrawTextArgs args     = new DrawTextArgs(value, font, false);
            Size         textSize = game.Drawer2D.MeasureSize(ref args);
            Size         size     = new Size(Math.Max(textSize.Width, DesiredMaxWidth),
                                             Math.Max(textSize.Height, DesiredMaxHeight));

            yOffset = 0;
            if (textSize.Height < DesiredMaxHeight)
            {
                yOffset = DesiredMaxHeight / 2 - textSize.Height / 2;
            }

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    drawer.DrawRect(backColour, 0, 0, size.Width, size.Height);
                    args.SkipPartsCheck = true;
                    drawer.DrawText(ref args, 0, 0);

                    args.Text           = Validator.Range;
                    args.SkipPartsCheck = false;
                    Size hintSize = drawer.MeasureSize(ref args);

                    args.SkipPartsCheck = true;
                    int hintX = size.Width - hintSize.Width;
                    if (textSize.Width < hintX)
                    {
                        drawer.DrawText(ref args, hintX, 0);
                    }
                    chatInputTexture = drawer.Make2DTexture(bmp, size, 0, yOffset);
                }

            X = CalcOffset(game.Width, size.Width, XOffset, HorizontalAnchor);
            Y = CalcOffset(game.Height, size.Height, YOffset, VerticalAnchor);
            chatCaretTexture.X1  = chatInputTexture.X1 = X;
            chatCaretTexture.X1 += textSize.Width;
            chatCaretTexture.Y1  = chatInputTexture.Y1 = Y;
            chatCaretTexture.Y1  = (Y + size.Height) - chatCaretTexture.Height;
            Width  = size.Width;
            Height = size.Height;
        }
        public void Redraw( IDrawer2D drawer, string text, Font font )
        {
            if( !Active )
                text = "&7" + Text;
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Size size = drawer.MeasureSize( ref args );
            int width = ButtonWidth, height = ButtonHeight;
            int xOffset = width - size.Width, yOffset = height - size.Height;

            if( Shadow )
                drawer.DrawRoundedRect( Active ? shadowColActive : shadowCol,
                                       3, X + IDrawer2D.Offset, Y + IDrawer2D.Offset, width, height );
            drawer.DrawRoundedRect( Active ? boxColActive : boxCol,
                                   3, X, Y, width, height );

            args.SkipPartsCheck = true;
            drawer.DrawText( ref args, X + 1 + xOffset / 2, Y + 1 + yOffset / 2 );
        }
        unsafe void DrawContent( IDrawer2D drawer, Font font, Element e, int yOffset )
        {
            string s = new String( '\0', e.CharsPerItem );
            int wrap = e.ItemsPerRow;
            DrawTextArgs args = new DrawTextArgs( s, font, false );

            fixed( char* ptr = s ) {
                for( int i = 0; i < e.Contents.Length; i += e.CharsPerItem ) {
                    for( int j = 0; j < e.CharsPerItem; j++ )
                        ptr[j] = e.Contents[i + j];
                    int item = i / e.CharsPerItem;

                    int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height;
                    y += yOffset;
                    drawer.DrawChatText( ref args, x, y );
                }
            }
        }
예제 #23
0
        public static Bitmap ReadBmp(IDrawer2D drawer, Stream src)
        {
                        #if !ANDROID
            Bitmap bmp = new Bitmap(src);
                        #else
            Bitmap bmp = BitmapFactory.DecodeStream(src);
                        #endif

            if (!ValidBitmap(bmp))
            {
                return(null);
            }
            if (!Is32Bpp(bmp))
            {
                drawer.ConvertTo32Bpp(ref bmp);
            }
            return(bmp);
        }
예제 #24
0
        public override void Init()
        {
            graphicsApi.Fog = false;
            SetTitle(serverName);
            SetMessage(serverMotd);
            progX = game.Width / 2f - progWidth / 2f;

            Size size = new Size(progWidth, progHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) {
                using (IDrawer2D drawer = game.Drawer2D) {
                    drawer.SetBitmap(bmp);
                    drawer.DrawRectBounds(FastColour.White, 3f, 0, 0, progWidth, progHeight);
                    progressBoxTexture = drawer.Make2DTexture(bmp, size, (int)progX, (int)progY);
                }
            }
            game.MapEvents.MapLoading += MapLoading;
        }
예제 #25
0
        unsafe void Make(Element e, Font font)
        {
            Size *sizes = stackalloc Size[e.Contents.Length / e.CharsPerItem];

            MeasureContentSizes(e, font, sizes);
            Size bodySize = CalculateContentSize(e, sizes, out elementSize);
            int  titleWidth = MeasureTitles(font), titleHeight = elements[0].TitleSize.Height;
            Size size = new Size(Math.Max(bodySize.Width, titleWidth), bodySize.Height + titleHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTitles(drawer, font);
                    drawer.Clear(new FastColour(30, 30, 30, 200), 0, titleHeight,
                                 size.Width, bodySize.Height);

                    DrawContent(drawer, font, e, titleHeight);
                    texture = drawer.Make2DTexture(bmp, size, X, Y);
                }
        }
예제 #26
0
        void MakeTexture(string text)
        {
            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = game.Drawer2D.MeasureChatSize(ref args);

            int xOffset = Math.Max(size.Width, DesiredMaxWidth) - size.Width;

            size.Width = Math.Max(size.Width, DesiredMaxWidth);
            int yOffset = Math.Max(size.Height, DesiredMaxHeight) - size.Height;

            size.Height = Math.Max(size.Height, DesiredMaxHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    args.SkipPartsCheck = true;
                    drawer.DrawChatText(ref args, xOffset / 2, yOffset / 2);
                    texture = drawer.Make2DTexture(bmp, size, 0, 0);
                }
        }
        public void WordWrap( IDrawer2D drawer, ref string[] lines, ref int[] lineLens, 
            int lineSize, int totalChars)
        {
            int len = Length;
            for( int i = 0; i < lines.Length; i++ ) {
                lines[i] = null;
                lineLens[i] = 0;
            }

            // Need to make a copy because we mutate the characters.
            char[] realText = value;
            MakeWrapCopy();

            int linesCount = 0;
            for( int index = 0; index < totalChars; index += lineSize ) {
                if( value[index] == '\0' )
                    break;

                int lineEnd = index + (lineSize - 1), nextLine = lineEnd + 1;
                linesCount++;

                // Do we need word wrapping?
                bool needWrap = !IsWrapper( value[lineEnd] )
                    && nextLine < totalChars && !IsWrapper( value[nextLine] );
                int wrappedLen = needWrap ? WrapLine( index, lineSize ) : lineSize;

                // Calculate the maximum size of this line
                int lineLen = lineSize;
                for( int i = lineEnd; i >= index; i-- ) {
                    if( value[i] != '\0' ) break;
                    lineLen--;
                }
                lineLens[index / lineSize] = Math.Min( lineLen, wrappedLen );
            }

            // Output the used lines
            OutputLines( drawer, ref lines, lineLens,
                        linesCount, lineSize, totalChars );
            value = realText;
        }
예제 #28
0
        unsafe void DrawContent(IDrawer2D drawer, Font font, Element e, int yOffset)
        {
            string       s    = new String('\0', e.CharsPerItem);
            int          wrap = e.ItemsPerRow;
            DrawTextArgs args = new DrawTextArgs(s, font, false);

            fixed(char *ptr = s)
            {
                for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
                {
                    for (int j = 0; j < e.CharsPerItem; j++)
                    {
                        ptr[j] = e.Contents[i + j];
                    }
                    int item = i / e.CharsPerItem;

                    int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height;
                    y += yOffset;
                    drawer.DrawChatText(ref args, x, y);
                }
            }
        }
        unsafe void SetCaretToCursor(int mouseX, int mouseY)
        {
            mouseX -= inputTex.X1; mouseY -= inputTex.Y1;
            DrawTextArgs args = new DrawTextArgs(null, font, true);
            IDrawer2D    drawer = game.Drawer2D;
            int          offset = 0, elemHeight = defaultHeight;
            string       oneChar = new String('A', 1);

            for (int y = 0; y < lines; y++)
            {
                string line = parts[y];
                if (line == null)
                {
                    continue;
                }

                for (int x = 0; x < line.Length; x++)
                {
                    args.Text = line.Substring(0, x);
                    int trimmedWidth = drawer.MeasureChatSize(ref args).Width;

                    // avoid allocating an unnecessary string
                    fixed(char *ptr = oneChar)
                    ptr[0] = line[x];

                    args.Text = oneChar;
                    int elemWidth = drawer.MeasureChatSize(ref args).Width;
                    if (Contains(trimmedWidth, y * elemHeight, elemWidth, elemHeight, mouseX, mouseY))
                    {
                        caretPos = offset + x;
                        CalculateCaretData(); return;
                    }
                }
                offset += partLens[y];
            }
            caretPos = -1;
            CalculateCaretData();
        }
        void DrawString()
        {
            int totalHeight = 0;

            for (int i = 0; i < lines; i++)
            {
                totalHeight += sizes[i].Height;
            }
            Size size = new Size(maxWidth, totalHeight);

            int realHeight = 0;

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTextArgs args = new DrawTextArgs(null, font, true);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        if (parts[i] == null)
                        {
                            break;
                        }
                        args.Text = parts[i];

                        drawer.DrawChatText(ref args, 0, realHeight);
                        realHeight += sizes[i].Height;
                    }
                    inputTex = drawer.Make2DTexture(bmp, size, 10, 0);
                }

            Height       = realHeight == 0 ? defaultHeight : realHeight;
            Y            = game.Height - Height - YOffset;
            inputTex.Y1  = Y;
            caretTex.Y1 += Y;
            Width        = size.Width;
        }
예제 #31
0
        void OutputLines(IDrawer2D drawer, ref string[] lines, int linesCount, int lineSize, int[] lineLens)
        {
            for (int i = 0; i < capacity; i++)
            {
                if (value[i] == '\0')
                {
                    value[i] = ' ';
                }
            }
            // convert %0-f to &0-f for colour preview.
            for (int i = 0; i < capacity - 1; i++)
            {
                if (value[i] == '%' && drawer.ValidColour(value[i + 1]))
                {
                    value[i] = '&';
                }
            }

            for (int i = 0; i < Math.Max(1, linesCount); i++)
            {
                lines[i] = new String(value, i * lineSize, lineLens[i]);
            }
        }
예제 #32
0
        public unsafe string Substring(int offset, int len)
        {
            if (len == 0)
            {
                return("");
            }
            char *tmp = stackalloc char[len];

            // convert %0-f to &0-f for colour preview.
            for (int i = 0; i < len; i++)
            {
                tmp[i] = value[offset + i];
                if (tmp[i] != '%' || (i + 1) >= len)
                {
                    continue;
                }
                if (IDrawer2D.ValidColCode(value[offset + i + 1]))
                {
                    tmp[i] = '&';
                }
            }
            return(new String(tmp, 0, len));
        }
예제 #33
0
        unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            LinkData data      = Split(index, text);
            Size     total     = Size.Empty;
            Size *   partSizes = stackalloc Size[data.parts.Length];

            linkData[index] = data;

            for (int i = 0; i < data.parts.Length; i++)
            {
                args.Text    = data.parts[i];
                args.Font    = (i & 1) == 0 ? font : underlineFont;
                partSizes[i] = game.Drawer2D.MeasureChatSize(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    int x = 0;

                    for (int i = 0; i < data.parts.Length; i++)
                    {
                        args.Text = data.parts[i];
                        args.Font = (i & 1) == 0 ? font : underlineFont;
                        Size size = partSizes[i];

                        drawer.DrawChatText(ref args, x, 0);
                        data.bounds[i].X     = x;
                        data.bounds[i].Width = size.Width;
                        x += size.Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }
        Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            string[] items = Split(index, text);
            Size     total = Size.Empty;

            Size[] partSizes = new Size[items.Length];

            for (int i = 0; i < items.Length; i++)
            {
                args.Text    = items[i];
                args.Font    = (i & 1) == 0 ? font : underlineFont;
                partSizes[i] = game.Drawer2D.MeasureChatSize(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    int x = 0;

                    for (int i = 0; i < items.Length; i++)
                    {
                        args.Text = items[i];
                        args.Font = (i & 1) == 0 ? font : underlineFont;
                        Size size = partSizes[i];

                        drawer.DrawChatText(ref args, x, 0);
                        urlBounds[index][i].X     = x;
                        urlBounds[index][i].Width = size.Width;
                        x += size.Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }
        public void Run()
        {
            Window = new NativeWindow( 640, 400, Program.AppName, 0,
                                      GraphicsMode.Default, DisplayDevice.Default );
            Window.Visible = true;
            Drawer = new GdiPlusDrawer2D( null );
            Init();
            TryLoadTexturePack();
            platformDrawer.Init( Window.WindowInfo );

            string audioPath = Path.Combine( Program.AppDirectory, "audio" );
            BinUnpacker.Unpack( audioPath, "dig" );
            BinUnpacker.Unpack( audioPath, "step" );

            fetcher = new ResourceFetcher();
            fetcher.CheckResourceExistence();
            checkTask = new UpdateCheckTask();
            checkTask.CheckForUpdatesAsync();
            if( !fetcher.AllResourcesExist )
                SetScreen( new ResourcesScreen( this ) );
            else
                SetScreen( new MainScreen( this ) );

            while( true ) {
                Window.ProcessEvents();
                if( !Window.Exists ) break;
                if( ShouldExit ) {
                    if( Screen != null )
                        Screen.Dispose();
                    break;
                }

                Screen.Tick();
                if( Dirty || Screen.Dirty )
                    Display();
                Thread.Sleep( 1 );
            }

            if( Options.Load() ) {
                LauncherSkin.SaveToOptions();
                Options.Save();
            }

            if( ShouldUpdate )
                Updater.Patcher.LaunchUpdateScript();
            if( Window.Exists )
                Window.Close();
        }
예제 #36
0
 public TerrainAtlas2D(IGraphicsApi graphics, IDrawer2D drawer)
 {
     this.graphics = graphics;
     this.drawer   = drawer;
 }
예제 #37
0
 public void Redraw( IDrawer2D drawer )
 {
     RecalculateDrawData();
     RedrawData( drawer );
 }
예제 #38
0
        int DrawColumn( IDrawer2D drawer, bool separator, Font font, Font titleFont,
            string header, int maxWidth, int x, Func<TableEntry, string> filter)
        {
            int y = table.Y + 3;
            DrawTextArgs args = new DrawTextArgs( header, titleFont, true );
            TableEntry headerEntry = default( TableEntry );
            DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref headerEntry );
            maxIndex = table.Count;
            y += 5;

            for( int i = table.CurrentIndex; i < table.Count; i++ ) {
                args = new DrawTextArgs( filter( table.usedEntries[i] ), font, true );
                if( i == table.SelectedIndex && !separator ) {
                    int startY = y - 3;
                    int height = Math.Min( startY + (entryHeight + 4), table.Y + table.Height ) - startY;
                    drawer.Clear( foreGridCol, table.X, startY, table.Width, height );
                }

                if( !DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref table.usedEntries[i] ) ) {
                    maxIndex = i; break;
                }
            }

            if( separator && !window.ClassicBackground )
                drawer.Clear( LauncherSkin.BackgroundCol, x - 7, table.Y, 2, table.Height );
            return maxWidth + 5;
        }
예제 #39
0
 public override void Redraw( IDrawer2D drawer )
 {
     if( Window.Minimised ) return;
     DrawTextArgs args = new DrawTextArgs( Text, font, true );
     drawer.DrawText( ref args, X, Y );
 }
예제 #40
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            try {
                Options.Load();
            } catch( IOException ) {
                Utils.LogWarning( "Unable to load options.txt" );
            }
            ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 );
            Keys = new KeyMap();
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            defaultIb = Graphics.MakeDefaultIb();

            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Graphics.PrintGraphicsInfo();
            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( this );
            EnvRenderer = new StandardEnvRenderer( this );
            if( IPAddress == null ) {
                Network = new Singleplayer.SinglePlayerServer( this );
            } else {
                Network = new NetworkProcessor( this );
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam = new FirstPersonCamera( this );
            thirdPersonCam = new ThirdPersonCamera( this );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            Graphics.SetVSync( this, true );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            Title = Utils.AppName;
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
예제 #41
0
 void LoadSavedInfo( IDrawer2D drawer )
 {
     Dictionary<string, object> metadata;
     // restore what user last typed into the various fields
     if( game.ScreenMetadata.TryGetValue( "screen-CC", out metadata ) ) {
         Set( 2, (string)metadata["user"] );
         Set( 3, (string)metadata["pass"] );
     } else {
         LoadFromOptions();
     }
 }
예제 #42
0
 public static Bitmap ReadBmp(IDrawer2D drawer, byte[] data)
 {
     return(ReadBmp(drawer, new MemoryStream(data)));
 }
예제 #43
0
 public TerrainAtlas2D(IGraphicsApi gfx, IDrawer2D drawer)
 {
     this.gfx    = gfx;
     this.drawer = drawer;
 }
예제 #44
0
 void DrawClassic( IDrawer2D drawer )
 {
     FastColour highlightCol = Active ? new FastColour( 189, 198, 255 ) : new FastColour( 168, 168, 168 );
     drawer.Clear( highlightCol, X + border + 1, Y + border, Width - (border * 2 + 1), border );
     drawer.Clear( highlightCol, X + border, Y + border + 1, border, Height - (border * 2 + 1) );
 }
예제 #45
0
 public abstract void Redraw( IDrawer2D drawer );
예제 #46
0
 void DrawScrollbar( IDrawer2D drawer )
 {
     FastColour col = window.ClassicBackground ? new FastColour( 80, 80, 80 ) : LauncherSkin.ButtonBorderCol;
     drawer.Clear( col, window.Width - 10, table.Y, 10, table.Height );
     col = window.ClassicBackground ? new FastColour( 160, 160, 160 ) : LauncherSkin.ButtonForeActiveCol;
     int yOffset, height;
     table.GetScrollbarCoords( out yOffset, out height );
     drawer.Clear( col, window.Width - 10, table.Y + yOffset, 10, height );
 }
예제 #47
0
 public LauncherScreen( LauncherWindow game )
 {
     this.game = game;
     drawer = game.Drawer;
 }
예제 #48
0
        void LoadSavedInfo( IDrawer2D drawer )
        {
            try {
                Options.Load();
            } catch( IOException ) {
                return;
            }

            string user = Options.Get( "launcher-cc-username" ) ?? "";
            string pass = Options.Get( "launcher-cc-password" ) ?? "";
            pass = Secure.Decode( pass, user );

            Set( 2, user );
            Set( 3, pass );
        }
 public void DrawAt( IDrawer2D drawer, Anchor horAnchor, Anchor verAnchor, int x, int y )
 {
     CalculateOffset( x, y, horAnchor, verAnchor );
     Redraw( drawer );
 }
예제 #50
0
 public TerrainAtlas2D( IGraphicsApi graphics, IDrawer2D drawer )
 {
     this.graphics = graphics;
     this.drawer = drawer;
 }
예제 #51
0
 void DrawNormal( IDrawer2D drawer )
 {
     if( Active ) return;
     FastColour lineCol = LauncherSkin.ButtonHighlightCol;
     drawer.Clear( lineCol, X + border + 1, Y + border, Width - (border * 2 + 1), border );
 }