Beispiel #1
0
        /** Check if a draw claim is allowed, possibly after playing "move".
         * @param move The move that may have to be made before claiming draw.
         * @return The draw string that claims the draw, or empty string if draw claim not valid.
         */
        private string canClaimDraw(Position pos, ulong[] posHashList, int posHashListSize, Move move)
        {
            string drawStr = "";

            if (Search.canClaimDraw50(pos))
            {
                drawStr = "draw 50";
            }
            else if (Search.canClaimDrawRep(pos, posHashList, posHashListSize, posHashListSize))
            {
                drawStr = "draw rep";
            }
            else
            {
                string strMove = TextIO.moveTostring(pos, move, false);
                posHashList[posHashListSize++] = pos.zobristHash();
                UndoInfo ui = new UndoInfo();
                pos.makeMove(move, ui);
                if (Search.canClaimDraw50(pos))
                {
                    drawStr = "draw 50 " + strMove;
                }
                else if (Search.canClaimDrawRep(pos, posHashList, posHashListSize, posHashListSize))
                {
                    drawStr = "draw rep " + strMove;
                }
                pos.unMakeMove(move, ui);
            }
            return(drawStr);
        }
Beispiel #2
0
        public List <string> getPosHistory()
        {
            List <string> ret = new List <string>();

            Position pos2 = new Position(pos /*this.pos*/);

            for (int i = currentMove; i > 0; i--)
            {
                pos2.unMakeMove(moveList[i - 1], uiInfoList[i - 1]);
            }
            ret.Add(TextIO.toFEN(pos2)); // Store initial FEN

            string moves = "";

            for (int i = 0; i < moveList.Count; i++)
            {
                Move   move    = moveList[i];
                string strMove = TextIO.moveTostring(pos2, move, false);
                moves += " " + strMove;
                UndoInfo ui = new UndoInfo();
                pos2.makeMove(move, ui);
            }
            ret.Add(moves); // Store move list string
            int numUndo = moveList.Count - currentMove;

            ret.Add(((int)numUndo).ToString());
            return(ret);
        }
Beispiel #3
0
        /** Search a position and return the best move and score. Used for test suite processing. */
        public TwoReturnValues <Move, string> searchPosition(Position pos, int maxTimeMillis)
        {
            // Create a search object
            ulong[] posHashList = new ulong[200];
            tt.nextGeneration();
            Search sc = new Search(pos, posHashList, 0, tt);

            // Determine all legal moves
            MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            sc.scoreMoveList(moves, 0);

            // Find best move using iterative deepening
            sc.timeLimit(maxTimeMillis, maxTimeMillis);
            Move bestM = sc.iterativeDeepening(moves, -1, -1, false);

            // Extract PV
            string   PV = TextIO.moveTostring(pos, bestM, false) + " ";
            UndoInfo ui = new UndoInfo();

            pos.makeMove(bestM, ui);
            PV += tt.extractPV(pos);
            pos.unMakeMove(bestM, ui);

//        tt.printStats();

            // Return best move and PV
            return(new TwoReturnValues <Move, string>(bestM, PV));
        }
        /// <summary>
        /// Pushes property undo information onto the undo stack.
        /// </summary>
        /// <param name="propertyInfo">Property information.</param>
        public void PushUndo(BaseEditorProxy proxy, PropertyInfo propertyInfo)
        {
            // Do nothing if locked
            if (lockUndoRedo)
            {
                return;
            }

            // Making a change invalidates redo.
            // This is to prevent inconsistent redo operations.
            if (redoStack.Count > 0)
            {
                redoStack.Clear();
            }

            // Set undo information
            UndoInfo undoInfo = new UndoInfo
            {
                Type         = UndoTypes.Property,
                Proxy        = proxy,
                PropertyInfo = propertyInfo,
                Value        = propertyInfo.GetValue(proxy, null),
            };

            // Push onto undo stack
            undoStack.Push(undoInfo);

            // Raise event
            if (OnPushUndo != null)
            {
                OnPushUndo(this, null);
            }
        }
        /// <summary>
        /// Pushes terrain deformation undo information onto the undo stack.
        /// </summary>
        /// <param name="info">Terrain undo information.</param>
        public void PushUndo(TerrainDeformUndoInfo info)
        {
            // Do nothing if locked
            if (lockUndoRedo)
            {
                return;
            }

            // Making a change invalidates redo.
            // This is to prevent inconsistent redo operations.
            if (redoStack.Count > 0)
            {
                redoStack.Clear();
            }

            // Set undo information
            UndoInfo undoInfo = new UndoInfo
            {
                Type = UndoTypes.TerrainDeformation,
                TerrainDeformInfo = info,
            };

            // Push onto undo stack
            undoStack.Push(undoInfo);

            // Raise event
            if (OnPushUndo != null)
            {
                OnPushUndo(this, null);
            }
        }
