[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 5 | * |
---|
| 6 | * This software was released into the Public Domain. As with most public |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
| 10 | |
---|
[555] | 11 | #if defined HAVE_CONFIG_H |
---|
| 12 | # include "config.h" |
---|
| 13 | #endif |
---|
[56] | 14 | |
---|
[131] | 15 | #include <string.h> |
---|
| 16 | |
---|
[512] | 17 | #include "common.h" |
---|
| 18 | |
---|
[481] | 19 | #include "input.h" |
---|
| 20 | #include "status.h" |
---|
| 21 | #include "timing.h" |
---|
| 22 | #include "guistat.h" |
---|
[2] | 23 | |
---|
| 24 | class gui_status_node |
---|
| 25 | { |
---|
[124] | 26 | public : |
---|
[2] | 27 | char *name; |
---|
| 28 | gui_status_node *next; |
---|
| 29 | visual_object *show; |
---|
[120] | 30 | Jwindow *stat_win; |
---|
[2] | 31 | int last_update; |
---|
| 32 | time_marker last_time; |
---|
[124] | 33 | gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next) |
---|
[131] | 34 | { name = strdup(Name); |
---|
[2] | 35 | show=Show; |
---|
[124] | 36 | next=Next; |
---|
[2] | 37 | last_update=0; |
---|
| 38 | stat_win=NULL; |
---|
| 39 | } |
---|
| 40 | ~gui_status_node(); |
---|
[124] | 41 | } ; |
---|
[2] | 42 | |
---|
| 43 | |
---|
| 44 | gui_status_node::~gui_status_node() |
---|
[124] | 45 | { |
---|
[129] | 46 | free(name); |
---|
[124] | 47 | if (show) |
---|
| 48 | delete show; |
---|
| 49 | if (stat_win) |
---|
[2] | 50 | { |
---|
| 51 | wm->close_window(stat_win); |
---|
| 52 | wm->flush_screen(); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void gui_status_manager::draw_bar(gui_status_node *whom, int perc) |
---|
| 57 | { |
---|
| 58 | long l=whom->stat_win->x2()-whom->stat_win->x1()-6; |
---|
| 59 | long h=wm->font()->height(); |
---|
| 60 | |
---|
| 61 | whom->stat_win->screen->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1, |
---|
[124] | 62 | whom->stat_win->y2()-1,wm->black()); |
---|
[2] | 63 | whom->stat_win->screen->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2, |
---|
[124] | 64 | whom->stat_win->y2()-2,wm->dark_color()); |
---|
[2] | 65 | if (perc) |
---|
| 66 | whom->stat_win->screen->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1, |
---|
[124] | 67 | whom->stat_win->x1()+l*perc/100, |
---|
| 68 | whom->stat_win->y2()-3,wm->bright_color()); |
---|
[2] | 69 | } |
---|
| 70 | |
---|
[39] | 71 | void gui_status_manager::push(char const *name, visual_object *show) |
---|
[2] | 72 | { |
---|
[124] | 73 | first=new gui_status_node(name,show,first); |
---|
[2] | 74 | } |
---|
| 75 | |
---|
[124] | 76 | gui_status_manager::gui_status_manager() |
---|
| 77 | { |
---|
| 78 | first=NULL; |
---|
| 79 | strcpy(title,"STATUS"); |
---|
[2] | 80 | last_perc=0; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void gui_status_manager::update(int percentage) |
---|
| 84 | { |
---|
| 85 | last_perc=percentage; |
---|
| 86 | if (first) |
---|
| 87 | { |
---|
| 88 | if (!first->stat_win) |
---|
| 89 | { |
---|
| 90 | time_marker now; |
---|
| 91 | if (now.diff_time(&first->last_time)>1) |
---|
| 92 | { |
---|
[124] | 93 | long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3, |
---|
| 94 | h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0; |
---|
[2] | 95 | |
---|
[124] | 96 | if (first->show) len2=first->show->width()/2; |
---|
| 97 | if (len2>len1) len3=len2; else len3=len1; |
---|
| 98 | wx-=len3/2; |
---|
[494] | 99 | |
---|
| 100 | |
---|
[124] | 101 | gui_status_node *p=first->next; |
---|
| 102 | while (p && !p->stat_win) p=p->next; |
---|
| 103 | if (p) wy=p->stat_win->y+p->stat_win->y2()+5; |
---|
[2] | 104 | |
---|
[124] | 105 | int mx = first->stat_win->x1() + 1; |
---|
| 106 | int my = first->stat_win->y1() + wm->font()->height() / 2; |
---|
| 107 | first->stat_win=wm->new_window(wx, wy, len3, h1*2+h2, NULL, "status"); |
---|
| 108 | wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->black()); |
---|
| 109 | wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->bright_color()); |
---|
| 110 | if (first->show) |
---|
| 111 | first->show->draw(first->stat_win->screen, (first->stat_win->x2()-first->stat_win->x1())/2- |
---|
| 112 | first->show->width()/2, my+h1, NULL); |
---|
[2] | 113 | |
---|
[124] | 114 | draw_bar(first,percentage); |
---|
| 115 | wm->flush_screen(); |
---|
[2] | 116 | } |
---|
| 117 | } else |
---|
| 118 | { |
---|
| 119 | if (percentage>first->last_update) |
---|
| 120 | { |
---|
[124] | 121 | first->last_update=percentage; |
---|
| 122 | draw_bar(first,percentage); |
---|
| 123 | wm->flush_screen(); |
---|
[2] | 124 | } |
---|
| 125 | } |
---|
[124] | 126 | } |
---|
[2] | 127 | } |
---|
| 128 | |
---|
| 129 | void gui_status_manager::force_display() |
---|
| 130 | { |
---|
| 131 | update(last_perc); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void gui_status_manager::pop() |
---|
| 135 | { |
---|
| 136 | CONDITION(first,"No status's to pop!"); |
---|
| 137 | gui_status_node *p=first; |
---|
| 138 | first=first->next; |
---|
| 139 | delete p; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|