📄 boardhandler.cpp
字号:
if ((x < 1 || x > board->getBoardSize() || y < 1 || y > board->getBoardSize()) && x != 20 && y != 20) return; Move *m = tree->getCurrent(); CHECK_PTR(m); m->setX(x); m->setY(y); m->setColor(c); if (m->getMatrix() == NULL) qFatal(" *** BoardHandler::editMove() - Current matrix is NULL! ***"); // if (x != 20 && y != 20) // m->getMatrix()->insertStone(x, y, c);}void BoardHandler::updateMove(Move *m, bool ignore_update){ if (m == NULL) { m = tree->getCurrent(); } //qDebug("BoardHandler::updateMove(Move *m)"); // Fastloading. Create matrix for current move and insert marks if (!m->checked) { qDebug("NOT CHECKED"); if (m->parent != NULL) {#ifndef NO_DEBUG if (tree->getCurrent()->getMatrix() != NULL) { qFatal("MOVE HAS A MATRIX BUT SHOULD NOT!"); }#endif Matrix *dad = m->parent->getMatrix(); Matrix *neu = new Matrix(*dad); m->setMatrix(neu); } addStoneSGF(m->getColor(), m->getX(), m->getY()); QIntDict<FastLoadMark> *d = m->fastLoadMarkDict; if (d != NULL && !d->isEmpty()) { QIntDictIterator<FastLoadMark> it(*d); while (it.current()) { m->getMatrix()->insertMark(it.current()->x, it.current()->y, it.current()->t); if (it.current()->t == markText && !(it.current()->txt).isNull()) m->getMatrix()->setMarkText(it.current()->x, it.current()->y, it.current()->txt); ++it; } delete d; m->fastLoadMarkDict = NULL; } m->checked = true; } CHECK_PTR(m); currentMove = m->getMoveNumber(); int brothers = getNumBrothers(); // Display move data and comment in the GUI if (m->getGameMode() == modeNormal) board->getInterfaceHandler()->setMoveData(currentMove, getBlackTurn(), brothers, getNumSons(), hasParent(), hasPrevBrother(), hasNextBrother(), m->getX(), m->getY()); else board->getInterfaceHandler()->setMoveData(currentMove, getBlackTurn(), brothers, getNumSons(), hasParent(), hasPrevBrother(), hasNextBrother()); if (board->get_isLocalGame()) board->getInterfaceHandler()->displayComment(m->getComment()); // Update comment board->getInterfaceHandler()->setSliderMax(currentMove + tree->getBranchLength()); // Update slider branch length // Get rid of the varation ghosts if (setting->readIntEntry("VAR_GHOSTS")) board->removeGhosts(); // Get rid of all marks except the last-move-mark board->hideAllMarks(); // Remove territory marks if (tree->getCurrent()->isTerritoryMarked()) { tree->getCurrent()->getMatrix()->clearTerritoryMarks(); tree->getCurrent()->setTerritoryMarked(false); } // Unshade dead stones if (markedDead) { stoneHandler->removeDeadMarks(); markedDead = false; } if (m->getGameMode() == modeNormal || m->getGameMode() == modeObserve ) //SL add eb 8 // If the node is in normal mode, show the circle to mark the last move board->updateLastMove(m->getColor(), m->getX(), m->getY()); else // ... if node is in edit mode, just delete that circle { board->removeLastMoveMark(); board->setCurStoneColor(); } // Update the ghosts indicating variations if (brothers && setting->readIntEntry("VAR_GHOSTS")) updateVariationGhosts(); // Oops, something serious went wrong if (m->getMatrix() == NULL) qFatal(" *** Move returns NULL pointer for matrix! ***"); // Synchronize the board with the current nodes matrix, provided we want to if (!ignore_update) //SL added eb 9 - this if we are browsing an observing game and an undo incomes stoneHandler->updateAll(m->getMatrix()); // Display captures or score in the GUI if (m->isScored()) // This move has been scored board->getInterfaceHandler()->setCaptures(m->getScoreBlack(), m->getScoreWhite(), true); else board->getInterfaceHandler()->setCaptures(m->getCapturesBlack(), m->getCapturesWhite()); // Display times if (currentMove == 0) { if (gameData->timelimit == 0) board->getInterfaceHandler()->setTimes("00:00", "-1", "00:00", "-1"); else { // set Black's and White's time to timelimit board->getInterfaceHandler()->setTimes(true, gameData->timelimit, -1); board->getInterfaceHandler()->setTimes(false, gameData->timelimit, -1); } } else if (m->getTimeinfo()) board->getInterfaceHandler()->setTimes(!getBlackTurn(), m->getTimeLeft(), m->getOpenMoves() == 0 ? -1 : m->getOpenMoves()); board->updateCanvas();}void BoardHandler::updateVariationGhosts(){ // qDebug("BoardHandler::updateVariationGhosts()"); Move *m = tree->getCurrent()->parent->son; CHECK_PTR(m); do { if (m == tree->getCurrent()) continue; board->setVarGhost(m->getColor(), m->getX(), m->getY()); } while ((m = m->brother) != NULL);}bool BoardHandler::nextMove(bool autoplay){ if (gameMode == modeScore) return false; CHECK_PTR(tree); Move *m = tree->nextMove(); if (m == NULL) return false; if (autoplay) setting->qgo->playAutoPlayClick(); updateMove(m); return true;}void BoardHandler::previousMove(){ if (gameMode == modeScore) return; CHECK_PTR(tree); Move *m = tree->previousMove(); if (m != NULL) updateMove(m);}void BoardHandler::previousComment() //added eb{ if (gameMode == modeScore) return; //ASSERT(n >= 0); CHECK_PTR(tree); Move *m = tree->getCurrent()->parent ; CHECK_PTR(m); while (m != NULL) { if (m->getComment() != "") break; if (m->parent == NULL) break; m = m->parent; } if (m != NULL) gotoMove(m);}void BoardHandler::nextComment(){ if (gameMode == modeScore) return; //ASSERT(n >= 0); CHECK_PTR(tree); Move *m = tree->getCurrent()->son ; CHECK_PTR(m); while (m != NULL) { if (m->getComment() != "" ) break; if (m->son == NULL) break; m = m->son; } if (m != NULL) gotoMove(m);} //end add ebvoid BoardHandler::nextVariation(){ if (gameMode == modeScore) return; CHECK_PTR(tree); Move *m = tree->nextVariation(); if (m == NULL) return; updateMove(m);}void BoardHandler::previousVariation(){ if (gameMode == modeScore) return; CHECK_PTR(tree); Move *m = tree->previousVariation(); if (m == NULL) return; updateMove(m);}void BoardHandler::gotoFirstMove(){ if (gameMode == modeScore) return; CHECK_PTR(tree); #if 0 // Set tree to root tree->setToFirstMove(); Move *m = tree->getCurrent(); updateMove(m);#else // We need to set the markers. So go the tree upwards Move *m = tree->getCurrent(); CHECK_PTR(m); // Ascent tree until root reached while (m->parent != NULL) m = tree->previousMove(); tree->setToFirstMove(); // Set move to root m = tree->getCurrent(); updateMove(m);#endif}void BoardHandler::gotoLastMove(){ if (gameMode == modeScore) return; CHECK_PTR(tree); Move *m = tree->getCurrent(); CHECK_PTR(m); // Descent tree to last son of main variation while (m->son != NULL) m = tree->nextMove(); if (m != NULL) updateMove(m);}// this slot is used for edit window to navigate to last made movevoid BoardHandler::gotoLastMoveByTime(){ if (gameMode == modeScore) return; CHECK_PTR(tree); tree->setToFirstMove(); Move *m = tree->getCurrent(); CHECK_PTR(m); // Descent tree to last son of latest variation while (m->son != NULL) { m = tree->nextMove(); for (int i = 0; i < tree->getNumBrothers(); i++) m = tree->nextVariation();/* Move *n = m; while (n != NULL && (n = n->brother) != NULL) { m = n; if (n->getTimeLeft() <= m->getTimeLeft() || n->getTimeLeft() != 0 && m->getTimeLeft() == 0) m = n; }*/ } if (m != NULL) updateMove(m);}void BoardHandler::gotoMainBranch(){ if (gameMode == modeScore) return; CHECK_PTR(tree); if (tree->getCurrent()->parent == NULL) return; Move *m = tree->getCurrent(), *old = m, *lastOddNode = NULL; if (m == NULL) return; while ((m = m->parent) != NULL) { if (tree->getNumSons(m) > 1 && old != m->son) // Remember a node when we came from a branch lastOddNode = m; m->marker = old; old = m; } if (lastOddNode == NULL) return; CHECK_PTR(lastOddNode); lastOddNode->marker = NULL; // Clear the marker, so we can proceed in the main branch tree->setCurrent(lastOddNode); updateMove(lastOddNode);}void BoardHandler::gotoVarStart(){ if (gameMode == modeScore) return; CHECK_PTR(tree); if (tree->getCurrent()->parent == NULL) return; Move *tmp = tree->previousMove(), *m = NULL; if (tmp == NULL) return; // Go up tree until we find a node that has > 1 sons while ((m = tree->previousMove()) != NULL && tree->getNumSons() <= 1) tmp = m; /* Remember move+1, as we set current to the * first move after the start of the variation */ if (m == NULL) // No such node found, so we reached root. { tmp = tree->getRoot(); // For convinience, if we have Move 1, go there. Looks better. if (tmp->son != NULL) tmp = tree->nextMove(); } // If found, set current to the first move inside the variation CHECK_PTR(tmp); tree->setCurrent(tmp); updateMove(tmp);}void BoardHandler::gotoNextBranch(){ if (gameMode == modeScore) return; CHECK_PTR(tree); Move *m = tree->getCurrent(), *remember = m; // Remember current in case we dont find a branch CHECK_PTR(m); // We are already on a node with 2 or more sons? if (tree->getNumSons() > 1) { m = tree->nextMove(); updateMove(m); return; } // Descent tree to last son of main variation while (m->son != NULL && tree->getNumSons() <= 1) m = tree->nextMove(); if (m != NULL && m != remember) { if (m->son != NULL) m = tree->nextMove(); updateMove(m); } else tree->setCurrent(remember);}void BoardHandler::gotoNthMove(int n){ if (gameMode == modeScore) return; ASSERT(n >= 0); CHECK_PTR(tree); Move *m = tree->getRoot(), *old = tree->getCurrent(); CHECK_PTR(m); while (m != NULL) { if (m->getMoveNumber() == n) break; if (m->son == NULL) break; m = m->son; } if (m != NULL && m != old) gotoMove(m);}void BoardHandler::gotoNthMoveInVar(int n){ if (gameMode == modeScore) return; ASSERT(n >= 0); CHECK_PTR(tree); Move *m = tree->getCurrent(), *old = m; CHECK_PTR(m); while (m != NULL) { if (m->getMoveNumber() == n) break; if ((n >= currentMove && m->son == NULL && m->marker == NULL) || (n < currentMove && m->parent == NULL)) break; if (n > currentMove) { if (m->marker == NULL) m = m->son; else m = m->marker; m->parent->marker = m; } else { m->parent->marker = m; m = m->parent; } } if (m != NULL && m != old) gotoMove(m);}void BoardHandler::deleteNode(){ CHECK_PTR(tree); Move *m = tree->getCurrent(), *remember = NULL, *remSon = NULL; CHECK_PTR(m); if (m->parent != NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -