Beispiel #1
0
static void wid_version_make_visible (void *context)
{
    wid_intro_ready = true;

    widp w = wid_popup(
                  "%%fg=green$Adventurine -- " VERSION,
                  "",               /* title */
                  0.9f, 0.95f,      /* x,y postition in percent */
                  0,                /* title font */
                  vsmall_font,      /* body font */
                  0,                /* button font */
                  0);               /* number args */
    wid_set_no_shape(w);
    wid_destroy_in(w, 10000);

    wid_move_end(w);
    wid_move_to_pct_centered(w, 0.9f, 0.95);

    wid_game_map_fini();
    game.level_no = 0;
    wid_game_map_init();

    if (!wid_change_level_timer) {
        wid_change_level_timer = action_timer_create(
            &wid_timers,
            (action_timer_callback)wid_change_level,
            (action_timer_destroy_callback)0,
            0, /* context */
            "change level",
            5000,
            0 /* jitter */);
    }
}
Beispiel #2
0
static void wid_intro_create (void)
{
    if (wid_intro) {
        return;
    }

    music_play_intro();

    wid_intro = wid_new_window("intro");

    wid_set_no_shape(wid_intro);

    fpoint tl = {0.0f, 0.0f};
    fpoint br = {1.0f, 1.0f};
    wid_set_tl_br_pct(wid_intro, tl, br);

    color col = BLACK;
    col.a = 0;
    glcolor(col);

    wid_set_mode(wid_intro, WID_MODE_NORMAL);
    wid_set_color(wid_intro, WID_COLOR_TL, col);
    wid_set_color(wid_intro, WID_COLOR_BR, col);
    wid_set_color(wid_intro, WID_COLOR_BG, col);

    wid_intro_bg_create();
    wid_update(wid_intro);

    wid_move_to_pct_centered(wid_intro, 0.5f, 0.5f);
    wid_fade_in(wid_intro_title, intro_effect_delay*2);

    wid_intro_menu_create();
}
/*
 * Replace or place a tile.
 */