Beispiel #6
0
        /**
         * Update the game state according to move/command string from a player.
         * @param str The move or command to process.
         * @return True if str was understood, false otherwise.
         */
        public bool processstring(string str)
        {
            if (handleCommand(str))
            {
                return(true);
            }
            if (getGameState() != GameState.ALIVE)
            {
                return(false);
            }

            Move m = TextIO.stringToMove(pos, str);

            if (m == null)
            {
                return(false);
            }

            UndoInfo ui = new UndoInfo();

            pos.makeMove(m, ui);
            TextIO.fixupEPSquare(pos);
            while (currentMove < moveList.Count)
            {
                moveList.RemoveAt(currentMove);
                uiInfoList.RemoveAt(currentMove);
                drawOfferList.RemoveAt(currentMove);
            }
            moveList.Add(m);
            uiInfoList.Add(ui);
            drawOfferList.Add(pendingDrawOffer);
            pendingDrawOffer = false;
            currentMove++;
            return(true);
        }
Beispiel #7
0
        static ulong perfT(MoveGen moveGen, Position pos, int depth)
        {
            if (depth == 0)
            {
                return(1);
            }
            ulong nodes = 0;

            MoveGen.MoveList moves = moveGen.pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            if (depth == 1)
            {
                int ret = moves.size;
                moveGen.returnMoveList(moves);
                return((ulong)ret);
            }
            UndoInfo ui = new UndoInfo();

            for (int mi = 0; mi < moves.size; mi++)
            {
                Move m = moves.m[mi];
                pos.makeMove(m, ui);
                nodes += perfT(moveGen, pos, depth - 1);
                pos.unMakeMove(m, ui);
            }
            moveGen.returnMoveList(moves);
            return(nodes);
        }
Beispiel #8
0
    void UndoChanges(UndoInfo ui)
    {
        if (ui.set != null && ui.set.gameObject.name == "bg")
        {
            /*     hm.beforeC = hm.set.color;
             *  hm.before = hm.set.sprite;
             *  hm.beforeC2 = Camera.main.backgroundColor; */
            Camera.main.backgroundColor = ui.beforeC2;
            ui.set.color  = ui.beforeC;
            ui.set.sprite = ui.before;
            return;
        }

        if (ui.set != null && ui.before != null)
        {
            if (ui.set.gameObject.name == "head")
            {
                changeSkin(ui.beforeC, ui.beforeC2);
            }

            else
            {
                if (ui.set.sprite.name == "b_92")
                {
                    ui.set.rectTransform.anchoredPosition = new Vector2(ui.set.rectTransform.anchoredPosition.x, 503);
                }
                else if (ui.set == fm.hair)
                {
                    ui.set.rectTransform.sizeDelta = new Vector2(ui.beforeC2.r * 1500, ui.beforeC2.g * 2500);
                }
                UndoHelper(ui);
            }
        }
        else
        {
            if (ui.set != null)
            {
                if (ui.set.sprite != null)
                {
                    fm.Remove(ui.set.sprite.name.Substring(0, 2));
                }
                else
                {
                    if (ui.set.gameObject.name == "wf")
                    {
                        ui.set.GetComponent <WaterfallScript>().LightColor = ui.beforeC;
                    }
                    else
                    {
                        ui.set.color = ui.beforeC;
                    }
                }
            }
            else if (ui.before != null && (ui.before.name != "GX" && !ui.before.name.ToLower().StartsWith("pa")))
            {
                string key = ui.before.name.Substring(0, 2);
                fm.Remove(key);
            }
        }
    }
Beispiel #9
0
        void HexBox_OnWrite(object sender, HexBoxWriteEventArgs e)
        {
            var hexBox = (HexBox)sender;
            var doc    = hexBox.Document;

            if (doc == null)
            {
                return;
            }
            if (e.IsBeforeWrite)
            {
                var info = new UndoInfo();
                info.OriginalData          = hexBox.Document.ReadBytes(e.StartOffset, e.Size);
                info.OriginalCaretPosition = hexBox.CaretPosition;
                e.Context[contextKey]      = info;
            }
            else
            {
                var info = (UndoInfo)e.Context[contextKey];

                bool updated = TryUpdateOldTextInputCommand(e.Type, hexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData);
                if (!updated)
                {
                    ClearTextInputCommand();
                    var cmd = new HexBoxUndoCommand(hexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData, GetDescription(e));
                    undoCommandManager.Add(cmd);
                    if (e.Type == HexWriteType.ByteInput || e.Type == HexWriteType.AsciiInput)
                    {
                        SetTextInputCommand(cmd);
                    }
                }
            }
        }
Beispiel #10
0
        void HexBox_OnWrite(object sender, HexBoxWriteEventArgs e)
        {
            const string key = "HexBoxUndo";
            var hts = (HexTabState)TabState.GetTabState((HexBox)sender);
            var doc = hts.HexBox.Document;
            if (doc == null)
                return;
            if (e.IsBeforeWrite) {
                var info = new UndoInfo();
                info.OriginalData = hts.HexBox.Document.Read(e.StartOffset, e.Size);
                info.OriginalCaretPosition = hts.HexBox.CaretPosition;
                e.Context[key] = info;
            }
            else {
                var info = (UndoInfo)e.Context[key];

                bool updated = TryUpdateOldTextInputCommand(e.Type, hts.HexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData);
                if (!updated) {
                    ClearTextInputCommand();
                    var cmd = new HexBoxUndoCommand(hts.HexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData, GetDescription(e));
                    UndoCommandManager.Instance.Add(cmd);
                    if (e.Type == HexWriteType.ByteInput || e.Type == HexWriteType.AsciiInput)
                        SetTextInputCommand(cmd);
                }
            }
        }
