예제 #1
0
        public BlitButton addButton(double x, double y, BlitRect blit, Action callback = null, Rectangle area = null, Boolean states = true)
        {
            var button = new BlitButton(x, y, blit, callback, area, states);

            buttons.push(button);
            return(button);
        }
예제 #2
0
        /* Add to list */
        public FX addFX(double x, double y, BlitRect blit, Point dir = null, int delay = 0, Boolean push = true, Boolean looped = false, Boolean killOffScreen = true, Boolean room = false)
        {
            var item = new FX(x, y, blit, bitmapData, canvasPoint, dir, delay, looped, killOffScreen);

            if (room)
            {
                if (push)
                {
                    roomFx.push(item);
                }
                else
                {
                    roomFx.unshift(item);
                }
            }
            else
            {
                if (push)
                {
                    fx.push(item);
                }
                else
                {
                    fx.unshift(item);
                }
            }
            return(item);
        }
예제 #3
0
        public TitleMenu()
        {
            uiManager = new UIManager();
            uiManager.selectSoundCallback = game.selectSound;
            levelButtonRect = new Rectangle(0, 0, renderer.numberButtonBlit.width - 1, renderer.numberButtonBlit.height - 1);

            mapCopyBuffer = Room.create2DArray(Level.ROOM_WIDTH, Level.ROOM_HEIGHT);

            // puzzle, adventure, editor
            puzzleButton    = uiManager.addButton(Game.WIDTH * 0.5 - renderer.puzzleButtonBlit.width * 2, Game.HEIGHT * 0.5 - renderer.puzzleButtonBlit.height * 0.5, renderer.puzzleButtonBlit, puzzlePressed);
            adventureButton = uiManager.addButton(Game.WIDTH * 0.5 - renderer.adventureButtonBlit.width * 0.5, Game.HEIGHT * 0.5 - renderer.adventureButtonBlit.height * 0.5, renderer.adventureButtonBlit, adventurePressed);
            editorButton    = uiManager.addButton(Game.WIDTH * 0.5 + renderer.editorButtonBlit.width, Game.HEIGHT * 0.5 - renderer.editorButtonBlit.height * 0.5, renderer.editorButtonBlit, puzzlePressed);

            // level button grid
            uiManager.addGroup();
            uiManager.changeGroup(1);
            levelButtons = new Array <BlitButton>();
            double     buttonX = Game.WIDTH * 0.5 - ((LEVEL_BUTTONS_WIDE - 1) * LEVEL_BUTTON_GAP + levelButtonRect.width * LEVEL_BUTTONS_WIDE) * 0.5;
            double     buttonY = Game.HEIGHT * 0.5 - ((LEVEL_BUTTONS_HIGH - 1) * LEVEL_BUTTON_GAP + levelButtonRect.height * LEVEL_BUTTONS_HIGH) * 0.5;
            BlitButton levelButton;

            for (r = 0; r < LEVEL_BUTTONS_HIGH; r++)
            {
                for (c = 0; c < LEVEL_BUTTONS_WIDE; c++)
                {
                    levelButton = uiManager.addButton(
                        buttonX + c * (levelButtonRect.width + LEVEL_BUTTON_GAP),
                        buttonY + r * (levelButtonRect.height + LEVEL_BUTTON_GAP),
                        renderer.numberButtonBlit, levelPressed, levelButtonRect
                        );
                    levelButton.releaseCallback = levelReleased;
                    levelButton.id       = c + r * LEVEL_BUTTONS_WIDE;
                    levelButton.targetId = 1;
                    levelButtons.push(levelButton);
                }
            }
            int border     = 2;
            var buttonRect = new Rectangle(0, 0, renderer.cancelButtonBlit.width, renderer.cancelButtonBlit.height);

            leftButton         = uiManager.addButton(Game.WIDTH * 0.5 - 3 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.leftButtonBlit, directionPressed, buttonRect);
            leftButton.visible = false;
            backButton         = uiManager.addButton(Game.WIDTH * 0.5 - 1 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.cancelButtonBlit, backPressed, buttonRect);
            rightButton        = uiManager.addButton(Game.WIDTH * 0.5 + 1 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.rightButtonBlit, directionPressed, buttonRect);
            if (!Game.MOBILE)
            {
                loadFromDesktopButton = uiManager.addButton(Game.WIDTH * 0.5 - 5 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.loadButtonBlit, loadFromDesktop, buttonRect);
                loadFromDesktopButton.feedCallbackToEvent = true;
                saveToDesktopButton = uiManager.addButton(Game.WIDTH * 0.5 + 3 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.saveButtonBlit, saveToDesktop, buttonRect);
                saveToDesktopButton.feedCallbackToEvent = true;
            }
            scoreTextBox       = new TextBox(Game.WIDTH, 8, 0x0, 0x0);
            scoreTextBox.align = "center";
            if (UserData.settings.best != null)
            {
                setScore((int)UserData.settings.best);
            }
            uiManager.changeGroup(0);
        }
