Skip to content

Commit

Permalink
Implement animated unit picture in unit info screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nextghost committed Jun 1, 2020
1 parent 622d31f commit 2816a62
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 196 deletions.
8 changes: 4 additions & 4 deletions signus/src/graphio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ void DrawLitMap()

///////// Putbitmap:

void PutBitmap(int x, int y, void *data, int w, int h)
void PutBitmap(int x, int y, const void *data, int w, int h)
{
register int ay;
register byte *aptr = (byte*) data;
register const byte *aptr = (const byte*) data;
register byte *vid;

if (SomeoneDrawing()) return;
Expand Down Expand Up @@ -479,11 +479,11 @@ void DrawVideoFrame(const uint8_t *frame, unsigned width, unsigned height) {
// KoPirovani mezi bitmapami - to ani nema cenu psat v ASM, stejne se to
// skoro nepouziva...

void CopyBmp(void *tar, int tarwidth, int x, int y, void *src, int w, int h)
void CopyBmp(void *tar, int tarwidth, int x, int y, const void *src, int w, int h)
{
int i, j;
byte *tp = ((byte *)tar) + x + y * tarwidth;
byte *sp = (byte *)src;
const byte *sp = (const byte *)src;
int dif = tarwidth - w;

for (i = 0; i < h; i++) {
Expand Down
4 changes: 2 additions & 2 deletions signus/src/graphio.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern void PutCurBack(void *src, int x, int y, int sx, int sy, int fromx, int f


// Kopirovani bmp do bmp:
extern void CopyBmp(void *tar, int tarwidth, int x, int y, void *src, int w, int h);
extern void CopyBmp(void *tar, int tarwidth, int x, int y, const void *src, int w, int h);
extern void CopyBmpNZ(void *tar, int tarwidth, int x, int y, void *src, int w, int h);
extern void CopyFromBmp(void *src, int srcwidth, int x, int y, void *tar, int w, int h);
// Kresleni do bitmapy:
Expand All @@ -109,7 +109,7 @@ extern void RectBmp(void *tar, int tarwidth, int x, int y, int w, int h, byte cl


// Vykresli obecnou bitmapu:
extern void PutBitmap(int x, int y, void *data, int w, int h);
extern void PutBitmap(int x, int y, const void *data, int w, int h);
extern void PutBitmapNZ(int x, int y, void *data, int w, int h);
#define PutBitmap32(x, y, data, w, h) PutBitmap(x, y, data, w, h)
extern void GetBitmap(int x, int y, void *data, int w, int h);
Expand Down
214 changes: 92 additions & 122 deletions signus/src/infobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,92 +28,19 @@ implementace Infoboxu jednotky (TUnit::DetailedInfo()...)



#include <climits>
#include "units.h"
#include "ui_toolkit.h"
#include "global.h"
#include "anims.h"
#include "sound.h"
#include "mouse.h"

#include "miniSDL_image.h"





////////////////////// flicer - prehrani vvf animace: ///////////////////////


#if 0 // FIXME
int flicer_x, flicer_y;

void flicer_DrawFrame(TMutationHeader *Mut, void *Buffer, int FromY, int ToY)
{
PutBitmap32(flicer_x, flicer_y + FromY, ((byte*)Buffer) + 256 * FromY, 256, (ToY-FromY+1));
}

int flicer_TestInterrupt()
{
TEvent e;

do {
GetEvent(&e);
if ((e.What != evNothing) && (e.What != evMouseMove)) {
PutEvent(&e);
return 1;
}
} while (e.What != evNothing);
return 0;
}

int flicer_SelectMutation(TMutationHeader *Muts, int Cnt) {return 0;}
int flicer_StartPlaying(TMutationHeader *Mut) {return 1;}
int flicer_StopPlaying(TMutationHeader *Mut) {return 1;}
#endif

extern void InitPalTimer();
extern void DonePalTimer();

int flicer_RunAnim(int x, int y, char *name)
{
#if 0 // FIXME
FILE *animf;
int (*ti)();
int rt;

DonePalTimer();
flicer_x = x, flicer_y = y;
VVF_SelectMutation = flicer_SelectMutation;
VVF_PlayDirect = TRUE;
VVF_InterpolateFrames = FALSE;
VVF_free = free;
VVF_malloc = malloc;
VVF_DrawFrame = flicer_DrawFrame;
VVF_StartPlaying = flicer_StartPlaying;
VVF_StopPlaying = flicer_StopPlaying;
VVF_CanSetPalette = FALSE;
ti = VVF_TestInterrupt;
VVF_TestInterrupt = flicer_TestInterrupt;

do {
animf = GetAnimFile(name);
rt = PlayVVF(animf);
fclose(animf);
} while (rt == 1);
VVF_TestInterrupt = ti;
InitPalTimer();
#endif

return 1;
}









///////////////////////////// info dialog: //////////////////////////////////


Expand Down Expand Up @@ -160,17 +87,17 @@ int IsUnitAT(TObject *unit)
#define cmAnim 9999

class TInfoDialog : public TDialog {
public:
void *pic;
int picnum;
TObject *unit;
TBitmap *bmp;
TBitmap *ArtefaktLogo;
TInfoDialog(int ax, int ay, TObject *u);
int SpecialHandle(TEvent *e, int Cmd);
int RunAnimation();
};
public:
void *pic;
int picnum;
TObject *unit;
TBitmap *bmp;
TBitmap *ArtefaktLogo;

TInfoDialog(int ax, int ay, TObject *u);
int SpecialHandle(TEvent *e, int Cmd);
int Exec();
};



Expand All @@ -197,54 +124,97 @@ TInfoDialog::TInfoDialog(int ax, int ay, TObject *u) :
Insert(new TBitmap(253, 288, FALSE,
LevelBmps[((TUnit*)u)->Level], 29, 16, FALSE));
}

TEvent e;
e.What = evMouseDown;
e.Mouse.Buttons = mbBottomButton | mbLeftButton | mbRightButton;
PutEvent(&e);
//DLG_backimg[0] = 0; // to disable redrawing

char filename[1024];
SDL_Surface *image;
snprintf(filename, 1024, "%s/nolang/unit-images/unit%i.jpg",
getSignusDataDir(), unit->GetType());
image = IMG_Load(filename);
byte *pall = (byte*)memalloc(256 * 192);
paletizeSurface(pall, image, "pal_rgb");
SDL_FreeSurface(image);
Insert(new TBitmap(22, 22, FALSE, pall, 256, 192));
}



int TInfoDialog::SpecialHandle(TEvent *e, int Cmd)
{
if ((e->What == evMouseDown) /* FIXME &&
(e->Mouse.Buttons == mbBottomButton | mbLeftButton | mbRightButton)*/) {
RunAnimation();
return -1;
}
else if (Cmd == cmNext) {
return -1;
}
else return TDialog::SpecialHandle(e, Cmd);
int TInfoDialog::SpecialHandle(TEvent *e, int Cmd) {
if (Cmd == cmNext) {
return -1;
}

return TDialog::SpecialHandle(e, Cmd);
}



int TInfoDialog::RunAnimation()
{
char b[20];
int rt;

sprintf(b, "unit%i", unit->Type);
rt = flicer_RunAnim(x + 22, y + 22, b);
return rt;
}
int TInfoDialog::Exec() {
File animfile;
VVFStream *anim = NULL;
int ret = -1;
unsigned awidth = 0, aheight = 0, timer = 0;
char filename[PATH_MAX];
TEvent e;

sprintf(filename, "unit%i", unit->Type);

if (open_anim_file(animfile, filename)) {
anim = new VVFStream(&animfile);
awidth = anim->video_width();
aheight = anim->video_height();
} else {
SDL_Surface *image;
snprintf(filename, PATH_MAX,"%s/nolang/unit-images/unit%i.jpg",
getSignusDataDir(), unit->GetType());
image = IMG_Load(filename);
byte *pall = (byte*)memalloc(256 * 192);
paletizeSurface(pall, image, "pal_rgb");
SDL_FreeSurface(image);
Insert(new TBitmap(22, 22, FALSE, pall, 256, 192));
}

DonePalTimer();
MouseSetCursor(mcurArrow);
Draw();

if (anim) {
anim->next_frame();
CopyBmp(DrwBuf, w, 22, 22, anim->videobuf(), awidth, aheight);
timer = anim->frame_time();
}

FadeDlg(TRUE);
MouseSetRect(x, y, x+w-1, y+h-1);
timer += SDL_GetTicks();

while (ret == -1) {
if (anim && timer <= SDL_GetTicks()) {
if (!anim->next_frame()) {
anim->reset();
anim->next_frame();

if (anim->error()) {
delete anim;
anim = NULL;
continue;
}
}

timer += anim->frame_time();
PutBitmap(x+22,y+22, anim->videobuf(), awidth,aheight);
}

if (MusicOn && (!IsMusicPlaying())) {
JukeboxNext();
}

do {
GetEvent(&e);
ret = HandleEvent(&e);
} while (ret == -1 && e.What != evNothing);
}

if (anim) {
// Show the last anim frame during dialog fade
CopyBmp(DrwBuf, w, 22, 22, anim->videobuf(), awidth, aheight);
delete anim;
}

MouseSetRect(0, 0, RES_X-1, RES_Y-1);
FadeDlg(FALSE);
InitPalTimer();
return ret;
}



Expand Down
Loading

0 comments on commit 2816a62

Please sign in to comment.