Beispiel #11
0
    void handleSeparateColors(ColorPicker cpa, UndoInfo fs, Button x)
    {
        Iris lr = cpa.getLeftRight();

        TurnCanvas(lr.transform, true);
        string lt, rt;

        switch (PlayerPrefs.GetInt("Lang"))
        {
        case 1:
            //chinese
            lt = "左"; rt = "右";
            break;

        case 2:
            //ja
            lt = "左"; rt = "右";
            break;

        case 3:
            //rus
            lt = "слева"; rt = "направо";
            break;

        case 4:
            //thai
            lt = "izquierda"; rt = "derecho";
            break;

        case 5:
            //thai
            lt = "ไปทางซ้าย"; rt = "ทางขวา";
            break;

        case 6:
            //thai
            lt = "gauche"; rt = "droite";
            break;

        default:
            //english
            lt = "left"; rt = "right";
            break;
        }

        lr.fillButtons(lt, rt,
                       () => { fs.set.color = cpa.Color; },
                       () => { fs.set2.color = cpa.Color; }
                       );
        cpa.Color = fs.set.color;
        x.onClick.AddListener(() =>
        {
            lr.gameObject.SetActive(false);
            TurnCanvas(lr.transform, false);
        });
        cpa.gameObject.SetActive(true);
        cpa.Reset();
    }
Beispiel #12
0
 //  Executed via TapGestureRecognizer
 //  Saves the color of the selected box in the undoList
 //  and sets the tapped box to the currentColor
 void OnBoxViewTapped(object sender, EventArgs args)
 {
     BoxView box = (BoxView)sender;
     UndoInfo info = new UndoInfo();  // save off current color in undo buffer
     info.box = box;
     info.color = box.Color;
     /*  add code here      */     //  add info to undoList
     undoButton.IsEnabled = true;  // we have something to undo
     /*  add code here      */     //  set the box's color to currentColor
 }
Beispiel #13
0
        private void initBook(bool verbose)
        {
            bookMap = new Dictionary <ulong, List <BookEntry> >();
            long t0 = SystemHelper.currentTimeMillis();

            numBookMoves = 0;
            try {
                /* read /book.bin into buf */
                Byte[]   buf      = Bookbin.DATA;
                Position startPos = TextIO.readFEN(TextIO.startPosFEN);
                Position pos      = new Position(startPos);
                UndoInfo ui       = new UndoInfo();
                int      len      = buf.Length;
                for (int i = 0; i < len; i += 2)
                {
                    int b0 = buf[i]; if (b0 < 0)
                    {
                        b0 += 256;
                    }
                    int b1 = buf[i + 1]; if (b1 < 0)
                    {
                        b1 += 256;
                    }
                    int move = (b0 << 8) + b1;
                    if (move == 0)
                    {
                        pos = new Position(startPos);
                    }
                    else
                    {
                        bool bad  = ((move >> 15) & 1) != 0;
                        int  prom = (move >> 12) & 7;
                        Move m    = new Move(move & 63, (move >> 6) & 63,
                                             promToPiece(prom, pos.whiteMove));
                        if (!bad)
                        {
                            addToBook(pos, m);
                        }
                        pos.makeMove(m, ui);
                    }
                }
            } catch (ChessParseError ex) {
                throw new RuntimeException();
            } catch (IOException ex) {
                SystemHelper.println("Can't read opening book resource");
                throw new RuntimeException();
            }
            if (verbose)
            {
                long t1 = SystemHelper.currentTimeMillis();
                SystemHelper.printf("Book moves: " + numBookMoves.ToString() +
                                    "(parse time: " + ((t1 - t0) / 1000).ToString() + ")");
            }
        }
Beispiel #14
0
 void UndoHelper(UndoInfo ui)
 {
     ui.set.sprite = ui.before;
     ui.set.color  = ui.beforeC;
     ui.set.SetNativeSize();
     if (ui.set2 != null)
     {
         ui.set2.sprite = ui.before;
         ui.set2.color  = ui.beforeC;
         ui.set2.SetNativeSize();
     }
 }
