source: abuse/trunk/src/imlib/status.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 12 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include <string.h>
14
15#include "macs.h"
16#include "status.h"
17#include "dprint.h"
18
19status_manager *stat_man=NULL;
20
21class text_status_node
22{
23  public :
24  char *name;
25  text_status_node *next;
26  visual_object *show;
27  int last_update;
28  text_status_node(char const *Name, visual_object *Show, text_status_node *Next)
29  { name = strdup(Name);
30    show = Show;
31    next = Next;
32    last_update = 0;
33  }
34  ~text_status_node() { free(name); if (show) delete show; }
35} ;
36
37
38
39text_status_manager::text_status_manager()
40{
41  first=NULL;
42  level=0;
43}
44
45void text_status_manager::push(char const *name, visual_object *show)
46{
47  level++;
48  first=new text_status_node(name,show,first);
49}
50
51void text_status_manager::update(int percentage)
52{
53//    return;
54  if (level==1 && percentage-first->last_update>4)
55  {
56      char s[256], len;
57    first->last_update=percentage;
58    sprintf(s,"\r%s [",first->name);
59    len = strlen(s);
60    int t=percentage*40/100;
61    int i=0;
62    for (; i<t; i++)
63      s[len+i] = '.';
64    for (; i<40; i++)
65        s[len+i] = ' ';
66    s[len+i++] = ']';
67    s[len+i] = 0;
68    dprintf("%s",s);
69  }
70}
71
72void text_status_manager::pop()
73{
74  CONDITION(first,"No status's to pop!");
75  if (level==1) dprintf("\n");
76  level--;
77  text_status_node *p=first; first=first->next;
78  delete p;
79}
80
81
82
83
84
Note: See TracBrowser for help on using the repository browser.