widp
wid_game_map_client_replace_tile (widp w, 
                                  double x, double y, 
                                  thingp t,
                                  tpp tp)
{
    tree_rootp thing_tiles;
    const char *tilename;
    tilep tile;
    widp child;

    verify(w);

    /*
     * Grow tl and br to fit the template thing. Use the first tile.
     */
    if (!tp) {
        tp = thing_tp(t);
        if (!tp) {
            ERR("no thing template to replace on client");
            return (0);
        }
    }

    if ((x < 0) || (y < 0) || (x >= MAP_WIDTH) || (y >= MAP_WIDTH)) {
        LOG("client: thing template [%s] cannot be placed at %f %f",
            tp_short_name(tp), x, y);
        return (0);
    }

    thing_tiles = tp_get_tiles(tp);
    if (!thing_tiles) {
        ERR("thing template [%s] has no tiles", tp_short_name(tp));
        return (0);
    }

    thing_tilep thing_tile;

    /*
     * Get a random tile to start with.
     */
    thing_tile = (typeof(thing_tile)) thing_tile_random(thing_tiles);

    /*
     * Find the real tile that corresponds to this name.
     */
    tilename = thing_tile_name(thing_tile);
    tile = tile_find(tilename);

    if (!tile) {
        ERR("tile name %s from thing %s not found on client",
            tilename,
            tp_short_name(tp));
        return (0);
    }

    /*
     * Make a new thing.
     */
    child = wid_new_square_button(wid_game_map_client_grid_container,
                                  "client map tile");

    wid_set_mode(child, WID_MODE_NORMAL);
    wid_set_no_shape(child);

    /*
     * "paint" the thing.
     */
    wid_game_map_client_set_thing_template(child, tp);

    if (!t) {
        t = thing_client_local_new(tp);
    }

    wid_set_thing(child, t);
    wid_set_tile(child, tile);

    double dx = 0;
    double dy = 0;

    /*
     * Does it appear as a different size on screen?
     */
    double scale = tp_get_scale(tp);

    /*
     * So we have baby and bigger slimes. But alas this is visual only and has 
     * no effect on hp on the server yet.
     */
    if (thing_is_variable_size(t)) {
        scale += gaussrand(0.0, 0.05);
    }

    if (scale != 1.0) {
        wid_scaling_blit_to_pct_in(child, scale, scale, 500, 9999999);
    }

    if (thing_is_cloud_effect(t)) {
        /*
         * The epicenter needs to be where it was on the server as we do a 
         * flood fill to see where the rest of the explosion goes.
         */
        if (!t->is_epicenter) {
            dx = gaussrand(0.0, 0.5);
            dy = gaussrand(0.0, 0.5);
        }

        wid_fade_out(child, 1000);
    }

    thing_client_wid_update(t, x + dx, y + dy, false /* smooth */,
                            true /* is new */);

    /*
     * Offset tall things
     */
    if (scale != 1.0) {
        if (thing_is_blit_y_offset(t)) {
            wid_set_blit_y_offset(child, 
                                  wid_get_height(child) * scale * -((scale - 1.0) / 2.0));
        }
    }

    /*
     * If this is a pre-existing thing perhaps being recreated ona new level
     * then it will have a direction already. Update it.
     */
    if (thing_is_animated(t)) {
        thing_animate(t);
    }

    /*
     * This adds it to the grid wid.
     */
#ifdef DEBUG_CLIENT_THING
    wid_update(child);
    char name[20];
    sprintf(name, "%d",t->thing_id);
    wid_set_text(child,name);
#endif

    /*
     * We've been told about the epicenter of an explsion, now emulate the 
     * blast.
     */
    if (t->is_epicenter && thing_is_cloud_effect(t) ) {

        if ((tp->id == THING_EXPLOSION1)        ||
            (tp->id == THING_EXPLOSION2)        ||
            (tp->id == THING_EXPLOSION3)        ||
            (tp->id == THING_EXPLOSION4)        ||
            (tp->id == THING_SMALL_EXPLOSION1)  ||
            (tp->id == THING_SMALL_EXPLOSION2)  ||
            (tp->id == THING_SMALL_EXPLOSION3)  ||
            (tp->id == THING_SMALL_EXPLOSION4)  ||
            (tp->id == THING_MED_EXPLOSION1)    ||
            (tp->id == THING_MED_EXPLOSION2)    ||
            (tp->id == THING_MED_EXPLOSION3)    ||
            (tp->id == THING_MED_EXPLOSION4)    ||
            (tp->id == THING_FIREBURST1)        ||
            (tp->id == THING_FIREBURST2)        ||
            (tp->id == THING_FIREBURST3)        ||
            (tp->id == THING_FIREBURST4)        ||
            (tp->id == THING_BOMB)              ||
            (tp->id == THING_POISON1)           ||
            (tp->id == THING_POISON2)           ||
            (tp->id == THING_CLOUDKILL1)        ||
            (tp->id == THING_CLOUDKILL2)) {

            level_place_explosion(client_level,
                                  0, /* owner */
                                  tp,
                                  t->x, t->y,
                                  t->x, t->y);
        } else {
            ERR("unknown explosion %s", thing_logname(t));
        }
    }

    const char *sound = tp_sound_on_creation(tp);
    if (sound) {
        if (thing_is_cloud_effect(t)) {
            if (t->is_epicenter) {
                sound_play_at(sound, t->x, t->y);
            }
        } else {
            sound_play_at(sound, t->x, t->y);
        }
    }

    return (child);
}
/*
 * Create the wid_game_map_client
 */
void wid_game_map_client_wid_create (void)
{
    if (sdl_is_exiting()) {
        return;
    }

    if (wid_game_map_client_window) {
        return;
    }

    wid_notify_flush();

    LOG("Client: Create map");

    {
        fpoint tl = {0.0f, 0.0f};
        fpoint br = {1.0f, 1.0f};

        wid_game_map_client_window = 
                        wid_new_square_window("wid_game_map_client");
        wid_set_movable(wid_game_map_client_window, false);
        wid_set_do_not_raise(wid_game_map_client_window, true);
        wid_set_no_shape(wid_game_map_client_window);

        wid_set_mode(wid_game_map_client_window, WID_MODE_NORMAL);

        wid_set_text_advance(wid_game_map_client_window, 0.9f);
        wid_set_text_scaling(wid_game_map_client_window, 2.0f);
        wid_set_text_pos(wid_game_map_client_window, true, 0.5f, 0.10f);

        wid_set_text_bot(wid_game_map_client_window, true);
        wid_set_text_lhs(wid_game_map_client_window, true);
        wid_set_tl_br_pct(wid_game_map_client_window, tl, br);

        fsize sz = {0.0f, 0.0f};
        wid_set_tex_tl(wid_game_map_client_window, sz);

        fsize sz2 = {1.0f, 1.0f};
        wid_set_tex_br(wid_game_map_client_window, sz2);

        wid_set_on_key_down(wid_game_map_client_window, 
                            wid_game_map_key_event);
        wid_set_on_joy_down(wid_game_map_client_window, 
                            wid_game_map_joy_event);
    }

    {
        fpoint tl = {0.00f, 0.00f};
        fpoint br = {1.00f, 1.00f};

        wid_game_map_client_grid_container =
                        wid_new_container(wid_game_map_client_window,
                                          "wid game client grid container");

        wid_set_no_shape(wid_game_map_client_grid_container);

        wid_set_color(wid_game_map_client_grid_container, WID_COLOR_TL, BLACK);
        wid_set_color(wid_game_map_client_grid_container, WID_COLOR_BG, BLACK);
        wid_set_color(wid_game_map_client_grid_container, WID_COLOR_BR, BLACK);
        wid_set_on_mouse_motion(wid_game_map_client_grid_container,
                                wid_game_map_client_receive_mouse_motion);

        wid_set_tl_br_pct(wid_game_map_client_grid_container, tl, br);
        wid_set_tex(wid_game_map_client_grid_container, 0, 0);

        wid_set_on_key_down(wid_game_map_client_grid_container, 
                            wid_game_map_key_event);

        wid_set_on_joy_down(wid_game_map_client_grid_container, 
                            wid_game_map_joy_event);

        LOG("Client: Created map container window");
    }

    {
        double base_tile_width =
                ((1.0f / ((double)TILES_SCREEN_WIDTH)) *
                    (double)global_config.video_gl_width);

        double base_tile_height =
                ((1.0f / ((double)TILES_SCREEN_HEIGHT)) *
                    (double)global_config.video_gl_height);

        fpoint tl = { 0, 0 };
        fpoint br = { 0, 0 };

        br.x += base_tile_width;
        br.y += base_tile_height;

        client_tile_width = br.x - tl.x;
        client_tile_height = br.y - tl.y;
        client_tile_width = br.x - tl.x;
        client_tile_height = br.y - tl.y;

        if (!client_tile_width) {
            client_tile_width = TILE_WIDTH;
        }

        if (!client_tile_height) {
            client_tile_height = TILE_HEIGHT;
        }

        wid_new_grid(wid_game_map_client_grid_container,
                     MAP_WIDTH,
                     MAP_HEIGHT, client_tile_width, client_tile_height);

        LOG("Client: Created map container window grid");
    }

    /*
     * Mark that we want to learn the starting stats so we can use those
     * when starting again with this player type.
     */
    global_config.starting_stats_inited = false;

    level_pos_t level_pos = global_config.stats.level_pos;

    if (!level_pos.x && !level_pos.y) {
        level_pos.x = (myrand() % LEVEL_INITIAL_RANDOM) + 1;
        level_pos.y = 1;
    }

    client_level = level_new(wid_game_map_client_grid_container, 
                             level_pos, 
                             false /* is_editor */,
                             false /* is_map_editor */,
                             false /* on_server */);

    LOG("Client: Created level %d.%d", level_pos.y, level_pos.x);

    if (!client_level) {
        WARN("failed to load level %u.%u", level_pos.y, level_pos.x);
    }

    wid_game_map_client_vert_scroll =
        wid_new_vert_scroll_bar(wid_game_map_client_window,
                                wid_game_map_client_grid_container);
    wid_game_map_client_horiz_scroll =
        wid_new_horiz_scroll_bar(wid_game_map_client_window,
                                 wid_game_map_client_grid_container);

    wid_visible(wid_get_parent(wid_game_map_client_vert_scroll), 0);
    wid_visible(wid_get_parent(wid_game_map_client_horiz_scroll), 0);
    wid_visible(wid_game_map_client_vert_scroll, 0);
    wid_visible(wid_game_map_client_horiz_scroll, 0);

    wid_update(wid_game_map_client_vert_scroll);
    wid_update(wid_game_map_client_horiz_scroll);

    wid_game_map_client_score_update(client_level, true /* redo */);

    wid_hide(wid_game_map_client_window, 0);

    if (global_config.server_current_players > 1) {
        wid_visible(wid_chat_window, 0);
    }
}
void wid_game_map_client_score_update (levelp level, uint8_t redo)
{
    /*
     * Huge hack - we don't send ping/pong in single player mode, so
     * we don't get the level name.
     */
    if (single_player_mode) {
        level = server_level;
    }

    if (!player) {
        return;
    }

    if (player->stats.pclass[0]) {
        wid_player_action_hide(true /* fast */, false /* player quit */);
        wid_player_action_visible(&player->stats, true /* fast */);
    }

    if (redo) {
        if (wid_scoreline_container_top) {
            wid_destroy(&wid_scoreline_container_top);
        }
    }

    uint8_t update;

    if (wid_scoreline_container_top) {
        update = true;
    } else {
        update = false;
    }

    /*
     * Create the area for the scores at the top.
     */
    if (!update) {
        fpoint tl;
        fpoint br;

        tl.x = 0.7;
        tl.y = 0.0;
        br.x = 1.0;
        br.y = 1.0;

        wid_scoreline_container_top =
            wid_new_container(wid_game_map_client_window, "scoreline top");

        wid_set_no_shape(wid_scoreline_container_top);
        wid_set_tl_br_pct(wid_scoreline_container_top, tl, br);

        wid_set_color(wid_scoreline_container_top, WID_COLOR_TL, BLACK);
        wid_set_color(wid_scoreline_container_top, WID_COLOR_BG, BLACK);
        wid_set_color(wid_scoreline_container_top, WID_COLOR_BR, BLACK);
    }

    double score_x = 0.78;
    double cash_x = 0.88;
    double player_y_offset = 0.17; // player start y
    double next_player_y_delta = 0.1;
    double score_and_cash_title_offset = 0.025;
    double score_and_cash_value_offset = 0.055;

    /*
     * Print the score.
     */
    for (;;) {
        msg_player_state *p = client_get_player();

        /*
         * Experience
         */
        char tmp[20];
        snprintf(tmp, sizeof(tmp), "%05u", p->stats.xp);

        static widp wid_score_container;

        if (!update) {
            wid_set_no_shape(
                wid_textbox(wid_scoreline_container_top,
                            &wid_score, tmp,
                            score_x, player_y_offset, med_font));

            wid_score_container = wid_score;
        } else {
            wid_set_text(wid_score_container, tmp);
            wid_set_text_outline(wid_score_container, true);
        }

        /*
         * cash
         */
        snprintf(tmp, sizeof(tmp), "%05u", p->stats.cash);

        static widp wid_cash_container;

        if (!update) {
            wid_set_no_shape(
                wid_textbox(wid_scoreline_container_top,
                            &wid_cash, tmp,
                            cash_x, player_y_offset, med_font));

            wid_cash_container = wid_cash;
        } else {
            wid_set_text(wid_cash_container, tmp);
            wid_set_text_outline(wid_cash_container, true);
        }

        if (update) {
            break;
        }

        /*
         * Score title
         */
        widp wid_score_title_container;

        wid_score_title_container = wid_textbox(
                                    wid_scoreline_container_top,
                                    &wid_score_title,
                                    "XP", 
                                    score_x, player_y_offset - 
                                    score_and_cash_title_offset,
                                    med_font);

        wid_set_no_shape(wid_score_title_container);

        /*
         * cash title
         */
        widp wid_cash_title_container;

        wid_cash_title_container = wid_textbox(
                                    wid_scoreline_container_top,
                                    &wid_cash_title,
                                    "$$$",  
                                    cash_x, player_y_offset - 
                                    score_and_cash_title_offset,
                                    med_font);

        wid_set_no_shape(wid_cash_title_container);

        /*
         * Score title
         */
        widp wid_name_title_container;

        char *name_title;
        /*
         * Just print the name, don't need the class as well.
         */
        if (p->stats.pname[0]) {
            name_title = dynprintf("%%%%fg=cyan$%s", p->stats.pname);
        } else {
            name_title = 0;
        }

        wid_name_title_container = wid_textbox(
                                    wid_scoreline_container_top,
                                    &wid_name_title,
                                    name_title ? name_title : "No player",
                                    (score_x + cash_x) / 2,
                                    player_y_offset - 
                                    score_and_cash_value_offset,
                                    med_font);
        if (name_title) {
            myfree(name_title);
        }

        wid_set_no_shape(wid_name_title_container);

        wid_set_color(wid_score, WID_COLOR_TEXT, RED);
        wid_set_color(wid_cash, WID_COLOR_TEXT, GOLD);
        wid_set_color(wid_score_title, WID_COLOR_TEXT, RED);
        wid_set_color(wid_cash_title, WID_COLOR_TEXT, GOLD);

        player_y_offset += next_player_y_delta;

        break;
    }

    if (update) {
        if (global_config.server_current_players > 1) {
            wid_raise(wid_chat_window);
            wid_visible(wid_chat_window, 0);
        }
        return;
    }

    /*
     * Print the level title.
     */
    if (level_get_title(level) &&
        strcasecmp(level_get_title(level), "(null)")) {

        widp wid_level_container;

        wid_level_container = wid_textbox(wid_scoreline_container_top,
                                          &wid_level,
                                          level_get_title(level),
                                          (score_x + cash_x) / 2.0, 0.02, 
                                          med_font);

        wid_set_no_shape(wid_level_container);
        wid_set_color(wid_level, WID_COLOR_TEXT, WHITE);
    }

    /*
     * Print the level.
     */
    if (client_level) {
        level_pos_t level_pos = level_get_level_pos(client_level);

        char *tmp = 
            dynprintf("%%%%fg=green$Depth %d.%d", level_pos.y, level_pos.x);

        widp wid_level_container;

        wid_level_container = wid_textbox(wid_scoreline_container_top,
                                          &wid_level,
                                          tmp, 
                                          (score_x + cash_x) / 2.0, 0.05, 
                                          med_font);
        myfree(tmp);

        wid_set_no_shape(wid_level_container);
        wid_set_color(wid_level, WID_COLOR_TEXT, WHITE);
    }

    if (client_level) {
        uint32_t seed = level_get_seed(client_level);

        if (seed) {
            char *tmp = 
                dynprintf("%%%%fg=green$Level %u", seed);

            widp wid_level_container;

            wid_level_container = wid_textbox(wid_scoreline_container_top,
                                            &wid_level,
                                            tmp, 
                                            (score_x + cash_x) / 2.0, 0.08, 
                                            med_font);
            myfree(tmp);

            wid_set_no_shape(wid_level_container);
            wid_set_color(wid_level, WID_COLOR_TEXT, WHITE);
        }
    }

    wid_raise(wid_scoreline_container_top);
    wid_update(wid_scoreline_container_top);

    wid_update_mouse();

    wid_set_focus(wid_game_map_client_grid_container);

    if (global_config.server_current_players > 1) {
        wid_raise(wid_chat_window);
        wid_visible(wid_chat_window, 0);
    }
}
static void wid_intro_settings_create (void)
{
    wid_intro_settings_restart_needed = false;

    if (wid_intro_settings) {
        return;
    }

    widp w = wid_intro_settings = wid_new_rounded_window("wid settings");

    fpoint tl = {0.0, 0.0};
    fpoint br = {1.0, 1.0};

    wid_set_tl_br_pct(w, tl, br);
    wid_set_no_shape(w);

    char *keys[WID_INTRO_MAX_SETTINGS];
    char *values[WID_INTRO_MAX_SETTINGS];

    int i;
    for (i = WID_INTRO_SETTINGS_ROW_WINDOW; i < WID_INTRO_MAX_SETTINGS; i++) {
        keys[i] = dynprintf("%s",
                wid_intro_button_name[i]);
        values[i] = dynprintf("%s",
                wid_intro_button_value_string[i][wid_intro_button_val[i]]);
    }

    i = WID_INTRO_SETTINGS_ROW_WINDOW;
    wid_intro_menu = wid_menu(wid_intro_settings,
                vvlarge_font,
                large_font,
                0, // on_update
                0.5, /* x */
                0.6, /* y */
                2, /* columns */
                saved_focus, /* focus */
                WID_INTRO_MAX_SETTINGS + 1, /* items */

                /*
                 * Column widths
                 */
                (double) 0.3, (double) 0.2,

                (int) '1', 
                keys[i], 
                values[i], 
                wid_intro_settings_mouse_event,

                (int) '2', 
                keys[i + 1], 
                values[i + 1], 
                wid_intro_settings_mouse_event,

                (int) '3', 
                keys[i + 2], 
                values[i + 2], 
                wid_intro_settings_mouse_event,

                (int) '4', 
                keys[i + 3], 
                values[i + 3], 
                wid_intro_settings_mouse_event,

                (int) '5', 
                keys[i + 4], 
                values[i + 4], 
                wid_intro_settings_mouse_event,

                (int) 'b', 
                "Back", 
                (char*) 0,
                wid_intro_settings_back_mouse_event);

    for (i = WID_INTRO_SETTINGS_ROW_WINDOW; i < WID_INTRO_MAX_SETTINGS; i++) {
        myfree(keys[i]);
        myfree(values[i]);
    }

    wid_raise(wid_intro_settings);
    wid_update(wid_intro_settings);
}