Beispiel #15
0
 void OnUndoButtonClicked(object sender, EventArgs args)
 {
     //  undo last color set
     UndoInfo info = undoList.Last();
     info.box.Color = info.color;  // restore previous color
     if(
         // remove this entry from list
     if (undoList.Count == 0)
     {
         undoButton.IsEnabled = false;
     }//  if undoList is empty, disable undoButton
 }
Beispiel #16
0
    void UndoHelper(UndoInfo ui)
    {
        ui.set.sprite = ui.before;
        ui.set.color  = ui.beforeC;

        setNative(ui.set);
        if (ui.set2 != null)
        {
            ui.set2.sprite = ui.before;
            // Debug.Log("undoing "+ui.set2.name+" with color "+ui.beforeC2);
            ui.set2.color = ui.beforeC2;
            setNative(ui.set2);
        }
    }
        /// <summary>
        /// Undo a property and push onto another stack.
        /// </summary>
        /// <param name="undoInfo">Undo info.</param>
        private void UndoProperty(UndoInfo undoInfo, Stack <UndoInfo> pushTo)
        {
            // Gets current property value
            object liveValue = undoInfo.PropertyInfo.GetValue(undoInfo.Proxy, null);

            // Restore previous property value
            lockUndoRedo = true;
            undoInfo.PropertyInfo.SetValue(undoInfo.Proxy, undoInfo.Value, null);
            lockUndoRedo = false;

            // Set undo to last property value
            undoInfo.Value = liveValue;

            // Push onto redo stack
            pushTo.Push(undoInfo);
        }
 public void refreshList(ArrayList array)
 {
     if (array == null)
     {
         return;
     }
     this.listBox_History.Items.Clear();
     for (int i = 0; i < array.Count; i++)
     {
         if (array[i] is UndoInfo)
         {
             UndoInfo info = (UndoInfo)array[i];
             listBox_History.Items.Add(info.m_undoCommand.GetText());
         }
     }
 }
Beispiel #19
0
    public void AddUndoStep(GameObject card, moveType move, int ups)
    {
        if (game_started)
        {
            if (undo_list.Count >= maxUndoSteps)
            {
                undo_list.RemoveAt(0);
            }

            UndoInfo undoInfo = new UndoInfo();
            undoInfo.card = card;
            undoInfo.move = move;
            undoInfo.undo_previous_score = ups;
            undo_list.Add(undoInfo);
        }
    }
Beispiel #20
0
 void UndoChanges(UndoInfo ui)
 {
     if (ui.set != null && ui.before != null)
     {
         if (ui.set.gameObject.name == "head")
         {
             changeSkin(ui.beforeC);
         }
         else
         {
             UndoHelper(ui);
         }
     }
     else
     {
         if (ui.set != null)
         {
             if (ui.set.sprite != null)
             {
                 fm.Remove(ui.set.sprite.name.Substring(0, 2));
             }
             else
             {
                 if (ui.set.gameObject.name == "wf")
                 {
                     ui.set.GetComponent <WaterfallScript>().LightColor = ui.beforeC;
                 }
                 else
                 {
                     ui.set.color = ui.beforeC;
                 }
             }
         }
         else if (ui.before != null && (ui.before.name != "GX" && !ui.before.name.StartsWith("pa") && !ui.before.name.StartsWith("pA")))
         {
             string key = ui.before.name.Substring(0, 2);
             fm.Remove(key);
         }
     }
 }
Beispiel #21
0
    // NOT TESTED WITH COMBO SCORES!!
    public void UndoLastMove()
    {
        if (undo_list.Count > 0 && player_can_move) //if player can ask an undo
        {
            current_target_deck_position--;         //remove last card from target deck

            UndoInfo undoInfo = undo_list [undo_list.Count - 1];

            if (undoInfo.move == moveType.ask_new_card_from_deck)//return last card to deck
            //Debug.Log("current_last_move == last_move.ask_new_card_from_deck");
            {
                deck_card_left++;
                deck_card_left_text.text = (deck_card_left - 1).ToString();
                current_deck_position--;

                StartCoroutine(NewCurrentCard(target_deck_cards [current_target_deck_position].suit, target_deck_cards [current_target_deck_position].rank, true, true));


                if (!this.gameObject.GetComponent <Image> ().enabled)
                {
                    StartCoroutine(EnableDeckImage());
                }

                mustEnableEndButton       = false;
                gpend_button.interactable = false;
            }
            else if (undoInfo.move == moveType.take_card_from_board) //return last card to board
            //Debug.Log("last_move.take_card_from_board");
            {
                current_total_card_on_board++;

                StartCoroutine(MoveTo(undoInfo.card, target_new_card.transform, undoInfo.card.transform, true));

                StartCoroutine(NewCurrentCard(target_deck_cards [current_target_deck_position].suit, target_deck_cards [current_target_deck_position].rank, false, true));
            }

            combo_count = previous_combo_count;
        }
    }
        /// <summary>
        /// Undo a deformation and push onto another stack.
        /// </summary>
        /// <param name="undoInfo">Undo info.</param>
        private void UndoDeformation(UndoInfo undoInfo, Stack <UndoInfo> pushTo)
        {
            // Get terrain editor reference
            TerrainEditor terrainEditor = undoInfo.TerrainDeformInfo.TerrainEditor;

            // Get current terrain deformation
            TerrainDeformUndoInfo?liveData = terrainEditor.GetHeightMapUndo(
                undoInfo.TerrainDeformInfo.TerrainComponent,
                undoInfo.TerrainDeformInfo.Position.X,
                undoInfo.TerrainDeformInfo.Position.Y,
                undoInfo.TerrainDeformInfo.Dimension);

            // Perform undo operation
            terrainEditor.RestoreHeightMapUndo(undoInfo.TerrainDeformInfo);

            // Push last value on redo stack if valid
            if (liveData != null)
            {
                // Push onto stack
                undoInfo.TerrainDeformInfo = liveData.Value;
                pushTo.Push(undoInfo);
            }
        }
        /// <summary>
        /// Pops property off redo stack and restores value.
        ///  Property is then pushed onto undo stack.
        /// </summary>
        public void PopRedo()
        {
            // Do nothing if locked or nothing to pop
            if (lockUndoRedo || redoStack.Count == 0)
            {
                return;
            }

            // Pop from redo stack
            UndoInfo undoInfo = redoStack.Pop();

            // Pop based on type
            if (undoInfo.Type == UndoTypes.Property)
            {
                UndoProperty(undoInfo, undoStack);
            }
            else if (undoInfo.Type == UndoTypes.TerrainDeformation)
            {
                UndoDeformation(undoInfo, undoStack);
            }
            else if (undoInfo.Type == UndoTypes.TerrainPaint)
            {
            }
        }
Beispiel #24
0
 void setHm(Vector2 placement, Image dup, Transform parent, int index, string key, ref UndoInfo hm)
 {
     if (!XtraStuff.ContainsKey(key))
     {
         hm.set = newImgAt(key, placement,
                           dup, parent, index);
     }
     else
     {
         hm.set    = XtraStuff[key];
         hm.before = hm.set.sprite;
         hm.set.rectTransform.anchoredPosition = placement;
     }
 }
Beispiel #25
0
 void setHmTwice(Vector2 placement, Vector2 placement2, Image dup, Transform parent, int index, string key, ref UndoInfo hm)
 {
     if (!XtraStuff.ContainsKey(key))
     {
         hm.set  = newImgAt(key, placement, dup, parent, index);
         hm.set2 = newImgAt(key, placement2, dup, parent, index);
         hm.set.rectTransform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0));
     }
     else
     {
         hm.set  = XtraStuff[key];
         hm.set2 = XtraStuff[key + "2"];
         hm.set.rectTransform.anchoredPosition  = placement;
         hm.set2.rectTransform.anchoredPosition = placement2;
         hm.before = hm.set.sprite;
     }
 }
    void SetUpButton(Button b, Sprite smth, itemType i,
                     DressManager dm, Func <Sprite, itemType, UndoInfo> faceSet, ColorPicker cpa)
    {
        b.onClick.RemoveAllListeners();
        b.onClick.AddListener(() =>
        {
            UndoInfo fs = faceSet(smth, i);
            if (i == itemType.glitch || i == itemType.eyes || i == itemType.nose || i == itemType.eyelid)
            {
                cpa.gameObject.SetActive(false);
                GameObject g = cpa.transform.parent.GetChild(4).gameObject;
                g.SetActive(true);
                Slider one = g.transform.GetChild(0).GetComponent <Slider>();
                Slider two = g.transform.GetChild(1).GetComponent <Slider>();
                one.onValueChanged.RemoveAllListeners();
                two.onValueChanged.RemoveAllListeners();

                dm.x.onClick.AddListener(() =>
                {
                    g.SetActive(false);
                });


                if (i == itemType.eyes)
                {
                    float ratio = 10;


                    RectTransform eye1 = (RectTransform)fs.set.rectTransform.parent;
                    RectTransform eye2 = (RectTransform)fs.set2.rectTransform.parent;

                    one.value = dm.fm.HorzEye / -ratio;
                    two.value = dm.fm.VertEye / ratio;

                    float origX = dm.fm.HorzEye;
                    float origY = dm.fm.VertEye;
                    two.onValueChanged.AddListener((float val) =>
                    {
                        // eye1.anchoredPosition = new Vector2(eye1.anchoredPosition.x, -25 + ratio * val);
                        // eye2.anchoredPosition = new Vector2(eye2.anchoredPosition.x, -25 + ratio * val);
                        dm.fm.VertEye = ratio * val;
                    });
                    one.onValueChanged.AddListener((float val) =>
                    {
                        dm.fm.HorzEye = ratio * val;
                    });

                    dm.x.onClick.AddListener(() =>
                    {
                        dm.fm.VertEye = origY;
                        dm.fm.HorzEye = origX;
                    });
                }
                else if (i == itemType.nose)
                {
                    float ratio  = 10;
                    float ratio2 = 20f;

                    one.transform.GetChild(2).eulerAngles = new Vector3(0, 0, 45);

                    one.value = (fs.set.rectTransform.sizeDelta.y - 304) / ratio2;
                    two.value = dm.fm.VertNose / ratio;

                    Vector2 origSize = fs.set.rectTransform.sizeDelta;
                    float VertNose   = dm.fm.VertNose;

                    dm.x.onClick.AddListener(() =>
                    {
                        one.transform.GetChild(2).eulerAngles = Vector3.zero;
                        fs.set.rectTransform.sizeDelta        = origSize;
                        dm.fm.VertNose = VertNose;
                    });

                    one.onValueChanged.AddListener((float val) =>
                    {
                        fs.set.rectTransform.sizeDelta = new Vector2(349 + ratio2 * val, 304 + ratio2 * val);
                    });
                    two.onValueChanged.AddListener((float val) =>
                    {
                        dm.fm.VertNose = ratio * val;
                    });
                }
                else if (i == itemType.glitch)
                {
                    float ratio  = 0.4f;
                    float ratio2 = 0.2f;
                    Glitch ag    = Camera.main.GetComponent <Glitch>();

                    one.value = ag.colorDrift;
                    two.value = ag.verticalJump / ratio2;

                    one.onValueChanged.AddListener((float val) =>
                    {
                        ag.colorDrift     = val;
                        ag.scanLineJitter = val * ratio;
                    });
                    two.onValueChanged.AddListener((float val) =>
                    {
                        ag.verticalJump = val * ratio2;
                    });



                    if (!transform.GetChild(0).gameObject.activeSelf)
                    {
                        dm.x.onClick.AddListener(() =>
                        {
                            Destroy(ag);
                            dm.fm.XtraStuff.Remove("GX");
                        });
                    }
                    else
                    {
                        float cD = ag.colorDrift;
                        float vJ = ag.verticalJump;
                        dm.x.onClick.AddListener(() =>
                        {
                            ag.colorDrift   = cD;
                            ag.verticalJump = vJ;
                        });
                    }
                }
                else if (i == itemType.eyelid)
                {
                    float ratio  = 10f;
                    float ratio2 = 14f;
                    // 20- 48

                    Image oneI    = one.transform.GetChild(2).GetComponent <Image>();
                    Sprite before = oneI.sprite;
                    oneI.sprite   = Resources.Load <Sprite>("random");
                    oneI.rectTransform.sizeDelta = Vector2.one * 64;
                    float origY = fs.set.rectTransform.anchoredPosition.y;
                    one.value   = fs.set.rectTransform.eulerAngles.z / ratio;
                    two.value   = (fs.set.rectTransform.anchoredPosition.y - 34f) / ratio2;

                    dm.x.onClick.AddListener(() =>
                    {
                        oneI.sprite = before;
                        oneI.rectTransform.sizeDelta      = Vector2.one * 80.99f;
                        fs.set.rectTransform.eulerAngles  = Vector3.zero;
                        fs.set2.rectTransform.eulerAngles = Vector3.zero;

                        fs.set.rectTransform.anchoredPosition = new Vector2(fs.set.rectTransform.anchoredPosition.x, origY);

                        fs.set2.rectTransform.anchoredPosition = new Vector2(fs.set2.rectTransform.anchoredPosition.x, origY);
                    });


                    one.onValueChanged.AddListener((float val) =>
                    {
                        fs.set.rectTransform.localRotation  = Quaternion.Euler(0, 0, ratio * val);
                        fs.set2.rectTransform.localRotation = Quaternion.Euler(0, 0, ratio * val);
                    });
                    two.onValueChanged.AddListener((float val) =>
                    {
                        fs.set.rectTransform.anchoredPosition  = new Vector2(fs.set.rectTransform.anchoredPosition.x, 34f + ratio2 * val);
                        fs.set2.rectTransform.anchoredPosition = new Vector2(fs.set2.rectTransform.anchoredPosition.x, 34f + ratio2 * val);
                    });
                }
            }
            else
            {
                if (fs.set != null)
                {
                    if (fs.set.gameObject.name == "iris")
                    {
                        Transform left = cpa.transform.parent.GetChild(5);
                        left.gameObject.SetActive(true);
                        Transform right = cpa.transform.parent.GetChild(6);
                        right.gameObject.SetActive(true);
                        cpa.Color = fs.set.color;
                        dm.x.onClick.AddListener(() =>
                        {
                            left.gameObject.SetActive(false);
                            right.gameObject.SetActive(false);
                        });
                        cpa.gameObject.SetActive(true);
                        cpa.Reset();
                    }
                    else if (i == itemType.WaterScript)
                    {
                        if (!transform.GetChild(0).gameObject.activeSelf)
                        {
                            dm.x.onClick.AddListener(() =>
                            {
                                dm.fm.XtraStuff.Remove("wd");
                                Destroy(dm.fm.transform.Find("wd").gameObject);
                            });
                        }
                        else
                        {
                            cpa.Color = fs.set.color;
                            cpa.Reset();
                        }
                    }
                    else if (i == itemType.WaterfallScript)
                    {
                        if (!transform.GetChild(0).gameObject.activeSelf)
                        {
                            dm.x.onClick.AddListener(() =>
                            {
                                dm.fm.XtraStuff.Remove("wf");
                                Destroy(dm.fm.transform.Find("wf").gameObject);
                            });
                        }
                        else
                        {
                            cpa.Color = fs.set.GetComponent <WaterfallScript>().LightColor;
                            cpa.Reset();
                        }
                    }
                    else if (i == itemType.bg && fs.set.sprite == null)
                    {
                        cpa.Color = Camera.main.backgroundColor; cpa.Reset();
                    }
                    else
                    {
                        cpa.Color = fs.set.color;
                        cpa.Reset();
                    }
                }
                else
                {
                    if (i == itemType.particles)
                    {
                        if (transform.GetChild(0).gameObject.activeSelf)
                        {
                            cpa.Color = GameObject.FindGameObjectWithTag("Finish").transform.Find(smth.name).GetComponent <ParticleSystem>().main.startColor.colorMin;
                            cpa.Reset();
                        }
                        else
                        {
                            dm.x.onClick.AddListener(() =>
                            {
                                string key = smth.name.Substring(0, 2);
                                dm.fm.Remove(key);
                            });
                        }
                    }
                }
                cpa.gameObject.SetActive(true);
            }
            dm.colorPick(fs, transform.GetChild(0).gameObject);
        });
    }
