示例#1
0
        ///<summary>Load settings from ini file (filename)</summary>
        public FunctionResult Load(string sFileName)
        {
            IniHold.IniFile uIni = new IniHold.IniFile();//Ini-file parser
            uIni.LoadIni(sFileName);//Load settings file

            //Load all settings
            sPlayerName = uIni.GetItemValue("PlayerName","Player");
            sSkin = uIni.GetItemValue("Skin","oq_16.bmp");//((TODO))
            sLastLevelSet = uIni.GetItemValue("LevelSet", "original.txt").ToLower();
            iLastLevelPlayed = OQConvertTools.string2int(uIni.GetItemValue("Level", "0"));
            bAnimateTravel = OQConvertTools.string2bool(uIni.GetItemValue("AnimateTravel", "true"));
            bAnimateBoxPushing = OQConvertTools.string2bool(uIni.GetItemValue("AnimateBoxPushing", "true"));
            bAnimateMassUndoRedo = OQConvertTools.string2bool(uIni.GetItemValue("AnimateMassUndoRedo", "true"));
            bShowOnlyUnsolvedLevels = OQConvertTools.string2bool(uIni.GetItemValue("ShowOnlyUnsolvedLevels", "false"));
            bAdditionalMessages = OQConvertTools.string2bool(uIni.GetItemValue("AdditionalMessages", "false"));
            bAskRecordName = OQConvertTools.string2bool(uIni.GetItemValue("AskRecordName", "false"));
            bAskSavingFirstSolution = OQConvertTools.string2bool(uIni.GetItemValue("AskSavingFirstSolution", "true"));
            bAutocalcDeadlocks = OQConvertTools.string2bool(uIni.GetItemValue("AutocalcDeadlocks", "true"));
            bDeadlockLimitsAutopush = OQConvertTools.string2bool(uIni.GetItemValue("DeadlockLimitsAutopush", "true"));
            iKeepAliveMinutes = OQConvertTools.string2int(uIni.GetItemValue("KeepAliveMinutes", "5"));
            bAutosize = OQConvertTools.string2bool(uIni.GetItemValue("Autosize", "true"));
            bAutosizeUseful = OQConvertTools.string2bool(uIni.GetItemValue("AutosizeUseful", "true"));
            iAutosizeLowerLimit = OQConvertTools.string2int(uIni.GetItemValue("AutosizeLowerLimit", "10"));
            sSkinSet = uIni.GetItemValue("SkinSet", "oq.sks");//((TODO))
            iBackgroundColor = OQConvertTools.hex2int(uIni.GetItemValue("BackgroundColor", "75759B"));
            if (iBackgroundColor == -1)
                iBackgroundColor = 0;//OQConvertTools.hex2int return -1 on errors
            sBackgroundImageFile = uIni.GetItemValue("BackgroundImageFile", "");

            iAnimationDelayTravel = OQConvertTools.string2int(uIni.GetItemValue("AnimationDelayTravel", "10"));
            iAnimationDelayBoxPushing = OQConvertTools.string2int(uIni.GetItemValue("AnimationDelayBoxPushing", "10"));
            iAnimationDelayMassUndoRedo = OQConvertTools.string2int(uIni.GetItemValue("AnimationDelayMassUndoRedo", "10"));
            iDragMinMove = OQConvertTools.string2int(uIni.GetItemValue("DragMinMove", "5"));
            bScrollLock = OQConvertTools.string2bool(uIni.GetItemValue("ScrollLock", "false"));
            bLogActions = OQConvertTools.string2bool(uIni.GetItemValue("LogActions", "false"));
            iBackgroundAutoDeadlocksLimit = OQConvertTools.string2int(uIni.GetItemValue("BackgroundAutoDeadlocksLimit", "500"));

            return FunctionResult.OK;
        }
