[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 | { |
---|
[655] | 58 | long l = whom->stat_win->x2() - whom->stat_win->x1() - 6; |
---|
[668] | 59 | long h = wm->font()->Size().y; |
---|
[2] | 60 | |
---|
[682] | 61 | whom->stat_win->m_surf->Bar(ivec2(whom->stat_win->x1() + 1, |
---|
[655] | 62 | whom->stat_win->y2() - h - 1), |
---|
[682] | 63 | ivec2(whom->stat_win->x2() - 1, |
---|
[655] | 64 | whom->stat_win->y2() - 1), |
---|
| 65 | wm->black()); |
---|
[682] | 66 | whom->stat_win->m_surf->Bar(ivec2(whom->stat_win->x1() + 2, |
---|
[655] | 67 | whom->stat_win->y2() - h), |
---|
[682] | 68 | ivec2(whom->stat_win->x2() - 2, |
---|
[655] | 69 | whom->stat_win->y2() - 2), |
---|
| 70 | wm->dark_color()); |
---|
| 71 | if (perc) |
---|
[682] | 72 | whom->stat_win->m_surf->Bar(ivec2(whom->stat_win->x1() + 3, |
---|
[655] | 73 | whom->stat_win->y2() - h + 1), |
---|
[682] | 74 | ivec2(whom->stat_win->x1() + l * perc / 100, |
---|
[655] | 75 | whom->stat_win->y2() - 3), |
---|
| 76 | wm->bright_color()); |
---|
[2] | 77 | } |
---|
| 78 | |
---|
[39] | 79 | void gui_status_manager::push(char const *name, visual_object *show) |
---|
[2] | 80 | { |
---|
[124] | 81 | first=new gui_status_node(name,show,first); |
---|
[2] | 82 | } |
---|
| 83 | |
---|
[124] | 84 | gui_status_manager::gui_status_manager() |
---|
| 85 | { |
---|
| 86 | first=NULL; |
---|
| 87 | strcpy(title,"STATUS"); |
---|
[2] | 88 | last_perc=0; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void gui_status_manager::update(int percentage) |
---|
| 92 | { |
---|
| 93 | last_perc=percentage; |
---|
| 94 | if (first) |
---|
| 95 | { |
---|
| 96 | if (!first->stat_win) |
---|
| 97 | { |
---|
| 98 | time_marker now; |
---|
| 99 | if (now.diff_time(&first->last_time)>1) |
---|
| 100 | { |
---|
[668] | 101 | long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->Size().x+10,len2=0,len3, |
---|
| 102 | h1=wm->font()->Size().y+5,h2=first->show ? first->show->height() : 0; |
---|
[2] | 103 | |
---|
[124] | 104 | if (first->show) len2=first->show->width()/2; |
---|
| 105 | if (len2>len1) len3=len2; else len3=len1; |
---|
| 106 | wx-=len3/2; |
---|
[494] | 107 | |
---|
| 108 | |
---|
[124] | 109 | gui_status_node *p=first->next; |
---|
| 110 | while (p && !p->stat_win) p=p->next; |
---|
[659] | 111 | if (p) wy=p->stat_win->m_pos.y+p->stat_win->y2()+5; |
---|
[2] | 112 | |
---|
[124] | 113 | int mx = first->stat_win->x1() + 1; |
---|
[668] | 114 | int my = first->stat_win->y1() + wm->font()->Size().y / 2; |
---|
[682] | 115 | first->stat_win=wm->CreateWindow(ivec2(wx, wy), ivec2(len3, h1*2+h2), NULL, "status"); |
---|
| 116 | wm->font()->PutString(first->stat_win->m_surf, ivec2(mx, my), first->name, wm->black()); |
---|
| 117 | wm->font()->PutString(first->stat_win->m_surf, ivec2(mx, my), first->name, wm->bright_color()); |
---|
[124] | 118 | if (first->show) |
---|
[644] | 119 | first->show->draw(first->stat_win->m_surf, (first->stat_win->x2()-first->stat_win->x1())/2- |
---|
[124] | 120 | first->show->width()/2, my+h1, NULL); |
---|
[2] | 121 | |
---|
[124] | 122 | draw_bar(first,percentage); |
---|
| 123 | wm->flush_screen(); |
---|
[2] | 124 | } |
---|
| 125 | } else |
---|
| 126 | { |
---|
| 127 | if (percentage>first->last_update) |
---|
| 128 | { |
---|
[124] | 129 | first->last_update=percentage; |
---|
| 130 | draw_bar(first,percentage); |
---|
| 131 | wm->flush_screen(); |
---|
[2] | 132 | } |
---|
| 133 | } |
---|
[124] | 134 | } |
---|
[2] | 135 | } |
---|
| 136 | |
---|
| 137 | void gui_status_manager::force_display() |
---|
| 138 | { |
---|
| 139 | update(last_perc); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | void gui_status_manager::pop() |
---|
| 143 | { |
---|
| 144 | CONDITION(first,"No status's to pop!"); |
---|
| 145 | gui_status_node *p=first; |
---|
| 146 | first=first->next; |
---|
| 147 | delete p; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | |
---|