aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-10-30 15:36:24 +0100
committerorwell96 <orwell@bleipb.de>2018-10-30 15:36:24 +0100
commitc4bac79bf07b2d94f97893c41889d619d1ef97e0 (patch)
tree4606c14e5685782262853dc132091439f713cd60
parent190b476b66b7fec28f49c8afddddea1af8c41650 (diff)
downloadadvtrains-c4bac79bf07b2d94f97893c41889d619d1ef97e0.tar.gz
advtrains-c4bac79bf07b2d94f97893c41889d619d1ef97e0.tar.bz2
advtrains-c4bac79bf07b2d94f97893c41889d619d1ef97e0.zip
Do not allow static signals for routesetting
-rw-r--r--advtrains_interlocking/tcb_ts_ui.lua29
1 files changed, 17 insertions, 12 deletions
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index c0e0d98..203e0b1 100644
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -141,20 +141,25 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
if vector.distance(pos, sigd.p)<=50 then
local is_signal = minetest.get_item_group(node.name, "advtrains_signal") >= 2
if is_signal then
- local tcbs = ildb.get_tcbs(sigd)
- if tcbs then
- tcbs.signal = pos
- if not tcbs.signal_name then
- tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p)
+ local ndef = minetest.registered_nodes[node.name]
+ if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
+ local tcbs = ildb.get_tcbs(sigd)
+ if tcbs then
+ tcbs.signal = pos
+ if not tcbs.signal_name then
+ tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p)
+ end
+ if not tcbs.routes then
+ tcbs.routes = {}
+ end
+ ildb.set_sigd_for_signal(pos, sigd)
+ minetest.chat_send_player(pname, "Configuring TCB: Successfully assigned signal.")
+ advtrains.interlocking.show_ip_form(pos, pname, true)
+ else
+ minetest.chat_send_player(pname, "Configuring TCB: Internal error, TCBS doesn't exist. Aborted.")
end
- if not tcbs.routes then
- tcbs.routes = {}
- end
- ildb.set_sigd_for_signal(pos, sigd)
- minetest.chat_send_player(pname, "Configuring TCB: Successfully assigned signal.")
- advtrains.interlocking.show_ip_form(pos, pname, true)
else
- minetest.chat_send_player(pname, "Configuring TCB: Internal error, TCBS doesn't exist. Aborted.")
+ minetest.chat_send_player(pname, "Configuring TCB: Cannot use static signals for routesetting. Aborted.")
end
else
minetest.chat_send_player(pname, "Configuring TCB: Not a compatible signal. Aborted.")
11 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
/*
Minetest
Copyright (C) 2019 EvicenceBKidscode / Pierre-Yves Rollo <dev@pyrollo.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "config.h" // for USE_FREETYPE

using namespace irr;

class ISimpleTextureSource;
class Client;

#if USE_FREETYPE
#include "irrlicht_changes/CGUITTFont.h"
#endif

class ParsedText
{
public:
	ParsedText(const wchar_t *text);
	~ParsedText();

	enum ElementType
	{
		ELEMENT_TEXT,
		ELEMENT_SEPARATOR,
		ELEMENT_IMAGE,
		ELEMENT_ITEM
	};

	enum BackgroundType
	{
		BACKGROUND_NONE,
		BACKGROUND_COLOR
	};

	enum FloatType
	{
		FLOAT_NONE,
		FLOAT_RIGHT,
		FLOAT_LEFT
	};

	enum HalignType
	{
		HALIGN_CENTER,
		HALIGN_LEFT,
		HALIGN_RIGHT,
		HALIGN_JUSTIFY
	};

	enum ValignType
	{
		VALIGN_MIDDLE,
		VALIGN_TOP,
		VALIGN_BOTTOM
	};

	typedef std::unordered_map<std::string, std::string> StyleList;
	typedef std::unordered_map<std::string, std::string> AttrsList;

	struct Tag
	{
		std::string name;
		AttrsList attrs;
		StyleList style;
	};

	struct Element
	{
		std::list<Tag *> tags;
		ElementType type;
		core::stringw text = "";

		core::dimension2d<u32> dim;
		core::position2d<s32> pos;
		s32 drawwidth;

		FloatType floating = FLOAT_NONE;

		ValignType valign;

		gui::IGUIFont *font;

		irr::video::SColor color;
		irr::video::SColor hovercolor;
		bool underline;

		s32 baseline = 0;

		// img & item specific attributes
		std::string name;
		v3s16 angle{0, 0, 0};
		v3s16 rotation{0, 0, 0};

		s32 margin = 10;

		void setStyle(StyleList &style);
	};

	struct Paragraph
	{
		std::vector<Element> elements;
		HalignType halign;
		s32 margin = 10;

		void setStyle(StyleList &style);
	};

	std::vector<Paragraph> m_paragraphs;

	// Element style
	s32 margin = 3;
	ValignType valign = VALIGN_TOP;
	BackgroundType background_type = BACKGROUND_NONE;
	irr::video::SColor background_color;

	Tag m_root_tag;

protected:
	typedef enum { ER_NONE, ER_TAG, ER_NEWLINE } EndReason;

	// Parser functions
	void enterElement(ElementType type);
	void endElement();
	void enterParagraph();
	void endParagraph(EndReason reason);
	void pushChar(wchar_t c);
	ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
	ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
	bool closeTag(const std::string &name);
	void parseGenericStyleAttr(const std::string &name, const std::string &value,
			StyleList &style);
	void parseStyles(const AttrsList &attrs, StyleList &style);
	void globalTag(const ParsedText::AttrsList &attrs);
	u32 parseTag(const wchar_t *text, u32 cursor);
	void parse(const wchar_t *text);

	std::unordered_map<std::string, StyleList> m_elementtags;
	std::unordered_map<std::string, StyleList> m_paragraphtags;

	std::vector<Tag *> m_not_root_tags;
	std::list<Tag *> m_active_tags;

	// Current values
	StyleList m_style;
	Element *m_element;
	Paragraph *m_paragraph;
	bool m_empty_paragraph;
	EndReason m_end_paragraph_reason;
};

class TextDrawer
{
public:
	TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
			ISimpleTextureSource *tsrc);

	void place(const core::rect<s32> &dest_rect);
	inline s32 getHeight() { return m_height; };
	void draw(const core::rect<s32> &dest_rect,
			const core::position2d<s32> &dest_offset);
	ParsedText::Element *getElementAt(core::position2d<s32> pos);
	ParsedText::Tag *m_hovertag;

protected: