1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This software was released into the Public Domain. As with most public |
---|
7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include "common.h" |
---|
16 | |
---|
17 | #include "devsel.h" |
---|
18 | #include "scroller.h" |
---|
19 | #include "cache.h" |
---|
20 | #include "game.h" |
---|
21 | |
---|
22 | void scale_put(image *im, image *screen, int x, int y, short new_width, short new_height); |
---|
23 | void scale_put_trans(image *im, image *screen, int x, int y, short new_width, short new_height); |
---|
24 | int cur_bg=0,cur_fg=0,cur_char=0; |
---|
25 | |
---|
26 | void tile_picker::recenter(image *screen) |
---|
27 | { |
---|
28 | set_x(get_current(), screen); |
---|
29 | } |
---|
30 | |
---|
31 | int tile_picker::picw() |
---|
32 | { |
---|
33 | switch (type) |
---|
34 | { |
---|
35 | case SPEC_FORETILE : |
---|
36 | { |
---|
37 | return cache.foret(foretiles[0])->im->Size().x/scale; |
---|
38 | } break; |
---|
39 | case SPEC_BACKTILE : |
---|
40 | { |
---|
41 | return cache.backt(backtiles[0])->im->Size().x/scale; |
---|
42 | } break; |
---|
43 | default : |
---|
44 | return 30/scale; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | int tile_picker::pich() |
---|
49 | { |
---|
50 | switch (type) |
---|
51 | { |
---|
52 | case SPEC_FORETILE : |
---|
53 | { |
---|
54 | return cache.foret(foretiles[0])->im->Size().y/scale; |
---|
55 | } break; |
---|
56 | case SPEC_BACKTILE : |
---|
57 | { |
---|
58 | return cache.backt(backtiles[0])->im->Size().y/scale; |
---|
59 | } break; |
---|
60 | default : |
---|
61 | return 40/scale; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | int tile_picker::total() |
---|
66 | { |
---|
67 | switch (type) |
---|
68 | { |
---|
69 | case SPEC_FORETILE : |
---|
70 | { return nforetiles; } break; |
---|
71 | case SPEC_BACKTILE : |
---|
72 | { return nbacktiles; } break; |
---|
73 | case SPEC_CHARACTER : |
---|
74 | { return total_objects; } break; |
---|
75 | } |
---|
76 | return 1; |
---|
77 | } |
---|
78 | |
---|
79 | tile_picker::tile_picker(int X, int Y, int ID, int spec_type, |
---|
80 | int Scale, int scroll_h, int Wid, ifield *Next) |
---|
81 | : scroller(X,Y,ID,2,2,1,0,Next) |
---|
82 | { |
---|
83 | wid=Wid; |
---|
84 | type=spec_type; |
---|
85 | th=scroll_h; |
---|
86 | scale=Scale; |
---|
87 | set_size(picw()*wid,pich()*th); |
---|
88 | sx=get_current(); |
---|
89 | t=total(); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | void tile_picker::scroll_event(int newx, image *screen) |
---|
94 | { |
---|
95 | int yo=y,ya=pich(),xw=picw(),c=get_current(),xo; |
---|
96 | image im(vec2i(xw, ya)); |
---|
97 | last_sel=newx; |
---|
98 | |
---|
99 | screen->bar(x,y,x+l-1,y+h-1,wm->black()); |
---|
100 | for (int i=newx; i<newx+th*wid; i++) |
---|
101 | { |
---|
102 | xo=x+((i-newx)%wid)*xw; |
---|
103 | yo=y+((i-newx)/wid)*ya; |
---|
104 | |
---|
105 | int blank=0; |
---|
106 | if (i<t) |
---|
107 | { |
---|
108 | switch (type) |
---|
109 | { |
---|
110 | case SPEC_FORETILE : |
---|
111 | { |
---|
112 | if (foretiles[i]<0) blank=1; |
---|
113 | else |
---|
114 | { |
---|
115 | im.clear(); |
---|
116 | the_game->get_fg(i)->im->PutImage(&im,vec2i(0,0)); |
---|
117 | |
---|
118 | if (rev) |
---|
119 | { |
---|
120 | screen->bar(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color()); |
---|
121 | scale_put_trans(&im,screen,xo,yo,xw,ya); |
---|
122 | } |
---|
123 | else scale_put(&im,screen,xo,yo,xw,ya); |
---|
124 | } |
---|
125 | } break; |
---|
126 | case SPEC_BACKTILE : |
---|
127 | { |
---|
128 | if (backtiles[i]<0) blank=1; |
---|
129 | else |
---|
130 | scale_put(the_game->get_bg(i)->im,screen,xo,yo,xw,ya); |
---|
131 | |
---|
132 | } break; |
---|
133 | case SPEC_CHARACTER : |
---|
134 | { |
---|
135 | figures[i]->get_sequence(stopped)->get_figure(0)->forward->PutImage(&im,vec2i(0,0)); |
---|
136 | scale_put(&im,screen,xo,yo,xw,ya); |
---|
137 | } break; |
---|
138 | } |
---|
139 | } else blank=1; |
---|
140 | |
---|
141 | if (i==c) |
---|
142 | screen->rectangle(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color()); |
---|
143 | |
---|
144 | |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | void tile_picker::handle_inside_event(Event &ev, image *screen, InputManager *inm) |
---|
150 | { |
---|
151 | if (ev.type==EV_MOUSE_BUTTON) |
---|
152 | { |
---|
153 | int sel=((ev.mouse_move.y-y)/pich()*wid)+(ev.mouse_move.x-x)/picw()+last_sel; |
---|
154 | if (sel<t && sel>=0 && sel!=get_current()) |
---|
155 | { |
---|
156 | set_current(sel); |
---|
157 | scroll_event(last_sel, screen); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | int tile_picker::get_current() |
---|
166 | { |
---|
167 | switch (type) |
---|
168 | { |
---|
169 | case SPEC_FORETILE : |
---|
170 | { return cur_fg; } break; |
---|
171 | case SPEC_BACKTILE : |
---|
172 | { return cur_bg; } break; |
---|
173 | case SPEC_CHARACTER : |
---|
174 | { return cur_char; } break; |
---|
175 | } |
---|
176 | return 0; |
---|
177 | } |
---|
178 | |
---|
179 | void tile_picker::set_current(int x) |
---|
180 | { |
---|
181 | switch (type) |
---|
182 | { |
---|
183 | case SPEC_FORETILE : |
---|
184 | { cur_fg=x; } break; |
---|
185 | case SPEC_BACKTILE : |
---|
186 | { cur_bg=x; } break; |
---|
187 | case SPEC_CHARACTER : |
---|
188 | { cur_char=x; } break; |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|