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, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <string.h> |
---|
16 | |
---|
17 | #include "common.h" |
---|
18 | |
---|
19 | #include "status.h" |
---|
20 | #include "dprint.h" |
---|
21 | |
---|
22 | status_manager *stat_man=NULL; |
---|
23 | |
---|
24 | class text_status_node |
---|
25 | { |
---|
26 | public : |
---|
27 | char *name; |
---|
28 | text_status_node *next; |
---|
29 | visual_object *show; |
---|
30 | int last_update; |
---|
31 | text_status_node(char const *Name, visual_object *Show, text_status_node *Next) |
---|
32 | { name = strdup(Name); |
---|
33 | show = Show; |
---|
34 | next = Next; |
---|
35 | last_update = 0; |
---|
36 | } |
---|
37 | ~text_status_node() { free(name); if (show) delete show; } |
---|
38 | } ; |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | text_status_manager::text_status_manager() |
---|
43 | { |
---|
44 | first=NULL; |
---|
45 | level=0; |
---|
46 | } |
---|
47 | |
---|
48 | void text_status_manager::push(char const *name, visual_object *show) |
---|
49 | { |
---|
50 | level++; |
---|
51 | first=new text_status_node(name,show,first); |
---|
52 | } |
---|
53 | |
---|
54 | void text_status_manager::update(int percentage) |
---|
55 | { |
---|
56 | // return; |
---|
57 | if (level==1 && percentage-first->last_update>4) |
---|
58 | { |
---|
59 | char s[256], len; |
---|
60 | first->last_update=percentage; |
---|
61 | sprintf(s,"\r%s [",first->name); |
---|
62 | len = strlen(s); |
---|
63 | int t=percentage*40/100; |
---|
64 | int i=0; |
---|
65 | for (; i<t; i++) |
---|
66 | s[len+i] = '.'; |
---|
67 | for (; i<40; i++) |
---|
68 | s[len+i] = ' '; |
---|
69 | s[len+i++] = ']'; |
---|
70 | s[len+i] = 0; |
---|
71 | dprintf("%s",s); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void text_status_manager::pop() |
---|
76 | { |
---|
77 | CONDITION(first,"No status's to pop!"); |
---|
78 | if (level==1) dprintf("\n"); |
---|
79 | level--; |
---|
80 | text_status_node *p=first; first=first->next; |
---|
81 | delete p; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|