+ if (*src_text_ptr != ' ')
+ *dst_text_ptr++ = *src_text_ptr;
+
+ src_text_ptr++;
+ }
+
+ *dst_text_ptr = '\0';
+
+ text_final = text_door_style;
+ }
+
+ setRequestPosition(&sx, &sy, FALSE);
+
+ ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ for (y = 0; y < y_steps; y++)
+ for (x = 0; x < x_steps; x++)
+ DrawEnvelopeBackgroundTiles(graphic, sx, sy,
+ x, y, x_steps, y_steps,
+ tile_size, tile_size);
+
+ /* force DOOR font inside door area */
+ game_status = GAME_MODE_PSEUDO_DOOR;
+
+ DrawTextBuffer(sx + sx_offset, sy + sy_offset, text_final, font_nr,
+ line_length, -1, max_lines, line_spacing, mask_mode,
+ request.autowrap, request.centered, FALSE);
+
+ game_status = last_game_status; /* restore current game status */
+
+ for (i = 0; i < NUM_TOOL_BUTTONS; i++)
+ RedrawGadget(tool_gadget[i]);
+
+ // store readily prepared envelope request for later use when animating
+ BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+
+ if (text_door_style)
+ free(text_door_style);
+}
+
+void AnimateEnvelopeRequest(int anim_mode, int action)
+{
+ int graphic = IMG_BACKGROUND_REQUEST;
+ boolean draw_masked = graphic_info[graphic].draw_masked;
+ int delay_value_normal = request.step_delay;
+ int delay_value_fast = delay_value_normal / 2;
+ boolean ffwd_delay = (tape.playing && tape.fast_forward);
+ boolean no_delay = (tape.warp_forward);
+ int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
+ int anim_delay_value = (no_delay ? 0 : delay_value + 500 * 0) / 2;
+ unsigned int anim_delay = 0;
+
+ int tile_size = MAX(request.step_offset, 1);
+ int max_xsize = request.width / tile_size;
+ int max_ysize = request.height / tile_size;
+ int max_xsize_inner = max_xsize - 2;
+ int max_ysize_inner = max_ysize - 2;
+
+ int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize_inner : 0);
+ int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize_inner : 0);
+ int xend = max_xsize_inner;
+ int yend = (anim_mode != ANIM_DEFAULT ? max_ysize_inner : 0);
+ int xstep = (xstart < xend ? 1 : 0);
+ int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
+ int start = 0;
+ int end = MAX(xend - xstart, yend - ystart);
+ int i;
+
+ if (setup.quick_doors)
+ {
+ xstart = xend;
+ ystart = yend;
+ end = 0;
+ }
+ else
+ {
+ if (action == ACTION_OPENING)
+ PlayMenuSoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE);
+ else if (action == ACTION_CLOSING)
+ PlayMenuSoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE);
+ }
+
+ for (i = start; i <= end; i++)
+ {
+ int last_frame = end; // last frame of this "for" loop
+ int x = xstart + i * xstep;
+ int y = ystart + i * ystep;
+ int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
+ int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
+ int xsize_size_left = (xsize - 1) * tile_size;
+ int ysize_size_top = (ysize - 1) * tile_size;
+ int max_xsize_pos = (max_xsize - 1) * tile_size;
+ int max_ysize_pos = (max_ysize - 1) * tile_size;
+ int width = xsize * tile_size;
+ int height = ysize * tile_size;
+ int src_x, src_y;
+ int dst_x, dst_y;
+ int xx, yy;
+
+ setRequestPosition(&src_x, &src_y, FALSE);
+ setRequestPositionExt(&dst_x, &dst_y, width, height, FALSE);
+
+ BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+
+ for (yy = 0; yy < 2; yy++)
+ {
+ for (xx = 0; xx < 2; xx++)
+ {
+ int src_xx = src_x + xx * max_xsize_pos;
+ int src_yy = src_y + yy * max_ysize_pos;
+ int dst_xx = dst_x + xx * xsize_size_left;
+ int dst_yy = dst_y + yy * ysize_size_top;
+ int xx_size = (xx ? tile_size : xsize_size_left);
+ int yy_size = (yy ? tile_size : ysize_size_top);
+
+ if (draw_masked)
+ BlitBitmapMasked(bitmap_db_cross, backbuffer,
+ src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
+ else
+ BlitBitmap(bitmap_db_cross, backbuffer,
+ src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
+ }
+ }
+
+ redraw_mask |= REDRAW_FIELD;
+
+ DoAnimation();
+ BackToFront();
+
+ SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
+ }
+}
+
+void ShowEnvelopeRequest(char *text, unsigned int req_state, int action)
+{
+ int graphic = IMG_BACKGROUND_REQUEST;
+ int sound_opening = SND_REQUEST_OPENING;
+ int sound_closing = SND_REQUEST_CLOSING;
+ int anim_mode_1 = request.anim_mode; /* (higher priority) */
+ int anim_mode_2 = graphic_info[graphic].anim_mode; /* (lower priority) */
+ int anim_mode = (anim_mode_1 != ANIM_DEFAULT ? anim_mode_1 : anim_mode_2);
+ int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
+ anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
+
+ if (game_status == GAME_MODE_PLAYING)
+ BlitScreenToBitmap(backbuffer);
+
+ SetDrawtoField(DRAW_BACKBUFFER);
+
+ // SetDrawBackgroundMask(REDRAW_NONE);
+
+ if (action == ACTION_OPENING)
+ {
+ BlitBitmap(backbuffer, bitmap_db_store, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+
+ if (req_state & REQ_ASK)
+ {
+ MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
+ MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
+ }
+ else if (req_state & REQ_CONFIRM)
+ {
+ MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
+ }
+ else if (req_state & REQ_PLAYER)
+ {
+ MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
+ MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
+ MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
+ MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
+ }
+
+ DrawEnvelopeRequest(text);
+
+ if (game_status != GAME_MODE_MAIN)
+ InitAnimation();
+ }
+
+ game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */
+
+ if (action == ACTION_OPENING)
+ {
+ PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
+
+ if (anim_mode == ANIM_DEFAULT)
+ AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_OPENING);
+
+ AnimateEnvelopeRequest(main_anim_mode, ACTION_OPENING);
+ }
+ else
+ {
+ PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
+
+ if (anim_mode != ANIM_NONE)
+ AnimateEnvelopeRequest(main_anim_mode, ACTION_CLOSING);
+
+ if (anim_mode == ANIM_DEFAULT)
+ AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_CLOSING);
+ }
+
+ game.envelope_active = FALSE;
+
+ if (action == ACTION_CLOSING)
+ {
+ if (game_status != GAME_MODE_MAIN)
+ StopAnimation();
+
+ BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ }
+
+ // SetDrawBackgroundMask(last_draw_background_mask);
+
+ redraw_mask |= REDRAW_FIELD;
+
+ if (game_status == GAME_MODE_MAIN)
+ DoAnimation();
+
+ BackToFront();
+
+ if (action == ACTION_CLOSING &&
+ game_status == GAME_MODE_PLAYING &&
+ level.game_engine_type == GAME_ENGINE_TYPE_RND)
+ SetDrawtoField(DRAW_FIELDBUFFER);