📄 sugarmemolearn2.c
字号:
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, interval);
break;
case 'E':
ms.eFactor -= 0.54;
if (ms.eFactor < 1.3) ms.eFactor = 1.3;
ms.difficulty = Difficulty(ms.eFactor);
ms.totalLapse++;
ms.step = 1;
interval = 8 - (Int32)((ms.eFactor - 1.3) * 3 / 1.2);
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, interval);
break;
case 'F':
ms.eFactor -= 0.8;
if (ms.eFactor < 1.3) ms.eFactor = 1.3;
ms.difficulty = Difficulty(ms.eFactor);
ms.totalLapse++;
ms.step = 0;
ms.lastTest = today;
DateSecondsToDate(0, &ms.nextTest);
break;
}
// clear testing status!
// Added by hytown
ts.firstRating = NoRating;
ts.secondRating = NoRating;
ts.totalFail = 0;
SetTestingStatus(CurrentDB, CurrentRecord, ts);
SetLearningStatus(CurrentDB, CurrentRecord, FirstLook);
SetMemorizingStatus(CurrentDB, CurrentRecord, ms);
if (rate == 'F')
SetQueue(CurrentDB, CurrentRecord, LearningQueue);
else
SetQueue(CurrentDB, CurrentRecord, WaitingQueue);
}
void Learn2FinishLearning(){
MemorizingStatus ms = GetMemorizingStatus(CurrentDB, CurrentRecord);
SetLearningStatus(CurrentDB, CurrentRecord, FirstLook);
/*
float eFactor; //E-Factor
UInt8 difficulty; //
UInt8 totalLapse;
UInt8 totalRecall;
UInt8 step; //step in current round
DateType lastTest;
DateType currentTest; //when the current test begins, only meaningful for drilling words
DateType nextTest;
DateType firstLearn;
DateType create;
*/
ms.step = 1;
DateSecondsToDate(TimGetSeconds(), &ms.lastTest);
ms.nextTest = ms.lastTest;
if (ZeroDate(ms.firstLearn)) {
ms.firstLearn = ms.nextTest;
DateAdjust(&ms.nextTest, 1);
}
else
DateAdjust(&ms.nextTest, 2);
SetMemorizingStatus(CurrentDB, CurrentRecord, ms);
SetQueue(CurrentDB, CurrentRecord, WaitingQueue);
}
UInt8 Difficulty(float efactor){
UInt8 x = (UInt8)((efactor - 1.3)*50);
if (x > 100) return (UInt8) 100;
return (UInt8)(100 - x);
}
void Learn2ProcessLearningRating(Boolean right){
UInt16 step;
PushHeaderBuffer(CurrentDB, LearningChoiceBuffer, CurrentRecord);
switch(CurrentLearningStatus){
case FirstLook:
step = 6;
break;
case TranslationRecollection:
step = 13;
break;
case WordRecollection:
step = 27;
break;
case TranslationTest:
step = 55;
break;
case WordTest:
step = 111;
break;
}
if (right) {
if (CurrentLearningStatus == WordTest)
Learn2FinishLearning();
else {
CurrentLearningStatus++;
SetLearningStatus(CurrentDB, CurrentRecord, CurrentLearningStatus);
MoveHeaderItem(CurrentDB, LearningRecordIndex, step);
}
}
else
MoveHeaderItem(CurrentDB, LearningRecordIndex, step);
if (LoadWord()) Learn2InitWord();
else Learn2FormQuit();
return;
}
void Learn2ProcessReviewRating(Rating rating){
TestingStatus ts = GetTestingStatus(CurrentDB, CurrentRecord);
UInt16 bits;
// Set rating status
if (ts.firstRating == NoRating) ts.firstRating = rating;
else if (ts.secondRating < rating) ts.secondRating = rating;
// I changed the statement back to original since I have changed the enum Rating
// Changed by hytown
// else if ((ts.secondRating == NoRating) || (ts.secondRating > rating)) ts.secondRating = rating;
if (rating == FailRating) ts.totalFail++;
SetTestingStatus(CurrentDB, CurrentRecord, ts);
PushHeaderBuffer(CurrentDB, TestingChoiceBuffer, CurrentRecord);
// if bingo
if (rating == BingoRating) {
// finish a review mode, set correspondent bit
/*
bits = (UInt16)ts.reviewMode.allBits;
SetBitMacro(bits, CurrentLearningStatus);
ts.reviewMode.allBits = (UInt8)bits;
SetTestingStatus(CurrentDB, CurrentRecord, ts);
if (TossNextReviewMode() == 0) Learn2FinishReview();
else MoveHeaderItem(CurrentDB, TestingRecordIndex, 55);
*/
Learn2FinishReview();
}
// if pass
else if (rating == PassRating){
bits = (UInt16)ts.reviewMode.allBits;
SetBitMacro(bits, CurrentLearningStatus);
ts.reviewMode.allBits = (UInt8)bits;
SetTestingStatus(CurrentDB, CurrentRecord, ts);
if (TossNextReviewMode() == 0) Learn2FinishReview();
else MoveHeaderItem(CurrentDB, TestingRecordIndex, 55);
}
// if fail
else
MoveHeaderItem(CurrentDB, TestingRecordIndex, 55);
if (LoadWord()) Learn2InitWord();
else Learn2FormQuit();
return;
}
Boolean Learn2FormDoHardKey(EventType* event){
Boolean selectChoice = false;
Boolean hitNext = false;
Boolean hitShow = false;
Boolean nextTab = false;
Boolean prevTab = false;
Boolean toggleRate = false;
Boolean pushRate = false;
Boolean prevChoice = false;
Boolean nextChoice = false;
Boolean handled = false;
Boolean lefty = Lefty();
ControlType* ctl;
TableType* table;
Int16 row, column;
FormType* form = FrmGetActiveForm();
UInt16 ObjIndex;
WChar key = event->data.keyDown.chr;
SndPlaySystemSound(sndClick);
if (key == hard1Chr || key == hard2Chr || key == hard3Chr || key == hard4Chr) handled = true;
if ((key <= vchrSonyMin) && (key >= vchrSonyMax)) handled = true;
if (ShowNext){
if (((key == hard2Chr) && lefty) || ((key == hard3Chr) && (!lefty)))
hitNext = true;
// Sony
if ((key == vchrJogPush) && lefty)
hitNext = true;
}
if (ShowShow){
if ((key == hard2Chr && lefty) || (key == hard3Chr && !lefty))
hitShow = true;
// Sony
if ((key == vchrJogPush) && lefty)
hitShow = true;
}
if (ShowRightWrong || ShowBingoPassFail){
if ((key == hard1Chr && lefty) || (key == hard4Chr && !lefty))
toggleRate = true;
if ((key == hard2Chr && lefty) || (key == hard3Chr && !lefty))
pushRate = true;
// Sony
if (lefty && (key == vchrJogDown))
toggleRate = true;
if (lefty && (key == vchrJogPush))
pushRate = true;
}
if (ShowNext || ShowRightWrong || ShowBingoPassFail){
if (key == hard1Chr && !lefty) prevTab = true;
if (key == hard2Chr && !lefty) nextTab = true;
if (key == hard3Chr && lefty) nextTab = true;
if (key == hard4Chr && lefty) prevTab = true;
// Sony
if (lefty && (key == vchrJogUp)) nextTab = true;
}
if (ShowChoices){
if (key == hard1Chr || key == hard2Chr || key == hard3Chr || key == hard4Chr)
selectChoice = true;
// Sony
if (lefty && (key == vchrJogPush))
selectChoice = true;
if (lefty && (key == vchrJogUp))
prevChoice = true;
if (lefty && (key == vchrJogDown))
nextChoice = true;
}
if (hitNext){
ctl = GetObjectPtr(Learn2NextButton);
CtlHitControl(ctl);
}
if (hitShow){
// Added by hytown
// Add some code to avoid crashing
if (FrmGetActiveFormID() != EditForm) {
ctl = GetObjectPtr(Learn2ShowButton);
CtlHitControl(ctl);
}
}
if (toggleRate){
if (ShowRightWrong){
ObjIndex = FrmGetControlGroupSelection(form, RightWrongGroup);
if (ObjIndex == GetObjectIndex(Learn2RightPushButton))
ObjIndex = Learn2WrongPushButton;
else
ObjIndex = Learn2RightPushButton;
FrmSetControlGroupSelection(form, RightWrongGroup, ObjIndex);
}
else if (ShowBingoPassFail){
ObjIndex = FrmGetControlGroupSelection(form, BingoPassFailGroup);
if (ObjIndex == GetObjectIndex(Learn2BingoPushButton))
ObjIndex = Learn2PassPushButton;
else if (ObjIndex == GetObjectIndex(Learn2PassPushButton))
ObjIndex = Learn2FailPushButton;
else
ObjIndex = Learn2BingoPushButton;
FrmSetControlGroupSelection(form, BingoPassFailGroup, ObjIndex);
}
}
if (pushRate){
if (ShowRightWrong)
ObjIndex = FrmGetControlGroupSelection(form, RightWrongGroup);
if (ShowBingoPassFail)
ObjIndex = FrmGetControlGroupSelection(form, BingoPassFailGroup);
if (ObjIndex != frmNoSelectedControl){
ctl = FrmGetObjectPtr(form, ObjIndex);
CtlHitControl(ctl);
}
}
if (prevTab) ToggleDynamicField(true);
if (nextTab) ToggleDynamicField(false);
if (selectChoice) {
table = GetObjectPtr(Learn2ChoiceTable);
if (TblGetSelection(table, &row, &column))
Learn2FormTableSelection(row);
}
if (prevChoice) Learn2ScrollChoiceSelection(true);
if (nextChoice) Learn2ScrollChoiceSelection(false);
return handled;
}
void ToggleDynamicField(Boolean prevField){
FormType* form = FrmGetActiveForm();
WordRecordType record;
MemHandle recordH;
SugarAppInfoType* app;
ControlType* ctl;
UInt16 objectID, controlID[WordFieldsCount];
UInt16 i, j, k, result;
objectID = (UInt16)FrmGetControlGroupSelection(form, DynamicPushButtonGroup);
if (objectID == frmNoSelectedControl) return;
// Get record
app = GetAppInfoPtr(CurrentDB);
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
// Get available tab list
j = 0;
for (i = WordFieldQuestion; i < WordFieldsCount; i++){
if (i == DefaultField || (GetBitMacro(app -> answerPageFields.allBits, i) != 0)
&& (record.field[i] != NULL)){
controlID[j] = DynamicPushButtonStart + i;
j++;
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
// Find selected tab
for (k = 0; k < j; k++){
if (FrmGetObjectIndex(form, controlID[k]) == objectID) {
break;
}
}
if (k == j) return;
if (prevField){
if (k == 0) result = controlID[j-1];
else result = controlID[k - 1];
}
else {
if (k == j - 1) result = controlID[0];
else result = controlID[k + 1];
}
FrmSetControlGroupSelection(form, DynamicPushButtonGroup, result);
ctl = GetObjectPtr(result);
CtlHitControl(ctl);
}
Boolean Lefty(){
SugarAppInfoType* app;
Boolean lefty;
app = GetAppInfoPtr(CurrentDB);
if (app == NULL){
ErrNonFatalDisplayIf(true, "cannot get lefty info");
return false;
}
if (app -> lefty == 0) lefty = false;
else lefty = true;
MemPtrUnlock(app);
return lefty;
}
void Learn2ScrollChoiceSelection(Boolean up){
TableType* table = GetObjectPtr(Learn2ChoiceTable);
Int16 row, column;
Int16 bottom;
if (!TblGetSelection(table, &row, &column)) {
row = TblGetLastUsableRow(table);
row = row / 2;
TblSelectItem(table, row, 0);
return;
}
bottom = TblGetLastUsableRow(table);
if (up){
if (row == 0) row = bottom;
else row --;
}
else{
if (row == bottom) row = 0;
else row ++;
}
TblSelectItem(table, row, 0);
}
void Learn2ClipBoardWord(){
WordRecordType record;
MemHandle recordH;
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
if (record.field[WordFieldQuestion] != NULL){
ClipboardAddItem(clipboardText, record.field[WordFieldQuestion], StrLen(record.field[WordFieldQuestion]));
}
MemHandleUnlock(recordH);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -