Beispiel #1
0
VoxelPos read_voxel_pos(const variant& v) {
	std::vector<int> res = v.as_list_int();
	ASSERT_LOG(res.size() == 3, "Illegal voxel pos: " << v.write_json() << " " << v.debug_location());
	VoxelPos result;
	result[0] = res[0];
	result[1] = res[1];
	result[2] = res[2];
	return result;
}
Beispiel #2
0
void read_voxels(const variant& v, VoxelMap* out) {
	std::vector<int> pos = v["loc"].as_list_int();
	ASSERT_LOG(pos.size()%3 == 0, "Bad location: " << v.write_json() << v.debug_location());
	graphics::color color(v["color"]);

	while(pos.empty() == false) {
		VoxelPair result;

		std::copy(pos.end()-3, pos.end(), &result.first[0]);
		result.second.color = color;
		out->insert(result);

		pos.resize(pos.size() - 3);
	}
}
void arrow_primitive::set_points(const variant& points)
{
	ASSERT_LOG(points.is_list(), "arrow points is not a list: " << points.debug_location());

	points_.clear();

	for(int n = 0; n != points.num_elements(); ++n) {
		variant p = points[n];
		ASSERT_LOG(p.is_list() && p.num_elements() == 2, "arrow points in invalid format: " << points.debug_location() << " : " << p.write_json());
		FPoint point;
		point[0] = p[0].as_int();
		point[1] = p[1].as_int();
		points_.push_back(point);
	}
}
Beispiel #4
0
grid::grid(const variant& v, game_logic::formula_callable* e)
	: scrollable_widget(v, e), row_height_(v["row_height"].as_int(0)), selected_row_(-1), 
	allow_selection_(false), must_select_(false),
    swallow_clicks_(false), hpad_(0), show_background_(false),
	max_height_(-1), allow_highlight_(true), set_h_(0), set_w_(0),
	default_selection_(v["default_select"].as_int(-1)), 
	draw_selection_highlight_(v["draw_selection_highlighted"].as_bool(false))
{
	ASSERT_LOG(get_environment() != 0, "You must specify a callable environment");
	if(v.has_key("on_select")) {
		const variant on_select_value = v["on_select"];
		if(on_select_value.is_function()) {
			ASSERT_LOG(on_select_value.min_function_arguments() <= 1 && on_select_value.max_function_arguments() >= 1, "on_select grid function should take 1 argument: " << v.debug_location());
			static const variant fml("fn(selection)");
			ffl_on_select_.reset(new game_logic::formula(fml));

			game_logic::map_formula_callable* callable = new game_logic::map_formula_callable;
			callable->add("fn", on_select_value);

			select_arg_.reset(callable);
		} else {
			ffl_on_select_ = get_environment()->create_formula(on_select_value);
		}
		on_select_ = boost::bind(&grid::select_delegate, this, _1);
	}
	if(v.has_key("on_mouseover")) {
		allow_selection_ = true;
		on_mouseover_ = boost::bind(&grid::mouseover_delegate, this, _1);
		const variant on_mouseover_value = v["on_mouseover"];
		if(on_mouseover_value.is_function()) {
			ASSERT_LOG(on_mouseover_value.min_function_arguments() <= 1 && on_mouseover_value.max_function_arguments() >= 1, "on_mouseover grid function should take 1 argument: " << v.debug_location());
			static const variant fml("fn(selection)");
			ffl_on_mouseover_.reset(new game_logic::formula(fml));

			game_logic::map_formula_callable* callable = new game_logic::map_formula_callable;
			callable->add("fn", on_mouseover_value);

			mouseover_arg_.reset(callable);
		} else {
			ffl_on_mouseover_ = get_environment()->create_formula(v["on_mouseover"]);
		}
	}

	ncols_ = v["columns"].as_int(1);
	if(v.has_key("column_widths")) {
		if(v["column_widths"].is_list()) {
			ASSERT_LOG(v["column_widths"].num_elements() == ncols_, "List of column widths must have " << ncols_ << " elements");
			std::vector<int> li = v["column_widths"].as_list_int();
			col_widths_.assign(li.begin(), li.end());
		} else if(v["column_widths"].is_int()) {
			col_widths_.assign(ncols_, v["column_widths"].as_int());
		} else {
			ASSERT_LOG(false, "grid: column_widths must be an int or list of ints");
		}
	} else {
		col_widths_.assign(ncols_, 0);
	}
	col_aligns_.resize(ncols_);
	if(v.has_key("column_alignments")) {
		if(v["column_alignments"].is_list()) {
			// XXX this could be a list of strings as well.
			int col = 0;
			foreach(const variant& c, v["column_alignments"].as_list()) {
				if(c.is_int()) {
					set_align(col, static_cast<COLUMN_ALIGN>(c.as_int()));
				} else if(c.is_string()) {
					const std::string& s = c.as_string();
					if(s == "center" || s == "centre") {
						set_align(col, ALIGN_CENTER);
					} else if(s == "right") {
						set_align(col, ALIGN_RIGHT);
					} else if(s == "left") {
						set_align(col, ALIGN_LEFT);
					} else {
						ASSERT_LOG(false, "grid: column_alignments must be \"left\", \"right\" or \"center\"");
					}
				} else {
					ASSERT_LOG(false, "grid: column alignment members must be an integer or a string.");
				}
				col++;
			}
		} else if(v["column_alignments"].is_int()) {
Beispiel #5
0
dialog::dialog(const variant& v, game_logic::formula_callable* e)
	: widget(v,e),
	opened_(false), cancelled_(false), 
	add_x_(0), add_y_(0), last_draw_(-1)
{
	forced_dimensions_ = rect(x(), y(), width(), height());
	padding_ = v["padding"].as_int(10);
	if(v.has_key("background_frame")) {
		background_framed_gui_element_ = v["background_frame"].as_string();
	}
	if(v.has_key("background_draw")) {
		std::string scene = v["background_draw"].as_string();
		if(scene == "last_scene") {
			draw_background_fn_ = boost::bind(&dialog::draw_last_scene);
		}
		// XXX could make this FFL callable. Or could allow any of the background scenes to be drawn. or both.
	}
	clear_bg_ = v["clear_background_alpha"].as_int(196);
	bg_alpha_ = v["background_alpha"].as_int(255) / GLfloat(255.0);
	if(v.has_key("cursor")) {
		std::vector<int> vi = v["cursor"].as_list_int();
		set_cursor(vi[0], vi[1]);
	}
	if(v.has_key("on_quit")) {
		on_quit_ = boost::bind(&dialog::quit_delegate, this);
		ASSERT_LOG(get_environment() != NULL, "environment not set");
		const variant on_quit_value = v["on_quit"];
		if(on_quit_value.is_function()) {
			ASSERT_LOG(on_quit_value.min_function_arguments() == 0, "on_quit_value dialog function should take 0 arguments: " << v.debug_location());
			static const variant fml("fn()");
			ffl_on_quit_.reset(new game_logic::formula(fml));

			game_logic::map_formula_callable* callable = new game_logic::map_formula_callable;
			callable->add("fn", on_quit_value);

			quit_arg_.reset(callable);
		} else {
			ffl_on_quit_ = get_environment()->create_formula(v["on_quit"]);
		}
	}
	if(v.has_key("on_close")) {
		on_close_ = boost::bind(&dialog::close_delegate, this, _1);
		ASSERT_LOG(get_environment() != NULL, "environment not set");
		const variant on_close_value = v["on_close"];
		if(on_close_value.is_function()) {
			ASSERT_LOG(on_close_value.min_function_arguments() <= 1 && on_close_value.max_function_arguments() >= 1, "on_close dialog function should take 1 argument: " << v.debug_location());
			static const variant fml("fn(selection)");
			ffl_on_close_.reset(new game_logic::formula(fml));

			game_logic::map_formula_callable* callable = new game_logic::map_formula_callable;
			callable->add("fn", on_close_value);

			close_arg_.reset(callable);
		} else {
			ffl_on_close_ = get_environment()->create_formula(v["on_close"]);
		}
	}
	std::vector<variant> children = v["children"].as_list();
	foreach(const variant& child, children) {
		widget_ptr w = widget_factory::create(child, e);
		if(w->x() != 0 || w->y() != 0) {
		//if(child.has_key("add_xy")) {
		//	std::vector<int> addxy = child["add_xy"].as_list_int();
		//	add_widget(widget_factory::create(child, e), addxy[0], addxy[1]);
			add_widget(w, w->x(), w->y());
		} else {
			add_widget(w);
		}
	}