Beispiel #27
0
    public void colorPick(UndoInfo ui, GameObject equipped)
    {
        CanvasGroup du = transform.GetChild(0).GetComponent <CanvasGroup>();
        CanvasGroup cp = transform.GetChild(1).GetComponent <CanvasGroup>();

        TurnOff(du);

        Color bg = Camera.main.backgroundColor;

        x.onClick.AddListener(() =>
        {
            if (ui.set != null && ui.set.gameObject.name == "bg")
            {
                UndoChangeBg(ui, bg);
            }
            else
            {
                UndoChanges(ui);
            }
            if (equipped)
            {
                transform.GetChild(1).GetChild(3).gameObject.SetActive(false);
            }
            TurnOff(cp);
            TurnOn(du);
            x.onClick.RemoveAllListeners();
        });

        setCPAListeners(ui);
        HashSet <string> s = new HashSet <string>(new string[] {
            "hair",
            "bangs",
            "eye",
            "brow",
            "lips",
            "nose",
            "bg",
            "head"
        });

        if (equipped.activeSelf && (ui.set == null || ui.set != null && !s.Contains(ui.set.gameObject.name)))
        {
            Button remove = transform.GetChild(1).GetChild(3).GetComponent <Button>();
            remove.gameObject.SetActive(true);
            remove.onClick.AddListener(() =>
            {
                equipped.SetActive(false);
                string key = "EMPTY";
                if (ui.set != null)
                {
                    if (ui.set.sprite != null)
                    {
                        key = ui.set.sprite.name.Substring(0, 2);
                    }
                    else
                    {
                        key = ui.set.gameObject.name.Substring(0, 2);
                    }
                }
                else if (ui.before != null)
                {
                    key = ui.before.name.Substring(0, 2);
                }
                if (key != "EMPTY")
                {
                    fm.Remove(key);
                }
                x.onClick.RemoveAllListeners();
                TurnOff(cp);
                TurnOn(du);
                remove.transform.parent.GetChild(4).gameObject.SetActive(false);
                remove.gameObject.SetActive(false);
                remove.onClick.RemoveAllListeners();
            });
        }

        LeanTween.value(gameObject, (float val) =>
        {
            cp.alpha = val;
        }, 0, 1, 0.4f).setEase(LeanTweenType.easeInCubic).setOnComplete(() =>
        {
            cp.interactable   = true;
            cp.blocksRaycasts = true;
        });
    }
