Ejemplo n.º 1
0
void input_manager::save()
{
    write_to_file( FILENAMES["user_keybindings"], [&]( std::ostream & data_file ) {
        JsonOut jsout( data_file, true );

        jsout.start_array();
        for( t_action_contexts::const_iterator a = action_contexts.begin(); a != action_contexts.end();
             ++a ) {
            const t_actions &actions = a->second;
            for( const auto &action : actions ) {
                const t_input_event_list &events = action.second.input_events;
                jsout.start_object();

                jsout.member( "id", action.first );
                jsout.member( "category", a->first );
                bool is_user_created = action.second.is_user_created;
                if( is_user_created ) {
                    jsout.member( "is_user_created", is_user_created );
                }

                jsout.member( "bindings" );
                jsout.start_array();
                for( const auto &event : events ) {
                    jsout.start_object();
                    switch( event.type ) {
                        case CATA_INPUT_KEYBOARD:
                            jsout.member( "input_method", "keyboard" );
                            break;
                        case CATA_INPUT_GAMEPAD:
                            jsout.member( "input_method", "gamepad" );
                            break;
                        case CATA_INPUT_MOUSE:
                            jsout.member( "input_method", "mouse" );
                            break;
                        default:
                            throw std::runtime_error( "unknown input_event_t" );
                    }
                    jsout.member( "key" );
                    jsout.start_array();
                    for( size_t i = 0; i < event.sequence.size(); i++ ) {
                        jsout.write( get_keyname( event.sequence[i], event.type, true ) );
                    }
                    jsout.end_array();
                    jsout.end_object();
                }
                jsout.end_array();

                jsout.end_object();
            }
        }
        jsout.end_array();
    }, _( "key bindings configuration" ) );
}
Ejemplo n.º 2
0
/*
 * listview_set_text - ListViewのテキストを設定
 */
static void listview_set_text(const HWND hListView, const int i)
{
	TOOL_INFO *ti;
	TCHAR buf[BUF_SIZE];

	if ((ti = (TOOL_INFO *)listview_get_lparam(hListView, i)) == NULL) {
		return;
	}
	// 形式名
	ListView_SetItemText(hListView, i, 0, ti->title);
	// DLL
	ListView_SetItemText(hListView, i, 1, ti->lib_file_path);
	// 関数名
	ListView_SetItemText(hListView, i, 2, ti->func_name);
	// ホットキー
	if (ti->call_type & CALLTYPE_MENU) {
		get_keyname(ti->modifiers, ti->virtkey, buf);
	} else {
		get_keyname(0, 0, buf);
	}
	ListView_SetItemText(hListView, i, 3, buf);
}
Ejemplo n.º 3
0
void input_manager::save()
{
    std::ofstream data_file;

    std::string file_name = FILENAMES["user_keybindings"];
    std::string file_name_tmp = file_name + ".tmp";
    data_file.open(file_name_tmp.c_str(), std::ifstream::binary);

    if(!data_file.good()) {
        throw std::runtime_error(file_name_tmp + ": could not write");
    }
    data_file.exceptions(std::ios::badbit | std::ios::failbit);
    JsonOut jsout(data_file, true);

    jsout.start_array();
    for (t_action_contexts::const_iterator a = action_contexts.begin(); a != action_contexts.end();
         ++a) {
        const t_actions &actions = a->second;
        for( const auto &action : actions ) {
            const t_input_event_list &events = action.second.input_events;
            jsout.start_object();

            jsout.member( "id", action.first );
            jsout.member("category", a->first);
            bool is_user_created = action.second.is_user_created;
            if (is_user_created) {
                jsout.member("is_user_created", is_user_created);
            }

            jsout.member("bindings");
            jsout.start_array();
            for( const auto &event : events ) {
                jsout.start_object();
                switch( event.type ) {
                case CATA_INPUT_KEYBOARD:
                    jsout.member("input_method", "keyboard");
                    break;
                case CATA_INPUT_GAMEPAD:
                    jsout.member("input_method", "gamepad");
                    break;
                case CATA_INPUT_MOUSE:
                    jsout.member("input_method", "mouse");
                    break;
                default:
                    throw std::runtime_error("unknown input_event_t");
                }
                jsout.member("key");
                jsout.start_array();
                for( size_t i = 0; i < event.sequence.size(); i++ ) {
                    jsout.write( get_keyname( event.sequence[i], event.type, true ) );
                }
                jsout.end_array();
                jsout.end_object();
            }
            jsout.end_array();

            jsout.end_object();
        }
    }
    jsout.end_array();

    data_file.close();
    if(!rename_file(file_name_tmp, file_name)) {
        throw std::string("Could not rename file to ") + file_name;
    }
}