home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glypha II 1.21 / source / Code ƒ / C-Dialogs.p < prev    next >
Encoding:
Text File  |  1993-07-01  |  13.3 KB  |  460 lines  |  [TEXT/PJMM]

  1. unit Dialogs;
  2.  
  3. interface
  4.     uses
  5.         Palettes, Sound, Globals;
  6.  
  7.     procedure ConfigureGame;
  8.     procedure ControlDialog (var keyboardControl: Boolean);
  9.     procedure WhosHiScore (var theName: Str255);
  10.     function YesNoAlert (whatGives: Integer): Boolean;
  11.  
  12. implementation
  13.  
  14.     var
  15.         GetSelection: DialogPtr;             {Name of dialog}
  16.         tempRect: Rect;                      {Temporary tectangle}
  17.         DType: Integer;                      {Type of dialog item}
  18.         Index: Integer;                      {For looping}
  19.         DItem: Handle;                       {Handle to the dialog item}
  20.         CItem, CTempItem: controlhandle;     {Control handle}
  21.         sTemp: Str255;                       {Get text entered, temp holding}
  22.         itemHit: Integer;                    {Get selection}
  23.         temp: Integer;                       {Get selection, temp holding}
  24.         ThisEditText: TEHandle;              {Handle to get the Dialogs TE record}
  25.         TheDialogPtr: DialogPeek;            {Pointer to Dialogs definition record, contains the TE record}
  26.         ExitDialog, keepIt: boolean;
  27.  
  28. {=================================}
  29.  
  30.     procedure ConfigureGame;
  31.         const
  32.             okayButt = 1;
  33.             cancelButt = 2;
  34.             soundOnRadio = 3;
  35.             soundOffRadio = 4;
  36.             fastRadio = 5;
  37.             slowRadio = 6;
  38.             levelEdit = 7;
  39.             userBox1 = 11;
  40.             userBox2 = 12;
  41.             userBox3 = 13;
  42.  
  43.         var
  44.             soundCopy: Boolean;
  45.             speedCopy, levelCopy, Index, tempVolume: Integer;
  46.             theValue: Integer;
  47.             nTemp: LongInt;
  48.             dummyInt: Integer;
  49.             dialHandle: DialogTHndl;
  50.             dialRect: Rect;
  51.  
  52. {---------------}
  53.  
  54.         procedure Refresh_Dialog;            {Refresh the dialogs non-controls    }
  55.         begin
  56.             PenNormal;
  57.             GetDItem(GetSelection, userBox1, DType, DItem, tempRect);
  58.             FillRect(tempRect, black);
  59.             GetDItem(GetSelection, userBox2, DType, DItem, tempRect);
  60.             FillRect(tempRect, black);
  61.             GetDItem(GetSelection, userBox3, DType, DItem, tempRect);
  62.             FillRect(tempRect, black);
  63.             GetDItem(GetSelection, okayButt, DType, DItem, tempRect);
  64.             PenSize(3, 3);
  65.             InsetRect(tempRect, -4, -4);
  66.             FrameRoundRect(tempRect, 16, 16);
  67.             PenSize(1, 1);
  68.         end;
  69.  
  70. {---------------}
  71.  
  72.     begin
  73.         levelCopy := levelStart;
  74.         soundCopy := soundOn;
  75.         speedCopy := gameSpeed;
  76.  
  77.         dialHandle := DialogTHndl(Get1Resource('DLOG', configGameDialID));
  78.         if (dialHandle <> nil) then
  79.             begin
  80.                 HNoPurge(Handle(dialHandle));
  81.                 dialRect := dialHandle^^.boundsRect;
  82.                 OffsetRect(dialRect, -dialRect.left, -dialRect.top);
  83.                 dummyInt := (screenBits.bounds.right - dialRect.right) div 2;
  84.                 OffsetRect(dialRect, dummyInt, 0);
  85.                 dummyInt := (screenBits.bounds.bottom - dialRect.bottom) div 3;
  86.                 OffsetRect(dialRect, 0, dummyInt);
  87.                 dialHandle^^.boundsRect := dialRect;
  88.                 HPurge(Handle(dialHandle));
  89.             end;
  90.  
  91.         GetSelection := GetNewDialog(configGameDialID, nil, Pointer(-1));
  92.  
  93.         ShowWindow(GrafPtr(GetSelection));
  94.         SelectWindow(GrafPtr(GetSelection));                        {Lets see it}
  95.         SetPort(GrafPtr(GetSelection));
  96.  
  97.         if (soundOn) then
  98.             GetDItem(GetSelection, soundOnRadio, DType, DItem, tempRect)
  99.         else
  100.             GetDItem(GetSelection, soundOffRadio, DType, DItem, tempRect);
  101.         CItem := Pointer(DItem);
  102.         SetCtlValue(CItem, 1);
  103.         GetSoundVol(tempVolume);
  104.         if ((inhibitSound) or (tempVolume = 0)) then
  105.             begin
  106.                 GetDItem(GetSelection, soundOnRadio, DType, DItem, tempRect);
  107.                 HiliteControl(Pointer(DItem), 255);
  108.                 GetDItem(GetSelection, soundOffRadio, DType, DItem, tempRect);
  109.                 HiliteControl(Pointer(DItem), 255);
  110.             end;
  111.  
  112.         if (speedCopy = 3) then
  113.             GetDItem(GetSelection, fastRadio, DType, DItem, tempRect)
  114.         else
  115.             GetDItem(GetSelection, slowRadio, DType, DItem, tempRect);
  116.         SetCtlValue(Pointer(DItem), 1);            {Select to slower}
  117.  
  118.         GetDItem(GetSelection, levelEdit, DType, DItem, tempRect);
  119.         NumToString(levelCopy, sTemp);
  120.         SetIText(DItem, sTemp);
  121.         SelIText(GetSelection, levelEdit, 0, 2);
  122.  
  123.         InitCursor;
  124.         Refresh_Dialog;
  125.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet    }
  126.  
  127.         repeat                                                {Start of dialog handle loop                }
  128.             ModalDialog(nil, itemHit);    {Wait until an item is hit                    }
  129.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect);    {Get item information    }
  130.             CItem := Pointer(DItem);        {Get the control handle                            }
  131.             if (ItemHit = okayButt) then    {Handle the Button being pressed                    }
  132.                 begin
  133.                     GetDItem(GetSelection, levelEdit, DType, DItem, tempRect); {Get the item handle}
  134.                     GetIText(DItem, sTemp);
  135.                     StringToNum(sTemp, nTemp);
  136.                     levelCopy := LoWord(nTemp);
  137.  
  138.                     if ((levelCopy < 1) or (levelCopy > 99)) then
  139.                         begin
  140.                             GetDItem(GetSelection, levelEdit, DType, DItem, tempRect);
  141.                             NumToString(levelCopy, sTemp);
  142.                             SetIText(DItem, sTemp);
  143.                             levelCopy := levelStart;
  144.                             Refresh_Dialog;
  145.                         end
  146.                     else
  147.                         begin
  148.                             levelStart := levelCopy;
  149.                             soundOn := soundCopy;
  150.                             gameSpeed := speedCopy;
  151.                             ExitDialog := TRUE;
  152.                         end;
  153.                 end;
  154.  
  155.             if (ItemHit = cancelButt) then
  156.                 ExitDialog := TRUE;
  157.  
  158.             if (itemHit = soundOnRadio) then
  159.                 begin
  160.                     GetDItem(GetSelection, soundOffRadio, DType, DItem, tempRect);
  161.                     SetCtlValue(Pointer(DItem), 0);
  162.  
  163.                     GetDItem(GetSelection, soundOnRadio, DType, DItem, tempRect);
  164.                     SetCtlValue(Pointer(DItem), 1);
  165.  
  166.                     soundCopy := TRUE;
  167.                 end;
  168.  
  169.             if (itemHit = soundOffRadio) then
  170.                 begin
  171.                     GetDItem(GetSelection, soundOnRadio, DType, DItem, tempRect);
  172.                     SetCtlValue(Pointer(DItem), 0);
  173.  
  174.                     GetDItem(GetSelection, soundOffRadio, DType, DItem, tempRect);
  175.                     SetCtlValue(Pointer(DItem), 1);
  176.  
  177.                     soundCopy := FALSE;
  178.                 end;
  179.  
  180.             if (itemHit = slowRadio) then
  181.                 begin
  182.                     GetDItem(GetSelection, fastRadio, DType, DItem, tempRect);
  183.                     SetCtlValue(Pointer(DItem), 0);
  184.  
  185.                     GetDItem(GetSelection, slowRadio, DType, DItem, tempRect);
  186.                     SetCtlValue(Pointer(DItem), 1);
  187.  
  188.                     speedCopy := 4;
  189.                 end;
  190.  
  191.             if (itemHit = fastRadio) then
  192.                 begin
  193.                     GetDItem(GetSelection, slowRadio, DType, DItem, tempRect);
  194.                     SetCtlValue(Pointer(DItem), 0);
  195.  
  196.                     GetDItem(GetSelection, fastRadio, DType, DItem, tempRect);
  197.                     SetCtlValue(Pointer(DItem), 1);
  198.  
  199.                     speedCopy := 3;
  200.                 end;
  201.  
  202.         until ExitDialog;
  203.  
  204.         DisposDialog(GetSelection);
  205.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, mainWndo^.visRgn);
  206.     end;
  207.  
  208. {=================================}
  209.  
  210.     function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  211.         var
  212.             MyPt: Point;
  213.     begin
  214.         MyFilter := FALSE;
  215.         if (theEvent.what = MouseDown) then
  216.             begin
  217.                 MyPt := theEvent.where;
  218.                 with theDialog^.portBits.bounds do
  219.                     begin
  220.                         myPt.h := myPt.h + left;
  221.                         myPt.v := myPt.v + top;
  222.                     end;
  223.             end;
  224.     end;
  225.  
  226. {=================================}
  227.  
  228.     procedure ControlDialog;
  229.         const
  230.             okayButt = 1;
  231.             cancelButt = 2;
  232.             keyRadio = 3;
  233.             mouseRadio = 4;
  234.             userBox1 = 15;
  235.             userBox2 = 16;
  236.             userBox3 = 17;
  237.  
  238.         var
  239.             Index: Integer;
  240.  
  241.             dummyInt: Integer;
  242.             dialHandle: DialogTHndl;
  243.             dialRect: Rect;
  244.  
  245.         procedure Refresh_Dialog;
  246.             var
  247.                 rTempRect: Rect;
  248.         begin
  249.             PenNormal;
  250.             GetDItem(GetSelection, userBox1, DType, DItem, tempRect);
  251.             FrameRect(tempRect);
  252.             GetDItem(GetSelection, userBox2, DType, DItem, tempRect);
  253.             FrameRect(tempRect);
  254.             GetDItem(GetSelection, userBox3, DType, DItem, tempRect);
  255.             FillRect(tempRect, black);
  256.             GetDItem(GetSelection, okayButt, DType, DItem, tempRect);
  257.             PenSize(3, 3);
  258.             InsetRect(tempRect, -4, -4);
  259.             FrameRoundRect(tempRect, 16, 16);
  260.             PenSize(1, 1);
  261.         end;
  262.  
  263.     begin
  264.         dialHandle := DialogTHndl(Get1Resource('DLOG', controlDialID));
  265.         if (dialHandle <> nil) then
  266.             begin
  267.                 HNoPurge(Handle(dialHandle));
  268.                 dialRect := dialHandle^^.boundsRect;
  269.                 OffsetRect(dialRect, -dialRect.left, -dialRect.top);
  270.                 dummyInt := (screenBits.bounds.right - dialRect.right) div 2;
  271.                 OffsetRect(dialRect, dummyInt, 0);
  272.                 dummyInt := (screenBits.bounds.bottom - dialRect.bottom) div 3;
  273.                 OffsetRect(dialRect, 0, dummyInt);
  274.                 dialHandle^^.boundsRect := dialRect;
  275.                 HPurge(Handle(dialHandle));
  276.             end;
  277.  
  278.         GetSelection := GetNewDialog(controlDialID, nil, Pointer(-1));
  279.  
  280.         ShowWindow(GetSelection);
  281.         SelectWindow(GetSelection);
  282.         SetPort(GrafPtr(GetSelection));
  283.  
  284.         if (keyboardControl) then
  285.             GetDItem(GetSelection, keyRadio, DType, DItem, tempRect)
  286.         else
  287.             GetDItem(GetSelection, mouseRadio, DType, DItem, tempRect);
  288.         CItem := Pointer(DItem);
  289.         SetCtlValue(CItem, 1);
  290.  
  291.         InitCursor;
  292.         Refresh_Dialog;
  293.         ExitDialog := FALSE;
  294.         repeat
  295.             ModalDialog(nil, itemHit);
  296.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect);
  297.             CItem := Pointer(DItem);
  298.             if (ItemHit = okayButt) then
  299.                 begin
  300.                     keepIt := TRUE;
  301.                     ExitDialog := TRUE;
  302.                     Refresh_Dialog;
  303.                 end;
  304.             if (ItemHit = cancelButt) then
  305.                 begin
  306.                     keepIt := FALSE;
  307.                     ExitDialog := TRUE;
  308.                     Refresh_Dialog;
  309.                 end;
  310.             if (ItemHit = keyRadio) or (ItemHit = mouseRadio) then
  311.                 begin
  312.                     for Index := keyRadio to mouseRadio do
  313.                         begin
  314.                             GetDItem(GetSelection, Index, DType, DItem, tempRect);
  315.                             CTempItem := Pointer(DItem);
  316.                             SetCtlValue(CTempItem, 0);
  317.                         end;
  318.                     SetCtlValue(CItem, 1);
  319.                 end;
  320.         until ExitDialog;
  321.  
  322.         Index := keyRadio;
  323.         repeat
  324.             GetDItem(GetSelection, Index, DType, DItem, tempRect);
  325.             CItem := Pointer(DItem);
  326.             temp := GetCtlValue(CItem);
  327.             Index := Index + 1;
  328.         until (temp <> 0) or (Index > mouseRadio);
  329.         temp := Index - keyRadio + 1;
  330.         if (keepIt) then
  331.             begin
  332.                 if (temp = 3) then
  333.                     keyboardControl := FALSE
  334.                 else
  335.                     keyboardControl := TRUE;
  336.             end;
  337.         DisposDialog(GetSelection);
  338.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, mainWndo^.visRgn);
  339.     end;
  340.  
  341. {=================================}
  342.  
  343.     procedure WhosHiScore;
  344.         const
  345.             okayButt = 1;
  346.             nameEdit = 2;
  347.  
  348.         var
  349.             excessSpace: Integer;
  350.             dotFiller, space: Str255;
  351.  
  352.             dummyInt: Integer;
  353.             dialHandle: DialogTHndl;
  354.             dialRect: Rect;
  355.  
  356. {-------------------------}
  357.  
  358.         procedure Refresh_Dialog;    {This draws the rounded-rectangular}
  359.         begin
  360.             SetPort(GetSelection);
  361.             GetDItem(GetSelection, okayButt, DType, DItem, tempRect);
  362.             PenSize(3, 3);
  363.             InsetRect(tempRect, -4, -4);
  364.             FrameRoundRect(tempRect, 16, 16);
  365.             PenSize(1, 1);
  366.         end;
  367.  
  368. {-------------------------}
  369.  
  370.     begin
  371.         dialHandle := DialogTHndl(Get1Resource('DLOG', hiNameDialID));
  372.         if (dialHandle <> nil) then
  373.             begin
  374.                 HNoPurge(Handle(dialHandle));
  375.                 dialRect := dialHandle^^.boundsRect;
  376.                 OffsetRect(dialRect, -dialRect.left, -dialRect.top);
  377.                 dummyInt := (screenBits.bounds.right - dialRect.right) div 2;
  378.                 OffsetRect(dialRect, dummyInt, 0);
  379.                 dummyInt := (screenBits.bounds.bottom - dialRect.bottom) div 3;
  380.                 OffsetRect(dialRect, 0, dummyInt);
  381.                 dialHandle^^.boundsRect := dialRect;
  382.                 HPurge(Handle(dialHandle));
  383.             end;
  384.  
  385.         GetSelection := GetNewDialog(hiNameDialID, nil, Pointer(-1));{Bring in the dialog resource}
  386.  
  387.         ShowWindow(GetSelection);
  388.         SelectWindow(GetSelection);                                {Lets see it}
  389.         SetPort(GrafPtr(GetSelection));                                        {Perpare to add conditional text}
  390.         GetDItem(GetSelection, nameEdit, DType, DItem, tempRect);
  391.         SetIText(DItem, theName);                                    {Set the default text}
  392.         SelIText(GetSelection, nameEdit, 0, 15);{Select the text}
  393.         ExitDialog := FALSE;                                            {Don't exit dialog loop yet}
  394.         Refresh_Dialog;
  395.         repeat                                                                        {Start of dialog loop}
  396.             ModalDialog(nil, itemHit);                            {Wait until item is hit}
  397.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  398.             CItem := Pointer(DItem);                                {Get the control handle}
  399.             if (ItemHit = okayButt) then                            {Handle the Button pressed}
  400.                 begin
  401.                     GetDItem(GetSelection, nameEdit, DType, DItem, tempRect); {Get the item handle}
  402.                     GetIText(DItem, sTemp);                            {Get the text entered}
  403.                     if (LENGTH(sTemp) > 15) then                {Make sure it's less than 15 characters}
  404.                         theName := COPY(sTemp, 1, 15)            {Just clip the first 15 if it is too long}
  405.                     else
  406.                         begin
  407.                             if (LENGTH(sTemp) < 15) then
  408.                                 begin
  409.                                     space := '               ';
  410.                                     excessSpace := 15 - LENGTH(sTemp);
  411.                                     dotFiller := COPY(space, 1, excessSpace);
  412.                                     sTemp := CONCAT(sTemp, dotfiller);
  413.                                 end;
  414.                             theName := sTemp;                            {Otherwise, take it as is}
  415.                         end;
  416.                     ExitDialog := TRUE;                                {Exit the dialog when this selection is made}
  417.                 end;                                                {End for this item selected}
  418.         until ExitDialog;                                        {Handle dialog items until exit selected}
  419.         DisposDialog(GetSelection);                        {Flush the dialog out of memory}
  420.     end;                                                        {End of procedure}
  421.  
  422. {=================================}
  423.  
  424.     function YesNoAlert;
  425.         var
  426.             dummyInt, goForIt: Integer;
  427.             line1: Str255;
  428.             alertHandle: AlertTHndl;
  429.             alertRect: Rect;
  430.     begin
  431.         YesNoAlert := FALSE;
  432.         InitCursor;
  433.         if (whatGives > 0) then
  434.             GetIndString(line1, yesNoStrIDs, whatGives)
  435.         else
  436.             Exit(YesNoAlert);
  437.  
  438.         ParamText(line1, '', '', '');
  439.         alertHandle := AlertTHndl(Get1Resource('ALRT', alertID));
  440.         if (alertHandle <> nil) then
  441.             begin
  442.                 HNoPurge(Handle(alertHandle));
  443.                 alertRect := alertHandle^^.boundsRect;
  444.                 OffsetRect(alertRect, -alertRect.left, -alertRect.top);
  445.                 dummyInt := (screenBits.bounds.right - alertRect.right) div 2;
  446.                 OffsetRect(alertRect, dummyInt, 0);
  447.                 dummyInt := (screenBits.bounds.bottom - alertRect.bottom) div 3;
  448.                 OffsetRect(alertRect, 0, dummyInt);
  449.                 alertHandle^^.boundsRect := alertRect;
  450.                 HPurge(Handle(alertHandle));
  451.             end;
  452.         goForIt := Alert(yesNoAlertID, nil);
  453.         if (goForIt = 1) then
  454.             YesNoAlert := TRUE;
  455.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, mainWndo^.visRgn);
  456.     end;
  457.  
  458. {=================================}
  459.  
  460. end.