示例#2
0
        ///<summary>Save settings to ini file (filename)</summary>
        public FunctionResult Save(string sFileName)
        {
            IniHold.IniFile uIni = new IniHold.IniFile();//Ini-file parser
            System.IO.StreamWriter hAppend;//For writing files
            try
            {
                hAppend = new System.IO.StreamWriter(sFileName, false);//Open file for overwriting
                uIni.SetWriter(hAppend);//Transmit file to ini-file parser

                //Save all settings
                uIni.SaveItem("PlayerName",sPlayerName);
                uIni.SaveItem("Skin",sSkin);
                uIni.SaveItem("LevelSet",sLastLevelSet);
                uIni.SaveItem("Level",iLastLevelPlayed.ToString());
                uIni.SaveItem("AnimateTravel",bAnimateTravel.ToString());
                uIni.SaveItem("AnimateBoxPushing", bAnimateBoxPushing.ToString());
                uIni.SaveItem("AnimateMassUndoRedo", bAnimateMassUndoRedo.ToString());
                uIni.SaveItem("ShowOnlyUnsolvedLevels", bShowOnlyUnsolvedLevels.ToString());
                uIni.SaveItem("AdditionalMessages", bAdditionalMessages.ToString());
                uIni.SaveItem("AskRecordName", bAskRecordName.ToString());
                uIni.SaveItem("AskSavingFirstSolution", bAskSavingFirstSolution.ToString());
                uIni.SaveItem("AutocalcDeadlocks", bAutocalcDeadlocks.ToString());
                uIni.SaveItem("DeadlockLimitsAutopush", bDeadlockLimitsAutopush.ToString());
                uIni.SaveItem("KeepAliveMinutes", iKeepAliveMinutes.ToString());
                uIni.SaveItem("Autosize", bAutosize.ToString());
                uIni.SaveItem("AutosizeUseful", bAutosizeUseful.ToString());
                uIni.SaveItem("AutosizeLowerLimit", iAutosizeLowerLimit.ToString());
                uIni.SaveItem("SkinSet", sSkinSet.ToString());
                uIni.SaveItem("BackgroundColor", iBackgroundColor.ToString("X").PadLeft(6,'0'));
                uIni.SaveItem("BackgroundImageFile", sBackgroundImageFile.ToString());
                uIni.SaveItem("AnimationDelayTravel", iAnimationDelayTravel.ToString());
                uIni.SaveItem("AnimationDelayBoxPushing", iAnimationDelayBoxPushing.ToString());
                uIni.SaveItem("AnimationDelayMassUndoRedo", iAnimationDelayMassUndoRedo.ToString());
                uIni.SaveItem("DragMinMove", iDragMinMove.ToString());
                uIni.SaveItem("ScrollLock", bScrollLock.ToString());
                uIni.SaveItem("LogActions", bLogActions.ToString());
                uIni.SaveItem("BackgroundAutoDeadlocksLimit", iBackgroundAutoDeadlocksLimit.ToString());
                hAppend.Close();//Close file

                return FunctionResult.OK;//Successfull
            }
            catch
            {
                return FunctionResult.ErrorOnWritingFile;//Some problems with writing file
            }
        }
示例#3
0
        ///<summary>Load set of skins from file (file with path)</summary>
        public FunctionResult Load(string sFileName)
        {
            /*
             * List of levelsets stored in 4 lines of ini files, started from LevelSet = ...
             */
            int i;
            int j=0;
            IniHold.IniFile uList = new IniHold.IniFile();//Use ini engine
            uList.LoadIni(sFileName);//Load file as ini file

            if (uList.iNumIniItems == 0)//No ini-items found
                return FunctionResult.NothingToDo;

            /*
            try
            {
                sPath = System.IO.Path.GetDirectoryName(sFileName);
            }
            catch
            {
                sPath = "";
            }*/

            iSkinUsed = uList.iNumIniItems;
            sSkins = new string[iSkinUsed];
            iSizes = new int[iSkinUsed];

            for (i = 0; i < uList.iNumIniItems; i++)//Iterate thru all items, founded by ini engine
            {
                iSizes[j] = OQConvertTools.string2int(uList.uIniItems[i].sID);//Convert ID (size) into int
                if (iSizes[j]>0)
                {   //If size have meaning
                    sSkins[j] = /*sPath + "\\" +*/ uList.uIniItems[i].sValue;//Store skin name
                    j++;
                }
            }
            iSkinUsed = j;

            if (iSkinUsed==0)
                return FunctionResult.NothingToDo;//No skin found

            return FunctionResult.OK;
        }
        /// <summary>Save list of levelsets into file</summary>
        public FunctionResult SaveList()
        {
            try
            {
                int i;
                IniHold.IniFile uList = new IniHold.IniFile();//Use ini engine
                System.IO.StreamWriter hWrite = new System.IO.StreamWriter(sFileName, false);//Open file for overwriting
                uList.SetWriter(hWrite);//Transmit file-writer into ini engine

                for (i = 0; i < iListUsed; i++)//Iterate thru whole list
                {
                    uList.SaveItem("LevelSet", uLevelSets[i].sFileName);//Save filename
                    uList.SaveItem("LevelsTotal", uLevelSets[i].iLevelsTotal.ToString());//Save total number of levels
                    uList.SaveItem("LevelsSolved", uLevelSets[i].iLevelsSolved.ToString());//Save number of solved levels
                    uList.SaveItem("Comment", uLevelSets[i].sComment);//Save user comment for levelset
                }
                hWrite.Close();//Close file
            }
            catch
            {   //On any error - exit
                return FunctionResult.ErrorOnWritingFile;
            }
            return FunctionResult.OK;//Saved successfully
        }
        /// <summary>Load list of levelsets from file</summary>
        public FunctionResult LoadList()
        {
            /*
             * List of levelsets stored in 4 lines of ini files, started from LevelSet = ...
             */
            int i;
            IniHold.IniFile uList = new IniHold.IniFile();//Use ini engine
            uList.LoadIni(sFileName);//Load file as ini file

            iListUsed = -1;//We are before first "LevelSet"
            for (i = 0; i < uList.iNumIniItems; i++)//Iterate thru all items, founded by ini engine
            {
                if (uList.uIniItems[i].sID == "LevelSet")
                {   //"LevelSet" found - new item in list
                    iListUsed++;
                    EnlargeArray();//Realloc array if needed
                    uLevelSets[iListUsed].sFileName = uList.uIniItems[i].sValue.ToLower();//Convert to lowercase for comparations
                }
                else if (iListUsed < 0)
                {   //Before first "LevelSet" - skip all
                    continue;
                }
                else if (uList.uIniItems[i].sID == "LevelsTotal")
                {   //LevelsTotal - number of levels
                    uLevelSets[iListUsed].iLevelsTotal = OQConvertTools.string2int(uList.uIniItems[i].sValue);
                }
                else if (uList.uIniItems[i].sID == "LevelsSolved")
                {   //LevelsSolved - number of solved levels
                    uLevelSets[iListUsed].iLevelsSolved = OQConvertTools.string2int(uList.uIniItems[i].sValue);
                }
                else if (uList.uIniItems[i].sID == "Comment")
                {   //Comment - user comment
                    uLevelSets[iListUsed].sComment = uList.uIniItems[i].sValue;
                }
            }
            iListUsed++;//Finish last item

            //Update displayed text for all loaded items
            for (i = 0; i < iListUsed; i++)
                UpdateDisplayed(i);

            return FunctionResult.OK;
        }
示例#6
0
        ///<summary>Save current position into file (filename, levelset name, level number, player name)
        ///!Recalc of stats should be done before calling</summary>
        public FunctionResult SavePosition(string sFileName)
        {
            System.IO.StreamWriter hWrite;

            try //Protection from file operations errors
            {
                hWrite = new System.IO.StreamWriter(sFileName, false);//Open file with overwrite
                IniHold.IniFile uIni = new IniHold.IniFile();//IniHold object - to store position as ini-file
                uIni.SetWriter(hWrite);//Transmit file-writer into inihold

                //Save level info, player info, statistics of positions
                uIni.SaveItem("Title", uGame.uStats.sName);
                uIni.SaveItem("LevelSet", uLevelSet.sFileName);
                uIni.SaveItem("Level", (uLevelSet.GetCurrentLevel()+1).ToString());//Saved level number is 1-based
                uIni.SaveItem("Player", uSetting.sPlayerName);
                uIni.SaveItem("Moves", uGame.uStats.iMoves.ToString());
                uIni.SaveItem("Pushes", uGame.uStats.iPushes.ToString());
                uIni.SaveItem("LinearMoves", uGame.uStats.iLinearMoves.ToString());
                uIni.SaveItem("LinearPushes", uGame.uStats.iLinearPushes.ToString());
                uIni.SaveItem("PushSessions", uGame.uStats.iPushSessions.ToString());
                uIni.SaveItem("BoxChanges", uGame.uStats.iBoxChanges.ToString());

                //And position
                uIni.SaveItem("Position", uGame.GetPositionLuRd());

                hWrite.Close();//Close file
                return FunctionResult.OK;
            }
            catch
            {
                return FunctionResult.ErrorOnWritingFile;//On error - return indication
            }
        }
