///<summary>User want to change skin set</summary> private void ActionLoadSkinSet() { OpenFile hSelectSkinSet = new OpenFile(); hSelectSkinSet.sFolder = sSkinsDirectory; hSelectSkinSet.sTitle = "Select SkinSet"; hSelectSkinSet.sFilter = "*.sks"; hSelectSkinSet.sFileName = uSetting.sSkinSet;//Transmit current skinset filename, to highlight it in filelist LogSimpleLine(ActionID.ShowForm, "Ask; Choose skinset to load"); if (hSelectSkinSet.SelectFileForLoad() == DialogResult.OK) //Show list of skins to user { FunctionResult uRV = uSkinSet.Load(hSelectSkinSet.sFolder + hSelectSkinSet.sFileName); if (uRV != FunctionResult.OK) { LogSimpleLine(ActionID.ShowDialog, "Error; Unable to load skinset; " + hSelectSkinSet.sFileName + "; " + uRV.ToString()); MessageBox.Show("Unable to load list of skins from this file, " + uRV.ToString()); return; } LogSimpleLine(ActionID.LoadSkinSet, "SkinSet loaded; " + uSetting.sSkin); if (uSetting.bAutosize) { ActionAutoSize(); //Load skin by using Autosize RecenterLevel(); //Draw level at center of the screen } } }
///<summary>User want to change background image</summary> private void ActionLoadBackground() { OpenFile hSelectImage = new OpenFile(); hSelectImage.sFolder = sBackgroundsDirectory; hSelectImage.sTitle = "Select Background Image"; hSelectImage.sFileName = uSetting.sBackgroundImageFile;//Transmit current skin filename, to highlight it in filelist LogSimpleLine(ActionID.ShowForm, "Ask; Choose background image to load"); if (hSelectImage.SelectFileForLoad() == DialogResult.OK) //Show list of skins to user { if (SetBackgroundImage(hSelectImage.sFolder + hSelectImage.sFileName) != FunctionResult.OK) { MessageBox.Show("Unable to load bitmap from this file"); return; } LogSimpleLine(ActionID.ChangedBackground, "Set background image; " + hSelectImage.sFileName); uSetting.sBackgroundImageFile = hSelectImage.sFileName;//Store skin name in settings SaveSettings(); //RecenterLevel();//Redraw level with recentering RedrawAllScreen(); } }
///<summary>User want to change skin</summary> private void ActionLoadSkin() { OpenFile hSelectSkin = new OpenFile(); hSelectSkin.sFolder = sSkinsDirectory; hSelectSkin.sTitle = "Select Skin"; hSelectSkin.sFileName = uSetting.sSkin;//Transmit current skin filename, to highlight it in filelist LogSimpleLine(ActionID.ShowForm, "Ask; Choose skin to load"); if (hSelectSkin.SelectFileForLoad() == DialogResult.OK) //Show list of skins to user { FunctionResult uRV = LoadSkin(hSelectSkin.sFolder + hSelectSkin.sFileName); if (uRV != FunctionResult.OK) { LogSimpleLine(ActionID.ShowDialog, "Error; Unable to load bitmap; " + hSelectSkin.sFileName+"; "+uRV.ToString()); MessageBox.Show("Unable to load bitmap from this file, "+uRV.ToString()); return; } LogSimpleLine(ActionID.LoadSkin, "Skin loaded; " + iSkinSize.ToString() + "; " + uSetting.sSkin); uSetting.sSkin = hSelectSkin.sFileName;//Store skin name in settings SaveSettings(); NonModalMessage("Skin " + uSetting.sSkin + " (" + iSkinSize.ToString() + "x" + iSkinSize.ToString() + ") loaded"); RecenterLevel();//Redraw level with recentering } }
///<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"); } } }