add more hax to CallButton
[openc2e.git] / Blackboard.cpp
blob91b38862359cdb86037c84640766a918835587c5
1 /*
2 * Blackboard.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Sat Jan 12 2008.
6 * Copyright (c) 2008 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "Blackboard.h"
21 #include "Engine.h"
22 #include "Backend.h"
24 Blackboard::Blackboard(std::string spritefile, unsigned int firstimage, unsigned int imagecount,
25 unsigned int tx, unsigned int ty, unsigned int bgcolour, unsigned int ckcolour,
26 unsigned int alcolour) : CompoundAgent(spritefile, firstimage, imagecount) {
27 textx = tx; texty = ty;
28 backgroundcolour = bgcolour; chalkcolour = ckcolour; aliascolour = alcolour;
30 if (engine.version == 1)
31 strings.resize(16, std::pair<unsigned int, std::string>(0, std::string()));
32 else
33 strings.resize(48, std::pair<unsigned int, std::string>(0, std::string()));
36 void Blackboard::addPart(CompoundPart *p) {
37 CompoundAgent::addPart(p);
39 // if we're adding the first part..
40 if (parts.size() == 1) {
41 // add the part responsible for text; id #10 keeps it safely out of the way
42 BlackboardPart *p = new BlackboardPart(this, 10);
43 addPart(p);
47 void Blackboard::showText(bool show) {
48 if (show && var[0].hasInt() && var[0].getInt() >= 0 && (unsigned int)var[0].getInt() < strings.size()) {
49 currenttext = strings[var[0].getInt()].second;
50 } else {
51 currenttext.clear();
55 void Blackboard::addBlackboardString(unsigned int n, unsigned int id, std::string text) {
56 strings[n] = std::pair<unsigned int, std::string>(id, text);
59 void Blackboard::renderText(class Surface *renderer, int xoffset, int yoffset) {
60 // TODO: is +1 really the right fix here?
61 renderer->renderText(xoffset + textx + 1, yoffset + texty + 1, currenttext, chalkcolour, backgroundcolour);
64 BlackboardPart::BlackboardPart(Blackboard *p, unsigned int _id) : CompoundPart(p, _id, 0, 0, 1) {
65 // TODO: think about plane
68 void BlackboardPart::partRender(class Surface *renderer, int xoffset, int yoffset) {
69 dynamic_cast<Blackboard *>(parent)->renderText(renderer, xoffset, yoffset);
72 /* vim: set noet: */