[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 | { |
---|
[659] | 29 | m_pos = vec2i(X, Y); id=ID; |
---|
[124] | 30 | next=Next; |
---|
[2] | 31 | blist=cur_but=butts; |
---|
| 32 | act=0; |
---|
[659] | 33 | for (ifield *b=blist; b; b=b->next) |
---|
| 34 | b->m_pos = m_pos; |
---|
[2] | 35 | while (cur_but && start_on--) cur_but=cur_but->next; |
---|
| 36 | if (!cur_but) cur_but=blist; |
---|
| 37 | } |
---|
| 38 | |
---|
[106] | 39 | void ico_switch_button::area(int &x1, int &y1, int &x2, int &y2) |
---|
[2] | 40 | { |
---|
| 41 | x1=10000; |
---|
| 42 | y1=10000; |
---|
| 43 | x2=-10000; |
---|
| 44 | y2=-10000; |
---|
| 45 | int X1,Y1,X2,Y2; |
---|
[494] | 46 | for (ifield *b=blist; b; b=b->next) |
---|
[124] | 47 | { |
---|
[106] | 48 | b->area(X1,Y1,X2,Y2); |
---|
[2] | 49 | if (X1<x1) x1=X1; |
---|
| 50 | if (Y1<y1) y1=Y1; |
---|
| 51 | if (X2>x2) x2=X2; |
---|
| 52 | if (Y2>y2) y2=Y2; |
---|
| 53 | } |
---|
[659] | 54 | if (!blist) { x1=x2=m_pos.x; y1=y2=m_pos.y; } |
---|
[2] | 55 | } |
---|
| 56 | |
---|
| 57 | ifield *ico_switch_button::unlink(int id) |
---|
| 58 | { |
---|
| 59 | ifield *last=NULL; |
---|
[494] | 60 | for (ifield *b=blist; b; b=b->next) |
---|
[2] | 61 | { |
---|
| 62 | if (b->id==id) |
---|
| 63 | { |
---|
| 64 | if (last) last->next=b->next; |
---|
| 65 | else blist=b->next; |
---|
| 66 | if (cur_but==b) cur_but=blist; |
---|
| 67 | return b; |
---|
[124] | 68 | } |
---|
[2] | 69 | ifield *x=b->unlink(id); |
---|
| 70 | if (x) return x; |
---|
| 71 | last=b; |
---|
| 72 | } |
---|
| 73 | return NULL; |
---|
| 74 | } |
---|
| 75 | |
---|
[643] | 76 | void ico_switch_button::handle_event(Event &ev, image *screen, InputManager *im) |
---|
[2] | 77 | { |
---|
| 78 | if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON && |
---|
| 79 | ev.mouse_button)) |
---|
| 80 | { |
---|
| 81 | cur_but=cur_but->next; |
---|
| 82 | if (!cur_but) cur_but=blist; |
---|
[106] | 83 | cur_but->draw(act,screen); |
---|
| 84 | cur_but->handle_event(ev,screen,im); |
---|
[2] | 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | |
---|
[106] | 89 | void ico_button::draw(int active, image *screen) |
---|
[2] | 90 | { |
---|
[644] | 91 | int x1, y1, x2, y2; |
---|
| 92 | area(x1, y1, x2, y2); |
---|
[124] | 93 | |
---|
[644] | 94 | if (active != act && activate_id != -1 && active) |
---|
| 95 | wm->Push(new Event(activate_id, NULL)); |
---|
[124] | 96 | |
---|
[644] | 97 | screen->PutImage(cache.img((up && !active) ? u : |
---|
| 98 | (up && active) ? ua : |
---|
[650] | 99 | (!up && !active) ? d : da), vec2i(x1, y1)); |
---|
[2] | 100 | |
---|
[644] | 101 | if (act != active && active && activate_id != -1) |
---|
| 102 | wm->Push(new Event(activate_id, NULL)); |
---|
| 103 | act = active; |
---|
[124] | 104 | |
---|
[644] | 105 | if (active && key[0]) |
---|
| 106 | { |
---|
| 107 | int g=80; |
---|
[655] | 108 | screen->Bar(vec2i(0, 0), vec2i(144, 20), 0); |
---|
[644] | 109 | wm->font()->put_string(screen, 0, 0, symbol_str(key), |
---|
| 110 | color_table->Lookup(g>>3, g>>3, g>>3)); |
---|
| 111 | } |
---|
| 112 | else if (!active && key[0]) |
---|
| 113 | { |
---|
[655] | 114 | screen->Bar(vec2i(0, 0), vec2i(144, 20), 0); |
---|
[644] | 115 | } |
---|
[2] | 116 | } |
---|
| 117 | |
---|
| 118 | extern long S_BUTTON_PRESS_SND; |
---|
| 119 | extern int sfx_volume; |
---|
| 120 | |
---|
[643] | 121 | void ico_button::handle_event(Event &ev, image *screen, InputManager *im) |
---|
[2] | 122 | { |
---|
| 123 | if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON && |
---|
| 124 | ev.mouse_button)) |
---|
| 125 | { |
---|
| 126 | int x1,y1,x2,y2; |
---|
[106] | 127 | area(x1,y1,x2,y2); |
---|
[2] | 128 | up=!up; |
---|
[106] | 129 | draw(act,screen); |
---|
[643] | 130 | wm->Push(new Event(id,(char *)this)); |
---|
[2] | 131 | if (S_BUTTON_PRESS_SND) |
---|
[123] | 132 | cache.sfx(S_BUTTON_PRESS_SND)->play(sfx_volume); |
---|
[2] | 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
[106] | 136 | void ico_button::area(int &x1, int &y1, int &x2, int &y2) |
---|
[2] | 137 | { |
---|
[659] | 138 | x1=m_pos.x; y1=m_pos.y; |
---|
| 139 | x2=m_pos.x+cache.img(u)->Size().x-1; |
---|
| 140 | y2=m_pos.y+cache.img(u)->Size().y-1; |
---|
[2] | 141 | } |
---|
| 142 | |
---|
[39] | 143 | 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] | 144 | { |
---|
| 145 | if (help_key) |
---|
| 146 | { |
---|
| 147 | strncpy(key,help_key,15); |
---|
| 148 | key[15]=0; |
---|
| 149 | } |
---|
| 150 | else key[0]=0; |
---|
| 151 | |
---|
| 152 | up=1; |
---|
[659] | 153 | m_pos = vec2i(X, Y); id=ID; |
---|
[2] | 154 | u=Up; d=down; |
---|
| 155 | ua=upa; da=downa; |
---|
| 156 | next=Next; |
---|
| 157 | activate_id=act_id; |
---|
[67] | 158 | act = 0; |
---|
[2] | 159 | } |
---|
| 160 | |
---|
| 161 | ico_switch_button::~ico_switch_button() |
---|
| 162 | { |
---|
| 163 | while (blist) |
---|
| 164 | { |
---|
| 165 | ifield *i=blist; |
---|
| 166 | blist=blist->next; |
---|
| 167 | delete i; |
---|
| 168 | } |
---|
| 169 | } |
---|