Beispiel #28
0
 private bool handleDrawCmd(string drawCmd)
 {
     if (drawCmd.StartsWith("rep") || drawCmd.StartsWith("50"))
     {
         bool   rep = drawCmd.StartsWith("rep");
         Move   m   = null;
         string ms  = drawCmd.Substring(drawCmd.IndexOf(" ") + 1);
         if (ms.Length > 0)
         {
             m = TextIO.stringToMove(pos, ms);
         }
         bool valid;
         if (rep)
         {
             valid = false;
             List <Position> oldPositions = new List <Position>();
             Position        tmpPos;
             if (m != null)
             {
                 UndoInfo ui = new UndoInfo();
                 tmpPos = new Position(pos);
                 tmpPos.makeMove(m, ui);
                 oldPositions.Add(tmpPos);
             }
             oldPositions.Add(pos);
             tmpPos = pos;
             for (int i = currentMove - 1; i >= 0; i--)
             {
                 tmpPos = new Position(tmpPos);
                 tmpPos.unMakeMove(moveList[i], uiInfoList[i]);
                 oldPositions.Add(tmpPos);
             }
             int      repetitions = 0;
             Position firstPos    = oldPositions[0];
             for (int i = 0; i < oldPositions.Count; i++)
             {
                 Position p = oldPositions[i];
                 if (p.drawRuleEquals(firstPos))
                 {
                     repetitions++;
                 }
             }
             if (repetitions >= 3)
             {
                 valid = true;
             }
         }
         else
         {
             Position tmpPos = new Position(pos);
             if (m != null)
             {
                 UndoInfo ui = new UndoInfo();
                 tmpPos.makeMove(m, ui);
             }
             valid = tmpPos.halfMoveClock >= 100;
         }
         if (valid)
         {
             drawState        = rep ? GameState.DRAW_REP : GameState.DRAW_50;
             drawStateMoveStr = null;
             if (m != null)
             {
                 drawStateMoveStr = TextIO.moveTostring(pos, m, false);
             }
         }
         else
         {
             pendingDrawOffer = true;
             if (m != null)
             {
                 processstring(ms);
             }
         }
         return(true);
     }
     else if (drawCmd.StartsWith("offer "))
     {
         pendingDrawOffer = true;
         string ms = drawCmd.Substring(drawCmd.IndexOf(" ") + 1);
         if (TextIO.stringToMove(pos, ms) != null)
         {
             processstring(ms);
         }
         return(true);
     }
     else if (drawCmd == "accept")
     {
         if (haveDrawOffer())
         {
             drawState = GameState.DRAW_AGREE;
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #29
0
        public string getMoveListstring(bool compressed)
        {
            string ret = "";

            // Undo all moves in move history.
            Position pos2 = new Position(pos /*this.pos*/);

            for (int i = currentMove; i > 0; i--)
            {
                pos2.unMakeMove(moveList[i - 1], uiInfoList[i - 1]);
            }

            // Print all moves
            string whiteMove = "";
            string blackMove = "";

            for (int i = 0; i < currentMove; i++)
            {
                Move   move    = moveList[i];
                string strMove = TextIO.moveTostring(pos2, move, false);
                if (drawOfferList[i])
                {
                    strMove += " (d)";
                }
                if (pos2.whiteMove)
                {
                    whiteMove = strMove;
                }
                else
                {
                    blackMove = strMove;
                    if (whiteMove.Length == 0)
                    {
                        whiteMove = "...";
                    }
                    if (compressed)
                    {
                        ret += pos2.fullMoveCounter.ToString() + ". " +
                               whiteMove + " " + blackMove + " ";
                    }
                    else
                    {
                        ret += pos2.fullMoveCounter.ToString() + ".   " +
                               whiteMove.PadRight(10) + " " + blackMove.PadRight(10) + " ";
                    }
                    whiteMove = "";
                    blackMove = "";
                }
                UndoInfo ui = new UndoInfo();
                pos2.makeMove(move, ui);
            }
            if ((whiteMove.Length > 0) || (blackMove.Length > 0))
            {
                if (whiteMove.Length == 0)
                {
                    whiteMove = "...";
                }

                if (compressed)
                {
                    ret += pos2.fullMoveCounter.ToString() + ". " +
                           whiteMove + " " + blackMove + " ";
                }
                else
                {
                    ret += pos2.fullMoveCounter.ToString() + ".   " +
                           whiteMove.PadRight(10) + " " + blackMove.PadRight(10) + " ";
                }
            }
            string gameResult = getPGNResultstring();

            if (gameResult != "*")
            {
                ret += gameResult;
            }
            return(ret);
        }
Beispiel #30
0
 void UndoChangeBg(UndoInfo ui, Color bg)
 {
     ui.set.sprite = ui.before;
     ui.set.color  = ui.beforeC;
     Camera.main.backgroundColor = bg;
 }
Beispiel #31
0
    void setCPAListeners(UndoInfo ui)
    {
        cpa.clearUpdateColor();

        if (ui.set != null)
        {
            if (ui.set.gameObject.name == "bg")
            {
                if (ui.set.sprite != null && ui.set.sprite.name[2] != 'p')
                {
                    cpa.UpdateColorAction += () => { ui.set.color = new Color(1, 1, 1, 1 - cpa.B); };
                }
                cpa.UpdateColorAction += () => { Camera.main.backgroundColor = cpa.Color; };
            }
            else if (ui.set.gameObject.name == "head")
            {
                cpa.UpdateColorAction += () =>
                {
                    changeSkin(new HSBColor(cpa.H, cpa.S, cpa.B, 1));
                };
            }
            else if (ui.set.gameObject.name == "wf")
            {
                WaterfallScript Waterfall = ui.set.GetComponent <WaterfallScript>();
                cpa.UpdateColorAction += () =>
                {
                    Waterfall.LightColor = cpa.Color;
                };
            }

            else
            {
                cpa.UpdateColorAction += () => { ui.set.color = cpa.Color; };


                if (ui.set2 != null)
                {
                    cpa.UpdateColorAction += () => { ui.set2.color = cpa.Color; };
                }

                if (ui.set.sprite != null && ui.set.sprite.name == "hart")
                {
                    setUpParticles(xtra[19], 1);
                }

                if (ui.set.gameObject.name == "bangs")
                {
                    Image shine = ui.set.transform.GetChild(0).GetComponent <Image>();
                    cpa.UpdateColorAction += () =>
                    {
                        shine.color = new Color(shine.color.r, shine.color.g, shine.color.b,
                                                Mathf.Lerp(1, 0.35f, cpa.B));
                        ;
                    };
                }
            }
        }
        else if (ui.before != null && (ui.before.name.StartsWith("pa") || ui.before.name.StartsWith("pA")))
        {
            setUpParticles(ui.before, 0);
        }
    }