source: trunk/monsterz/thumbs.cpp @ 340

Last change on this file since 340 was 340, checked in by sam, 10 years ago

Add a Thumbs class to display the sidebar thumbnail icons.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//
2// Monsterz
3//
4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19
20#include "core.h"
21#include "thumbs.h"
22#include "monsterz.h"
23
24/*
25 * Thumbs implementation class
26 */
27
28class ThumbsData
29{
30    friend class Thumbs;
31
32private:
33    int npieces;
34    int icons;
35
36    Text *text[MAX_PIECES];
37    int count[MAX_PIECES];
38};
39
40/*
41 * Public Thumbs class
42 */
43
44Thumbs::Thumbs(int npieces)
45  : data(new ThumbsData())
46{
47    data->npieces = npieces;
48    data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f);
49
50    for (int n = 0; n < data->npieces; n++)
51    {
52        data->count[n] = 0;
53        data->text[n] = new Text(NULL, "monsterz/gfx/font1.png");
54        Ticker::Ref(data->text[n]);
55        int3 p = int3(476, 383 - 28 * n, 1);
56        data->text[n]->SetPos(p);
57    }
58
59#if 0
60    position = int3(24, 72, 1);
61    bbox[0] = position;
62    bbox[1] = bbox[0] + int3(384, 384, 0);
63#endif
64}
65
66void Thumbs::TickGame(float deltams)
67{
68    Entity::TickGame(deltams);
69
70    for (int n = 0; n < data->npieces; n++)
71        data->text[n]->SetInt(data->count[n]);
72}
73
74void Thumbs::TickDraw(float deltams)
75{
76    Entity::TickDraw(deltams);
77
78    for (int n = 0; n < data->npieces; n++)
79    {
80        int2 p = int2(444, 380 - 28 * n);
81        Scene::GetDefault()->AddTile((data->icons << 16) | n, p.x, p.y, 11, 0);
82    }
83}
84
85void Thumbs::AddCount(int id, int count)
86{
87    if (id >= 0 && id < data->npieces)
88        data->count[id] += count;
89}
90
91Thumbs::~Thumbs()
92{
93    for (int n = 0; n < data->npieces; n++)
94        Ticker::Unref(data->text[n]);
95    Tiler::Deregister(data->icons);
96    delete data;
97}
98
Note: See TracBrowser for help on using the repository browser.