Ejemplo n.º 1
0
 public void SetColors(TCODConsole screen, bool selected, bool enabled)
 {
     if (enabled)
     {
         if (selected)
         {
             screen.setForegroundColor(ColorPresets.LightGray);
             screen.setBackgroundColor(ColorPresetsFromTCOD.BrightBlue);
         }
         else
         {
             screen.setForegroundColor(ColorPresets.Gray);
             screen.setBackgroundColor(ColorPresets.Black);
         }
     }
     else
     {
         if (selected)
         {
             screen.setForegroundColor(ColorPresets.Red);
             screen.setBackgroundColor(ColorPresetsFromTCOD.BrightYellow);
         }
         else
         {
             screen.setForegroundColor(ColorPresets.Red);
             screen.setBackgroundColor(ColorPresets.Black);
         }
     }
 }
Ejemplo n.º 2
0
        // Display a line of text
        public void DisplayText(string textToDisplay, int x, int y, TCODColor foregroundColor, TCODColor backgroundColor, int Index)
        {
            // Handle mainmenu colour-swapping
            if (Index == (int)currentMenuOption)
            {
                foregroundColor   = TCODColor.black;
                colourInterpolate = colourInterpolate + colourInterpolateStep;
                if (colourInterpolate >= 0.91)
                {
                    colourInterpolateStep = -0.01;
                }
                else if (colourInterpolate <= 0.11)
                {
                    colourInterpolateStep = 0.01;
                }
                backgroundColor = TCODColor.Interpolate(TCODColor.yellow, TCODColor.red, (float)colourInterpolate);
            }

            rootConsole.setBackgroundColor(backgroundColor);
            rootConsole.setForegroundColor(foregroundColor);

            if (Index != -1)
            {
                System.Text.StringBuilder OffSetString = new System.Text.StringBuilder();
                OffSetString.Append(' ', (36 - textToDisplay.Length) / 2);
                textToDisplay = OffSetString + textToDisplay + OffSetString;
            }
            else
            {
                if (x == -1)
                {
                    x = (consoleWidth - textToDisplay.Length) / 2;
                }
            }

            int offset = 0;

            foreach (char value in textToDisplay)
            {
                if (value == '[')
                {
                    rootConsole.setForegroundColor(foregroundColor);
                }
                else if (value == ']')
                {
                    rootConsole.setForegroundColor(foregroundColor);
                }
                else if (offset == 1 && textToDisplay[0] == '[')
                {
                    rootConsole.setForegroundColor(foregroundColor);
                }
                else
                {
                    rootConsole.setForegroundColor(foregroundColor);
                }
                offset++;
                rootConsole.setCharBackground(x + offset, y, backgroundColor, TCODBackgroundFlag.Set);
                rootConsole.print(x + offset, y, value.ToString());
            }
        }
Ejemplo n.º 3
0
        private static void RenderAllConsoles(Game game, TCODConsole rootConsole, TCODConsole playConsole, TCODColor fogOfWarColour,
                                              TCODConsole playerConsole, TCODConsole competitorConsole,
                                              TCODConsole eventsConsole, Rectangle playBounds, Rectangle playerBounds,
                                              Rectangle competitorBounds, Rectangle eventBounds)
        {
            rootConsole.clear();
            rootConsole.setForegroundColor(ColorPresets.White);
            rootConsole.setBackgroundColor(ColorPresets.Black);

            RenderPlayConsole(game, playConsole, fogOfWarColour, playBounds);
            RenderPlayerConsole(game.Player, playerConsole, playerBounds);
            //RenderThreatConsole(game.Player, game.Actors, threatConsole, threatBounds);
            RenderCompetitorConsole(game, competitorConsole, competitorBounds);
            RenderEventsConsole(game, eventsConsole, eventBounds);

            TCODConsole.blit(playConsole, 0, 0, playBounds.Width, playBounds.Height, rootConsole, playBounds.X, playBounds.Y);
            TCODConsole.blit(playerConsole, 0, 0, playerBounds.Width, playerBounds.Height, rootConsole, playerBounds.X, playerBounds.Y);
            TCODConsole.blit(competitorConsole, 0, 0, competitorBounds.Width, competitorBounds.Height, rootConsole, competitorBounds.X, competitorBounds.Y);
            TCODConsole.blit(eventsConsole, 0, 0, eventBounds.Width, eventBounds.Height, rootConsole, eventBounds.X, eventBounds.Y);

            //playConsole.Blit(0, 0, playBounds.Width, playBounds.Height, rootConsole, playBounds.X, playBounds.Y);
            //playerConsole.Blit(0, 0, playerBounds.Width, playerBounds.Height, rootConsole, playerBounds.X,
            //                   playerBounds.Y);

            //competitorConsole.Blit(0, 0, competitorBounds.Width, competitorBounds.Height, rootConsole,
            //                       competitorBounds.X, competitorBounds.Y);
            //eventsConsole.Blit(0, 0, eventBounds.Width, eventBounds.Height, rootConsole, eventBounds.X, eventBounds.Y);
        }
Ejemplo n.º 4
0
        public void Draw()
        {
            int lightLenght = (int)((1 - _player.Light.Used) * 80);

            _root.setBackgroundColor(TCODColor.black);
            _root.setForegroundColor(TCODColor.white);
            Map.Draw(_mapConsole);
            _messages.Draw();
            TCODConsole.blit(_mapConsole, 0, 0, 80, 50, _root, 0, 1);
            TCODConsole.blit(_messages.Console, 0, 0, 80, 10, _root, 0, 51);
            _root.hline(0, 0, 80, TCODBackgroundFlag.Set);
            _root.setBackgroundColor(TCODColor.amber);
            _root.setForegroundColor(TCODColor.amber);
            _root.hline(0, 0, lightLenght, TCODBackgroundFlag.Set);
            TCODConsole.flush();
        }