예제 #4
0
        /* Returns a list of x positions for given widths and gaps spread out from cx */
        public static Array <double> distributeRects(double cx, double width, double gap, int total)
        {
            var    list = new Array <double>();
            double x    = cx - (width * total + gap * (total - 1)) * 0.5;

            for (; total > 0; total--)
            {
                list.push(x);
                x += width + gap;
            }
            return(list);
        }
예제 #5
0
        private BlitButton addPropertyButton(double x, double y, int property, int cancels, Boolean silent = false)
        {
            var button = uiManager.addButton(x, y + back.y, game.level.getPropertyBlit(property), propertySelect, new Rectangle(0, 0, Game.SCALE, Game.SCALE), false);

            button.id        = property;
            button.active    = false;
            button.targetId  = cancels;
            button.frame     = button.blit is BlitClip ? (button.blit as BlitClip).frame : 0;
            button.focusLock = false;
            button.silent    = silent;
            properties.push(button);
            return(button);
        }
예제 #6
0
        /// <summary>
        /// Adds elements to and removes elements from an array. This method modifies the array without making a copy.
        /// </summary>
        /// <param name="startIndex">An integer that specifies the index of the element in the array where the insertion or deletion begins. You can use a negative integer to specify a position relative to the end of the array (for example, -1 is the last element of the array).</param>
        /// <param name="deleteCount">An integer that specifies the number of elements to be deleted. This number includes the element specified in the startIndex parameter. If you do not specify a value for the deleteCount parameter, the method deletes all of the values from the startIndex element to the last element in the array. If the value is 0, no elements are deleted</param>
        /// <param name="p">An optional list of one or more comma-separated values to insert into the array at the position specified in the startIndex parameter. If an inserted value is of type Array, the array is kept intact and inserted as a single element. For example, if you splice an existing array of length three with another array of length three, the resulting array will have only four elements. One of the elements, however, will be an array of length three</param>
        /// <returns>An array containing the elements that were removed from the original array.</returns>
        public Array <T> splice(int startIndex, uint deleteCount, params T[] p)
        {
            var array = new Array <T>();

            for (int i = 0; i < deleteCount; i++)
            {
                array.push(this[startIndex + i]);
            }

            this.RemoveRange(startIndex, (int)deleteCount);

            if (p != null)
            {
                InsertRange(startIndex, p);
            }

            return(array);
        }
예제 #7
0
        /* Calculates an array of BitmapDatas needed to render the text */
        protected void updateText()
        {
            _stringLines.Clear();
            _stringLines.Add("");

            // we create an array called lines that holds references to all of the
            // bitmapDatas needed and structure it like the text

            // the lines property is public so it can be used to ticker text
            lines      = new Array <Array <Rectangle> >();
            lineWidths = new Array <double>();
            textLines  = new Array <Array <char?> >();

            var  currentLine        = new Array <Rectangle>();
            var  currentTextLine    = new Array <char?>();
            int  wordBeginning      = 0;
            int  currentLineWidth   = 0;
            int  completeWordsWidth = 0;
            int  wordWidth          = 0;
            var  newLine            = new Array <Rectangle>();
            var  newTextLine        = new Array <char?>();
            char c;

            if (_text == null)
            {
                _text = "";
            }

            String upperCaseText = _text.ToUpper();

            for (int i = 0; i < upperCaseText.Length; i++)
            {
                c = upperCaseText[i];

                // new line characters
                if (c == '\n' || c == '\r' || c == '|')
                {
                    lines.push(currentLine);
                    textLines.push(currentTextLine);
                    lineWidths.push(currentLineWidth);
                    currentLineWidth   = 0;
                    completeWordsWidth = 0;
                    wordBeginning      = 0;
                    wordWidth          = 0;
                    currentLine        = new Array <Rectangle>();
                    currentTextLine    = new Array <char?>();

                    _stringLines.Add("");
                    continue;
                }

                _stringLines[_stringLines.Count - 1] += c;

                // push a character into the array
                if (characters.ContainsKey(c))
                {
                    // check we're in the middle of a word - spaces are null
                    if (currentLine.length > 0 && currentLine[currentLine.length - 1] != null)
                    {
                        currentLineWidth += tracking;
                        wordWidth        += tracking;
                    }
                    wordWidth        += (int)characters[c].width;
                    currentLineWidth += (int)characters[c].width;
                    currentLine.push(characters[c]);
                    currentTextLine.push(c);

                    // the character is a SPACE or unrecognised and will be treated as a SPACE
                }
                else
                {
                    if (currentLine.length > 0 && currentLine[currentLine.length - 1] != null)
                    {
                        completeWordsWidth = currentLineWidth;
                    }
                    currentLineWidth += whitespaceLength;
                    currentLine.push(null);
                    currentTextLine.push(null);
                    wordBeginning = currentLine.length;
                    wordWidth     = 0;
                }

                // if the length of the current line exceeds the width, we splice it into the next line
                // effecting word wrap

                if (currentLineWidth > _width - (BORDER_ALLOWANCE * 2) && wordWrap)
                {
                    // in the case where the word is larger than the text field we take back the last character
                    // and jump to a new line with it
                    if (wordBeginning == 0 && currentLine[currentLine.length - 1] != null)
                    {
                        currentLineWidth -= tracking + (int)currentLine[currentLine.length - 1].width;
                        // now we take back the offending last character
                        var lastBitmapData = currentLine.pop();
                        var lastChar       = currentTextLine.pop();

                        lines.push(currentLine);
                        textLines.push(currentTextLine);
                        lineWidths.push(currentLineWidth);

                        currentLineWidth   = (int)lastBitmapData.width;
                        completeWordsWidth = 0;
                        wordBeginning      = 0;
                        wordWidth          = (int)lastBitmapData.width;
                        currentLine        = new Array <Rectangle>();
                        currentLine.push(lastBitmapData);
                        currentTextLine = new Array <char?>();
                        currentTextLine.push(lastChar);
                        continue;
                    }

                    newLine     = currentLine.splice(wordBeginning, (uint)(currentLine.length - wordBeginning));
                    newTextLine = currentTextLine.splice(wordBeginning, (uint)(currentTextLine.length - wordBeginning));
                    lines.push(currentLine);
                    textLines.push(currentTextLine);
                    lineWidths.push(completeWordsWidth);
                    completeWordsWidth = 0;
                    wordBeginning      = 0;
                    currentLine        = newLine;
                    currentTextLine    = newTextLine;
                    currentLineWidth   = wordWidth;
                }
            }
            // save the last line
            lines.push(currentLine);
            textLines.push(currentTextLine);
            lineWidths.push(currentLineWidth);
        }
예제 #8
0
 public void update(double mouseX, double mouseY, Boolean mousePressed, Boolean mouseClick, Boolean mouseReleased = false)
 {
     buttonsOver.length = 0;
     if (!mousePressed)
     {
         mouseLock = false;
         ignore    = false;
     }
     else
     {
         if (ignore)
         {
             return;
         }
     }
     mouseOver = false;
     button    = buttons[0];
     for (i = buttons.length - 1; i > -1; i--)
     {
         button = buttons[i];
         if (
             button.visible &&
             mouseX >= button.x + button.area.x &&
             mouseY >= button.y + button.area.y &&
             mouseX < button.x + button.area.x + button.area.width &&
             mouseY < button.y + button.area.y + button.area.height
             )
         {
             button.over = Game.MOBILE ? (mousePressed || mouseReleased) : true;
             if (button.over)
             {
                 mouseOver = true;
                 if (button == lastButton)
                 {
                     buttonsOver.unshift(button);
                 }
                 else
                 {
                     buttonsOver.push(button);
                 }
             }
             if (mouseClick)
             {
                 lastButton = button;
                 if (button.callback != null)
                 {
                     if (button.feedCallbackToEvent)
                     {
                         mousePressedCallback = button.callback;
                     }
                     else
                     {
                         button.callback();
                         if ((selectSoundCallback != null) && !button.silent)
                         {
                             selectSoundCallback();
                         }
                     }
                 }
                 mouseLock        = true;
                 button.heldCount = BlitButton.HELD_DELAY;
                 break;
             }
             else if (mousePressed)
             {
                 if (button == lastButton)
                 {
                     if (button.heldCount > 0)
                     {
                         button.heldCount--;
                     }
                     else
                     {
                         button.held = true;
                         if (button.heldCallback != null)
                         {
                             button.heldCount = BlitButton.HELD_DELAY;
                             button.heldCallback();
                         }
                     }
                 }
                 else
                 {
                     if (!button.focusLock)
                     {
                         lastButton = button;
                         if (button.callback != null)
                         {
                             button.callback();
                             if (selectSoundCallback != null && !button.silent)
                             {
                                 selectSoundCallback();
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (button.over)
             {
                 button.over = false;
                 button.held = false;
             }
         }
     }
     if (mouseReleased)
     {
         if (lastButton != null && lastButton.over && lastButton.releaseCallback != null)
         {
             lastButton.releaseCallback();
             lastButton.over = false;
         }
     }
     if (mouseClick && !mouseOver)
     {
         ignore = true;
     }
 }
예제 #9
0
 public void addGroup()
 {
     buttonGroups.push(new Array <BlitButton>());
 }