void Animation::drawFrame(BITMAP *dest, int frame, int x, int y, bool hflip, bool vflip)
{
	BITMAP *src = getFrame(frame);

	if (hflip && vflip) {
		draw_sprite_vh_flip(dest, src, x, y);
	} else if (hflip && !vflip) {
		draw_sprite_h_flip(dest, src, x, y);
	} else if (!hflip && vflip) {
		draw_sprite_v_flip(dest, src, x, y);
	} else {
		draw_sprite(dest, src, x, y);
	}
	return;
}
void Bitmap::FlipBlt(Bitmap *src, int dst_x, int dst_y, BitmapFlip flip)
{	
	BITMAP *al_src_bmp = src->_alBitmap;
	if (flip == kBitmap_HFlip)
	{
		draw_sprite_h_flip(_alBitmap, al_src_bmp, dst_x, dst_y);
	}
	else if (flip == kBitmap_VFlip)
	{
		draw_sprite_v_flip(_alBitmap, al_src_bmp, dst_x, dst_y);
	}
	else if (flip == kBitmap_HVFlip)
	{
		draw_sprite_vh_flip(_alBitmap, al_src_bmp, dst_x, dst_y);
	}
}
Exemple #3
0
BITMAP* generate_bg(BITMAP *img, unsigned char r, unsigned char g, unsigned char b)
{
    bg_r = r;
    bg_g = g;
    bg_b = b;
    
    BITMAP *bg2 = create_bitmap(img->w*2, img->h*2);
    BITMAP *bg = create_bitmap(img->w*2, img->h*2);
    draw_sprite(bg, img, 0,0);
    draw_sprite_h_flip(bg, img, img->w,0);
    draw_sprite_v_flip(bg, img, 0,img->h);
    draw_sprite_vh_flip(bg, img, img->w,img->h);
    
    set_trans_blender(r,g,b,255);
    draw_lit_sprite(bg2, bg, 0,0, 96);

	destroy_bitmap(bg);
    
    return bg2;
}
Exemple #4
0
void apply_texture_to_map(BITMAP *tex)
{
	int tw = tex->w;
	int th = tex->h;
    int nw = (level->w / tw)+1;
    int nh = (level->h / th)+1;
	    
    // Copy texture across map
	for(int y=0; y < nh; y++)
    {
        for(int x=0; x < nw; x++)
        {
            if(x % 2 == 1 && y % 2 == 1)
                draw_sprite_vh_flip(level, tex, x*tex->w,y*tex->h);
            else if(x % 2 == 1)
                draw_sprite_h_flip(level, tex, x*tex->w,y*tex->h);
            else if(y % 2 == 1)
                draw_sprite_v_flip(level, tex, x*tex->w,y*tex->h);
            else
                draw_sprite(level, tex, x*tex->w,y*tex->h);
        }
    }
}
Exemple #5
0
// See also: Inventory::draw(), Soldier::draw_inventory()
// Called by: Connect::do_planner() via Units::execute and execute_main()
void Editor::show()
{
    reset_video();
    destroy_bitmap(screen2);
    screen2 = create_bitmap(640, 400); 
    clear(screen2);

    // Prepare background picture for editor screen to improve 
    // performance a bit (static image that is never changed)
    BITMAP *editor_bg = create_bitmap(640, 400);
    clear_to_color(editor_bg, COLOR_BLACK1);
    SPK *tac01 = new SPK("$(xcom)/ufograph/tac01.scr");  // Picture with buttons
    tac01->show(editor_bg, 0, 0); // draw buttons: OK, Next-Man, Prev-Man, Unload-clip, Scroll-right
    delete tac01;
    BITMAP *b5 = create_bitmap(32, 15); clear(b5);  // Button for Scroll-left
    blit(editor_bg, b5, 288, 137, 0, 0, 32, 15);
    draw_sprite_vh_flip(editor_bg, b5, 255, 137); // Button: Scroll-left
    destroy_bitmap(b5);
    rectfill(editor_bg, 288, 32, 319, 57, COLOR_GRAY15);    //hide unused "unload" button
    text_mode(-1);
    textout(editor_bg, g_small_font, _("Click-and-drop weapons from the armory to the soldier, right-click to remove"), 0, 364 + 22, COLOR_WHITE); 

    position_mouse(320, 200);
    MouseRange temp_mouse_range(0, 0, 639, 400);

    int DONE = 0;
    int mouse_leftr = 1, mouse_rightr = 1;
    int i;
    int color = COLOR_LT_OLIVE;
    int A1 = 0, A2 = 0;

    while (mouse_b & 3) rest(1);

    g_console->resize(SCREEN_W, SCREEN_H - 400);
    g_console->set_full_redraw();
    g_console->redraw(screen, 0, 400);

    while (!DONE) {

        net->check();

        rest(1); // Don't eat all CPU resources

        if (CHANGE) {
            g_console->redraw(screen, 0, 400);

            blit(editor_bg, screen2, 0, 0, 0, 0, editor_bg->w, editor_bg->h);
            man->showspk(screen2); // Show "bigpicture" of soldier in choosen armor

            color = COLOR_DK_GRAY;
            if (man->x != 0)   // ??? This soldier already selected for the mission ?
                color = COLOR_LT_OLIVE;
            text_mode(-1);
            textout(screen2, large, man->md.Name, 0, 0, color);

            for (i = 0; i < NUMBER_OF_PLACES; i++) //man->drawgrid();
                man->place(i)->drawgrid(screen2, i);
            m_armoury->drawgrid(screen2, P_ARMOURY);

            man->draw_unibord(1, 320, 0);  // Attribute-Barchart
            if (sel_item != NULL) {
                if (sel_item_place == P_ARMOURY)
                    sel_item->od_info(330, 235, COLOR_WHITE);
                else
                    sel_item->od_info(330, 235, COLOR_OLIVE);

                textprintf(screen2, g_small_font, 128, 140, COLOR_GREEN,  "%s", sel_item->name().c_str());

                if (sel_item->haveclip()) {
                    //textprintf(screen2, font, 272, 80, color, "%d", sel_item->roundsremain());
                    textout(screen2, g_small_font, _("AMMO:"),  272, 64, COLOR_LT_OLIVE);
                    textout(screen2, g_small_font, _("ROUNDS"), 272, 72, COLOR_LT_OLIVE);
                    textout(screen2, g_small_font, _("LEFT="),  272, 80, COLOR_LT_OLIVE);
                    textprintf(screen2, g_small_font,           299, 80, COLOR_ORANGE, "%d", sel_item->roundsremain());
                    rect(screen2, 272, 88, 303, 135, COLOR_DK_GRAY);      //clip
                    PCK::showpck(sel_item->clip()->obdata_pInv(), 272, 88 + 8);
                } else if (sel_item->obdata_isAmmo()) {
                    //textprintf(screen2, font, 272, 80, color, "%d", sel_item->rounds);
                    textout(screen2, g_small_font, _("AMMO:"),  272, 64, COLOR_LT_OLIVE);
                    textout(screen2, g_small_font, _("ROUNDS"), 272, 72, COLOR_LT_OLIVE);
                    textout(screen2, g_small_font, _("LEFT="),  272, 80, COLOR_LT_OLIVE);
                    textprintf(screen2, g_small_font,           299, 80, COLOR_ORANGE, "%d", sel_item->m_rounds);
                    rect(screen2, 272, 88, 303, 135, COLOR_DK_GRAY);      //clip
                    PCK::showpck(sel_item->obdata_pInv(), 272, 88 + 8);
                }
                PCK::showpck(sel_item->obdata_pInv(),
                                mouse_x - sel_item->obdata_width()  * 16 / 2,
                                mouse_y - sel_item->obdata_height() * 16 / 2 + 8);
            } else {
                Item *it = m_armoury->item_under_mouse(0, 0);
                if (it != NULL) {
                    if (is_item_allowed(it->m_type))
                        it->od_info(330, 235, COLOR_GRAY05);
                    else
                        it->od_info(330, 235, COLOR_GRAY10);
                } else {
                    //textprintf(screen2, large, 330, 220, COLOR_LT_BLUE, _("Click here to change equipment set"));
                    int ty = 235;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("       F1: Help")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("    F2/F3: Save/load team")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("       F4: Edit soldier attributes")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("       F5: Change weaponset")); ty += 15;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("       F6: Save as weapon set template")); ty += 15;

                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _(" Ctrl+Ins: Copy current soldier")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("Shift+Ins: Paste on current soldier")); ty += 15;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("      Del: Delete items of current man")); /*ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("Shift+Del: Drop items of current man"));*/ ty += 15;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("      F11: Cycle through appearences")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("      F12: Cycle through human armours")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("Shift+F12: Cycle through alien races")); ty += 15;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("      Tab: Next soldier")); ty += 10;
                    textprintf(screen2, font,  330, ty, COLOR_BLUE,     _("Shift+Tab: Previous soldier")); ty += 10;
                }
            }

            int wht = man->count_weight();
            int max_wht = man->md.Strength;
            color       = max_wht < wht ? COLOR_RED03 : COLOR_GRAY02;
            textprintf(screen2, g_small_font, 0, 20, color, _("Equipment weight: %2d/%2d"), wht, max_wht);
            char str1[64]; // to adjust position of translated string
          //int x1 = 120;
            int x2 = 236;
            sprintf(str1, "%s: %4d", _("Soldier cost"), man->calc_full_ammunition_cost() );
            int w1 = text_length(g_small_font, str1);  // right-justify string
            textprintf(screen2, g_small_font, x2-w1, 20, COLOR_GRAY02, "%s", str1);

            draw_alpha_sprite(screen2, mouser, mouse_x, mouse_y);
            blit(screen2, screen, 0, 0, 0, 0, screen2->w, screen2->h);
            CHANGE = 0;
        }

        if ((mouse_b & 1) && (mouse_leftr)) { //left mouseclick
            mouse_leftr = 0;
            CHANGE = 1;

            if (handle_mouse_leftclick())
                DONE = 1;
        }

        if ((mouse_b & 2) && (mouse_rightr)) { //right mouseclick: get & put items
            mouse_rightr = 0;
            CHANGE = 1;
            if (sel_item != NULL) {
                if (sel_item_place == P_ARMOURY) {
                    // If item was taken from the armoury - just delete it
                    delete sel_item;
                    sel_item = NULL;
                } else {
                    // If item was taken from the the soldier - put it back
                    man->putitem(sel_item, sel_item_place, sel_item->m_x, sel_item->m_y);
                    sel_item = NULL;
                }
            } else {
                // Delete item under mouse cursor
                for (i = 0; i < NUMBER_OF_PLACES; i++) {
                    Item *it = man->place(i)->mselect(0, 0);
                    if (it != NULL) delete(it);
                }
            }
        }

        if (!(mouse_b & 1)) {
            mouse_leftr = 1;
        }

        if (!(mouse_b & 2)) {
            mouse_rightr = 1;
        }

        if (keypressed()) {
            CHANGE = 1;
          //int c = readkey();
          //switch (c >> 8) {
            int scancode; int keycode = ureadkey(&scancode); 
            switch (scancode) { 
                case KEY_F1:
                    help( HELP_INVENTORY );
                    break;
                // Todo: Change from "Save&Load Team" to "Save&Load Soldier" 
                // Todo: move "Save&Load Team" to Mission-planner (connect.cpp)
                case KEY_F2:
                    //if (askmenu("SAVE DATA")) {
                    save();
                    //}
                    break;
                case KEY_F3:
                    //if (askmenu("LOAD DATA")) {
                    load();
                    //}
                    break;
                case KEY_F4:
                    edit_soldier();   // Edit Attributes+Armor
                    break;

                case KEY_F5:
                    change_equipment();
                    break;

                case KEY_F6:
                    export_weaponset();
                    break;

                case KEY_F10:
                    change_screen_mode();
                    break;

                case KEY_F11:  // cycle thru apperances:
                    A1 = man->md.Appearance;
                    A2 = man->md.fFemale;
                    if ((key[KEY_LSHIFT]) || (key[KEY_RSHIFT]) ) { // Shift-F11: 
                        A2++;
                        if (A2 >= 2) A2 = 0;
                        man->md.fFemale    = A2;
                    } else { // F11: 
                        A1 = A1 + (A2 ? 4 : 0);
                        A1++;
                        if (A1 >= 8) A1 = 0;
                        man->md.fFemale    = A1 >= 4;
                        man->md.Appearance = A1 % 4;
                    }
                    man->process_MANDATA();
                    break;
                case KEY_F12:  // cycle thru armor-types:
                    A1 = man->md.SkinType;
                    if ((key[KEY_LSHIFT]) || (key[KEY_RSHIFT]) ) // Shift-F12: Aliens
                        man->skin()->next_alien();
                    else // F12: Human Armor
                        man->skin()->next_human();
                    man->process_MANDATA();
                    break;
//
                case KEY_INSERT:  // Todo: Copy items from last DEL to current man
                    if ((key[KEY_LCONTROL]) || (key[KEY_RCONTROL])) {
                        copy_soldier(man);
                        break;
                    }
                    if ((key[KEY_LSHIFT]) || (key[KEY_RSHIFT])) {
                        paste_soldier(man);
                        break;
                    }
                    break;
                case KEY_DEL:  // Todo: store the deleted items (where?) for KEY_INSERT
                    if ((key[KEY_LSHIFT]) || (key[KEY_RSHIFT]) ) { // Shift-DEL:
                      // Drop all carried items:   // Todo: drop to common pool
                        Item * it;
                        for (int i = 0; i < NUMBER_OF_CARRIED_PLACES; i++) {
                            it = man->item(i);
                            if (it != NULL)
                                man->putitem(it, P_MAP);
                        }
                    } else { // DEL:
                        // Destroy items of current man, including those on the ground:
                        man->destroy_all_items();
                    }
                    break;

                case KEY_TAB:   // jump to next/prev. soldier
                    if ((key[KEY_LSHIFT]) || (key[KEY_RSHIFT]) ) { // Shift-TAB:
                        man = man->prevman();
                    } else { // TAB:
                        man = man->nextman();
                    }
                    break;
                case KEY_LEFT:
                    man = man->prevman();
                    break;
                case KEY_RIGHT:
                    man = man->nextman();
                    break;     

                 case KEY_PGUP:
                    scroll_equipment(-1);
                    break;
                 case KEY_PGDN:
                    scroll_equipment(+1);
                    break;
                case KEY_PRTSCR:
                    if (askmenu(_("SCREEN-SNAPSHOT"))) {
                        savescreen();
                    }
                    break;
                case KEY_ESC:
                    DONE = 1;
                    break;
                default: 
                    if (g_console->process_keyboard_input(keycode, scancode))
                        net->send_message((char *)g_console->get_text());
            }
        }
    }

    m_plt->save_FULLDATA("$(home)/squad.lua");

    destroy_bitmap(editor_bg);
    destroy_bitmap(screen2);
    screen2 = create_bitmap(SCREEN2W, SCREEN2H); clear(screen2);

    g_console->resize(SCREEN_W, SCREEN_H - SCREEN2H);
    g_console->set_full_redraw();

    clear(screen);
}