[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 | |
---|
[39] | 15 | #include <math.h> |
---|
| 16 | |
---|
[512] | 17 | #include "common.h" |
---|
| 18 | |
---|
[481] | 19 | #include "game.h" |
---|
[88] | 20 | |
---|
[481] | 21 | #include "jwindow.h" |
---|
| 22 | #include "lisp.h" |
---|
| 23 | #include "scroller.h" |
---|
| 24 | #include "id.h" |
---|
| 25 | #include "cache.h" |
---|
| 26 | #include "dprint.h" |
---|
| 27 | #include "loader2.h" |
---|
[2] | 28 | |
---|
| 29 | extern int dev_ok; |
---|
[110] | 30 | palette *old_pal = NULL; |
---|
[2] | 31 | |
---|
| 32 | class gray_picker : public spicker |
---|
| 33 | { |
---|
| 34 | public: |
---|
[110] | 35 | int sc; |
---|
| 36 | virtual void draw_item(image *screen, int x, int y, int num, int active) |
---|
| 37 | { |
---|
| 38 | long x2 = x + item_width() - 1; |
---|
| 39 | long y2 = y + item_height() - 1; |
---|
[655] | 40 | screen->Bar(vec2i(x, y), vec2i(x2, y2), 0); |
---|
| 41 | screen->Bar(vec2i(x, y), vec2i(x2 - 3, y2), sc + num); |
---|
[110] | 42 | if(active) |
---|
| 43 | { |
---|
[655] | 44 | screen->Rectangle(vec2i(x, y), vec2i(x2, y2), 255); |
---|
[110] | 45 | } |
---|
| 46 | } |
---|
| 47 | void set_pos(int x) { cur_sel = x; } |
---|
| 48 | virtual int total() { return 32; } |
---|
| 49 | virtual int item_width() { return 12; } |
---|
| 50 | virtual int item_height() { return 20; } |
---|
| 51 | virtual int activate_on_mouse_move() { return 0; } |
---|
[2] | 52 | |
---|
[110] | 53 | gray_picker(int X, int Y, int ID, int start, int current, ifield *Next) : spicker(X, Y, ID, 1, 20, 0, 0, Next) |
---|
| 54 | { |
---|
| 55 | cur_sel = current; |
---|
| 56 | sc = start; |
---|
| 57 | reconfigure(); |
---|
| 58 | cur_sel=current; |
---|
| 59 | } |
---|
[2] | 60 | }; |
---|
| 61 | |
---|
[142] | 62 | static char const *lang_string(char const *symbol) |
---|
| 63 | { |
---|
[492] | 64 | LSymbol *v = LSymbol::Find(symbol); |
---|
[484] | 65 | if (!v || !DEFINEDP(v->GetValue())) |
---|
| 66 | return "Language symbol missing!"; |
---|
| 67 | return lstring_value(v->GetValue()); |
---|
[142] | 68 | } |
---|
[2] | 69 | |
---|
| 70 | void gamma_correct(palette *&pal, int force_menu) |
---|
| 71 | { |
---|
[110] | 72 | long dg=0,old_dg=0; |
---|
| 73 | int abort=0; |
---|
[2] | 74 | |
---|
[110] | 75 | // see if user has already done this routine |
---|
[492] | 76 | LSymbol *gs = LSymbol::Find("darkest_gray"); |
---|
[2] | 77 | |
---|
[110] | 78 | if(old_pal) |
---|
| 79 | { |
---|
| 80 | delete pal; |
---|
| 81 | pal = old_pal; |
---|
| 82 | old_pal = NULL; |
---|
| 83 | } |
---|
[2] | 84 | |
---|
[484] | 85 | if(gs && DEFINEDP(gs->GetValue()) && !force_menu) |
---|
[110] | 86 | { |
---|
[484] | 87 | dg = lnumber_value(gs->GetValue()); |
---|
[110] | 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
[484] | 91 | if(gs && DEFINEDP(gs->GetValue())) |
---|
[110] | 92 | { |
---|
[484] | 93 | dg = old_dg = lnumber_value(gs->GetValue()); |
---|
[110] | 94 | } |
---|
| 95 | // load in a fine gray palette they can chose from |
---|
| 96 | palette *gray_pal = pal->copy(); |
---|
| 97 | int i = 0; |
---|
| 98 | int tc = 32; |
---|
[2] | 99 | |
---|
[494] | 100 | for(; i < tc; i++) |
---|
[110] | 101 | { |
---|
| 102 | gray_pal->set(i, i * 4, i * 4, i * 4); |
---|
| 103 | } |
---|
[2] | 104 | |
---|
[110] | 105 | gray_pal->load(); |
---|
[2] | 106 | |
---|
[110] | 107 | int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color(); |
---|
[2] | 108 | |
---|
[110] | 109 | int br_r = pal->red(wm_bc) + 20; |
---|
| 110 | if(br_r > 255) |
---|
| 111 | br_r = 255; |
---|
| 112 | int br_g = pal->green(wm_bc) + 20; |
---|
| 113 | if(br_g > 255) |
---|
| 114 | br_g = 255; |
---|
| 115 | int br_b = pal->blue(wm_bc) + 20; |
---|
| 116 | if(br_b > 255) |
---|
| 117 | br_b = 255; |
---|
[2] | 118 | |
---|
[110] | 119 | int md_r = pal->red(wm_mc) - 20; |
---|
| 120 | if(md_r < 0) |
---|
| 121 | md_r = 0; |
---|
| 122 | int md_g = pal->green(wm_mc) - 20; |
---|
| 123 | if(md_g < 0) |
---|
| 124 | md_g = 0; |
---|
| 125 | int md_b = pal->blue(wm_mc) - 20; |
---|
| 126 | if(md_b < 0) |
---|
| 127 | md_b = 0; |
---|
[2] | 128 | |
---|
[110] | 129 | int dr_r = pal->red(wm_dc) - 40; |
---|
| 130 | if(dr_r < 0) |
---|
| 131 | dr_r = 0; |
---|
| 132 | int dr_g = pal->green(wm_dc) - 40; |
---|
| 133 | if(dr_g < 0) |
---|
| 134 | dr_g = 0; |
---|
| 135 | int dr_b = pal->blue(wm_dc) - 40; |
---|
| 136 | if(dr_b < 0) |
---|
| 137 | dr_b = 0; |
---|
[2] | 138 | |
---|
[110] | 139 | wm->set_colors(gray_pal->find_closest(br_r, br_g, br_b), |
---|
| 140 | gray_pal->find_closest(md_r, md_g, md_b), |
---|
| 141 | gray_pal->find_closest(dr_r, dr_g, dr_b)); |
---|
[2] | 142 | |
---|
[110] | 143 | int sh = wm->font()->height() + 35; |
---|
[123] | 144 | button *but = new button(5, 5 + sh * 3, ID_GAMMA_OK, cache.img(ok_button), |
---|
[111] | 145 | new info_field(35, 10 + sh * 3, ID_NULL, lang_string("gamma_msg"), 0)); |
---|
[2] | 146 | |
---|
[111] | 147 | gray_picker *gp = new gray_picker(2, 5 + sh, ID_GREEN_PICKER, 0, dg / 4, but); |
---|
[110] | 148 | gp->set_pos(dg / 4); |
---|
[2] | 149 | |
---|
[120] | 150 | Jwindow *gw = wm->new_window(xres / 2 - 190, yres / 2 - 90, -1, -1, gp); |
---|
[2] | 151 | |
---|
[643] | 152 | Event ev; |
---|
[110] | 153 | wm->flush_screen(); |
---|
[632] | 154 | #if !defined __CELLOS_LV2__ |
---|
[110] | 155 | do |
---|
| 156 | { |
---|
| 157 | do |
---|
| 158 | { |
---|
| 159 | wm->get_event(ev); |
---|
[646] | 160 | } while(ev.type == EV_MOUSE_MOVE && wm->IsPending()); |
---|
[110] | 161 | wm->flush_screen(); |
---|
| 162 | if(ev.type == EV_CLOSE_WINDOW) |
---|
| 163 | abort = 1; |
---|
| 164 | if(ev.type == EV_KEY && ev.key == JK_ESC) |
---|
| 165 | abort = 1; |
---|
| 166 | } while(!abort && (ev.type != EV_MESSAGE || ev.message.id != ID_GAMMA_OK)); |
---|
[2] | 167 | |
---|
[110] | 168 | dg = ((spicker *)gw->inm->get(ID_GREEN_PICKER))->first_selected() * 4; |
---|
[632] | 169 | #else |
---|
| 170 | /* Do not display the gamma window on the PS3 for now. */ |
---|
| 171 | #endif |
---|
[2] | 172 | |
---|
[110] | 173 | wm->close_window(gw); |
---|
| 174 | wm->flush_screen(); |
---|
[2] | 175 | |
---|
[110] | 176 | wm->set_colors(wm_bc, wm_mc, wm_dc); |
---|
| 177 | delete gray_pal; |
---|
[2] | 178 | |
---|
[110] | 179 | if(!abort) |
---|
| 180 | { |
---|
| 181 | char *gammapath; |
---|
| 182 | FILE *fp; |
---|
[2] | 183 | |
---|
[129] | 184 | gammapath = (char *)malloc(strlen(get_save_filename_prefix()) + 10); |
---|
[110] | 185 | sprintf(gammapath, "%sgamma.lsp", get_save_filename_prefix()); |
---|
| 186 | fp = open_FILE(gammapath, "wb"); |
---|
| 187 | if(fp) |
---|
| 188 | { |
---|
| 189 | fprintf(fp, "(setq darkest_gray %ld)\n", dg); |
---|
| 190 | fclose(fp); |
---|
[635] | 191 | LSpace *sp = LSpace::Current; |
---|
| 192 | LSpace::Current = &LSpace::Perm; |
---|
[492] | 193 | LSymbol::FindOrCreate("darkest_gray")->SetNumber(dg); |
---|
[2] | 194 | |
---|
[635] | 195 | LSpace::Current = sp; |
---|
[110] | 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | dprintf("Unable to write to file gamma.lsp\n"); |
---|
| 200 | } |
---|
[129] | 201 | free(gammapath); |
---|
[110] | 202 | } |
---|
| 203 | } |
---|
[2] | 204 | |
---|
[110] | 205 | if(abort) |
---|
| 206 | dg = old_dg; |
---|
[2] | 207 | |
---|
[110] | 208 | if(dg < 1) |
---|
| 209 | dg = 1; |
---|
| 210 | else if(dg > 128) |
---|
| 211 | dg = 128; |
---|
[2] | 212 | |
---|
[110] | 213 | double gamma = log(dg / 255.0) / log(16.0 / 255.0); |
---|
[2] | 214 | |
---|
[110] | 215 | old_pal = pal; |
---|
| 216 | pal = new palette; |
---|
| 217 | for(int i = 0; i < 256; i++) |
---|
| 218 | { |
---|
| 219 | uint8_t oldr, oldg, oldb; |
---|
| 220 | old_pal->get(i, oldr, oldg, oldb); |
---|
| 221 | pal->set(i, (int)(pow(oldr / 255.0, gamma) * 255), |
---|
| 222 | (int)(pow(oldg / 255.0, gamma) * 255), |
---|
| 223 | (int)(pow(oldb / 255.0, gamma) * 255)); |
---|
| 224 | } |
---|
[2] | 225 | |
---|
[110] | 226 | pal->load(); |
---|
[2] | 227 | } |
---|