示例#7
0
        ///<summary>User want to load position (0 - chose from all know positions and solutions / 1 - only of this level / 2 - autoload autosaved position, forcing loading level with levelset)</summary>
        public void ActionLoadPosition(int iUseFilter, bool bForceLoadLevel)
        {
            FunctionResult uRV;
            OpenFile hSelectPosition = new OpenFile();
            bool bOtherLevel=false;
            hSelectPosition.sFolder = sSolutionsDirectory;
            hSelectPosition.sTitle = "Select Position";

            switch (iUseFilter)
            {
                case 0:
                    hSelectPosition.sFilter = "*.?o*";//Filter for all positions and solutions (.?o* - to select .pos and .sol)
                    LogSimpleLine(ActionID.ShowForm, "Ask; Choose position to load, from all saved");
                    break;
                case 1:
                    hSelectPosition.sFilter = FilterForPositions();//Filter for pos/sol of this level
                    LogSimpleLine(ActionID.ShowForm, "Ask; Choose position to load, for this leve");
                    break;
                case 2:
                    hSelectPosition.sFileName = AutoNameAutoSavePosition();
                    //goto lAfterFileSelection;
                    break;
            }

            if (iUseFilter==2 || hSelectPosition.SelectFileForLoad() == DialogResult.OK) //Show list of pos/sol to user, or skip it if ???
            {
            //lAfterFileSelection:
                IniHold.IniFile uIni = new IniHold.IniFile();//IniHold object - to treat position file as ini-file
                uIni.LoadIni(sSolutionsDirectory + hSelectPosition.sFileName);//Load file as ini-file

                string sLoadedPosition = uIni.GetItemValue("Position");//Get sequence of moves

                //If sequence is empty or not present - exit
                if (sLoadedPosition.Length == 0)
                    return;

                string sQuestion;//String to ask user

                string sLoadedLevelSet = uIni.GetItemValue("LevelSet", "<unknown>").ToLower();//Load levelset name
                int iLoadedLevelNumber = OQConvertTools.string2int(uIni.GetItemValue("Level", "0"));//Load level numder
                iLoadedLevelNumber--;//Levels numbered from 1 in files

                if (bForceLoadLevel)
                {
                    //Position is loaded with level and levelset

                    if (sLoadedLevelSet != uLevelSet.sFileName)
                    {   //Loading levelset is required
                        uRV = uLevelSetList.LoadLevelSet(uLevelSet, sLoadedLevelSet);
                        if (uRV != FunctionResult.OK)
                        {   //Not loaded
                            bOtherLevel = true;
                            LogSimpleLine(ActionID.ShowDialog, "Error; Levelset from position file was not loaded!; " + sLoadedLevelSet + "; " + uRV.ToString());
                            MessageBox.Show("LevelSet '" + sLoadedLevelSet + "' from position file was not loaded! Result: " + uRV.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                            uRV = uLevelSetList.LoadLevelSet(uLevelSet, uSetting.sLastLevelSet);//Reload previous levelset
                            if (uRV != FunctionResult.OK)
                            {   //Not loaded also
                                LogSimpleLine(ActionID.ShowDialog, "Error; Previous levelset was not loaded!; " + uSetting.sLastLevelSet + "; " + uRV.ToString());
                                MessageBox.Show("Previous LevelSet '" + uSetting.sLastLevelSet + "' was not loaded! Result: " + uRV.ToString() + "\r\nRandom level will be loaded.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                uLevelSetList.GenNullLevelSet(uLevelSet);//Generate random level
                                iLoadedLevelNumber = 0;
                            }
                            else
                            {
                                //Ok, previous levelset loaded, use previos level number
                                iLoadedLevelNumber = uSetting.iLastLevelPlayed;
                            }
                        }
                        else
                        {
                            //Ok, levelset loaded, save it's name
                            uSetting.sLastLevelSet = sLoadedLevelSet;
                        }
                    }

                    uRV = LoadLevel(uGame, iLoadedLevelNumber);//Load level
                    if (uRV == FunctionResult.OK)
                    {   //Level loaded successfully
                        AfterLoadLevel();
                    }
                    else
                    {   //Level not loaded (only variant - FunctionResult.OutOfLevelSet)
                        bOtherLevel = true;
                        LogSimpleLine(ActionID.ShowDialog, "Error; Unable to load level; " + (iLoadedLevelNumber + 1).ToString() + "; " + uRV.ToString());
                        MessageBox.Show("Unable to load level " + (iLoadedLevelNumber + 1).ToString() + ", result: " + uRV.ToString() + "\r\nRandom level will be selected.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        ActionRandLevel();
                    }
                }
                else
                {
                    //Position is loaded for current level

                    if (uGame.uStats.iMoves != 0)
                    {//Restart level, if player is moved
                        ActionRestartLevel();
                    }
                    //Check, that position from same level

                    if (sLoadedLevelSet != uLevelSet.sFileName || iLoadedLevelNumber != uLevelSet.GetCurrentLevel()) //Position may be not for current level - warn user
                    {
                        string sLevelNum;
                        if (iLoadedLevelNumber == -1)
                            sLevelNum = "<unknown> level"; //Level number not specified in file
                        else
                            sLevelNum = "level " + iLoadedLevelNumber.ToString();//Level number specified
                        if (sLoadedLevelSet != uLevelSet.sFileName) //Levelset is different
                            sQuestion = "This position from " + sLevelNum + " of " + sLoadedLevelSet + " levelset\r\nAre you sure?";
                        else //Levelset is the same, but levelnumber is different
                            sQuestion = "This position from " + sLevelNum + "\r\nAre you sure?";
                        LogSimpleLine(ActionID.ShowDialog, "Ask; Load position from different level/set; " + sLevelNum + "; " + sLoadedLevelSet);
                        if (MessageBox.Show(sQuestion, "Loading position", MessageBoxButtons.OKCancel, MessageBoxIcon.None, MessageBoxDefaultButton.Button2) == DialogResult.Cancel) //Ask user
                            return; //Exit, if user decide so
                    }
                }

                if (bForceLoadLevel)
                {

                }

                if (bOtherLevel)
                {   //Exact levelset and level not loaded due to some error, so loaded position is not valid
                    return;
                }

                //Use loaded position
                uGame.PastePositionLuRd(sLoadedPosition);

                //Redo position with checks for deadlocks (this only required if called FastCheckForDeadlocks)
                while (uGame.Redo() != MoveResult.WayBlocked)
                {
                    CheckForDeadlocks();
                }
                while (uGame.Undo() != MoveResult.WayBlocked) //...And undo it back
                { }

                //ActionFullRedo();//Show full redo - to reach end of solution/position
                FullRedo();//Show full redo - to reach end of solution/position

                uGame.SetMarkersOnBoxChanges();//Set markers for group undo/redo - on changing box

                if (bForceLoadLevel)
                {
                    LogSimpleLine(ActionID.LoadPosition, "Position loaded with level; " + uGame.uStats.iMoves.ToString() + " moves; " + hSelectPosition.sFileName);
                    NonModalMessage("Game loaded");
                }
                else
                {
                    LogSimpleLine(ActionID.LoadPosition, "Position loaded; " + uGame.uStats.iMoves.ToString() + " moves; " + hSelectPosition.sFileName);
                    if (iUseFilter != 2)
                        NonModalMessage("Position loaded");
                }
            }
        }