Esempio n. 1
0
/* creat the doctor's response */
void respond(char *s) {
    char t[80];
    int loc;
    if (strlen(s) < VERYSHORT && strcmp(s, "bye")) {
        if (find_topic(t)) {
            printf("You just said:");
            printf("%s\n", t);
            printf("tell me more .\n");
        } else {
            if (!*response[res]) res = 0; /* start over again */
            printf("%s\n", response[res++]);
        }
        return;
    }
    if (in_topics(s)) {
        printf("Stop repeating yourself !\n");
        return;
    }
    if (strlen(s) > SHORT) assert_topic(s);
    do {
        get_token();
        loc = lookup(token);
        if (loc != -1) {
            printf("%s\n", trans[loc + 1]);
            return;
        }
    } while (*token);
    /* comment of last resort */
    if (strlen(s) > SHORT)
        printf("It's seem intersting , tell me more ...\n");
    else printf("Tell me more ...\n");
}
Esempio n. 2
0
void help_browser::handle_event(const SDL_Event &event)
{
	SDL_MouseButtonEvent mouse_event = event.button;
	if (event.type == SDL_MOUSEBUTTONDOWN) {
		if (mouse_event.button == SDL_BUTTON_LEFT) {
			// Did the user click a cross-reference?
			const int mousex = mouse_event.x;
			const int mousey = mouse_event.y;
			const std::string ref = text_area_.ref_at(mousex, mousey);
			if (ref != "") {
				const topic *t = find_topic(toplevel_, ref);
				if (t == NULL) {
					std::stringstream msg;
					msg << _("Reference to unknown topic: ") << "'" << ref << "'.";
					gui2::show_transient_message(disp_.video(), "", msg.str());
					update_cursor();
				}
				else {
					show_topic(*t);
					update_cursor();
				}
			}
		}
	}
	else if (event.type == SDL_MOUSEMOTION) {
		update_cursor();
	}
}
Esempio n. 3
0
int opal_show_help(const char *filename, const char *topic, 
                   bool want_error_header, ...)
{
    int ret;
    va_list arglist;
    char **array = NULL;

    if (OPAL_SUCCESS != (ret = open_file(filename, topic))) {
        return ret;
    }
    if (OPAL_SUCCESS != (ret = find_topic(filename, topic))) {
        fclose(opal_show_help_yyin);
        return ret;
    }

    ret = read_message(&array);
    opal_show_help_finish_parsing();
    fclose(opal_show_help_yyin);
    if (OPAL_SUCCESS != ret) {
        destroy_message(array);
        return ret;
    }

    va_start(arglist, want_error_header);
    output(want_error_header, array, filename, topic, arglist);
    va_end(arglist);

    destroy_message(array);
    return ret;
}
Esempio n. 4
0
void help_browser::show_topic(const std::string &topic_id)
{
	const topic *t = find_topic(toplevel_, topic_id);

	if (t != NULL) {
		show_topic(*t);
	} else if (topic_id.find(unit_prefix)==0 || topic_id.find(hidden_symbol() + unit_prefix)==0) {
		show_topic(unknown_unit_topic);
	} else {
		std::cerr << "Help browser tried to show topic with id '" << topic_id
				  << "' but that topic could not be found." << std::endl;
	}
}
Esempio n. 5
0
topic* find_topic(section &sec, const std::string &id)
{
	topic_list::iterator tit =
		std::find_if(sec.topics.begin(), sec.topics.end(), has_id(id));
	if (tit != sec.topics.end()) {
		return &(*tit);
	}
	section_list::iterator sit;
	for (sit = sec.sections.begin(); sit != sec.sections.end(); ++sit) {
		topic *t = find_topic(*(*sit), id);
		if (t != NULL) {
			return t;
		}
	}
	return NULL;
}
Esempio n. 6
0
void tbook::section_2_tv_internal(ttree_view_node& htvroot, const help::section& parent)
{
	std::stringstream strstr;
	string_map tree_group_field;
	std::map<std::string, string_map> tree_group_item;

	for (std::vector<help::section *>::const_iterator it = parent.sections.begin(); it != parent.sections.end(); ++ it) {
		const help::section& sec = **it;

		strstr.str("");
		strstr << sec.title;
		tree_group_field["label"] = strstr.str();
		tree_group_item["text"] = tree_group_field;
		ttree_view_node& htvi = htvroot.add_child("item", tree_group_item);

		ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(htvi.find("tree_view_node_label", true));
		toggle->set_callback_state_change(boost::bind(&tbook::technology_toggled, this, _1));
		toggle->set_data(increase_id_);
		cookies_.insert(std::make_pair(increase_id_ ++, tcookie(find_topic(toplevel, help::section_topic_prefix + sec.id), &htvi)));

		htvi.find("icon", true)->set_visible(twidget::INVISIBLE);

		if (!sec.sections.empty() || !sec.topics.empty()) {
			section_2_tv_internal(htvi, sec);
		}
	}

	for (std::list<help::topic>::const_iterator it = parent.topics.begin(); it != parent.topics.end(); ++ it) {
		const help::topic& t = *it;

		if (t.id.find(help::section_topic_prefix) == 0) {
			continue;
		}

		strstr.str("");
		strstr << t.title;
		tree_group_field["label"] = strstr.str();
		tree_group_item["text"] = tree_group_field;
		ttree_view_node& htvi = htvroot.add_child("item", tree_group_item);

		ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(htvi.find("tree_view_node_label", true));
		toggle->set_callback_state_change(boost::bind(&tbook::technology_toggled, this, _1));
		toggle->set_data(increase_id_);
		cookies_.insert(std::make_pair(increase_id_ ++, tcookie(&t, &htvi)));
	}
}
Esempio n. 7
0
void tbook::ref_at(twindow& window)
{
	tscroll_label& content = find_widget<tscroll_label>(&window, "content", false);
	tlabel* label = dynamic_cast<tlabel*>(content.find("_label", true));
	tintegrate integrate(current_topic_->text.parsed_text(), label->get_width(), -1, label->config()->text_font_size, font::NORMAL_COLOR);

	int mousex, mousey;
	SDL_GetMouseState(&mousex,&mousey);

	const std::string ref = integrate.ref_at(mousex - label->get_x(), mousey - label->get_y());
	if (!ref.empty()) {
		const help::topic* t = find_topic(toplevel, ref);
		tree_->set_select_item(cookie_rfind_node(t));

		switch_to_topic(*window_, *t);
	}
}
Esempio n. 8
0
void tbook::pre_show(CVideo& /*video*/, twindow& window)
{
	help::init_book(&game_config_, map_, false);
	window_ = &window;

	const config *help_config = &game_config_.find_child("book", "id", tag_);
	if (!*help_config) {
		help_config = &help::dummy_cfg;
	}

	std::stringstream strstr;
	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	if (help_config->has_attribute("title")) {
		strstr << help_config->get("title")->str();
	}
	label->set_label(strstr.str());

	help::generate_contents(tag_, toplevel);

	ttree_view& parent_tree = find_widget<ttree_view>(&window, "default", false);
	tree_ = &parent_tree;

	section_2_tv_internal(tree_->get_root_node(), toplevel);
	if (!cookies_.empty()) {
		const std::string default_topic_id = "title";
		const help::topic* t = find_topic(toplevel, default_topic_id);
		if (!t) {
			t = cookies_.find(0)->second.t;
		}
		if (t) {
			switch_to_topic(*window_, *t);
			tree_->set_select_item(cookie_rfind_node(t));

		}
	}

	tscroll_label& content = find_widget<tscroll_label>(&window, "content", false);
	content.connect_signal<event::LEFT_BUTTON_DOWN>(
			  boost::bind(
				    &tbook::ref_at
				  , this
				  , boost::ref(window))
			, event::tdispatcher::front_pre_child);

	tree_->get_root_node().fold_children();
}
Esempio n. 9
0
void help_text_area::handle_ref_cfg(const config &cfg)
{
	const std::string dst = cfg["dst"];
	const std::string text = cfg["text"];
	bool force = cfg["force"].to_bool();

	if (dst == "") {
		std::stringstream msg;
		msg << "Ref markup must have dst attribute. Please submit a bug"
		       " report if you have not modified the game files yourself. Erroneous config: ";
		write(msg, cfg);
		throw parse_error(msg.str());
	}

	if (find_topic(toplevel_, dst) == NULL && !force) {
		// detect the broken link but quietly silence the hyperlink for normal user
		add_text_item(text, game_config::debug ? dst : "", true);

		// FIXME: workaround: if different campaigns define different
		// terrains, some terrains available in one campaign will
		// appear in the list of seen terrains, and be displayed in the
		// help, even if the current campaign does not handle such
		// terrains. This will lead to the unit page generator creating
		// invalid references.
		//
		// Disabling this is a kludgey workaround until the
		// encountered_terrains system is fixed
		//
		// -- Ayin apr 8 2005
#if 0
		if (game_config::debug) {
			std::stringstream msg;
			msg << "Reference to non-existent topic '" << dst
			    << "'. Please submit a bug report if you have not"
			       "modified the game files yourself. Erroneous config: ";
			write(msg, cfg);
			throw parse_error(msg.str());
		}
#endif
	} else {
		add_text_item(text, dst);
	}
}
Esempio n. 10
0
int help_menu::process()
{
    int res = menu::process();
    int mousex, mousey;
    SDL_GetMouseState(&mousex,&mousey);

    if (!visible_items_.empty() &&
            static_cast<size_t>(res) < visible_items_.size()) {

        selected_item_ = visible_items_[res];
        const section* sec = selected_item_.sec;
        if (sec != nullptr) {
            // Check how we click on the section
            int x = mousex - menu::location().x;

            const std::string icon_img = expanded(*sec) ? open_section_img : closed_section_img;
            // we remove the right thickness (ne present between icon and text)
            int text_start = style_->item_size(indent_list(icon_img, sec->level)).w - style_->get_thickness();

            // NOTE: if you want to forbid click to the left of the icon
            // also check x >= text_start-image_width(icon_img)
            if (menu::double_clicked() || x < text_start) {
                // Open or close a section if we double-click on it
                // or do simple click on the icon.
                expanded(*sec) ? contract(*sec) : expand(*sec);
                update_visible_items(toplevel_);
                display_visible_items();
            } else if (x >= text_start) {
                // click on title open the topic associated to this section
                chosen_topic_ = find_topic(default_toplevel, ".."+sec->id );
            }
        } else if (selected_item_.t != nullptr) {
            /// Choose a topic if it is clicked.
            chosen_topic_ = selected_item_.t;
        }
    }
    return res;
}
Esempio n. 11
0
void generate_contents(const std::string& tag, section& toplevel)
{
	toplevel.clear();
	hidden_sections.clear();

	const config *help_config = &game_cfg->find_child("book", "id", tag);
	if (!*help_config) {
		help_config = &dummy_cfg;
	}
	try {
		toplevel = parse_config(help_config);
		// Create a config object that contains everything that is
		// not referenced from the toplevel element. Read this
		// config and save these sections and topics so that they
		// can be referenced later on when showing help about
		// specified things, but that should not be shown when
		// opening the help browser in the default manner.
		config hidden_toplevel;
		std::stringstream ss;
		BOOST_FOREACH (const config &section, help_config->child_range("section"))
		{
			const std::string id = section["id"];
			if (find_section(toplevel, id) == NULL) {
				// This section does not exist referenced from the
				// toplevel. Hence, add it to the hidden ones if it
				// is not referenced from another section.
				if (!section_is_referenced(id, *help_config)) {
					if (ss.str() != "") {
						ss << ",";
					}
					ss << id;
				}
			}
		}
		hidden_toplevel["sections"] = ss.str();
		ss.str("");
		BOOST_FOREACH (const config &topic, help_config->child_range("topic"))
		{
			const std::string id = topic["id"];
			if (find_topic(toplevel, id) == NULL) {
				if (!topic_is_referenced(id, *help_config)) {
					if (ss.str() != "") {
						ss << ",";
					}
					ss << id;
				}
			}
		}
		hidden_toplevel["topics"] = ss.str();
		config hidden_cfg = *help_config;
		// Change the toplevel to our new, custom built one.
		hidden_cfg.clear_children("toplevel");
		hidden_cfg.add_child("toplevel", hidden_toplevel);
		hidden_sections = parse_config(&hidden_cfg);
	}
	catch (help::parse_error e) {
		std::stringstream msg;
		msg << "Parse error when parsing help text: '" << e.message << "'";
		VALIDATE(false, msg.str());
	}
}