home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-25 | 12.2 KB | 415 lines | [TEXT/KAHL] |
- // prefs.c
- // handle the prefs dialog 'n stuff
-
- #include "cheatprefs.h"
- #include "cheatWindow.h"
- #include "main.h"
- #include "cheat.h"
- #include "ResRefs.h"
- #include "error.h"
-
- // items in dialog
-
- #define pOkay 1
- #define pCancel 2
- #define pTimeUnit 4
- #define pTimeVar (pTimeUnit + 2)
- #define pTotalUnit 8
- #define pTotalVar (pTotalUnit + 2)
- #define pInitBal 12
- #define pRateTitle 14
- #define pRateVar (pRateTitle + 2)
- #define pSymbol 18
- #define pSymbolLeft 19
- #define pSymbolRight 20
- #define pRateAdd 22
- #define pRateMult 23
- #define pDecRate 26
- #define pDecTotal 27
-
- // the variables related to what we get from prefs dialog
-
- Str255 stimeunit = "\pDay";
- Str255 stimevar = "\pd";
- Str255 stotalunit = "\pBalance";
- Str255 stotalvar = "\pb";
- Str255 sinitbal = "\pInitial Balance";
- Str255 sratetitle = "\pTransaction";
- Str255 sratevar = "\pt";
- Str255 ssymbol = "\p$";
- Str255 DscaleMinS = "\p0", DscaleMaxS = "\p50";
- int onleft = true; // where to place symbol
- int ratetype = kadditiverate;
- int tdecplaces = 2, bdecplaces = 1; // digits after decimal point
-
- typedef struct {
- short itemType;
- Handle item;
- Rect box;
- } iteminfo;
-
- #define kNumItems 27
-
- void doPrefDialog(void)
- {
- DialogPtr dialog;
- Rect newrect;
- DialogTHndl dlogTemplate;
- short hitItem; // result of ModalDialog
- Rect theBox;
- long ignoreLong;
- Str255 s;
- iteminfo ilist[kNumItems+1];
- int i, sympos, newrate;
- WindowPtr saveport;
- long l;
-
- dialog = GetNewDialog(rPrefDlog, nil, (WindowPtr) -1); verify(dialog);
- for (i=1;i<=kNumItems;i++) {
- GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
- verify(ilist[i].item);
- }
- // now set up the items how we last had them . . .
- SetIText(ilist[pTimeUnit].item, stimeunit);
- SetIText(ilist[pTimeVar].item, stimevar);
- SetIText(ilist[pTotalUnit].item, stotalunit);
- SetIText(ilist[pTotalVar].item, stotalvar);
- SetIText(ilist[pInitBal].item, sinitbal);
- SetIText(ilist[pRateTitle].item, sratetitle);
- SetIText(ilist[pRateVar].item, sratevar);
- SetIText(ilist[pSymbol].item, ssymbol);
- SetCtlValue((ControlHandle) ((onleft == true) ? ilist[pSymbolLeft].item : ilist[pSymbolRight].item), true);
- SetCtlValue((ControlHandle) ((ratetype == kadditiverate) ?
- ilist[pRateAdd].item : ilist[pRateMult].item), true);
- NumToString(tdecplaces, s); SetIText(ilist[pDecRate].item, s);
- NumToString(bdecplaces, s); SetIText(ilist[pDecTotal].item, s);
- ShowWindow(dialog);
-
- // draw circle around button -- pity this won't update . . .
- GetPort(&saveport);
- SetPort(dialog);
- theBox = ilist[pOkay].box;
- PenSize(3, 3);
- InsetRect(&theBox, -4, -4);
- FrameRoundRect(&theBox, 16, 16);
- PenSize(1, 1);
- SetPort(saveport);
-
- // set some temp vars, don't want to use real things 'cause of cancel button
- sympos = onleft;
- newrate = ratetype;
- do {
- ModalDialog(nil, &hitItem);
- switch (hitItem) {
- case pSymbolLeft: case pSymbolRight:
- sympos = (hitItem == pSymbolLeft) ? true : false;
- SetCtlValue((ControlHandle) ilist[pSymbolLeft].item, sympos);
- SetCtlValue((ControlHandle) ilist[pSymbolRight].item, !sympos);
- break;
- case pRateAdd: case pRateMult:
- newrate = (hitItem == pRateAdd) ? kadditiverate : kmultrate;
- SetCtlValue((ControlHandle) ilist[pRateAdd].item, newrate == kadditiverate);
- SetCtlValue((ControlHandle) ilist[pRateMult].item, newrate == kmultrate);
- break;
- default: break;
- }
- } while ((hitItem != pOkay) && (hitItem != pCancel));
- if (hitItem == pOkay) { // change real values
- GetIText(ilist[pTimeUnit].item, stimeunit);
- GetIText(ilist[pTimeVar].item, stimevar);
- GetIText(ilist[pTotalUnit].item, stotalunit);
- GetIText(ilist[pTotalVar].item, stotalvar);
- GetIText(ilist[pInitBal].item, sinitbal);
- GetIText(ilist[pRateTitle].item, sratetitle);
- GetIText(ilist[pRateVar].item, sratevar);
- GetIText(ilist[pSymbol].item, ssymbol);
- onleft = sympos;
- ratetype = newrate;
- GetIText(ilist[pDecRate].item, s); StringToNum(s, (long *) &l); tdecplaces = l;
- GetIText(ilist[pDecTotal].item, s); StringToNum(s, (long *) &l); bdecplaces = l;
- if (tdecplaces>8) tdecplaces = 8;
- if (bdecplaces>8) bdecplaces = 8;
- }
- DisposDialog(dialog); // we outta 5000, g
- }
-
- #undef kNumItems
- #undef pOkay
- #undef pCancel
- #undef pTimeUnit
- #undef pTimeVar
- #undef pTotalUnit
- #undef pTotalVar
- #undef pInitBal
- #undef pRateTitle
- #undef pRateVar
- #undef pSymbol
- #undef pSymbolLeft
- #undef pSymbolRight
- #undef pRateAdd
- #undef pRateMult
-
- // next up is the scale dialog
- //
- //
-
- // items in dialog
-
- #define kNumItems 14
- #define pOkay 1
- #define pCancel 2
- #define pBalString 3
- #define pTransString 4
- #define pMaxTrans 5
- #define pMinTrans 6
- #define pMaxBalance 8
- #define pMinBalance 7
- #define pMinDays 9
- #define pMaxDays 10
- #define pDaysString 11
-
- #define SCALE_BASE 255
- #define tscaleX 50
- #define bscaleX 180
- #define dscaleX 270
-
- static int filterproc(DialogPtr daDialog, EventRecord *event, int *itemhit)
- {
- return false;
- }
-
- // the variables related to what we get from scale dialog are in main
-
- // this code is so ugly it makes me scream. wow. I hated writing this crap.
- void doScaleDialog(void)
- {
- DialogPtr dialog;
- Rect newrect;
- DialogTHndl dlogTemplate;
- short hitItem; // result of ModalDialog
- Rect theBox;
- long ignoreLong;
- Str255 s, s2;
- iteminfo ilist[kNumItems+1];
- int i, sympos, newrate;
- WindowPtr saveport;
- float min, max; long lmin, lmax;
- struct scale newbal, newtrans;
- Rect rtrans = {SCALE_BASE - 205, tscaleX-5, SCALE_BASE+8, tscaleX+85};
- Rect rbal = {SCALE_BASE - 205, bscaleX-5, SCALE_BASE+8, bscaleX+85};
- Rect rdays = {SCALE_BASE - 205, dscaleX-5, SCALE_BASE+8, dscaleX+68};
-
- newbal = balScale; newtrans = transScale;
- dialog = GetNewDialog(rScaleDlog, nil, (WindowPtr) -1); verify(dialog);
- for (i=1;i<=kNumItems;i++) {
- GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
- verify(ilist[i].item);
- }
- // now set up the items how we last had them . . .
- SetIText(ilist[pDaysString].item, stimeunit);
- SetIText(ilist[pBalString].item, stotalunit);
- SetIText(ilist[pTransString].item, sratetitle);
-
- float2pstr(TscaleMin, s, tdecplaces); SetIText(ilist[pMinTrans].item, s);
- float2pstr(TscaleMax, s, tdecplaces); SetIText(ilist[pMaxTrans].item, s);
- float2pstr(BscaleMin, s, bdecplaces); SetIText(ilist[pMinBalance].item, s);
- float2pstr(BscaleMax, s, bdecplaces); SetIText(ilist[pMaxBalance].item, s);
- NumToString(DscaleMin, s); SetIText(ilist[pMinDays].item, s);
- NumToString(DscaleMax, s2); SetIText(ilist[pMaxDays].item, s2);
- ShowWindow(dialog);
-
- // draw circle around button -- pity this won't update . . .
- GetPort(&saveport);
- SetPort(dialog);
- theBox = ilist[pOkay].box;
- PenSize(3, 3);
- InsetRect(&theBox, -4, -4);
- FrameRoundRect(&theBox, 16, 16);
- PenSize(1, 1);
- DrawScale(&newtrans, tscaleX, SCALE_BASE);
- DrawScale(&newbal, bscaleX, SCALE_BASE);
- TextFont(monaco);
- TextSize(9);
- MoveTo(dscaleX, SCALE_BASE); /* Start at baseline of scale. */
- Line(0,-newbal.totalPixels); /* Draw vertical line for scale. */
- MoveTo(dscaleX + 8, SCALE_BASE + 6);
- DrawString(s);
- MoveTo(dscaleX + 8, SCALE_BASE + 6 - newbal.totalPixels);
- DrawString(s2);
- SetPort(saveport);
-
- // set some temp vars, don't want to use real things 'cause of cancel button
- sympos = onleft;
- newrate = ratetype;
- do {
- ModalDialog(nil, &hitItem);
- GetPort(&saveport);
- SetPort(dialog);
- switch (hitItem) {
- case pMinTrans: case pMaxTrans:
- GetIText(ilist[pMinTrans].item, s); min = pstr2float(s);
- GetIText(ilist[pMaxTrans].item, s); max = pstr2float(s);
- if (min < max) {
- RecalcScale(&newtrans, min, max);
- EraseRect(&rtrans);
- DrawScale(&newtrans, tscaleX, SCALE_BASE);
- }
- break;
- case pMinBalance: case pMaxBalance:
- GetIText(ilist[pMinBalance].item, s); min = pstr2float(s);
- GetIText(ilist[pMaxBalance].item, s); max = pstr2float(s);
- if (min < max) {
- RecalcScale(&newbal, min, max);
- EraseRect(&rbal);
- DrawScale(&newbal, bscaleX, SCALE_BASE);
- }
- break;
- case pMinDays: case pMaxDays:
- GetIText(ilist[pMinDays].item, s); StringToNum(s, &lmin);
- GetIText(ilist[pMaxDays].item, s2); StringToNum(s2, &lmax);
- if (s[0] > 10) s[0] = 10;
- if (s2[0] > 10) s2[0] = 10;
- if ((lmin>=0) && (lmin < lmax)) {
- TextFont(monaco);
- TextSize(9);
- EraseRect(&rdays);
- MoveTo(dscaleX, SCALE_BASE); /* Start at baseline of scale. */
- Line(0,-newbal.totalPixels); /* Draw vertical line for scale. */
- MoveTo(dscaleX + 8, SCALE_BASE + 6);
- DrawString(s);
- MoveTo(dscaleX + 8, SCALE_BASE + 6 - newbal.totalPixels);
- DrawString(s2);
- }
- break;
- case pOkay: // check values, make sure they're okay
- GetIText(ilist[pMinTrans].item, s); min = pstr2float(s);
- GetIText(ilist[pMaxTrans].item, s); max = pstr2float(s);
- if (min >= max) {
- StopAlert(rRangeAlrt, nil);
- hitItem = 0; // they can't leave yet bwahahah
- break;
- }
- GetIText(ilist[pMinBalance].item, s); min = pstr2float(s);
- GetIText(ilist[pMaxBalance].item, s); max = pstr2float(s);
- if (min >= max) {
- StopAlert(rRangeAlrt, nil);
- hitItem = 0; // they can't leave yet bwahahah
- break;
- }
- GetIText(ilist[pMinDays].item, s); StringToNum(s, &lmin);
- GetIText(ilist[pMaxDays].item, s); StringToNum(s, &lmax);
- if (lmin < 0) { // no negative days
- StopAlert(rBackInTimeAlrt, nil);
- hitItem = 0; // they can't leave yet bwahahah
- break;
- }
- if (lmin >= lmax) {
- StopAlert(rRangeAlrt, nil);
- hitItem = 0; // they can't leave yet bwahahah
- break;
- }
- break;
- default: break;
- }
- SetPort(saveport);
- } while ((hitItem != pOkay) && (hitItem != pCancel));
- if (hitItem == pOkay) { // change real values
- GetIText(ilist[pMinTrans].item, s); TscaleMin = pstr2float(s);
- GetIText(ilist[pMaxTrans].item, s); TscaleMax = pstr2float(s);
- GetIText(ilist[pMinBalance].item, s); BscaleMin = pstr2float(s);
- GetIText(ilist[pMaxBalance].item, s); BscaleMax = pstr2float(s);
- GetIText(ilist[pMinDays].item, DscaleMinS); StringToNum(DscaleMinS, &DscaleMin);
- GetIText(ilist[pMaxDays].item, DscaleMaxS); StringToNum(DscaleMaxS, &DscaleMax);
- RecalcScale(&transScale, TscaleMin, TscaleMax);
- RecalcScale(&balScale, BscaleMin, BscaleMax);
- }
- DisposDialog(dialog); // we outta 5000, g
- }
-
- // undef items in dialog
-
- #undef kNumItems
- #undef pOkay
- #undef pCancel
- #undef pBalString
- #undef pTransString
- #undef pMaxTrans
- #undef pMinTrans
- #undef pMaxBalance
- #undef pMinBalance
- #undef pMinDays
- #undef pMaxDays
- #undef pDaysString
-
-
- // next up is the time dialog
- //
- //
-
- // items in dialog
-
- #define kNumItems 7
- #define pOkay 1
- #define pCancel 2
- #define pRegTime 6
- #define pRepTime 7
-
- // the variables related to what we get from scale dialog are in main
-
- long updateTime = 5, replayTime = 5; // times for the day cycle thing
-
- void doTimeDialog(void) // doing time . . . I'm such the criminal
- {
- DialogPtr dialog;
- Rect newrect;
- DialogTHndl dlogTemplate;
- short hitItem; // result of ModalDialog
- Rect theBox;
- long ignoreLong;
- Str255 s;
- iteminfo ilist[kNumItems+1];
- int i, sympos, newrate;
- WindowPtr saveport;
- long reg, rep;
-
- dialog = GetNewDialog(rTimeDlog, nil, (WindowPtr) -1); verify(dialog);
- for (i=1;i<=kNumItems;i++) {
- GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
- verify(ilist[i].item);
- }
- // now set up the items how we last had them . . .
- NumToString(updateTime, s); SetIText(ilist[pRegTime].item, s);
- NumToString(replayTime, s); SetIText(ilist[pRepTime].item, s);
- ShowWindow(dialog);
-
- // draw circle around button -- pity this won't update . . .
- GetPort(&saveport);
- SetPort(dialog);
- theBox = ilist[pOkay].box;
- PenSize(3, 3);
- InsetRect(&theBox, -4, -4);
- FrameRoundRect(&theBox, 16, 16);
- PenSize(1, 1);
- SetPort(saveport);
-
- do {
- ModalDialog(nil, &hitItem);
- switch (hitItem) {
- case pOkay: // check values, make sure they're okay
- GetIText(ilist[pRegTime].item, s); StringToNum(s, ®);
- GetIText(ilist[pRepTime].item, s); StringToNum(s, &rep);
- if ((reg < 1) || (rep < 1)) {
- StopAlert(rBadTimeAlrt, nil);
- hitItem = 0; // they can't leave yet bwahahah
- break;
- }
- default: break;
- }
- } while ((hitItem != pOkay) && (hitItem != pCancel));
- if (hitItem == pOkay) { // change real values
- GetIText(ilist[pRegTime].item, s); StringToNum(s, &updateTime);
- GetIText(ilist[pRepTime].item, s); StringToNum(s, &replayTime);
- startTime = 0; // the arc starts from scratch now
- }
- DisposDialog(dialog); // we outta 5000, g
- }