[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 | |
---|
[643] | 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 | { |
---|
[644] | 90 | int x1, y1, x2, y2; |
---|
| 91 | area(x1, y1, x2, y2); |
---|
[124] | 92 | |
---|
[644] | 93 | if (active != act && activate_id != -1 && active) |
---|
| 94 | wm->Push(new Event(activate_id, NULL)); |
---|
[124] | 95 | |
---|
[644] | 96 | screen->PutImage(cache.img((up && !active) ? u : |
---|
| 97 | (up && active) ? ua : |
---|
[650] | 98 | (!up && !active) ? d : da), vec2i(x1, y1)); |
---|
[2] | 99 | |
---|
[644] | 100 | if (act != active && active && activate_id != -1) |
---|
| 101 | wm->Push(new Event(activate_id, NULL)); |
---|
| 102 | act = active; |
---|
[124] | 103 | |
---|
[644] | 104 | if (active && key[0]) |
---|
| 105 | { |
---|
| 106 | int g=80; |
---|
| 107 | screen->bar(0, 0, 144, 20, 0); |
---|
| 108 | wm->font()->put_string(screen, 0, 0, symbol_str(key), |
---|
| 109 | color_table->Lookup(g>>3, g>>3, g>>3)); |
---|
| 110 | } |
---|
| 111 | else if (!active && key[0]) |
---|
| 112 | { |
---|
| 113 | screen->bar(0, 0, 144, 20, 0); |
---|
| 114 | } |
---|
[2] | 115 | } |
---|
| 116 | |
---|
| 117 | extern long S_BUTTON_PRESS_SND; |
---|
| 118 | extern int sfx_volume; |
---|
| 119 | |
---|
[643] | 120 | void ico_button::handle_event(Event &ev, image *screen, InputManager *im) |
---|
[2] | 121 | { |
---|
| 122 | if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON && |
---|
| 123 | ev.mouse_button)) |
---|
| 124 | { |
---|
| 125 | int x1,y1,x2,y2; |
---|
[106] | 126 | area(x1,y1,x2,y2); |
---|
[2] | 127 | up=!up; |
---|
[106] | 128 | draw(act,screen); |
---|
[643] | 129 | wm->Push(new Event(id,(char *)this)); |
---|
[2] | 130 | if (S_BUTTON_PRESS_SND) |
---|
[123] | 131 | cache.sfx(S_BUTTON_PRESS_SND)->play(sfx_volume); |
---|
[2] | 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
[106] | 135 | void ico_button::area(int &x1, int &y1, int &x2, int &y2) |
---|
[2] | 136 | { |
---|
| 137 | x1=x; y1=y; |
---|
[512] | 138 | x2=x+cache.img(u)->Size().x-1; |
---|
| 139 | y2=y+cache.img(u)->Size().y-1; |
---|
[2] | 140 | } |
---|
| 141 | |
---|
[39] | 142 | 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] | 143 | { |
---|
| 144 | if (help_key) |
---|
| 145 | { |
---|
| 146 | strncpy(key,help_key,15); |
---|
| 147 | key[15]=0; |
---|
| 148 | } |
---|
| 149 | else key[0]=0; |
---|
| 150 | |
---|
| 151 | up=1; |
---|
| 152 | x=X; y=Y; id=ID; |
---|
| 153 | u=Up; d=down; |
---|
| 154 | ua=upa; da=downa; |
---|
| 155 | next=Next; |
---|
| 156 | activate_id=act_id; |
---|
[67] | 157 | act = 0; |
---|
[2] | 158 | } |
---|
| 159 | |
---|
| 160 | ico_switch_button::~ico_switch_button() |
---|
| 161 | { |
---|
| 162 | while (blist) |
---|
| 163 | { |
---|
| 164 | ifield *i=blist; |
---|
| 165 | blist=blist->next; |
---|
| 166 | delete i; |
---|
| 167 | } |
---|
| 168 | } |
---|