// // Monsterz // // Copyright: (c) 2005-2011 Sam Hocevar // This program is free software; you can redistribute it and/or // modify it under the terms of the Do What The Fuck You Want To // Public License, Version 2, as published by Sam Hocevar. See // http://sam.zoy.org/projects/COPYING.WTFPL for more details. // #if defined HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include "core.h" #include "thumbs.h" #include "monsterz.h" /* * Thumbs implementation class */ class ThumbsData { friend class Thumbs; private: int npieces; int icons; Text *text[MAX_PIECES]; int count[MAX_PIECES]; }; /* * Public Thumbs class */ Thumbs::Thumbs(int npieces) : data(new ThumbsData()) { data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f); data->npieces = 0; SetMax(npieces); #if 0 position = int3(24, 72, 1); bbox[0] = position; bbox[1] = bbox[0] + int3(384, 384, 0); #endif } void Thumbs::TickGame(float deltams) { Entity::TickGame(deltams); for (int n = 0; n < data->npieces; n++) data->text[n]->SetInt(data->count[n]); } void Thumbs::TickDraw(float deltams) { Entity::TickDraw(deltams); for (int n = 0; n < data->npieces; n++) { int2 p = int2(444, 380 - 28 * n); Scene::GetDefault()->AddTile((data->icons << 16) | n, p.x, p.y, 11, 0); } } void Thumbs::SetMax(int npieces) { for (int n = npieces; n < data->npieces; n++) Ticker::Unref(data->text[n]); for (int n = data->npieces; n < npieces; n++) { data->count[n] = 0; data->text[n] = new Text(NULL, "monsterz/gfx/font1.png"); Ticker::Ref(data->text[n]); int3 p = int3(476, 383 - 28 * n, 1); data->text[n]->SetPos(p); } data->npieces = npieces; } void Thumbs::AddCount(int id, int count) { if (id >= 0 && id < data->npieces) data->count[id] += count; } Thumbs::~Thumbs() { for (int n = 0; n < data->npieces; n++) Ticker::Unref(data->text[n]); Tiler::Deregister(data->icons); delete data; }