00001
00002
00003
00004
00005
00006
00007
00008 #include "ui.h"
00009 #include "ufwoom.h"
00010 #include "group.h"
00011 #include "button.h"
00012 #include "window.h"
00013 #include <conio.h>
00014 #include <stdio.h>
00015 #include <alloc.h>
00016 #include <assert.h>
00017
00018
00019
00020 int* UserInterface::UFWOOM()
00021 {
00022 Display UFWOOMDisplay;
00023 int* info;
00024
00025 int Num_Buttons = 0;
00026 int Num_Square_CheckBoxes = 0;
00027 int Num_Circle_CheckBoxes = 0;
00028 int Num_Groups = 0;
00029
00030 char buf[40];
00031
00032 int i;
00033 info = new int[6];
00034
00035 UFWOOMDisplay.SetBkColor (BLACK);
00036 UFWOOMDisplay.Clear ();
00037
00038 CheckBox *box [MaxPlayers*3];
00039 for (int plyr = 0; plyr < MaxPlayers; plyr++)
00040 {
00041 box[plyr*2] = new CheckBox ("Computer", BLACK, PColor[plyr], Initial_Square_CheckBox_ID + Num_Square_CheckBoxes, Square);
00042 Num_Square_CheckBoxes++;
00043 box[(plyr*2)+1] = new CheckBox ("Human", BLACK, PColor[plyr], Initial_Square_CheckBox_ID + Num_Square_CheckBoxes, Square);
00044 Num_Square_CheckBoxes++;
00045 }
00046
00047 box[Num_Square_CheckBoxes + Num_Circle_CheckBoxes] = new CheckBox ("Mr. X", BLACK, PColor[0], Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes, Circle);
00048 Num_Circle_CheckBoxes++;
00049
00050 for (i = 0; i < MaxPlayers; i++) {
00051 sprintf (buf, "Detective %d", i+1);
00052 box[Num_Square_CheckBoxes + Num_Circle_CheckBoxes] = new CheckBox (buf, BLACK, PColor[i+1], Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes, Circle);
00053 Num_Circle_CheckBoxes++;
00054 }
00055
00056 PushButton *pb = new PushButton ("Play Game", BLUE, Initial_Button_ID);
00057 Num_Buttons++;
00058
00059
00060 for (i=0; i < (Num_Square_CheckBoxes + Num_Circle_CheckBoxes); i++)
00061 assert (box[i] != NULL);
00062 assert (pb != NULL);
00063
00064 Group *g[6];
00065
00066 for (i=0; i < MaxPlayers; i++)
00067 {
00068 g[i] = new Group (2, Initial_Group_ID + Num_Groups);
00069 Num_Groups++;
00070 }
00071
00072 Window *w = new Window (376, 235, RED, LIGHTGRAY, "Player Information", WHITE);
00073 assert (w != NULL);
00074
00075 UFWOOMDisplay.Add (w, UFWOOMDisplay.GetMaxX()/2-(376/2), UFWOOMDisplay.GetMaxY()/2-(235/2));
00076 for(i=0; i<MaxPlayers; i++)
00077 w->Client().Add (g[i], 0, 0);
00078
00079 for (i=0; i<12; i+=2) {
00080 g[i/2]->Add(box[i], 167, 40+(20*(i/2)));
00081 g[i/2]->Add(box[i+1], 267, 40+(20*(i/2)));
00082 }
00083
00084 for (i=0; i < MaxPlayers; i++)
00085 w->Client().Add (box[i+12], 10, 40+(20*i));
00086
00087 w->Client().Add (pb, (w->Client().GetMaxX()/2)-(pb->GetXDim()/2), w->Client().GetMaxY() - pb->GetYDim() - 5);
00088
00089 DrawTitleScreen();
00090
00091 UFWOOMDisplay.Draw ();
00092
00093 w->Client().SetTextStyle(DEFAULT_FONT, 0, 1);
00094 w->Client().SetColor(WHITE);
00095 w->Client().OutTextXY(15, 20, "Players");
00096 w->Client().OutTextXY(170, 20, "Control");
00097
00098 for(i=102; i<107; i++)
00099 UFWOOMDisplay.Dispatch (Message (GodMsg, Disable, i-100+200));
00100
00101
00102 box[12] -> ChangeStatus (On);
00103 box[12] -> SetPseudo (Off);
00104 box[13] -> ChangeStatus (On);
00105 box[13] -> SetPseudo (Off);
00106
00107 Message DoneMsg (ButtonMsg, ButtonPress, 0xFF), m;
00108
00109 do {
00110 m = UFWOOMDisplay.Dispatch (Mouse.Event ());
00111
00112 if ((m.origin==ButtonMsg)&&(m.code==Status)&&(m.d2)) {
00113 for(i=102; i<107; i++) {
00114 if(m.d1==i)
00115 UFWOOMDisplay.Dispatch (Message (GodMsg, Enable, i-100+200));
00116 }
00117 }
00118 else
00119 if ((m.origin == ButtonMsg) && (m.code == Status)&&(!m.d2)) {
00120 for(i=102; i<107; i++) {
00121 if(m.d1==i)
00122 UFWOOMDisplay.Dispatch (Message (GodMsg, Disable, i-100+200));
00123 }
00124 }
00125 } while (m != DoneMsg);
00126
00127
00128 for (i = Initial_Circle_CheckBox_ID; i < Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes; i++) {
00129 m = UFWOOMDisplay.Dispatch (Message (GodMsg, RequestStatus, i));
00130 info[i - Initial_Circle_CheckBox_ID] = Inactive;
00131 if ((m.origin == ButtonMsg) && (m.code == Status) && (m.d1 == i))
00132 {
00133 if (m.d2)
00134 {
00135 m = UFWOOMDisplay.Dispatch (Message (GodMsg, RequestStatus, (Initial_Square_CheckBox_ID + ((i - Initial_Circle_CheckBox_ID) *2))));
00136 if ((m.origin == ButtonMsg) && (m.code == Status) && (m.d1 == Initial_Square_CheckBox_ID + ((i - Initial_Circle_CheckBox_ID) *2)))
00137 {
00138 if (m.d2)
00139 {info[i - Initial_Circle_CheckBox_ID] = ComputerP;}
00140 else if (!m.d2)
00141 {info[i - Initial_Circle_CheckBox_ID] = HumanP;}
00142 }
00143 }
00144 }
00145 }
00146 return (info);
00147 }
00148
00149