Ejemplo n.º 5
0
        public static TCODConsole LoadImage(string fileName)
        {
            var         transparentColor = new TCODColor(255, 0, 255);
            TCODConsole image            = null;

            try {
                using (var file = File.Open(fileName, FileMode.Open)) {
                    var decrompressedStream = new GZipStream(file, CompressionMode.Decompress);
                    var reader      = new BinaryReader(decrompressedStream);
                    var fileVersion = reader.ReadInt32();
                    var layerCount  = reader.ReadInt32();

                    // Reserving space for these in advance, so I'm not doing memory
                    // allocations repeatedly in the loop.
                    int       layerWidth = 0;
                    int       layerHeight = 0;
                    int       x, y;
                    int       characterCode = 0;
                    TCODColor foreground    = new TCODColor();
                    TCODColor background    = new TCODColor();

                    for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
                    {
                        layerWidth  = reader.ReadInt32();
                        layerHeight = reader.ReadInt32();
                        if (image == null)
                        {
                            image = new TCODConsole(layerWidth, layerHeight);
                            image.setBackgroundColor(transparentColor);
                            image.clear();
                            image.setKeyColor(transparentColor);
                        }

                        for (var charIndex = 0; charIndex < layerWidth * layerHeight; ++charIndex)
                        {
                            x                = charIndex / layerHeight;
                            y                = charIndex % layerHeight;
                            characterCode    = reader.ReadInt32();
                            foreground.Red   = reader.ReadByte();
                            foreground.Green = reader.ReadByte();
                            foreground.Blue  = reader.ReadByte();
                            background.Red   = reader.ReadByte();
                            background.Green = reader.ReadByte();
                            background.Blue  = reader.ReadByte();

                            // Check if the current cell is transparent.
                            if (background.NotEqual(transparentColor))
                            {
                                image.putCharEx(x, y, characterCode, foreground, background);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Logger.Error($"Error loading file '{fileName}': {e.Message}");
            }
            return(image);
        }
Ejemplo n.º 6
0
 public void ResetColors(TCODConsole screen)
 {
     if (m_stuffSaved)
     {
         screen.setForegroundColor(m_savedForeground);
         screen.setBackgroundColor(m_savedBackground);
         m_stuffSaved = false;
     }
 }
Ejemplo n.º 7
0
 public GUI(Window win, TCODConsole main, Camera camera)
 {
     statusWindow = new TCODConsole(Window.StatusPanelWidth, win.Height);
     eventLog = new TCODConsole(win.Width - Window.StatusPanelWidth, Window.MessagePanelHeight);
     statusWindow.setAlignment(TCODAlignment.CenterAlignment);
     statusWindow.setBackgroundColor(TCODColor.darkestRed.Multiply(0.1f));
     this.main = main;
     this.window = win;
     this.camera = camera;
 }
Ejemplo n.º 8
0
Archivo: Fov.cs Proyecto: dritory/Janus
        public Fov(Actor owner, params object[] args) : base(owner, args)
        {
            if (args.Length > 0)
            {
                if (args[0].GetType() == typeof(string))
                {
                    fovRadius = int.Parse((string)args[0]);
                }
                else
                {
                    fovRadius = (int)args[0];
                }
            }
            if (args.Length > 1)
            {
                if (args[1].GetType() == typeof(string))
                {
                    strenght = byte.Parse((string)args[1]);
                }
                else
                {
                    strenght = (byte)(int)args[1];
                }
            }
            if (args.Length > 2)
            {
                try
                {
                    System.Reflection.PropertyInfo property = typeof(libtcod.TCODColor).GetProperty(args[2].ToString().ToLower());
                    if (property != null)
                    {
                        color = (libtcod.TCODColor)property.GetValue(color, null);
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }
            mapx   = (fovRadius);
            mapy   = (fovRadius);
            height = mapx;
            width  = mapy;

            fovMaps    = new TCODMap[2];
            fovMaps[0] = new TCODMap(width * 2, height * 2);
            fovMaps[1] = new TCODMap(width * 2, height * 2);

            calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length];
            lightmap       = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            update();
        }
Ejemplo n.º 9
0
        public override void DrawNewFrame(TCODConsole screen)
        {
            if (m_isSelectionCursor)
            {
                screen.setCharBackground(ScreenCenter.X + 1, ScreenCenter.Y + 1, TCODColor.darkYellow);

                if (ToolTipsEnabled)
                {
                    if (TCODSystem.getElapsedMilli() - m_lastCursorMovedTime > TimeUntilToolTipPopup)
                    {
                        if (m_currentToolTips.Count > 0)
                        {
                            const int MaxNumberOfLinesToShow = 3;
                            int numberOfLinesToShow = System.Math.Min(m_currentToolTips.Count, MaxNumberOfLinesToShow);

                            int longestLine = 0;
                            for (int i = 0; i < numberOfLinesToShow; ++i)
                                longestLine = System.Math.Max(longestLine, m_currentToolTips[i].Length);

                            // If we're going to need to print "...more..." make sure we have the width
                            if (m_currentToolTips.Count > MaxNumberOfLinesToShow)
                                longestLine = System.Math.Max(longestLine, 10);

                            screen.setBackgroundColor(ColorPresets.DarkGray);

                            int frameHeight = m_currentToolTips.Count > MaxNumberOfLinesToShow ? 3 + numberOfLinesToShow : 2 + numberOfLinesToShow;
                            screen.printFrame(ScreenCenter.X + 2, ScreenCenter.Y - 2, longestLine + 2, frameHeight, false, TCODBackgroundFlag.Multiply);

                            for (int i = 0; i < numberOfLinesToShow; ++i)
                                screen.printEx(ScreenCenter.X + 3, ScreenCenter.Y - 1 + i, TCODBackgroundFlag.Multiply, TCODAlignment.LeftAlignment, m_currentToolTips[i]);

                            if (m_currentToolTips.Count > MaxNumberOfLinesToShow)
                                screen.printEx(ScreenCenter.X + 3, ScreenCenter.Y - 1 + MaxNumberOfLinesToShow, TCODBackgroundFlag.Multiply, TCODAlignment.LeftAlignment, "...more...");

                            screen.setBackgroundColor(ColorPresets.Black);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
Archivo: Fov.cs Proyecto: dritory/Janus
        public override void load(Actor owner)
        {
            base.load(owner);
            lightmap = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            fovMaps    = new TCODMap[2];
            fovMaps[0] = new TCODMap(width * 2, height * 2);
            fovMaps[1] = new TCODMap(width * 2, height * 2);

            calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length];
            initializeFov  = true;
        }
Ejemplo n.º 11
0
        public DynamicFov() : base()
        {
            mapx   = 0;
            mapy   = 0;
            height = map.renderHeight + (mapy);
            width  = map.renderWidth + (mapx);

            fovMaps    = new TCODMap[1];
            fovMaps[0] = new TCODMap(width, height);
            lightmap   = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            update();
        }
Ejemplo n.º 12
0
        public override void load(Actor owner)
        {
            base.load(owner);
            mapx   = 0;
            mapy   = 0;
            height = map.renderHeight + (mapy);
            width  = map.renderWidth + (mapx);

            fovMaps    = new TCODMap[1];
            fovMaps[0] = new TCODMap(width, height);
            lightmap   = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            initializeFov = true;
            update();
        }
Ejemplo n.º 13
0
 //Initialisation logic
 public void Init()
 {
     TCODConsole.setCustomFont("oryx_tiles.png", ((int)TCODFontFlags.Greyscale | (int)TCODFontFlags.LayoutTCOD), 32, 12);
     TCODConsole.initRoot(80, 50, "DarkRL", false, TCODRendererType.GLSL);
     console = TCODConsole.root;
     TCODConsole.checkForKeypress();
     console.setBackgroundColor(TCODColor.black);
 }
Ejemplo n.º 14
0
 public void SetBackgroundColour(TCODColor colour)
 {
     _console.setBackgroundColor(colour);
 }
Ejemplo n.º 15
0
        public void Render(TCODConsole con, bool linewrap = true)
        {
            int maxlines = con.getHeight()-2;   //Corrected for border
            int maxchars = con.getWidth()-2;
            List<String> lines = new List<string>();
            List<MessageColor> colors = new List<MessageColor>();
            string temp;

            if (log.Count == 0)
                return;

            int i = log.Count-maxlines-1;
            if (log.Count <= maxlines)
                i = 0;
            while (i < log.Count)
            {
                if (log[i].MessageText.Length > maxchars && linewrap)
                {
                    //Oh god the horror that is this function
                    //
                    //Further down, lines are printed from latest to newest (added to "lines")
                    //so in order to display multiline messages correctly, the last of the multiple
                    //lines must be added to lines first and the first last. This is done via
                    //a temporary array which is filled from highest to lowest and then added to lines.
                    int templines =(int)Math.Ceiling((double)log[i].MessageText.Length / (double)maxchars);
                    string[] temparr = new string[templines];
                    int k = templines-1;

                    temp = log[i].MessageText;
                    while (temp.Length > maxchars)
                    {
                        temparr[k] = temp.Substring(0, maxchars);
                        colors.Add(log[i].GetMessageColor());
                        temp = temp.Remove(0, maxchars);
                        k--;
                    }
                    temparr[k] = temp;

                    foreach (String s in temparr)
                    {
                        lines.Add(s);
                    }

                    colors.Add(log[i].GetMessageColor());
                }
                else
                {
                    lines.Add(log[i].MessageText);
                    colors.Add(log[i].GetMessageColor());
                }
                i++;
            }

            int endcount = lines.Count - maxlines;
            if (lines.Count < maxlines)
                endcount = 0;
            int y = 0;
            for (int j = lines.Count-1; j >= endcount; j--)
            {
                con.setForegroundColor(colors[j].ForeColor);
                con.setBackgroundFlag(TCODBackgroundFlag.None);
                if (colors[j].BackColor != null)
                {
                    con.setBackgroundColor(colors[j].BackColor);
                    con.setBackgroundFlag(TCODBackgroundFlag.Screen);
                }

                con.print(1, 1 + y, lines[j]);
                y++;
            }
        }
Ejemplo n.º 16
0
        public int Run(string[] args)
        {
            fillSampleList();

            int curSample = 0; // index of the current sample
            bool first = true; // first time we render a sample
            TCODKey key = new TCODKey();
            string font = "celtic_garamond_10x10_gs_tc.png";
            int numberCharsHorz = 32;
            int numberCharsVert = 8;
            int fullscreenWidth = 0;
            int fullscreenHeight = 0;
            bool fullscreen = false;
            bool credits = false;
            TCODFontFlags flags = TCODFontFlags.Grayscale | TCODFontFlags.LayoutTCOD;
            TCODFontFlags newFlags = 0;

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i] == "-font" && ArgsRemaining(args, i, 1))
                {
                    i++;
                    font = args[i];
                }
                else if (args[i] == "-font-char-numberRows" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    numberCharsHorz = System.Convert.ToInt32(args[i]);
                    i++;
                    numberCharsVert = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen-resolution" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    fullscreenWidth = System.Convert.ToInt32(args[i]);
                    i++;
                    fullscreenHeight = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen")
                {
                    fullscreen = true;
                }
                else if (args[i] == "-font-in-row")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.LayoutAsciiInRow;
                }
                else if (args[i] == "-font-greyscale")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.Grayscale;
                }
                else if (args[i] == "-font-tcod")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.LayoutTCOD;
                }
                else if (args[i] == "-help")
                {
                    System.Console.Out.WriteLine("options : \n");
                    System.Console.Out.WriteLine("-font <filename> : use a custom font\n");
                    System.Console.Out.WriteLine("-font-char-size <char_width> <char_height> : size of the custom font's characters\n");
                    System.Console.Out.WriteLine("-font-in-row : the font layout is in row instead of columns\n");
                    System.Console.Out.WriteLine("-font-tcod : the font uses TCOD layout instead of ASCII\n");
                    System.Console.Out.WriteLine("-font-greyscale : antialiased font using greyscale bitmap\n");
                    System.Console.Out.WriteLine("-fullscreen : start in fullscreen\n");
                    System.Console.Out.WriteLine("-fullscreen-resolution <screen_width> <screen_height> : force fullscreen resolution\n");
                    return 0;
                }
            }
            if (flags == 0)
                flags = newFlags;

            if (fullscreenWidth > 0)
                TCODSystem.forceFullscreenResolution(fullscreenWidth, fullscreenHeight);

            TCODConsole.setCustomFont(font, (int)flags, numberCharsHorz, numberCharsVert);
            TCODConsole.initRoot(80, 50, "tcodlib C# sample", fullscreen, TCODRendererType.SDL);
            rootConsole = TCODConsole.root;
            sampleConsole = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);

            setupStaticData();
            rootConsole.setBackgroundFlag(TCODBackgroundFlag.Set);
            rootConsole.setAlignment(TCODAlignment.LeftAlignment);
            do
            {
                rootConsole.clear();
                if (!credits)
                    credits = TCODConsole.renderCredits(60, 42, false);
                for (int i = 0; i < sampleList.Length; i++)
                {
                    if (i == curSample)
                    {
                        // set colors for currently selected sample
                        rootConsole.setForegroundColor(TCODColor.white);
                        rootConsole.setBackgroundColor(TCODColor.blue);
                    }
                    else
                    {
                        // set colors for other samples
                        rootConsole.setForegroundColor(TCODColor.grey);
                        rootConsole.setBackgroundColor(TCODColor.black);
                    }
                    rootConsole.print(2, 45 - sampleList.Length + i, sampleList[i].name);
                }
                rootConsole.setForegroundColor(TCODColor.grey);
                rootConsole.setBackgroundColor(TCODColor.black);
                rootConsole.printEx(79, 46, TCODBackgroundFlag.Set, TCODAlignment.RightAlignment, "last frame : " + ((int)(TCODSystem.getLastFrameLength() * 1000)).ToString() + " ms ( " + TCODSystem.getFps() + "fps)");
                rootConsole.printEx(79, 47, TCODBackgroundFlag.Set, TCODAlignment.RightAlignment, "elapsed : " + TCODSystem.getElapsedMilli() + "ms " + (TCODSystem.getElapsedSeconds().ToString("0.00")) + "s");
                rootConsole.putChar(2, 47, (char)TCODSpecialCharacter.ArrowNorth);
                rootConsole.putChar(3, 47, (char)TCODSpecialCharacter.ArrowSouth);
                rootConsole.print(4, 47, " : select a sample");
                rootConsole.print(2, 48, "ALT-ENTER : switch to " + (TCODConsole.isFullscreen() ? "windowed mode  " : "fullscreen mode"));

                sampleList[curSample].render(first, key);
                first = false;

                TCODConsole.blit(sampleConsole, 0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, rootConsole, SAMPLE_SCREEN_X, SAMPLE_SCREEN_Y);

                TCODConsole.flush();
                key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (key.KeyCode == TCODKeyCode.Down)
                {
                    // down arrow : next sample
                    curSample = (curSample + 1) % sampleList.Length;
                    first = true;
                }
                else if (key.KeyCode == TCODKeyCode.Up)
                {
                    // up arrow : previous sample
                    curSample--;
                    if (curSample < 0)
                        curSample = sampleList.Length - 1;
                    first = true;
                }
                else if (key.KeyCode == TCODKeyCode.Enter && (key.LeftAlt || key.RightAlt))
                {
                    // ALT-ENTER : switch fullscreen
                    TCODConsole.setFullscreen(!TCODConsole.isFullscreen());
                }
                else if (key.KeyCode == TCODKeyCode.F1)
                {
                    System.Console.Out.WriteLine("key.pressed" + " " +
                        key.LeftAlt + " " + key.LeftControl + " " + key.RightAlt +
                        " " + key.RightControl + " " + key.Shift);
                }

            }
            while (!TCODConsole.isWindowClosed());
            return 0;
        }
Ejemplo n.º 17
0
Archivo: Game.cs Proyecto: bilwis/SH2RL
        public void RenderInventory(TCODConsole con, int con_x, int con_y, int width, int height)
        {
            con.setForegroundColor(TCODColor.darkAzure);
            con.setBackgroundColor(TCODColor.darkestBlue);
            con.setBackgroundFlag(TCODBackgroundFlag.Set);

            con.printFrame(con_x + 1, con_y + 1, width - 2, height - 2);

            con.setBackgroundFlag(TCODBackgroundFlag.Default);

            con.vline(width / 2, con_y + 2 + 5, height - 4 - 5);
            con.hline(con_x + 2, con_y + 1 + 5, width - 4);

            con.print(con_x + 2, con_y + 2, "GRZ64 INTEGRATED BACKPACK INTERFACE V1.14 REV 1984");
            con.print(con_x + 2, con_y + 3, "UNREGISTERED TRIAL VERSION");

            con.print(con_x + 2, con_y + 5, "LOADING INVENTORY DATA...");

            if (player.Inventory.Count > 0)
            {
                int cap = (height - 5) - (con_y + 7);
                int count = player.Inventory.Count;

                if (menu_selection >= count)
                    menu_selection = (menu_selection - count);

                if (menu_selection < 0)
                    menu_selection = count - 1;

                int top = menu_selection > cap ? (menu_selection - cap) : 0;
                int bottom = top + count > cap ? cap : top + count;

                int it = 0;

                List<Item> item_list = player.Inventory.GetItemList();
                Item sel_item = item_list[menu_selection];

                //Item list
                for (int i = top; i < bottom; i++)
                {
                    con.setBackgroundFlag(TCODBackgroundFlag.Default);

                    if (i == menu_selection)
                    {
                        //con.setBackgroundFlag(TCODBackgroundFlag.Set);
                        //con.setBackgroundColor(TCODColor.azure);
                        con.setForegroundColor(TCODColor.azure);
                    }
                    if (i == menu_selection + 1)
                    {
                        con.setForegroundColor(TCODColor.darkAzure);
                    }

                    if (item_list[i].GetType().IsSubclassOf(typeof(EquippableItem)))
                    {
                        EquippableItem ei = (EquippableItem)item_list[i];
                        if (ei.IsEquipped())
                        {
                            con.setBackgroundFlag(TCODBackgroundFlag.Set);
                            con.setBackgroundColor(TCODColor.lightAzure);
                        }
                    }

                    con.print(con_x + 3, con_y + 7 + it, item_list[i].Name);
                    it++;
                }

                con.setBackgroundFlag(TCODBackgroundFlag.Default);

                con.setForegroundColor(TCODColor.darkAzure);
                int left_offset = width / 2 + 1;
                int top_offset = con_y + 7;

                //Item stats
                con.print(left_offset, top_offset + 0, "NAME         : " + sel_item.Name);
                con.print(left_offset, top_offset + 1, "WEIGHT       : " + sel_item.Weight);

                // type specifics
                if (sel_item.GetType() == typeof(Firearm))
                {
                    Firearm f = (Firearm)sel_item;
                    con.print(left_offset, top_offset + 3, "TYPE         : Firearm");
                    con.print(left_offset, top_offset + 5, "CLASS        : " + f.type.ToString());

                    String fm_str = "";

                    foreach (FireMode fm in f.modes)
                    {
                        fm_str += fm.ToString() + " ";
                    }
                    con.print(left_offset, top_offset + 6, "FIREMODES    : " + fm_str);

                    con.print(left_offset, top_offset + 8, "CALIBER      : " + f.caliber.ToString());
                    con.print(left_offset, top_offset + 9, "MAG. CAPACITY: " + f.MagazineCapacity);

                }

                //Item description
                List<String> lines = wrap(sel_item.Description, width / 2 - 2);
                top_offset = con_y + (int)(height * 0.45d);

                for (int j = 0; j < lines.Count; j++)
                {
                    con.print(left_offset, top_offset + j, lines[j]);
                }

                con.hline(left_offset, top_offset - 1, width / 2 - 2);

                //Item actions
                con.hline(width / 2 + 1, height - 4 - 5, width / 2 - 2);
                //con.print(width / 2 + 2, height - 4 - 4, "R/M/T - Equip Rngd/Mlee/Thrwn");
                //con.print(width / 2 + 2, height - 4 - 3, "  E/L - Equip Armor/Lightsrc");
                con.print(width / 2 + 2, height - 4 - 4, "    E - Equip");
                con.print(width / 2 + 2, height - 4 - 3, "    U - Unequip");
                con.print(width / 2 + 2, height - 4 - 2, "    D - Drop Item");
                con.print(width / 2 + 2, height - 4 - 1, "    Q - Quit");
                con.print(width / 2 + 2, height - 4 + 0, "  +,- - Select");
                con.print(width / 2 + 2, height - 4 + 1, "    C - Consume");
                con.print(width / 2 + 2, height - 4 + 2, "    U - Use");
            }
        }
Ejemplo n.º 18
0
Archivo: Map.cs Proyecto: bilwis/SH2RL
        public bool Render(TCODConsole con, int con_x, int con_y, int width, int height)
        {
            //This method is fairly convoluted because of all the intricacies of rendering ALL THE THINGS properly.
            //It could really use a makeover, but I'm not in the "OMGWTFBBQ MAJOR REWRITE UP IN THIS BIATCH" phase
            // and I'm afraid of breaking things.

            #region "Viewport setup"
            //In hnjah, the "viewport" is set up. The viewport is what the camera is in 3D games.
            //It determines what needs to be rendered (everything not in the viewport on any of the three
            //axes is "culled", i.e. not rendered).
            //The viewport is ALWAYS centered on the player.

            int top; //Y
            int left; //X
            int right;
            int bottom;

            top = Player.Y - (height / 2);
            bottom = top + height;

            left = Player.X - (width / 2);
            right = left + width;

            if (top >= bottom || left >= right)
                return false;

            if (top < 0)
            {
                bottom -= top; //Bottom - Top (which is negative): ex.: new Bottom (10-(-5) = 15)
                top = 0;
            }

            if (bottom > wm.GLOBAL_HEIGHT)
            {
                top -= (bottom - wm.GLOBAL_HEIGHT); //ex.: bottom = 15, Globalheight = 10, Top = 5; => Top = 5 - (15-10) = 0
                bottom = wm.GLOBAL_HEIGHT;
            }

            if (left < 0)
            {
                right -= left;
                left = 0;
            }

            if (right > wm.GLOBAL_WIDTH)
            {
                left -= (right - wm.GLOBAL_WIDTH);
                right = wm.GLOBAL_WIDTH;
            }
            #endregion

            #region "Map rendering"

            int abs_x, abs_y, abs_z;
            int rel_x, rel_y;
            int cell_rel_x, cell_rel_y;
            Tile t;
            TCODColor tinted_fore, tinted_back;
            bool floor = false;

            Random rand = new Random();

            int curr_z = Player.Z;
            abs_z = Player.Z - 1;

            String displ_string = " ";

            //Debug vars:
            Stopwatch sw = new Stopwatch();
            int debug_prints = 0;

            sw.Start();
            //AND THEY'RE OFF!

            //Buffer all tiles in the viewport into a two dimensional ushort array
            ushort[,] tilearr = new ushort[right - left + 1, bottom - top + 1];
            for (abs_x = left; abs_x < right; abs_x++)
            {
                for (abs_y = top; abs_y < bottom; abs_y++)
                {
                    tilearr[abs_x - left, abs_y - top] = getTileIDFromCells(abs_x, abs_y, abs_z);
                }
            }
            //Update tint
            UpdateTintMap(width, height);

            //Calculate the player's FOV
            tcod_map.computeFov(Player.X - cells[0, 0, 0].X, Player.Y - cells[0, 0, 0].Y, right - left, true, TCODFOVTypes.RestrictiveFov);

            float color_intensity = 1.0f;
            int light_level = 0;

            //Now go through all the tiles...
            for (abs_x = left; abs_x < right; abs_x++)
            {
                for (abs_y = top; abs_y < bottom; abs_y++)
                {
                    //...determine their relative coordinates (relative to the upper left
                    // corner of the viewport *and the tile byte array*, that is)
                    rel_x = abs_x - left;
                    rel_y = abs_y - top;
                    cell_rel_x = abs_x - cells[0, 0, 0].X;
                    cell_rel_y = abs_y - cells[0, 0, 0].Y;

                    //The light level determines the "color intensity", that is the gradient between the
                    // actual color and TCODColor.black, with intensity=1.0 meaning all color and 0.0 meaning
                    // all black.
                    //Since the light level is additive, it is clamped to MAX_LIGHT_LEVEL
                    light_level = wm.GetCellFromCoordinates(abs_x, abs_y, Player.Z).GetLightLevel(abs_x, abs_y, Player.Z);
                    //light_level = rand.Next((int)(light_level - (LIGHT_LEVEL_VARIANCE_LOWER * light_level)),
                    //    (int)(light_level + (LIGHT_LEVEL_VARIANCE_UPPER * light_level)));

                    light_level = light_level > MAX_LIGHT_LEVEL ? MAX_LIGHT_LEVEL : light_level;
                    light_level = light_level < MIN_LIGHT_LEVEL ? MIN_LIGHT_LEVEL : light_level;

                    color_intensity = (float)light_level / MAX_LIGHT_LEVEL;

                    //Check if the tile is in viewport and not in darkness
                    if (!tcod_map.isInFov(cell_rel_x, cell_rel_y) || wm.GetCellFromCoordinates(abs_x, abs_y, Player.Z).GetLightLevel(abs_x, abs_y, Player.Z) < LIGHT_LEVEL_CUTOFF_LOWER)
                    {
                        //if it is: If the tile was seen (is discovered) before, have a little bit of it be rendered
                        if (wm.GetCellFromCoordinates(abs_x, abs_y, Player.Z).IsDiscovered(abs_x, abs_y, Player.Z))
                            color_intensity = (float)MIN_LIGHT_LEVEL / (float)MAX_LIGHT_LEVEL;
                        else //or not
                            color_intensity = 0.0f;
                    }
                    else if (wm.GetCellFromCoordinates(abs_x, abs_y, Player.Z).GetLightLevel(abs_x, abs_y, Player.Z) > 0)
                        wm.GetCellFromCoordinates(abs_x, abs_y, Player.Z).DiscoverTile(abs_x, abs_y, Player.Z); //also if visible, discover!

                    //If current Tile is Air, skip ahead, because no hot rendering action is needed
                    if (tilearr[rel_x, rel_y] == 0) //Air Tile
                        continue;

                    //Retrieve the actual tile data
                    //If tile is transparent, display the tile BELOW (floor)
                    if (tcod_map.isTransparent(cell_rel_x, cell_rel_y))
                    {
                        t = wm.GetTileFromID(tilearr[rel_x, rel_y]);
                        floor = true;
                    }
                    else //the wall!
                    {
                        t = getTileFromCells(abs_x, abs_y, Player.Z);
                        floor = false;
                    }

                    //Safeguard
                    if (t.ForeColor == null)
                        continue;

                    //Prepare for render...
                    tinted_fore = t.ForeColor;//TCODColor.Interpolate(Util.DecodeRGB(light_tint[rel_x, rel_y]), t.ForeColor, 0.5f);

                    con.setBackgroundFlag(TCODBackgroundFlag.Default);
                    con.setForegroundColor(TCODColor.Interpolate(TCODColor.black, tinted_fore, color_intensity));
                    displ_string = t.DisplayString;

                    if (t.BackColor != null)
                    {
                        //
                        tinted_back = floor ? TCODColor.Interpolate(Util.DecodeRGB(light_tint[rel_x, rel_y]), t.BackColor, 0.5f) : t.BackColor;

                        con.setBackgroundColor(TCODColor.Interpolate(TCODColor.black, tinted_back, color_intensity));
                        con.setBackgroundFlag(TCODBackgroundFlag.Set);
                    }

                    //DO IT!
                    debug_prints++;
                    con.print(con_x + (abs_x - left), con_y + (abs_y - top), displ_string);
                }
            }
            sw.Stop();
            #endregion

            //Report the time it took to render one frame! (but only if in Debug mode!)
            if (DEBUG_OUTPUT)
            {
                _out.SendMessage("Drew frame, printed " + debug_prints + " tiles, took " + sw.ElapsedMilliseconds + "ms.");

                _out.SendMessage("Light Level at Player Pos:  " + cells[1, 1, 1].GetLightLevel(Player.X, Player.Y, Player.Z));
            }

            #region "Object rendering"
            //RenderAll the player
            con.setBackgroundFlag(TCODBackgroundFlag.Default);
            con.setForegroundColor(Player.ForeColor);

            con.print(con_x + (Player.X - left), con_y + (Player.Y - top), Player.DisplayString);

            //RenderAll the creatures
            foreach (Creature c in CreatureList.GetValues())
            {
                if (c.Z >= curr_z - Map.VIEW_DISTANCE_CREATURES_DOWN_Z && c.Z <= curr_z + Map.VIEW_DISTANCE_CREATURES_UP_Z)
                {
                    con.setForegroundColor(c.ForeColor);
                    con.print(con_x + (c.X - left), con_y + (c.Y - top), c.DisplayString);
                }
            }

            //RenderAll the items
            foreach (Item i in ItemList.GetValues())
            {
                if (!i.IsVisible)
                    continue;

                if (i.Z >= curr_z - Map.VIEW_DISTANCE_CREATURES_DOWN_Z && i.Z <= curr_z + Map.VIEW_DISTANCE_CREATURES_UP_Z)
                {
                    con.setForegroundColor(i.ForeColor);
                    con.print(con_x + (i.X - left), con_y + (i.Y - top), i.DisplayString);
                }
            }
            #endregion

            //DONE!
            return true;
        }
Ejemplo n.º 19
0
        public void PickupItem()
        {
            List<int> items = GetEntitiesSharingTileWithThis();
            if(items.Count == 0)
            {
                DarkRL.WriteMessage("There's nothing to pick up..");
                return;
            }
            else if (items.Count == 1)
                base.PickupItem((Item)level.GetEntity(items[0]));
            else //there's multiple items here
            {
                TCODConsole pickup = new TCODConsole(30, items.Count+1);
                pickup.setBackgroundColor(TCODColor.black);
                pickup.setForegroundColor(TCODColor.white);
                char sym = 'a';
                int y = 0;
                //now display them all
                foreach (Item i in items.Select(t => level.GetEntity(t)))
                {

                    pickup.print(0, y, sym.ToString() + ")" + i.ToString());
                    ++y;
                    ++sym;
                }
                DarkRL.WriteMessage("What do you want to pick up?");
                DarkRL.AddOverlayConsole(pickup, 0, 0, pickup.getWidth(), pickup.getHeight(), TCODConsole.root, Window.StatusPanelWidth,
                    Window.MessagePanelHeight);
                Key input = InputSystem.WaitForAndReturnInput();
                char index = (char)(input.Character - 'a');
                if (index >= items.Count|| index < 0)
                {
                    DarkRL.WriteMessage("Couldn't find anything..");
                    return;
                }
                //so pick it up
                base.PickupItem((Item)level.GetEntity(items[index]));
                DarkRL.WriteMessage("You pick up the " + level.GetEntity(items[index]).Name);
                return;
            }
            DarkRL.WriteMessage("You pick up the " + level.GetEntity(items[0]).Name);
        }
Ejemplo n.º 20
0
        public new void Render(TCODConsole con)
        {
            int maxchars = con.getWidth() - 4;
            int y = 2;
            int cap_lines = 0;

            con.setBackgroundColor(TCODColor.black);
            con.setBackgroundFlag(TCODBackgroundFlag.Set);
            con.clear();
            con.setBackgroundFlag(TCODBackgroundFlag.Default);

            con.setForegroundColor(TCODColor.darkerAzure);
            con.printFrame(0, 0, con.getWidth(), con.getHeight());
            con.setForegroundColor(TCODColor.white);

            List<string> lines = new List<string>();

            lines.AddRange(wrapLine(Text, maxchars));
            cap_lines = lines.Count;

            foreach (KeyValuePair<char, string> kv in responses)
            {
                lines.Add(kv.Key + ") " + kv.Value);
            }

            for (int i = 0; i < lines.Count; i++)
            {
                con.setBackgroundFlag(TCODBackgroundFlag.Set);
                if (i - cap_lines == selectedIndex)
                    con.setBackgroundColor(TCODColor.sepia);
                else
                    con.setBackgroundColor(TCODColor.black);

                con.print(2, y+i, lines[i]);
                con.setBackgroundFlag(TCODBackgroundFlag.Default);
            }
        }
Ejemplo n.º 21
0
Archivo: Map.cs Proyecto: bilwis/SH2RL
        /// <summary>
        /// This function renders the particles of the given particle emitter onto the given console object.
        /// </summary>
        public void RenderParticles(ParticleEmitter emitter, TCODConsole con, int width, int height)
        {
            //Check if emitter is on player level
            if (emitter.abs_z != Player.Z)
                return;

            #region "Viewport setup"

            int top; //Y
            int left; //X
            int right;
            int bottom;

            top = Player.Y - (height / 2);
            bottom = top + height;

            left = Player.X - (width / 2);
            right = left + width;

            if (top >= bottom || left >= right)
                return;

            if (top < 0)
            {
                bottom -= top; //Bottom - Top (which is negative): ex.: new Bottom (10-(-5) = 15)
                top = 0;
            }

            if (bottom > wm.GLOBAL_HEIGHT)
            {
                top -= (bottom - wm.GLOBAL_HEIGHT); //ex.: bottom = 15, Globalheight = 10, Top = 5; => Top = 5 - (15-10) = 0
                bottom = wm.GLOBAL_HEIGHT;
            }

            if (left < 0)
            {
                right -= left;
                left = 0;
            }

            if (right > wm.GLOBAL_WIDTH)
            {
                left -= (right - wm.GLOBAL_WIDTH);
                right = wm.GLOBAL_WIDTH;
            }

            #endregion

            //Iterate through the particles and render them
            foreach (Particle p in emitter.particles)
            {
                if (tcod_map.isInFov((int)p.abs_x - cells[0, 0, 0].X, (int)p.abs_y - cells[0, 0, 0].Y))
                {
                    con.setBackgroundFlag(TCODBackgroundFlag.Screen);
                    con.setBackgroundColor(TCODColor.Interpolate(TCODColor.black, p.color, p.intensity));

                    con.print(1 + ((int)p.abs_x - left), 1 + ((int)p.abs_y - top), " ");
                }

            }
        }
Ejemplo n.º 22
0
Archivo: Game.cs Proyecto: rezich/zday
        public void DrawHUD()
        {
            TCODConsole r                  = TCODConsole.root;
            int         sidebarWidth       = 33;
            int         windowWidth        = 80;
            int         windowHeight       = 50;
            int         vWidth             = 47;
            int         vHeight            = 47;
            int         weaponBoxWidth     = 16;
            int         weaponBoxHeight    = 4;
            int         characterBoxHeight = 11;


            // bottom bar
            r.printFrame(0, windowHeight - 3, windowWidth - sidebarWidth, 3);
            r.printEx(vHeight / 2 + 1, windowHeight - 2, TCODBackgroundFlag.Default, TCODAlignment.CenterAlignment, Area.Current.DescribeTile(Player.Position));


            // character box
            r.printFrame(vWidth, 0, windowWidth - vWidth, characterBoxHeight);
            r.print(vWidth + 2, 0, "CHARACTER");
            r.print(vWidth + 2, 2, "Adam");
            r.print(vWidth + 2, 3, "LVL: " + Convert.ToString(Player.Level));
            r.print(vWidth + 2, 4, "ATK: " + (Player.AttackMultiplier > 1 ? Player.AttackMultiplier.ToString() : "") + "d" + Player.AttackDie.ToString() + (Player.AttackModifier > 0 ? "+" + Player.AttackModifier.ToString() : ""));

            float barHP      = ((float)Player.HP / (float)Player.MaxHP) * (windowWidth - vWidth - 4);
            float barStamina = ((float)Player.Stamina / (float)Player.MaxStamina) * (windowWidth - vWidth - 4);
            float barXP      = ((float)(Player.XP - Character.LevelXP(Player.Level)) / (float)(Character.LevelXP(Player.Level + 1) - Character.LevelXP(Player.Level))) * (windowWidth - vWidth - 4);

            r.setBackgroundFlag(TCODBackgroundFlag.Set);
            r.setBackgroundColor(TCODColor.darkGreen);
            r.rect(vWidth + 2, 6, (int)barHP, 1, false);
            r.setBackgroundColor(TCODColor.grey);
            r.printEx(vWidth + 2 + ((windowWidth - vWidth - 4) / 2), 6, TCODBackgroundFlag.Darken, TCODAlignment.CenterAlignment, " HP: " + Convert.ToString(Player.HP) + "/" + Convert.ToString(Player.MaxHP) + " ");
            r.setBackgroundColor(TCODColor.darkBlue);
            r.rect(vWidth + 2, 7, (int)barStamina, 1, false);
            r.setBackgroundColor(TCODColor.grey);
            r.printEx(vWidth + 2 + ((windowWidth - vWidth - 4) / 2), 7, TCODBackgroundFlag.Darken, TCODAlignment.CenterAlignment, " STM: " + Convert.ToString(Math.Round((float)Player.Stamina / (float)Player.MaxStamina * 100)) + "%% ");
            r.setBackgroundColor(TCODColor.darkYellow);
            r.rect(vWidth + 2, 8, (int)barXP, 1, false);
            r.setBackgroundColor(TCODColor.grey);
            r.printEx(vWidth + 2 + ((windowWidth - vWidth - 4) / 2), 8, TCODBackgroundFlag.Darken, TCODAlignment.CenterAlignment, " XP: " + Convert.ToString(Player.XP) + " / " + Convert.ToString(Character.LevelXP(Player.Level + 1)) + " ");
            r.setBackgroundColor(TCODColor.black);

            r.print(vWidth + 16, 2, "STR: " + Convert.ToString(Player.Strength));
            r.print(vWidth + 16, 3, "DEX: " + Convert.ToString(Player.Dexterity));
            r.print(vWidth + 24, 2, "CON: " + Convert.ToString(Player.Constitution));
            r.print(vWidth + 24, 3, "INT: " + Convert.ToString(Player.Intelligence));
            r.print(vWidth + 16, 4, "DEF: " + Convert.ToString(Player.Defense));
            r.print(vWidth + 24, 4, "SPD: " + Convert.ToString(Player.Speed));



            // console box
            r.printFrame(vWidth, characterBoxHeight, windowWidth - vWidth, windowHeight - weaponBoxHeight - characterBoxHeight);
            r.print(vWidth + 2, characterBoxHeight, "CONSOLE");
            int remainingLines = windowHeight - weaponBoxHeight - characterBoxHeight - 2;
            int i = Console.Lines.Count - 1;

            while (remainingLines > 0 && i > -1)
            {
                string         text      = Console.Lines[i].Text;
                Queue <string> lines     = new Queue <string>();
                int            maxLength = windowWidth - vWidth - 2;
                while (text.Length > maxLength)
                {
                    string split = text.Substring(0, maxLength);
                    if (text.Substring(maxLength, 1) != " ")
                    {
                        split = split.Substring(0, split.LastIndexOf(" ")).TrimEnd();
                    }
                    split = split.TrimEnd();
                    lines.Enqueue(split);
                    text = " " + text.Substring(split.Length).Trim();
                }
                lines.Enqueue(text);
                remainingLines -= lines.Count;
                int j = 0;
                while (lines.Count > 0)
                {
                    string line = lines.Dequeue();
                    if (characterBoxHeight + 1 + remainingLines + j > characterBoxHeight)
                    {
                        r.print(vWidth + 1, characterBoxHeight + 1 + remainingLines + j, line);
                    }
                    j++;
                }

                i -= 1;
            }



            // weapon box
            r.printFrame(vWidth, windowHeight - weaponBoxHeight, weaponBoxWidth, weaponBoxHeight);
            r.print(vWidth + 1, windowHeight - weaponBoxHeight + 1, Player.Weapon == null ? "unarmed" : Player.Weapon.ToString());


            // time box
            r.printFrame(vWidth + weaponBoxWidth, windowHeight - weaponBoxHeight, windowWidth - vWidth - weaponBoxWidth, weaponBoxHeight);
            string strKilled = Convert.ToString(Player.Kills) + " KILLED";
            string strTime   = "DAY 1 00:00.00";

            r.print(80 - strKilled.Length - 1, 48, strKilled);
            r.print(80 - strTime.Length - 1, 47, strTime);
        }