[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 5 | * |
---|
| 6 | * This software was released into the Public Domain. As with most public |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
| 10 | |
---|
[555] | 11 | #if defined HAVE_CONFIG_H |
---|
| 12 | # include "config.h" |
---|
| 13 | #endif |
---|
[56] | 14 | |
---|
[512] | 15 | #include "common.h" |
---|
| 16 | |
---|
[481] | 17 | #include "cache.h" |
---|
| 18 | #include "gui.h" |
---|
| 19 | #include "dev.h" |
---|
| 20 | #include "loader2.h" |
---|
[2] | 21 | |
---|
| 22 | void ico_button::set_act_id(int id) |
---|
| 23 | { |
---|
| 24 | activate_id=id; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | ico_switch_button::ico_switch_button(int X, int Y, int ID, int start_on, ifield *butts, ifield *Next) |
---|
| 28 | { |
---|
| 29 | x=X; y=Y; id=ID; |
---|
[124] | 30 | next=Next; |
---|
[2] | 31 | blist=cur_but=butts; |
---|
| 32 | act=0; |
---|
[494] | 33 | for (ifield *b=blist; b; b=b->next) { b->x=x; b->y=y; } |
---|
[2] | 34 | while (cur_but && start_on--) cur_but=cur_but->next; |
---|
| 35 | if (!cur_but) cur_but=blist; |
---|
| 36 | } |
---|
| 37 | |
---|
[106] | 38 | void ico_switch_button::area(int &x1, int &y1, int &x2, int &y2) |
---|
[2] | 39 | { |
---|
| 40 | x1=10000; |
---|
| 41 | y1=10000; |
---|
| 42 | x2=-10000; |
---|
| 43 | y2=-10000; |
---|
| 44 | int X1,Y1,X2,Y2; |
---|
[494] | 45 | for (ifield *b=blist; b; b=b->next) |
---|
[124] | 46 | { |
---|
[106] | 47 | b->area(X1,Y1,X2,Y2); |
---|
[2] | 48 | if (X1<x1) x1=X1; |
---|
| 49 | if (Y1<y1) y1=Y1; |
---|
| 50 | if (X2>x2) x2=X2; |
---|
| 51 | if (Y2>y2) y2=Y2; |
---|
| 52 | } |
---|
| 53 | if (!blist) { x1=x2=x; y1=y2=y; } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | ifield *ico_switch_button::unlink(int id) |
---|
| 57 | { |
---|
| 58 | ifield *last=NULL; |
---|
[494] | 59 | for (ifield *b=blist; b; b=b->next) |
---|
[2] | 60 | { |
---|
| 61 | if (b->id==id) |
---|
| 62 | { |
---|
| 63 | if (last) last->next=b->next; |
---|
| 64 | else blist=b->next; |
---|
| 65 | if (cur_but==b) cur_but=blist; |
---|
| 66 | return b; |
---|
[124] | 67 | } |
---|
[2] | 68 | ifield *x=b->unlink(id); |
---|
| 69 | if (x) return x; |
---|
| 70 | last=b; |
---|
| 71 | } |
---|
| 72 | return NULL; |
---|
| 73 | } |
---|
| 74 | |
---|
[120] | 75 | void ico_switch_button::handle_event(event &ev, image *screen, InputManager *im) |
---|
[2] | 76 | { |
---|
| 77 | if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON && |
---|
| 78 | ev.mouse_button)) |
---|
| 79 | { |
---|
| 80 | cur_but=cur_but->next; |
---|
| 81 | if (!cur_but) cur_but=blist; |
---|
[106] | 82 | cur_but->draw(act,screen); |
---|
| 83 | cur_but->handle_event(ev,screen,im); |
---|
[2] | 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
[106] | 88 | void ico_button::draw(int active, image *screen) |
---|
[2] | 89 | { |
---|
| 90 | int x1,y1,x2,y2; |
---|
[124] | 91 | area(x1,y1,x2,y2); |
---|
| 92 | |
---|
[2] | 93 | if (active!=act && activate_id!=-1 && active) |
---|
| 94 | wm->push_event(new event(activate_id,NULL)); |
---|
[124] | 95 | |
---|
[2] | 96 | if (up && !active) |
---|
[123] | 97 | cache.img(u)->put_image(screen,x1,y1); |
---|
[2] | 98 | else if (up && active) |
---|
[123] | 99 | cache.img(ua)->put_image(screen,x1,y1); |
---|
[2] | 100 | else if (!up && !active) |
---|
[123] | 101 | cache.img(d)->put_image(screen,x1,y1); |
---|
| 102 | else cache.img(da)->put_image(screen,x1,y1); |
---|
[2] | 103 | |
---|
| 104 | if (act!=active && active && activate_id!=-1) |
---|
| 105 | wm->push_event(new event(activate_id,NULL)); |
---|
| 106 | act=active; |
---|
[124] | 107 | |
---|
[2] | 108 | if (active && key[0]) |
---|
| 109 | { |
---|
| 110 | int g=80; |
---|
| 111 | screen->bar(0,0,144,20,0); |
---|
| 112 | wm->font()->put_string(screen,0,0,symbol_str(key),color_table->lookup_color(g>>3,g>>3,g>>3)); |
---|
| 113 | } else if (!active && key[0]) |
---|
| 114 | { |
---|
| 115 | screen->bar(0,0,144,20,0); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | extern long S_BUTTON_PRESS_SND; |
---|
| 121 | extern int sfx_volume; |
---|
| 122 | |
---|
[120] | 123 | void ico_button::handle_event(event &ev, image *screen, InputManager *im) |
---|
[2] | 124 | { |
---|
| 125 | if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON && |
---|
| 126 | ev.mouse_button)) |
---|
| 127 | { |
---|
| 128 | int x1,y1,x2,y2; |
---|
[106] | 129 | area(x1,y1,x2,y2); |
---|
[2] | 130 | up=!up; |
---|
[106] | 131 | draw(act,screen); |
---|
[2] | 132 | wm->push_event(new event(id,(char *)this)); |
---|
| 133 | if (S_BUTTON_PRESS_SND) |
---|
[123] | 134 | cache.sfx(S_BUTTON_PRESS_SND)->play(sfx_volume); |
---|
[2] | 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
[106] | 138 | void ico_button::area(int &x1, int &y1, int &x2, int &y2) |
---|
[2] | 139 | { |
---|
| 140 | x1=x; y1=y; |
---|
[512] | 141 | x2=x+cache.img(u)->Size().x-1; |
---|
| 142 | y2=y+cache.img(u)->Size().y-1; |
---|
[2] | 143 | } |
---|
| 144 | |
---|
[39] | 145 | ico_button::ico_button(int X, int Y, int ID, int Up, int down, int upa, int downa, ifield *Next, int act_id, char const *help_key) |
---|
[2] | 146 | { |
---|
| 147 | if (help_key) |
---|
| 148 | { |
---|
| 149 | strncpy(key,help_key,15); |
---|
| 150 | key[15]=0; |
---|
| 151 | } |
---|
| 152 | else key[0]=0; |
---|
| 153 | |
---|
| 154 | up=1; |
---|
| 155 | x=X; y=Y; id=ID; |
---|
| 156 | u=Up; d=down; |
---|
| 157 | ua=upa; da=downa; |
---|
| 158 | next=Next; |
---|
| 159 | activate_id=act_id; |
---|
[67] | 160 | act = 0; |
---|
[2] | 161 | } |
---|
| 162 | |
---|
| 163 | ico_switch_button::~ico_switch_button() |
---|
| 164 | { |
---|
| 165 | while (blist) |
---|
| 166 | { |
---|
| 167 | ifield *i=blist; |
---|
| 168 | blist=blist->next; |
---|
| 169 | delete i; |
---|
| 170 | } |
---|
| 171 | } |
---|