Skyscraper 2.0
indicator.cpp
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Indicator Object
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#include "globals.h"
25#include "sbs.h"
26#include "mesh.h"
27#include "manager.h"
28#include "texture.h"
29#include "timer.h"
30#include "sound.h"
31#include "indicator.h"
32
33namespace SBS {
34
36{
37public:
39 Timer(const std::string &name, Indicator *parent) : TimerObject(parent, name)
40 {
41 this->parent = parent;
42 }
43 virtual void Notify();
44};
45
46Indicator::Indicator(Object *parent, const std::string &sound, const std::string &texture_prefix, const std::string &blank_texture, const std::string &direction, Real CenterX, Real CenterZ, Real width, Real height, Real voffset, Real timer_duration) : Object(parent)
47{
48 //creates a new display panel at the specified position
49
50 //set up SBS object
51 SetValues("Indicator", "Indicator", false);
52
53 is_enabled = true;
54 Prefix = texture_prefix;
55 Blank = blank_texture;
56 this->timer_duration = timer_duration;
57 this->sound = 0;
58
59 //std::string name = "Display Panel " + ToString(elevator);
60 //SetName(name);
61
62 Mesh = new MeshObject(this, "Display Panel", 0, "", "", sbs->GetConfigFloat("Skyscraper.SBS.MaxSmallRenderDistance", 100));
63
64 std::string tmpdirection = direction;
65 SetCase(tmpdirection, false);
66
67 Wall *wall = Mesh->CreateWallObject("Indicator");
68 if (tmpdirection == "front" || tmpdirection == "back")
69 {
70 if (tmpdirection == "front")
71 sbs->DrawWalls(true, false, false, false, false, false);
72 else
73 sbs->DrawWalls(false, true, false, false, false, false);
74
75 sbs->AddWallMain(wall, "Indicator", Blank, 0, -width / 2, 0, width / 2, 0, height, height, 0, 0, 1, 1, false);
76 }
77 else if (tmpdirection == "left" || tmpdirection == "right")
78 {
79 if (tmpdirection == "left")
80 sbs->DrawWalls(true, false, false, false, false, false);
81 else
82 sbs->DrawWalls(false, true, false, false, false, false);
83
84 sbs->AddWallMain(wall, "Indicator", Blank, 0, 0, width / 2, 0, -width / 2, height, height, 0, 0, 1, 1, false);
85 }
86 sbs->ResetWalls();
87
88 //create sound
89 if (sound != "")
90 {
91 this->sound = new Sound(this, "Indicator Sound", true);
94 }
95
96 //move object
97 Move(CenterX, voffset, CenterZ);
98
99 //create timer
100 timer = new Timer("Dispatch Timer", this);
101
102 EnableLoop(true);
103}
104
106{
107 if (Mesh)
108 {
109 Mesh->parent_deleting = true;
110 delete Mesh;
111 }
112 Mesh = 0;
113
114 if (sound)
115 {
116 sound->parent_deleting = true;
117 delete sound;
118 }
119 sound = 0;
120
121 //unregister from parent
122 /*if (sbs->FastDelete == false && parent_deleting == false)
123 {
124 std::string type = GetParent()->GetType();
125
126 if (type == "ElevatorCar")
127 static_cast<ElevatorCar*>(GetParent())->RemoveFloorIndicator(this);
128 else if (type == "Floor")
129 static_cast<Floor*>(GetParent())->RemoveFloorIndicator(this);
130 }*/
131}
132
133void Indicator::Enabled(bool value)
134{
135 //turns display on/off
136
137 if (is_enabled == value)
138 return;
139
140 Mesh->Enabled(value);
141 is_enabled = value;
142}
143
144void Indicator::Update(const std::string &text, bool play_sound)
145{
146 //update display with given text
147
148 if (text == "" && Blank != "")
149 {
151 return;
152 }
153
154 //don't update texture if no value
155 if (text == "")
156 return;
157
158 std::string texture = text;
159 texture.insert(0, Prefix);
160
161 Mesh->ChangeTexture(texture);
162 sbs->GetTextureManager()->EnableLighting(texture, false);
163
164 active_text = text;
165 if (play_sound == true)
166 PlaySound();
167
168 timer->Start(timer_duration * 1000.0);
169}
170
172{
173 if (Blank != "")
175
176 active_text = "";
177}
178
180{
181 //turn off indicator display when timer expires
182
183 parent->Off();
184}
185
187{
188 //play floor beep sound
189
190 if (soundfile == "" || !sound)
191 return false;
192
193 if (sbs->Verbose)
194 Report("playing indicator sound");
195
196 std::string newsound = soundfile;
197 std::string expanded = active_text;
198
199 //don't use a sound file name with the "??" characters, expand to a full name for both error types
200 if (active_text == "??")
201 expanded = "invalid";
202 if (active_text == "XX")
203 expanded = "error";
204
205 //remove direction characters
206 ReplaceAll(expanded, "<", "");
207 ReplaceAll(expanded, ">", "");
208 ReplaceAll(expanded, "[]", "");
209
210 //change the asterisk into the current active text value
211 ReplaceAll(newsound, "*", expanded);
212 TrimString(newsound);
213 sound->Stop();
214 sound->Load(newsound);
215 sound->SetLoopState(false);
216 sound->Play();
217 return true;
218}
219
221{
222 if (sbs->GetPower() == false)
223 Off();
224}
225
226}
virtual void Notify()
Timer(const std::string &name, Indicator *parent)
Definition indicator.cpp:39
Timer * timer
Definition indicator.h:57
Real timer_duration
Definition indicator.h:58
std::string soundfile
Definition indicator.h:53
MeshObject * Mesh
Definition indicator.h:47
std::string active_text
Definition indicator.h:54
Indicator(Object *parent, const std::string &sound, const std::string &texture_prefix, const std::string &blank_texture, const std::string &direction, Real CenterX, Real CenterZ, Real width, Real height, Real voffset, Real timer_duration)
Definition indicator.cpp:46
void Update(const std::string &text, bool play_sound=true)
std::string Blank
Definition indicator.h:34
std::string Prefix
Definition indicator.h:33
void Enabled(bool value)
Sound * sound
Definition indicator.h:52
void Enabled(bool value)
Definition mesh.cpp:154
bool ChangeTexture(const std::string &texture, bool matcheck=true)
Definition mesh.cpp:709
Wall * CreateWallObject(const std::string &name)
Definition mesh.cpp:208
virtual void Report(const std::string &message)
Definition object.cpp:78
bool parent_deleting
Definition object.h:64
virtual void Move(const Vector3 &vector, Real speed=1.0)
Definition object.cpp:253
void SetValues(const std::string &type, const std::string &name, bool is_permanent, bool is_movable=true)
Definition object.cpp:144
void EnableLoop(bool value)
Definition object.cpp:521
bool GetPower()
Definition sbs.cpp:4701
Real GetConfigFloat(const std::string &key, Real default_value)
Definition sbs.cpp:3249
bool AddWallMain(Wall *wallobject, const std::string &name, const std::string &texture, Real thickness, Real x1, Real z1, Real x2, Real z2, Real height_in1, Real height_in2, Real altitude1, Real altitude2, Real tw, Real th, bool autosize)
Definition sbs.cpp:690
void ResetWalls(bool ToDefaults=false)
Definition sbs.cpp:1854
TextureManager * GetTextureManager()
Definition sbs.cpp:4558
void DrawWalls(bool MainN, bool MainP, bool SideN, bool SideP, bool Top, bool Bottom)
Definition sbs.cpp:1833
bool Verbose
Definition sbs.h:186
bool Load(const std::string &filename, bool force=false)
Definition sound.cpp:386
void Stop()
Definition sound.cpp:292
bool Play(bool reset=true)
Definition sound.cpp:321
void SetLoopState(bool value)
Definition sound.cpp:204
void EnableLighting(const std::string &material_name, bool value)
Definition texture.cpp:2207
void Start(int milliseconds=-1, bool oneshot=false)
Definition timer.cpp:49
Ogre::Real Real
Definition globals.h:57
void ReplaceAll(std::string &string, const std::string &original, const std::string &replacement)
Definition globals.cpp:201
void SetCase(std::string &string, bool uppercase)
Definition globals.cpp:172
void TrimString(std::string &string)
Definition globals.cpp:188