|
GUI Design and Implementation for Noobs - 2nd part |
kingnoob
Member #18,984
January 2021
|
1void Stand() {
2 int i;
3
4 if (mbu) {
5
6 if (mbu == 2) {
7 if (over > 0 && ships > 0 && over >= ships) {
8 orders[org].dst = dst;
9 orders[org].over = over;
10 orders[org].send = ships;
11 orders[org].bump = bump;
12 orders[org].owner = star[dst].owner;
13 }
14 over = 0;
15 ships = 0;
16 bump = 0;
17 gui[ui] = NONE;
18 ui--;
19 }
20 else if (mux > gx + 435 && mux < gx + 475 && muy > gy + 4 && muy < gy + 44) {
21 if (over > 0 && ships > 0 && over >= ships) {
22 orders[org].dst = dst;
23 orders[org].over = over;
24 orders[org].send = ships;
25 orders[org].bump = bump;
26 orders[org].owner = star[dst].owner;
27 }
28 over = 0;
29 ships = 0;
30 bump = 0;
31 gui[ui] = NONE;
32 ui--;
33 }
34 else if (mux > gx + 10 && mux < gx + 469 && muy > gy + 80 && muy < gy + 160) {
35 if (active == 0) {
36 if (over < 10000000) {
37 i = (mux - gx - 10) / 46;
38 over = over * 10 + i;
39 }
40 }
41 if (active == 1) {
42 if (ships < 10000000) {
43 i = (mux - gx - 10) / 46;
44 ships = ships * 10 + i;
45 }
46 }
47 if (active == 2) {
48 if (ships < 10000000) {
49 i = (mux - gx - 10) / 46;
50 bump = bump * 10 + i;
51 }
52 }
53 }
54 else if (mux > gx + 140 && mux < gx + 340 && muy > gy + 168 && muy < gy + 208) {
55 active = 0;
56 }
57 else if (mux > gx + 140 && mux < gx + 340 && muy > gy + 228 && muy < gy + 268) {
58 active = 1;
59 }
60 else if (mux > gx + 140 && mux < gx + 340 && muy > gy + 288 && muy < gy + 328) {
61 active = 2;
62 }
63 else if (mux > gx + 350 && mux < gx + 420 && muy > gy + 168 && muy < gy + 208) {
64 if (active == 0) over = 0;
65 if (active == 1) ships = 0;
66 if (active == 2) bump = 0;
67 }
68 else if (mux > gx + 430 && mux < gx + 469 && muy > gy + 168 && muy < gy + 208) {
69 if (active == 0) over /= 10;
70 if (active == 1) ships /= 10;
71 if (active == 2) bump /= 10;
72 }
73 else if (mux > gx + 350 && mux < gx + 469 && muy > gy + 228 && muy < gy + 268) {
74 for (i = 0; i < numStars; i++) orders[i].over = 0;
75 over = 0;
76 ships = 0;
77 bump = 0;
78 gui[ui] = NONE;
79 ui--;
80 }
81 else if (mux > gx + 350 && mux < gx + 469 && muy > gy + 288 && muy < gy + 328) {
82 if (over > 0 && ships > 0 && over >= ships) {
83 orders[org].dst = dst;
84 orders[org].over = over;
85 orders[org].send = ships;
86 orders[org].bump = bump;
87 orders[org].owner = star[dst].owner;
88 }
89 over = 0;
90 ships = 0;
91 bump = 0;
92 gui[ui] = NONE;
93 ui--;
94 }
95 else if (mux > gx + 10 && mux < gx + 469 && muy > gy + 348 && muy < gy + 388) {
96 for (i = 0; i < numStars; i++) {
97 if (orders[i].dst == org) {
98 orders[i].dst = dst;
99 over = 0;
100 ships = 0;
101 }
102 }
103 gui[ui] = NONE;
104 ui--;
105 }
106 mbu = false;
107 }
108}
All this code does is process input for the standing orders GUI element while it is active. It is too much to explain here but one can look at the attachment and figure out how it works. Just two notes about noobishness. One, I have not yet added the tab key code so for now one has to click on an input field to make it the active field. Also keypad entry has not been added yet. King Noobs must remain true to the King Noob way. The last code snippet is just the game loop as it is now. I don't know why it may be useful but just in case. 1int main() {
2 bool play = true;
3
4 Initialize();
5
6 while (play) {
7 play = GetEvent();
8 ProcessEvent();
9 if (!paused) {
10 fc++; // fc is the frame counter, see I can comment code :)
11 Computer();
12 Update();
13 }
14 DrawFrame();
15 }
16 al_destroy();
17 return 0;
18}
Well that is the end of GUI Design and Implementation for Noobs. My hope is that at least one Noob finds it useful! |
Bad Ash Games
Member #18,627
October 2020
|
I'm a noob and I found this useful. Thanks!
|
kingnoob
Member #18,984
January 2021
|
Mission accomplished then! |
|